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 /// A [`TextMark`][crate::TextMark] is 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
163mod sealed {
164 pub trait Sealed {}
165 impl<T: super::IsA<super::TextMark>> Sealed for T {}
166}
167
168/// Trait containing all [`struct@TextMark`] methods.
169///
170/// # Implementors
171///
172/// [`TextMark`][struct@crate::TextMark]
173pub trait TextMarkExt: IsA<TextMark> + sealed::Sealed + 'static {
174 /// Gets the buffer this mark is located inside.
175 ///
176 /// Returns [`None`] if the mark is deleted.
177 ///
178 /// # Returns
179 ///
180 /// the mark’s [`TextBuffer`][crate::TextBuffer]
181 #[doc(alias = "gtk_text_mark_get_buffer")]
182 #[doc(alias = "get_buffer")]
183 fn buffer(&self) -> Option<TextBuffer> {
184 unsafe {
185 from_glib_none(ffi::gtk_text_mark_get_buffer(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 /// Returns [`true`] if the mark has been removed from its buffer.
192 ///
193 /// See [`TextBufferExt::add_mark()`][crate::prelude::TextBufferExt::add_mark()] for a way to add it
194 /// to a buffer again.
195 ///
196 /// # Returns
197 ///
198 /// whether the mark is deleted
199 #[doc(alias = "gtk_text_mark_get_deleted")]
200 #[doc(alias = "get_deleted")]
201 fn is_deleted(&self) -> bool {
202 unsafe {
203 from_glib(ffi::gtk_text_mark_get_deleted(
204 self.as_ref().to_glib_none().0,
205 ))
206 }
207 }
208
209 /// Determines whether the mark has left gravity.
210 ///
211 /// # Returns
212 ///
213 /// [`true`] if the mark has left gravity, [`false`] otherwise
214 #[doc(alias = "gtk_text_mark_get_left_gravity")]
215 #[doc(alias = "get_left_gravity")]
216 #[doc(alias = "left-gravity")]
217 fn is_left_gravity(&self) -> bool {
218 unsafe {
219 from_glib(ffi::gtk_text_mark_get_left_gravity(
220 self.as_ref().to_glib_none().0,
221 ))
222 }
223 }
224
225 /// Returns the mark name.
226 ///
227 /// Returns [`None`] for anonymous marks.
228 ///
229 /// # Returns
230 ///
231 /// mark name
232 #[doc(alias = "gtk_text_mark_get_name")]
233 #[doc(alias = "get_name")]
234 fn name(&self) -> Option<glib::GString> {
235 unsafe { from_glib_none(ffi::gtk_text_mark_get_name(self.as_ref().to_glib_none().0)) }
236 }
237
238 /// Returns [`true`] if the mark is visible.
239 ///
240 /// A cursor is displayed for visible marks.
241 ///
242 /// # Returns
243 ///
244 /// [`true`] if visible
245 #[doc(alias = "gtk_text_mark_get_visible")]
246 #[doc(alias = "get_visible")]
247 fn is_visible(&self) -> bool {
248 unsafe {
249 from_glib(ffi::gtk_text_mark_get_visible(
250 self.as_ref().to_glib_none().0,
251 ))
252 }
253 }
254
255 /// Sets the visibility of @self.
256 ///
257 /// The insertion point is normally visible, i.e. you can see it as
258 /// a vertical bar. Also, the text widget uses a visible mark to
259 /// indicate where a drop will occur when dragging-and-dropping text.
260 /// Most other marks are not visible.
261 ///
262 /// Marks are not visible by default.
263 /// ## `setting`
264 /// visibility of mark
265 #[doc(alias = "gtk_text_mark_set_visible")]
266 fn set_visible(&self, setting: bool) {
267 unsafe {
268 ffi::gtk_text_mark_set_visible(self.as_ref().to_glib_none().0, setting.into_glib());
269 }
270 }
271}
272
273impl<O: IsA<TextMark>> TextMarkExt for O {}