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