Skip to main content

gtk4/auto/
style_context.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{Border, StateFlags, StyleContextPrintFlags, StyleProvider, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkStyleContext")]
16    pub struct StyleContext(Object<ffi::GtkStyleContext, ffi::GtkStyleContextClass>);
17
18    match fn {
19        type_ => || ffi::gtk_style_context_get_type(),
20    }
21}
22
23impl StyleContext {
24    pub const NONE: Option<&'static StyleContext> = None;
25}
26
27pub trait StyleContextExt: IsA<StyleContext> + 'static {
28    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29    #[allow(deprecated)]
30    #[doc(alias = "gtk_style_context_add_class")]
31    fn add_class(&self, class_name: &str) {
32        unsafe {
33            ffi::gtk_style_context_add_class(
34                self.as_ref().to_glib_none().0,
35                class_name.to_glib_none().0,
36            );
37        }
38    }
39
40    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
41    #[allow(deprecated)]
42    #[doc(alias = "gtk_style_context_add_provider")]
43    fn add_provider(&self, provider: &impl IsA<StyleProvider>, priority: u32) {
44        unsafe {
45            ffi::gtk_style_context_add_provider(
46                self.as_ref().to_glib_none().0,
47                provider.as_ref().to_glib_none().0,
48                priority,
49            );
50        }
51    }
52
53    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
54    #[allow(deprecated)]
55    #[doc(alias = "gtk_style_context_get_border")]
56    #[doc(alias = "get_border")]
57    fn border(&self) -> Border {
58        unsafe {
59            let mut border = Border::uninitialized();
60            ffi::gtk_style_context_get_border(
61                self.as_ref().to_glib_none().0,
62                border.to_glib_none_mut().0,
63            );
64            border
65        }
66    }
67
68    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
69    #[allow(deprecated)]
70    #[doc(alias = "gtk_style_context_get_color")]
71    #[doc(alias = "get_color")]
72    fn color(&self) -> gdk::RGBA {
73        unsafe {
74            let mut color = gdk::RGBA::uninitialized();
75            ffi::gtk_style_context_get_color(
76                self.as_ref().to_glib_none().0,
77                color.to_glib_none_mut().0,
78            );
79            color
80        }
81    }
82
83    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
84    #[allow(deprecated)]
85    #[doc(alias = "gtk_style_context_get_display")]
86    #[doc(alias = "get_display")]
87    fn display(&self) -> gdk::Display {
88        unsafe {
89            from_glib_none(ffi::gtk_style_context_get_display(
90                self.as_ref().to_glib_none().0,
91            ))
92        }
93    }
94
95    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
96    #[allow(deprecated)]
97    #[doc(alias = "gtk_style_context_get_margin")]
98    #[doc(alias = "get_margin")]
99    fn margin(&self) -> Border {
100        unsafe {
101            let mut margin = Border::uninitialized();
102            ffi::gtk_style_context_get_margin(
103                self.as_ref().to_glib_none().0,
104                margin.to_glib_none_mut().0,
105            );
106            margin
107        }
108    }
109
110    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
111    #[allow(deprecated)]
112    #[doc(alias = "gtk_style_context_get_padding")]
113    #[doc(alias = "get_padding")]
114    fn padding(&self) -> Border {
115        unsafe {
116            let mut padding = Border::uninitialized();
117            ffi::gtk_style_context_get_padding(
118                self.as_ref().to_glib_none().0,
119                padding.to_glib_none_mut().0,
120            );
121            padding
122        }
123    }
124
125    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
126    #[allow(deprecated)]
127    #[doc(alias = "gtk_style_context_get_scale")]
128    #[doc(alias = "get_scale")]
129    fn scale(&self) -> i32 {
130        unsafe { ffi::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
131    }
132
133    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
134    #[allow(deprecated)]
135    #[doc(alias = "gtk_style_context_get_state")]
136    #[doc(alias = "get_state")]
137    fn state(&self) -> StateFlags {
138        unsafe {
139            from_glib(ffi::gtk_style_context_get_state(
140                self.as_ref().to_glib_none().0,
141            ))
142        }
143    }
144
145    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
146    #[allow(deprecated)]
147    #[doc(alias = "gtk_style_context_has_class")]
148    fn has_class(&self, class_name: &str) -> bool {
149        unsafe {
150            from_glib(ffi::gtk_style_context_has_class(
151                self.as_ref().to_glib_none().0,
152                class_name.to_glib_none().0,
153            ))
154        }
155    }
156
157    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
158    #[allow(deprecated)]
159    #[doc(alias = "gtk_style_context_lookup_color")]
160    fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
161        unsafe {
162            let mut color = gdk::RGBA::uninitialized();
163            let ret = from_glib(ffi::gtk_style_context_lookup_color(
164                self.as_ref().to_glib_none().0,
165                color_name.to_glib_none().0,
166                color.to_glib_none_mut().0,
167            ));
168            if ret { Some(color) } else { None }
169        }
170    }
171
172    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
173    #[allow(deprecated)]
174    #[doc(alias = "gtk_style_context_remove_class")]
175    fn remove_class(&self, class_name: &str) {
176        unsafe {
177            ffi::gtk_style_context_remove_class(
178                self.as_ref().to_glib_none().0,
179                class_name.to_glib_none().0,
180            );
181        }
182    }
183
184    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
185    #[allow(deprecated)]
186    #[doc(alias = "gtk_style_context_remove_provider")]
187    fn remove_provider(&self, provider: &impl IsA<StyleProvider>) {
188        unsafe {
189            ffi::gtk_style_context_remove_provider(
190                self.as_ref().to_glib_none().0,
191                provider.as_ref().to_glib_none().0,
192            );
193        }
194    }
195
196    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
197    #[allow(deprecated)]
198    #[doc(alias = "gtk_style_context_restore")]
199    fn restore(&self) {
200        unsafe {
201            ffi::gtk_style_context_restore(self.as_ref().to_glib_none().0);
202        }
203    }
204
205    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
206    #[allow(deprecated)]
207    #[doc(alias = "gtk_style_context_save")]
208    fn save(&self) {
209        unsafe {
210            ffi::gtk_style_context_save(self.as_ref().to_glib_none().0);
211        }
212    }
213
214    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
215    #[allow(deprecated)]
216    #[doc(alias = "gtk_style_context_set_display")]
217    #[doc(alias = "display")]
218    fn set_display(&self, display: &impl IsA<gdk::Display>) {
219        unsafe {
220            ffi::gtk_style_context_set_display(
221                self.as_ref().to_glib_none().0,
222                display.as_ref().to_glib_none().0,
223            );
224        }
225    }
226
227    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
228    #[allow(deprecated)]
229    #[doc(alias = "gtk_style_context_set_scale")]
230    fn set_scale(&self, scale: i32) {
231        unsafe {
232            ffi::gtk_style_context_set_scale(self.as_ref().to_glib_none().0, scale);
233        }
234    }
235
236    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
237    #[allow(deprecated)]
238    #[doc(alias = "gtk_style_context_set_state")]
239    fn set_state(&self, flags: StateFlags) {
240        unsafe {
241            ffi::gtk_style_context_set_state(self.as_ref().to_glib_none().0, flags.into_glib());
242        }
243    }
244
245    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
246    #[allow(deprecated)]
247    #[doc(alias = "gtk_style_context_to_string")]
248    fn to_string(&self, flags: StyleContextPrintFlags) -> glib::GString {
249        unsafe {
250            from_glib_full(ffi::gtk_style_context_to_string(
251                self.as_ref().to_glib_none().0,
252                flags.into_glib(),
253            ))
254        }
255    }
256
257    #[doc(alias = "display")]
258    fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
259        unsafe extern "C" fn notify_display_trampoline<
260            P: IsA<StyleContext>,
261            F: Fn(&P) + 'static,
262        >(
263            this: *mut ffi::GtkStyleContext,
264            _param_spec: glib::ffi::gpointer,
265            f: glib::ffi::gpointer,
266        ) {
267            unsafe {
268                let f: &F = &*(f as *const F);
269                f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
270            }
271        }
272        unsafe {
273            let f: Box_<F> = Box_::new(f);
274            connect_raw(
275                self.as_ptr() as *mut _,
276                c"notify::display".as_ptr(),
277                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
278                    notify_display_trampoline::<Self, F> as *const (),
279                )),
280                Box_::into_raw(f),
281            )
282        }
283    }
284}
285
286impl<O: IsA<StyleContext>> StyleContextExt for O {}