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