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