1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "PanelThemeSelector")]
16 pub struct ThemeSelector(Object<ffi::PanelThemeSelector, ffi::PanelThemeSelectorClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::panel_theme_selector_get_type(),
20 }
21}
22
23impl ThemeSelector {
24 #[doc(alias = "panel_theme_selector_new")]
25 pub fn new() -> ThemeSelector {
26 assert_initialized_main_thread!();
27 unsafe { gtk::Widget::from_glib_none(ffi::panel_theme_selector_new()).unsafe_cast() }
28 }
29
30 pub fn builder() -> ThemeSelectorBuilder {
35 ThemeSelectorBuilder::new()
36 }
37
38 #[doc(alias = "panel_theme_selector_get_action_name")]
39 #[doc(alias = "get_action_name")]
40 #[doc(alias = "action-name")]
41 pub fn action_name(&self) -> glib::GString {
42 unsafe {
43 from_glib_none(ffi::panel_theme_selector_get_action_name(
44 self.to_glib_none().0,
45 ))
46 }
47 }
48
49 #[doc(alias = "panel_theme_selector_set_action_name")]
50 #[doc(alias = "action-name")]
51 pub fn set_action_name(&self, action_name: &str) {
52 unsafe {
53 ffi::panel_theme_selector_set_action_name(
54 self.to_glib_none().0,
55 action_name.to_glib_none().0,
56 );
57 }
58 }
59
60 #[doc(alias = "action-name")]
61 pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
62 unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&ThemeSelector) + 'static>(
63 this: *mut ffi::PanelThemeSelector,
64 _param_spec: glib::ffi::gpointer,
65 f: glib::ffi::gpointer,
66 ) {
67 let f: &F = &*(f as *const F);
68 f(&from_glib_borrow(this))
69 }
70 unsafe {
71 let f: Box_<F> = Box_::new(f);
72 connect_raw(
73 self.as_ptr() as *mut _,
74 c"notify::action-name".as_ptr() as *const _,
75 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
76 notify_action_name_trampoline::<F> as *const (),
77 )),
78 Box_::into_raw(f),
79 )
80 }
81 }
82}
83
84impl Default for ThemeSelector {
85 fn default() -> Self {
86 Self::new()
87 }
88}
89
90#[must_use = "The builder must be built to be used"]
95pub struct ThemeSelectorBuilder {
96 builder: glib::object::ObjectBuilder<'static, ThemeSelector>,
97}
98
99impl ThemeSelectorBuilder {
100 fn new() -> Self {
101 Self {
102 builder: glib::object::Object::builder(),
103 }
104 }
105
106 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
107 Self {
108 builder: self.builder.property("action-name", action_name.into()),
109 }
110 }
111
112 pub fn can_focus(self, can_focus: bool) -> Self {
113 Self {
114 builder: self.builder.property("can-focus", can_focus),
115 }
116 }
117
118 pub fn can_target(self, can_target: bool) -> Self {
119 Self {
120 builder: self.builder.property("can-target", can_target),
121 }
122 }
123
124 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
125 Self {
126 builder: self.builder.property("css-classes", css_classes.into()),
127 }
128 }
129
130 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
131 Self {
132 builder: self.builder.property("css-name", css_name.into()),
133 }
134 }
135
136 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
137 Self {
138 builder: self.builder.property("cursor", cursor.clone()),
139 }
140 }
141
142 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
143 Self {
144 builder: self.builder.property("focus-on-click", focus_on_click),
145 }
146 }
147
148 pub fn focusable(self, focusable: bool) -> Self {
149 Self {
150 builder: self.builder.property("focusable", focusable),
151 }
152 }
153
154 pub fn halign(self, halign: gtk::Align) -> Self {
155 Self {
156 builder: self.builder.property("halign", halign),
157 }
158 }
159
160 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
161 Self {
162 builder: self.builder.property("has-tooltip", has_tooltip),
163 }
164 }
165
166 pub fn height_request(self, height_request: i32) -> Self {
167 Self {
168 builder: self.builder.property("height-request", height_request),
169 }
170 }
171
172 pub fn hexpand(self, hexpand: bool) -> Self {
173 Self {
174 builder: self.builder.property("hexpand", hexpand),
175 }
176 }
177
178 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
179 Self {
180 builder: self.builder.property("hexpand-set", hexpand_set),
181 }
182 }
183
184 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
185 Self {
186 builder: self
187 .builder
188 .property("layout-manager", layout_manager.clone().upcast()),
189 }
190 }
191
192 #[cfg(feature = "gtk_v4_18")]
193 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
194 pub fn limit_events(self, limit_events: bool) -> Self {
195 Self {
196 builder: self.builder.property("limit-events", limit_events),
197 }
198 }
199
200 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
201 Self {
202 builder: self.builder.property("margin-bottom", margin_bottom),
203 }
204 }
205
206 pub fn margin_end(self, margin_end: i32) -> Self {
207 Self {
208 builder: self.builder.property("margin-end", margin_end),
209 }
210 }
211
212 pub fn margin_start(self, margin_start: i32) -> Self {
213 Self {
214 builder: self.builder.property("margin-start", margin_start),
215 }
216 }
217
218 pub fn margin_top(self, margin_top: i32) -> Self {
219 Self {
220 builder: self.builder.property("margin-top", margin_top),
221 }
222 }
223
224 pub fn name(self, name: impl Into<glib::GString>) -> Self {
225 Self {
226 builder: self.builder.property("name", name.into()),
227 }
228 }
229
230 pub fn opacity(self, opacity: f64) -> Self {
231 Self {
232 builder: self.builder.property("opacity", opacity),
233 }
234 }
235
236 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
237 Self {
238 builder: self.builder.property("overflow", overflow),
239 }
240 }
241
242 pub fn receives_default(self, receives_default: bool) -> Self {
243 Self {
244 builder: self.builder.property("receives-default", receives_default),
245 }
246 }
247
248 pub fn sensitive(self, sensitive: bool) -> Self {
249 Self {
250 builder: self.builder.property("sensitive", sensitive),
251 }
252 }
253
254 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
255 Self {
256 builder: self
257 .builder
258 .property("tooltip-markup", tooltip_markup.into()),
259 }
260 }
261
262 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
263 Self {
264 builder: self.builder.property("tooltip-text", tooltip_text.into()),
265 }
266 }
267
268 pub fn valign(self, valign: gtk::Align) -> Self {
269 Self {
270 builder: self.builder.property("valign", valign),
271 }
272 }
273
274 pub fn vexpand(self, vexpand: bool) -> Self {
275 Self {
276 builder: self.builder.property("vexpand", vexpand),
277 }
278 }
279
280 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
281 Self {
282 builder: self.builder.property("vexpand-set", vexpand_set),
283 }
284 }
285
286 pub fn visible(self, visible: bool) -> Self {
287 Self {
288 builder: self.builder.property("visible", visible),
289 }
290 }
291
292 pub fn width_request(self, width_request: i32) -> Self {
293 Self {
294 builder: self.builder.property("width-request", width_request),
295 }
296 }
297
298 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
299 Self {
300 builder: self.builder.property("accessible-role", accessible_role),
301 }
302 }
303
304 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
307 pub fn build(self) -> ThemeSelector {
308 assert_initialized_main_thread!();
309 self.builder.build()
310 }
311}