1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use glib::{prelude::*, translate::*};
use std::fmt;
glib::wrapper! {
///
///
/// ## Properties
///
///
/// #### `buffer`
/// The [`gtk::TextBuffer`][crate::gtk::TextBuffer]. The [`Region`][crate::Region] has a weak reference to the
/// buffer.
///
/// Readable | Writeable | Construct Only
///
/// # Implements
///
/// [`RegionExt`][trait@crate::prelude::RegionExt]
#[doc(alias = "GtkSourceRegion")]
pub struct Region(Object<ffi::GtkSourceRegion, ffi::GtkSourceRegionClass>);
match fn {
type_ => || ffi::gtk_source_region_get_type(),
}
}
impl Region {
pub const NONE: Option<&'static Region> = None;
/// ## `buffer`
/// a [`gtk::TextBuffer`][crate::gtk::TextBuffer].
///
/// # Returns
///
/// a new [`Region`][crate::Region] object for `buffer`.
#[doc(alias = "gtk_source_region_new")]
pub fn new(buffer: &impl IsA<gtk::TextBuffer>) -> Region {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gtk_source_region_new(buffer.as_ref().to_glib_none().0)) }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Region`] objects.
///
/// This method returns an instance of [`RegionBuilder`](crate::builders::RegionBuilder) which can be used to create [`Region`] objects.
pub fn builder() -> RegionBuilder {
RegionBuilder::new()
}
}
impl Default for Region {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
impl fmt::Display for Region {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&RegionExt::to_str(self))
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Region`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct RegionBuilder {
builder: glib::object::ObjectBuilder<'static, Region>,
}
impl RegionBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The [`gtk::TextBuffer`][crate::gtk::TextBuffer]. The [`Region`][crate::Region] has a weak reference to the
/// buffer.
pub fn buffer(self, buffer: &impl IsA<gtk::TextBuffer>) -> Self {
Self {
builder: self.builder.property("buffer", buffer.clone().upcast()),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Region`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Region {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Region>> Sealed for T {}
}
/// Trait containing all [`struct@Region`] methods.
///
/// # Implementors
///
/// [`Region`][struct@crate::Region]
pub trait RegionExt: IsA<Region> + sealed::Sealed + 'static {
/// Adds `region_to_add` to `self`. `region_to_add` is not modified.
/// ## `region_to_add`
/// the [`Region`][crate::Region] to add to `self`, or [`None`].
#[doc(alias = "gtk_source_region_add_region")]
fn add_region(&self, region_to_add: Option<&impl IsA<Region>>) {
unsafe {
ffi::gtk_source_region_add_region(
self.as_ref().to_glib_none().0,
region_to_add.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Adds the subregion delimited by `_start` and `_end` to `self`.
/// ## `_start`
/// the start of the subregion.
/// ## `_end`
/// the end of the subregion.
#[doc(alias = "gtk_source_region_add_subregion")]
fn add_subregion(&self, _start: >k::TextIter, _end: >k::TextIter) {
unsafe {
ffi::gtk_source_region_add_subregion(
self.as_ref().to_glib_none().0,
_start.to_glib_none().0,
_end.to_glib_none().0,
);
}
}
/// Gets the `start` and `end` bounds of the `self`.
///
/// # Returns
///
/// [`true`] if `start` and `end` have been set successfully (if non-[`None`]),
/// or [`false`] if the `self` is empty.
///
/// ## `start`
/// iterator to initialize with the start of `self`,
/// or [`None`].
///
/// ## `end`
/// iterator to initialize with the end of `self`,
/// or [`None`].
#[doc(alias = "gtk_source_region_get_bounds")]
#[doc(alias = "get_bounds")]
fn bounds(&self) -> Option<(gtk::TextIter, gtk::TextIter)> {
unsafe {
let mut start = gtk::TextIter::uninitialized();
let mut end = gtk::TextIter::uninitialized();
let ret = from_glib(ffi::gtk_source_region_get_bounds(
self.as_ref().to_glib_none().0,
start.to_glib_none_mut().0,
end.to_glib_none_mut().0,
));
if ret {
Some((start, end))
} else {
None
}
}
}
///
/// # Returns
///
/// the [`gtk::TextBuffer`][crate::gtk::TextBuffer].
#[doc(alias = "gtk_source_region_get_buffer")]
#[doc(alias = "get_buffer")]
fn buffer(&self) -> Option<gtk::TextBuffer> {
unsafe {
from_glib_none(ffi::gtk_source_region_get_buffer(
self.as_ref().to_glib_none().0,
))
}
}
//#[doc(alias = "gtk_source_region_get_start_region_iter")]
//#[doc(alias = "get_start_region_iter")]
//fn start_region_iter(&self, iter: /*Ignored*/RegionIter) {
// unsafe { TODO: call ffi:gtk_source_region_get_start_region_iter() }
//}
/// Returns the intersection between `self` and `region2`. `self` and
/// `region2` are not modified.
/// ## `region2`
/// a [`Region`][crate::Region], or [`None`].
///
/// # Returns
///
/// the intersection as a [`Region`][crate::Region]
/// object.
#[doc(alias = "gtk_source_region_intersect_region")]
#[must_use]
fn intersect_region(&self, region2: Option<&impl IsA<Region>>) -> Option<Region> {
unsafe {
from_glib_full(ffi::gtk_source_region_intersect_region(
self.as_ref().to_glib_none().0,
region2.map(|p| p.as_ref()).to_glib_none().0,
))
}
}
/// Returns the intersection between `self` and the subregion delimited by
/// `_start` and `_end`. `self` is not modified.
/// ## `_start`
/// the start of the subregion.
/// ## `_end`
/// the end of the subregion.
///
/// # Returns
///
/// the intersection as a new
/// [`Region`][crate::Region].
#[doc(alias = "gtk_source_region_intersect_subregion")]
#[must_use]
fn intersect_subregion(&self, _start: >k::TextIter, _end: >k::TextIter) -> Option<Region> {
unsafe {
from_glib_full(ffi::gtk_source_region_intersect_subregion(
self.as_ref().to_glib_none().0,
_start.to_glib_none().0,
_end.to_glib_none().0,
))
}
}
/// Returns whether the `self` is empty. A [`None`] `self` is considered empty.
///
/// # Returns
///
/// whether the `self` is empty.
#[doc(alias = "gtk_source_region_is_empty")]
fn is_empty(&self) -> bool {
unsafe {
from_glib(ffi::gtk_source_region_is_empty(
self.as_ref().to_glib_none().0,
))
}
}
/// Subtracts `region_to_subtract` from `self`. `region_to_subtract` is not
/// modified.
/// ## `region_to_subtract`
/// the [`Region`][crate::Region] to subtract from
/// `self`, or [`None`].
#[doc(alias = "gtk_source_region_subtract_region")]
fn subtract_region(&self, region_to_subtract: Option<&impl IsA<Region>>) {
unsafe {
ffi::gtk_source_region_subtract_region(
self.as_ref().to_glib_none().0,
region_to_subtract.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Subtracts the subregion delimited by `_start` and `_end` from `self`.
/// ## `_start`
/// the start of the subregion.
/// ## `_end`
/// the end of the subregion.
#[doc(alias = "gtk_source_region_subtract_subregion")]
fn subtract_subregion(&self, _start: >k::TextIter, _end: >k::TextIter) {
unsafe {
ffi::gtk_source_region_subtract_subregion(
self.as_ref().to_glib_none().0,
_start.to_glib_none().0,
_end.to_glib_none().0,
);
}
}
/// Gets a string represention of `self`, for debugging purposes.
///
/// The returned string contains the character offsets of the subregions. It
/// doesn't include a newline character at the end of the string.
///
/// # Returns
///
/// a string represention of `self`. Free
/// with `g_free()` when no longer needed.
#[doc(alias = "gtk_source_region_to_string")]
#[doc(alias = "to_string")]
fn to_str(&self) -> glib::GString {
unsafe {
from_glib_full(ffi::gtk_source_region_to_string(
self.as_ref().to_glib_none().0,
))
}
}
}
impl<O: IsA<Region>> RegionExt for O {}