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