1use crate::{ffi, GutterRenderer, GutterRendererAlignmentMode};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSourceGutterRendererText")]
16 pub struct GutterRendererText(Object<ffi::GtkSourceGutterRendererText, ffi::GtkSourceGutterRendererTextClass>) @extends GutterRenderer, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::gtk_source_gutter_renderer_text_get_type(),
20 }
21}
22
23impl GutterRendererText {
24 pub const NONE: Option<&'static GutterRendererText> = None;
25
26 #[doc(alias = "gtk_source_gutter_renderer_text_new")]
27 pub fn new() -> GutterRendererText {
28 assert_initialized_main_thread!();
29 unsafe {
30 GutterRenderer::from_glib_full(ffi::gtk_source_gutter_renderer_text_new()).unsafe_cast()
31 }
32 }
33
34 pub fn builder() -> GutterRendererTextBuilder {
39 GutterRendererTextBuilder::new()
40 }
41}
42
43impl Default for GutterRendererText {
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49#[must_use = "The builder must be built to be used"]
54pub struct GutterRendererTextBuilder {
55 builder: glib::object::ObjectBuilder<'static, GutterRendererText>,
56}
57
58impl GutterRendererTextBuilder {
59 fn new() -> Self {
60 Self {
61 builder: glib::object::Object::builder(),
62 }
63 }
64
65 pub fn markup(self, markup: impl Into<glib::GString>) -> Self {
66 Self {
67 builder: self.builder.property("markup", markup.into()),
68 }
69 }
70
71 pub fn text(self, text: impl Into<glib::GString>) -> Self {
72 Self {
73 builder: self.builder.property("text", text.into()),
74 }
75 }
76
77 pub fn alignment_mode(self, alignment_mode: GutterRendererAlignmentMode) -> Self {
78 Self {
79 builder: self.builder.property("alignment-mode", alignment_mode),
80 }
81 }
82
83 pub fn xalign(self, xalign: f32) -> Self {
84 Self {
85 builder: self.builder.property("xalign", xalign),
86 }
87 }
88
89 pub fn xpad(self, xpad: i32) -> Self {
90 Self {
91 builder: self.builder.property("xpad", xpad),
92 }
93 }
94
95 pub fn yalign(self, yalign: f32) -> Self {
96 Self {
97 builder: self.builder.property("yalign", yalign),
98 }
99 }
100
101 pub fn ypad(self, ypad: i32) -> Self {
102 Self {
103 builder: self.builder.property("ypad", ypad),
104 }
105 }
106
107 pub fn can_focus(self, can_focus: bool) -> Self {
108 Self {
109 builder: self.builder.property("can-focus", can_focus),
110 }
111 }
112
113 pub fn can_target(self, can_target: bool) -> Self {
114 Self {
115 builder: self.builder.property("can-target", can_target),
116 }
117 }
118
119 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
120 Self {
121 builder: self.builder.property("css-classes", css_classes.into()),
122 }
123 }
124
125 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
126 Self {
127 builder: self.builder.property("css-name", css_name.into()),
128 }
129 }
130
131 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
132 Self {
133 builder: self.builder.property("cursor", cursor.clone()),
134 }
135 }
136
137 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
138 Self {
139 builder: self.builder.property("focus-on-click", focus_on_click),
140 }
141 }
142
143 pub fn focusable(self, focusable: bool) -> Self {
144 Self {
145 builder: self.builder.property("focusable", focusable),
146 }
147 }
148
149 pub fn halign(self, halign: gtk::Align) -> Self {
150 Self {
151 builder: self.builder.property("halign", halign),
152 }
153 }
154
155 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
156 Self {
157 builder: self.builder.property("has-tooltip", has_tooltip),
158 }
159 }
160
161 pub fn height_request(self, height_request: i32) -> Self {
162 Self {
163 builder: self.builder.property("height-request", height_request),
164 }
165 }
166
167 pub fn hexpand(self, hexpand: bool) -> Self {
168 Self {
169 builder: self.builder.property("hexpand", hexpand),
170 }
171 }
172
173 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
174 Self {
175 builder: self.builder.property("hexpand-set", hexpand_set),
176 }
177 }
178
179 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
180 Self {
181 builder: self
182 .builder
183 .property("layout-manager", layout_manager.clone().upcast()),
184 }
185 }
186
187 #[cfg(feature = "gtk_v4_18")]
188 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
189 pub fn limit_events(self, limit_events: bool) -> Self {
190 Self {
191 builder: self.builder.property("limit-events", limit_events),
192 }
193 }
194
195 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
196 Self {
197 builder: self.builder.property("margin-bottom", margin_bottom),
198 }
199 }
200
201 pub fn margin_end(self, margin_end: i32) -> Self {
202 Self {
203 builder: self.builder.property("margin-end", margin_end),
204 }
205 }
206
207 pub fn margin_start(self, margin_start: i32) -> Self {
208 Self {
209 builder: self.builder.property("margin-start", margin_start),
210 }
211 }
212
213 pub fn margin_top(self, margin_top: i32) -> Self {
214 Self {
215 builder: self.builder.property("margin-top", margin_top),
216 }
217 }
218
219 pub fn name(self, name: impl Into<glib::GString>) -> Self {
220 Self {
221 builder: self.builder.property("name", name.into()),
222 }
223 }
224
225 pub fn opacity(self, opacity: f64) -> Self {
226 Self {
227 builder: self.builder.property("opacity", opacity),
228 }
229 }
230
231 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
232 Self {
233 builder: self.builder.property("overflow", overflow),
234 }
235 }
236
237 pub fn receives_default(self, receives_default: bool) -> Self {
238 Self {
239 builder: self.builder.property("receives-default", receives_default),
240 }
241 }
242
243 pub fn sensitive(self, sensitive: bool) -> Self {
244 Self {
245 builder: self.builder.property("sensitive", sensitive),
246 }
247 }
248
249 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
250 Self {
251 builder: self
252 .builder
253 .property("tooltip-markup", tooltip_markup.into()),
254 }
255 }
256
257 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
258 Self {
259 builder: self.builder.property("tooltip-text", tooltip_text.into()),
260 }
261 }
262
263 pub fn valign(self, valign: gtk::Align) -> Self {
264 Self {
265 builder: self.builder.property("valign", valign),
266 }
267 }
268
269 pub fn vexpand(self, vexpand: bool) -> Self {
270 Self {
271 builder: self.builder.property("vexpand", vexpand),
272 }
273 }
274
275 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
276 Self {
277 builder: self.builder.property("vexpand-set", vexpand_set),
278 }
279 }
280
281 pub fn visible(self, visible: bool) -> Self {
282 Self {
283 builder: self.builder.property("visible", visible),
284 }
285 }
286
287 pub fn width_request(self, width_request: i32) -> Self {
288 Self {
289 builder: self.builder.property("width-request", width_request),
290 }
291 }
292
293 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
294 Self {
295 builder: self.builder.property("accessible-role", accessible_role),
296 }
297 }
298
299 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
302 pub fn build(self) -> GutterRendererText {
303 assert_initialized_main_thread!();
304 self.builder.build()
305 }
306}
307
308pub trait GutterRendererTextExt: IsA<GutterRendererText> + 'static {
309 #[doc(alias = "gtk_source_gutter_renderer_text_measure")]
310 fn measure(&self, text: &str) -> (i32, i32) {
311 unsafe {
312 let mut width = std::mem::MaybeUninit::uninit();
313 let mut height = std::mem::MaybeUninit::uninit();
314 ffi::gtk_source_gutter_renderer_text_measure(
315 self.as_ref().to_glib_none().0,
316 text.to_glib_none().0,
317 width.as_mut_ptr(),
318 height.as_mut_ptr(),
319 );
320 (width.assume_init(), height.assume_init())
321 }
322 }
323
324 #[doc(alias = "gtk_source_gutter_renderer_text_measure_markup")]
325 fn measure_markup(&self, markup: &str) -> (i32, i32) {
326 unsafe {
327 let mut width = std::mem::MaybeUninit::uninit();
328 let mut height = std::mem::MaybeUninit::uninit();
329 ffi::gtk_source_gutter_renderer_text_measure_markup(
330 self.as_ref().to_glib_none().0,
331 markup.to_glib_none().0,
332 width.as_mut_ptr(),
333 height.as_mut_ptr(),
334 );
335 (width.assume_init(), height.assume_init())
336 }
337 }
338
339 #[doc(alias = "gtk_source_gutter_renderer_text_set_markup")]
340 #[doc(alias = "markup")]
341 fn set_markup(&self, markup: &str) {
342 let length = markup.len() as _;
343 unsafe {
344 ffi::gtk_source_gutter_renderer_text_set_markup(
345 self.as_ref().to_glib_none().0,
346 markup.to_glib_none().0,
347 length,
348 );
349 }
350 }
351
352 #[doc(alias = "gtk_source_gutter_renderer_text_set_text")]
353 #[doc(alias = "text")]
354 fn set_text(&self, text: &str) {
355 let length = text.len() as _;
356 unsafe {
357 ffi::gtk_source_gutter_renderer_text_set_text(
358 self.as_ref().to_glib_none().0,
359 text.to_glib_none().0,
360 length,
361 );
362 }
363 }
364
365 fn markup(&self) -> Option<glib::GString> {
366 ObjectExt::property(self.as_ref(), "markup")
367 }
368
369 fn text(&self) -> Option<glib::GString> {
370 ObjectExt::property(self.as_ref(), "text")
371 }
372
373 #[doc(alias = "markup")]
374 fn connect_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
375 unsafe extern "C" fn notify_markup_trampoline<
376 P: IsA<GutterRendererText>,
377 F: Fn(&P) + 'static,
378 >(
379 this: *mut ffi::GtkSourceGutterRendererText,
380 _param_spec: glib::ffi::gpointer,
381 f: glib::ffi::gpointer,
382 ) {
383 let f: &F = &*(f as *const F);
384 f(GutterRendererText::from_glib_borrow(this).unsafe_cast_ref())
385 }
386 unsafe {
387 let f: Box_<F> = Box_::new(f);
388 connect_raw(
389 self.as_ptr() as *mut _,
390 c"notify::markup".as_ptr() as *const _,
391 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
392 notify_markup_trampoline::<Self, F> as *const (),
393 )),
394 Box_::into_raw(f),
395 )
396 }
397 }
398
399 #[doc(alias = "text")]
400 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
401 unsafe extern "C" fn notify_text_trampoline<
402 P: IsA<GutterRendererText>,
403 F: Fn(&P) + 'static,
404 >(
405 this: *mut ffi::GtkSourceGutterRendererText,
406 _param_spec: glib::ffi::gpointer,
407 f: glib::ffi::gpointer,
408 ) {
409 let f: &F = &*(f as *const F);
410 f(GutterRendererText::from_glib_borrow(this).unsafe_cast_ref())
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 c"notify::text".as_ptr() as *const _,
417 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418 notify_text_trampoline::<Self, F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424}
425
426impl<O: IsA<GutterRendererText>> GutterRendererTextExt for O {}