gtk4/auto/text_mark.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, TextBuffer};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// Marks a position in a `GtkTextbuffer` that is preserved
10 /// across modifications.
11 ///
12 /// You may wish to begin by reading the
13 /// [text widget conceptual overview](section-text-widget.html),
14 /// which gives an overview of all the objects and data types
15 /// related to the text widget and how they work together.
16 ///
17 /// A [`TextMark`][crate::TextMark] is like a bookmark in a text buffer; it preserves
18 /// a position in the text. You can convert the mark to an iterator using
19 /// [`TextBufferExt::iter_at_mark()`][crate::prelude::TextBufferExt::iter_at_mark()]. Unlike iterators, marks remain
20 /// valid across buffer mutations, because their behavior is defined when
21 /// text is inserted or deleted. When text containing a mark is deleted,
22 /// the mark remains in the position originally occupied by the deleted
23 /// text. When text is inserted at a mark, a mark with “left gravity” will
24 /// be moved to the beginning of the newly-inserted text, and a mark with
25 /// “right gravity” will be moved to the end.
26 ///
27 /// Note that “left” and “right” here refer to logical direction (left
28 /// is the toward the start of the buffer); in some languages such as
29 /// Hebrew the logically-leftmost text is not actually on the left when
30 /// displayed.
31 ///
32 /// Marks are reference counted, but the reference count only controls
33 /// the validity of the memory; marks can be deleted from the buffer at
34 /// any time with [`TextBufferExt::delete_mark()`][crate::prelude::TextBufferExt::delete_mark()]. Once deleted from
35 /// the buffer, a mark is essentially useless.
36 ///
37 /// Marks optionally have names; these can be convenient to avoid passing
38 /// the [`TextMark`][crate::TextMark] object around.
39 ///
40 /// Marks are typically created using the [`TextBufferExt::create_mark()`][crate::prelude::TextBufferExt::create_mark()]
41 /// function.
42 ///
43 /// ## Properties
44 ///
45 ///
46 /// #### `left-gravity`
47 /// Whether the mark has left gravity.
48 ///
49 /// When text is inserted at the mark’s current location, if the mark
50 /// has left gravity it will be moved to the left of the newly-inserted
51 /// text, otherwise to the right.
52 ///
53 /// Readable | Writeable | Construct Only
54 ///
55 ///
56 /// #### `name`
57 /// The name of the mark or [`None`] if the mark is anonymous.
58 ///
59 /// Readable | Writeable | Construct Only
60 ///
61 /// # Implements
62 ///
63 /// [`TextMarkExt`][trait@crate::prelude::TextMarkExt], [`trait@glib::ObjectExt`]
64 #[doc(alias = "GtkTextMark")]
65 pub struct TextMark(Object<ffi::GtkTextMark, ffi::GtkTextMarkClass>);
66
67 match fn {
68 type_ => || ffi::gtk_text_mark_get_type(),
69 }
70}
71
72impl TextMark {
73 pub const NONE: Option<&'static TextMark> = None;
74
75 /// Creates a text mark.
76 ///
77 /// Add it to a buffer using [`TextBufferExt::add_mark()`][crate::prelude::TextBufferExt::add_mark()].
78 /// If @name is [`None`], the mark is anonymous; otherwise, the mark can be
79 /// retrieved by name using [`TextBufferExt::mark()`][crate::prelude::TextBufferExt::mark()]. If a mark
80 /// has left gravity, and text is inserted at the mark’s current location,
81 /// the mark will be moved to the left of the newly-inserted text. If the
82 /// mark has right gravity (@left_gravity = [`false`]), the mark will end up
83 /// on the right of newly-inserted text. The standard left-to-right cursor
84 /// is a mark with right gravity (when you type, the cursor stays on the
85 /// right side of the text you’re typing).
86 /// ## `name`
87 /// mark name
88 /// ## `left_gravity`
89 /// whether the mark should have left gravity
90 ///
91 /// # Returns
92 ///
93 /// new [`TextMark`][crate::TextMark]
94 #[doc(alias = "gtk_text_mark_new")]
95 pub fn new(name: Option<&str>, left_gravity: bool) -> TextMark {
96 assert_initialized_main_thread!();
97 unsafe {
98 from_glib_full(ffi::gtk_text_mark_new(
99 name.to_glib_none().0,
100 left_gravity.into_glib(),
101 ))
102 }
103 }
104
105 // rustdoc-stripper-ignore-next
106 /// Creates a new builder-pattern struct instance to construct [`TextMark`] objects.
107 ///
108 /// This method returns an instance of [`TextMarkBuilder`](crate::builders::TextMarkBuilder) which can be used to create [`TextMark`] objects.
109 pub fn builder() -> TextMarkBuilder {
110 TextMarkBuilder::new()
111 }
112}
113
114impl Default for TextMark {
115 fn default() -> Self {
116 glib::object::Object::new::<Self>()
117 }
118}
119
120// rustdoc-stripper-ignore-next
121/// A [builder-pattern] type to construct [`TextMark`] objects.
122///
123/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
124#[must_use = "The builder must be built to be used"]
125pub struct TextMarkBuilder {
126 builder: glib::object::ObjectBuilder<'static, TextMark>,
127}
128
129impl TextMarkBuilder {
130 fn new() -> Self {
131 Self {
132 builder: glib::object::Object::builder(),
133 }
134 }
135
136 /// Whether the mark has left gravity.
137 ///
138 /// When text is inserted at the mark’s current location, if the mark
139 /// has left gravity it will be moved to the left of the newly-inserted
140 /// text, otherwise to the right.
141 pub fn left_gravity(self, left_gravity: bool) -> Self {
142 Self {
143 builder: self.builder.property("left-gravity", left_gravity),
144 }
145 }
146
147 /// The name of the mark or [`None`] if the mark is anonymous.
148 pub fn name(self, name: impl Into<glib::GString>) -> Self {
149 Self {
150 builder: self.builder.property("name", name.into()),
151 }
152 }
153
154 // rustdoc-stripper-ignore-next
155 /// Build the [`TextMark`].
156 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
157 pub fn build(self) -> TextMark {
158 assert_initialized_main_thread!();
159 self.builder.build()
160 }
161}
162
163/// Trait containing all [`struct@TextMark`] methods.
164///
165/// # Implementors
166///
167/// [`TextMark`][struct@crate::TextMark]
168pub trait TextMarkExt: IsA<TextMark> + 'static {
169 /// Gets the buffer this mark is located inside.
170 ///
171 /// Returns [`None`] if the mark is deleted.
172 ///
173 /// # Returns
174 ///
175 /// the mark’s [`TextBuffer`][crate::TextBuffer]
176 #[doc(alias = "gtk_text_mark_get_buffer")]
177 #[doc(alias = "get_buffer")]
178 fn buffer(&self) -> Option<TextBuffer> {
179 unsafe {
180 from_glib_none(ffi::gtk_text_mark_get_buffer(
181 self.as_ref().to_glib_none().0,
182 ))
183 }
184 }
185
186 /// Returns [`true`] if the mark has been removed from its buffer.
187 ///
188 /// See [`TextBufferExt::add_mark()`][crate::prelude::TextBufferExt::add_mark()] for a way to add it
189 /// to a buffer again.
190 ///
191 /// # Returns
192 ///
193 /// whether the mark is deleted
194 #[doc(alias = "gtk_text_mark_get_deleted")]
195 #[doc(alias = "get_deleted")]
196 fn is_deleted(&self) -> bool {
197 unsafe {
198 from_glib(ffi::gtk_text_mark_get_deleted(
199 self.as_ref().to_glib_none().0,
200 ))
201 }
202 }
203
204 /// Determines whether the mark has left gravity.
205 ///
206 /// # Returns
207 ///
208 /// [`true`] if the mark has left gravity, [`false`] otherwise
209 #[doc(alias = "gtk_text_mark_get_left_gravity")]
210 #[doc(alias = "get_left_gravity")]
211 #[doc(alias = "left-gravity")]
212 fn is_left_gravity(&self) -> bool {
213 unsafe {
214 from_glib(ffi::gtk_text_mark_get_left_gravity(
215 self.as_ref().to_glib_none().0,
216 ))
217 }
218 }
219
220 /// Returns the mark name.
221 ///
222 /// Returns [`None`] for anonymous marks.
223 ///
224 /// # Returns
225 ///
226 /// mark name
227 #[doc(alias = "gtk_text_mark_get_name")]
228 #[doc(alias = "get_name")]
229 fn name(&self) -> Option<glib::GString> {
230 unsafe { from_glib_none(ffi::gtk_text_mark_get_name(self.as_ref().to_glib_none().0)) }
231 }
232
233 /// Returns [`true`] if the mark is visible.
234 ///
235 /// A cursor is displayed for visible marks.
236 ///
237 /// # Returns
238 ///
239 /// [`true`] if visible
240 #[doc(alias = "gtk_text_mark_get_visible")]
241 #[doc(alias = "get_visible")]
242 fn is_visible(&self) -> bool {
243 unsafe {
244 from_glib(ffi::gtk_text_mark_get_visible(
245 self.as_ref().to_glib_none().0,
246 ))
247 }
248 }
249
250 /// Sets the visibility of @self.
251 ///
252 /// The insertion point is normally visible, i.e. you can see it as
253 /// a vertical bar. Also, the text widget uses a visible mark to
254 /// indicate where a drop will occur when dragging-and-dropping text.
255 /// Most other marks are not visible.
256 ///
257 /// Marks are not visible by default.
258 /// ## `setting`
259 /// visibility of mark
260 #[doc(alias = "gtk_text_mark_set_visible")]
261 fn set_visible(&self, setting: bool) {
262 unsafe {
263 ffi::gtk_text_mark_set_visible(self.as_ref().to_glib_none().0, setting.into_glib());
264 }
265 }
266}
267
268impl<O: IsA<TextMark>> TextMarkExt for O {}