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