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