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