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