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 5 use crate::Alignment; 6 use crate::AttrList; 7 use crate::Context; 8 #[cfg(any(feature = "v1_46", feature = "dox"))] 9 #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))] 10 use crate::Direction; 11 use crate::EllipsizeMode; 12 use crate::FontDescription; 13 use crate::LayoutIter; 14 use crate::LayoutLine; 15 use crate::Rectangle; 16 use crate::TabArray; 17 use crate::WrapMode; 18 use glib::translate::*; 19 use std::fmt; 20 use std::mem; 21 22 glib::wrapper! { 23 #[doc(alias = "PangoLayout")] 24 pub struct Layout(Object<ffi::PangoLayout, ffi::PangoLayoutClass>); 25 26 match fn { 27 type_ => || ffi::pango_layout_get_type(), 28 } 29 } 30 31 impl Layout { 32 #[doc(alias = "pango_layout_new")] new(context: &Context) -> Layout33 pub fn new(context: &Context) -> Layout { 34 unsafe { from_glib_full(ffi::pango_layout_new(context.to_glib_none().0)) } 35 } 36 37 #[doc(alias = "pango_layout_context_changed")] context_changed(&self)38 pub fn context_changed(&self) { 39 unsafe { 40 ffi::pango_layout_context_changed(self.to_glib_none().0); 41 } 42 } 43 44 #[doc(alias = "pango_layout_copy")] copy(&self) -> Option<Layout>45 pub fn copy(&self) -> Option<Layout> { 46 unsafe { from_glib_full(ffi::pango_layout_copy(self.to_glib_none().0)) } 47 } 48 49 #[doc(alias = "pango_layout_get_alignment")] 50 #[doc(alias = "get_alignment")] alignment(&self) -> Alignment51 pub fn alignment(&self) -> Alignment { 52 unsafe { from_glib(ffi::pango_layout_get_alignment(self.to_glib_none().0)) } 53 } 54 55 #[doc(alias = "pango_layout_get_attributes")] 56 #[doc(alias = "get_attributes")] attributes(&self) -> Option<AttrList>57 pub fn attributes(&self) -> Option<AttrList> { 58 unsafe { from_glib_none(ffi::pango_layout_get_attributes(self.to_glib_none().0)) } 59 } 60 61 #[doc(alias = "pango_layout_get_auto_dir")] 62 #[doc(alias = "get_auto_dir")] is_auto_dir(&self) -> bool63 pub fn is_auto_dir(&self) -> bool { 64 unsafe { from_glib(ffi::pango_layout_get_auto_dir(self.to_glib_none().0)) } 65 } 66 67 #[doc(alias = "pango_layout_get_baseline")] 68 #[doc(alias = "get_baseline")] baseline(&self) -> i3269 pub fn baseline(&self) -> i32 { 70 unsafe { ffi::pango_layout_get_baseline(self.to_glib_none().0) } 71 } 72 73 #[doc(alias = "pango_layout_get_character_count")] 74 #[doc(alias = "get_character_count")] character_count(&self) -> i3275 pub fn character_count(&self) -> i32 { 76 unsafe { ffi::pango_layout_get_character_count(self.to_glib_none().0) } 77 } 78 79 #[doc(alias = "pango_layout_get_context")] 80 #[doc(alias = "get_context")] context(&self) -> Option<Context>81 pub fn context(&self) -> Option<Context> { 82 unsafe { from_glib_none(ffi::pango_layout_get_context(self.to_glib_none().0)) } 83 } 84 85 #[doc(alias = "pango_layout_get_cursor_pos")] 86 #[doc(alias = "get_cursor_pos")] cursor_pos(&self, index_: i32) -> (Rectangle, Rectangle)87 pub fn cursor_pos(&self, index_: i32) -> (Rectangle, Rectangle) { 88 unsafe { 89 let mut strong_pos = Rectangle::uninitialized(); 90 let mut weak_pos = Rectangle::uninitialized(); 91 ffi::pango_layout_get_cursor_pos( 92 self.to_glib_none().0, 93 index_, 94 strong_pos.to_glib_none_mut().0, 95 weak_pos.to_glib_none_mut().0, 96 ); 97 (strong_pos, weak_pos) 98 } 99 } 100 101 #[cfg(any(feature = "v1_46", feature = "dox"))] 102 #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))] 103 #[doc(alias = "pango_layout_get_direction")] 104 #[doc(alias = "get_direction")] direction(&self, index: i32) -> Direction105 pub fn direction(&self, index: i32) -> Direction { 106 unsafe { 107 from_glib(ffi::pango_layout_get_direction( 108 self.to_glib_none().0, 109 index, 110 )) 111 } 112 } 113 114 #[doc(alias = "pango_layout_get_ellipsize")] 115 #[doc(alias = "get_ellipsize")] ellipsize(&self) -> EllipsizeMode116 pub fn ellipsize(&self) -> EllipsizeMode { 117 unsafe { from_glib(ffi::pango_layout_get_ellipsize(self.to_glib_none().0)) } 118 } 119 120 #[doc(alias = "pango_layout_get_extents")] 121 #[doc(alias = "get_extents")] extents(&self) -> (Rectangle, Rectangle)122 pub fn extents(&self) -> (Rectangle, Rectangle) { 123 unsafe { 124 let mut ink_rect = Rectangle::uninitialized(); 125 let mut logical_rect = Rectangle::uninitialized(); 126 ffi::pango_layout_get_extents( 127 self.to_glib_none().0, 128 ink_rect.to_glib_none_mut().0, 129 logical_rect.to_glib_none_mut().0, 130 ); 131 (ink_rect, logical_rect) 132 } 133 } 134 135 #[doc(alias = "pango_layout_get_font_description")] 136 #[doc(alias = "get_font_description")] font_description(&self) -> Option<FontDescription>137 pub fn font_description(&self) -> Option<FontDescription> { 138 unsafe { 139 from_glib_none(ffi::pango_layout_get_font_description( 140 self.to_glib_none().0, 141 )) 142 } 143 } 144 145 #[doc(alias = "pango_layout_get_height")] 146 #[doc(alias = "get_height")] height(&self) -> i32147 pub fn height(&self) -> i32 { 148 unsafe { ffi::pango_layout_get_height(self.to_glib_none().0) } 149 } 150 151 #[doc(alias = "pango_layout_get_indent")] 152 #[doc(alias = "get_indent")] indent(&self) -> i32153 pub fn indent(&self) -> i32 { 154 unsafe { ffi::pango_layout_get_indent(self.to_glib_none().0) } 155 } 156 157 #[doc(alias = "pango_layout_get_iter")] 158 #[doc(alias = "get_iter")] iter(&self) -> Option<LayoutIter>159 pub fn iter(&self) -> Option<LayoutIter> { 160 unsafe { from_glib_full(ffi::pango_layout_get_iter(self.to_glib_none().0)) } 161 } 162 163 #[doc(alias = "pango_layout_get_justify")] 164 #[doc(alias = "get_justify")] is_justify(&self) -> bool165 pub fn is_justify(&self) -> bool { 166 unsafe { from_glib(ffi::pango_layout_get_justify(self.to_glib_none().0)) } 167 } 168 169 #[doc(alias = "pango_layout_get_line")] 170 #[doc(alias = "get_line")] line(&self, line: i32) -> Option<LayoutLine>171 pub fn line(&self, line: i32) -> Option<LayoutLine> { 172 unsafe { from_glib_none(ffi::pango_layout_get_line(self.to_glib_none().0, line)) } 173 } 174 175 #[doc(alias = "pango_layout_get_line_count")] 176 #[doc(alias = "get_line_count")] line_count(&self) -> i32177 pub fn line_count(&self) -> i32 { 178 unsafe { ffi::pango_layout_get_line_count(self.to_glib_none().0) } 179 } 180 181 #[doc(alias = "pango_layout_get_line_readonly")] 182 #[doc(alias = "get_line_readonly")] line_readonly(&self, line: i32) -> Option<LayoutLine>183 pub fn line_readonly(&self, line: i32) -> Option<LayoutLine> { 184 unsafe { 185 from_glib_none(ffi::pango_layout_get_line_readonly( 186 self.to_glib_none().0, 187 line, 188 )) 189 } 190 } 191 192 #[cfg(any(feature = "v1_44", feature = "dox"))] 193 #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))] 194 #[doc(alias = "pango_layout_get_line_spacing")] 195 #[doc(alias = "get_line_spacing")] line_spacing(&self) -> f32196 pub fn line_spacing(&self) -> f32 { 197 unsafe { ffi::pango_layout_get_line_spacing(self.to_glib_none().0) } 198 } 199 200 #[doc(alias = "pango_layout_get_lines")] 201 #[doc(alias = "get_lines")] lines(&self) -> Vec<LayoutLine>202 pub fn lines(&self) -> Vec<LayoutLine> { 203 unsafe { 204 FromGlibPtrContainer::from_glib_none(ffi::pango_layout_get_lines(self.to_glib_none().0)) 205 } 206 } 207 208 #[doc(alias = "pango_layout_get_lines_readonly")] 209 #[doc(alias = "get_lines_readonly")] lines_readonly(&self) -> Vec<LayoutLine>210 pub fn lines_readonly(&self) -> Vec<LayoutLine> { 211 unsafe { 212 FromGlibPtrContainer::from_glib_none(ffi::pango_layout_get_lines_readonly( 213 self.to_glib_none().0, 214 )) 215 } 216 } 217 218 //#[doc(alias = "pango_layout_get_log_attrs")] 219 //#[doc(alias = "get_log_attrs")] 220 //pub fn log_attrs(&self, attrs: /*Ignored*/Vec<LogAttr>) -> i32 { 221 // unsafe { TODO: call ffi:pango_layout_get_log_attrs() } 222 //} 223 224 //#[doc(alias = "pango_layout_get_log_attrs_readonly")] 225 //#[doc(alias = "get_log_attrs_readonly")] 226 //pub fn log_attrs_readonly(&self) -> /*Ignored*/Vec<LogAttr> { 227 // unsafe { TODO: call ffi:pango_layout_get_log_attrs_readonly() } 228 //} 229 230 #[doc(alias = "pango_layout_get_pixel_extents")] 231 #[doc(alias = "get_pixel_extents")] pixel_extents(&self) -> (Rectangle, Rectangle)232 pub fn pixel_extents(&self) -> (Rectangle, Rectangle) { 233 unsafe { 234 let mut ink_rect = Rectangle::uninitialized(); 235 let mut logical_rect = Rectangle::uninitialized(); 236 ffi::pango_layout_get_pixel_extents( 237 self.to_glib_none().0, 238 ink_rect.to_glib_none_mut().0, 239 logical_rect.to_glib_none_mut().0, 240 ); 241 (ink_rect, logical_rect) 242 } 243 } 244 245 #[doc(alias = "pango_layout_get_pixel_size")] 246 #[doc(alias = "get_pixel_size")] pixel_size(&self) -> (i32, i32)247 pub fn pixel_size(&self) -> (i32, i32) { 248 unsafe { 249 let mut width = mem::MaybeUninit::uninit(); 250 let mut height = mem::MaybeUninit::uninit(); 251 ffi::pango_layout_get_pixel_size( 252 self.to_glib_none().0, 253 width.as_mut_ptr(), 254 height.as_mut_ptr(), 255 ); 256 let width = width.assume_init(); 257 let height = height.assume_init(); 258 (width, height) 259 } 260 } 261 262 #[doc(alias = "pango_layout_get_serial")] 263 #[doc(alias = "get_serial")] serial(&self) -> u32264 pub fn serial(&self) -> u32 { 265 unsafe { ffi::pango_layout_get_serial(self.to_glib_none().0) } 266 } 267 268 #[doc(alias = "pango_layout_get_single_paragraph_mode")] 269 #[doc(alias = "get_single_paragraph_mode")] is_single_paragraph_mode(&self) -> bool270 pub fn is_single_paragraph_mode(&self) -> bool { 271 unsafe { 272 from_glib(ffi::pango_layout_get_single_paragraph_mode( 273 self.to_glib_none().0, 274 )) 275 } 276 } 277 278 #[doc(alias = "pango_layout_get_size")] 279 #[doc(alias = "get_size")] size(&self) -> (i32, i32)280 pub fn size(&self) -> (i32, i32) { 281 unsafe { 282 let mut width = mem::MaybeUninit::uninit(); 283 let mut height = mem::MaybeUninit::uninit(); 284 ffi::pango_layout_get_size( 285 self.to_glib_none().0, 286 width.as_mut_ptr(), 287 height.as_mut_ptr(), 288 ); 289 let width = width.assume_init(); 290 let height = height.assume_init(); 291 (width, height) 292 } 293 } 294 295 #[doc(alias = "pango_layout_get_spacing")] 296 #[doc(alias = "get_spacing")] spacing(&self) -> i32297 pub fn spacing(&self) -> i32 { 298 unsafe { ffi::pango_layout_get_spacing(self.to_glib_none().0) } 299 } 300 301 #[doc(alias = "pango_layout_get_tabs")] 302 #[doc(alias = "get_tabs")] tabs(&self) -> Option<TabArray>303 pub fn tabs(&self) -> Option<TabArray> { 304 unsafe { from_glib_full(ffi::pango_layout_get_tabs(self.to_glib_none().0)) } 305 } 306 307 #[doc(alias = "pango_layout_get_text")] 308 #[doc(alias = "get_text")] text(&self) -> Option<glib::GString>309 pub fn text(&self) -> Option<glib::GString> { 310 unsafe { from_glib_none(ffi::pango_layout_get_text(self.to_glib_none().0)) } 311 } 312 313 #[doc(alias = "pango_layout_get_unknown_glyphs_count")] 314 #[doc(alias = "get_unknown_glyphs_count")] unknown_glyphs_count(&self) -> i32315 pub fn unknown_glyphs_count(&self) -> i32 { 316 unsafe { ffi::pango_layout_get_unknown_glyphs_count(self.to_glib_none().0) } 317 } 318 319 #[doc(alias = "pango_layout_get_width")] 320 #[doc(alias = "get_width")] width(&self) -> i32321 pub fn width(&self) -> i32 { 322 unsafe { ffi::pango_layout_get_width(self.to_glib_none().0) } 323 } 324 325 #[doc(alias = "pango_layout_get_wrap")] 326 #[doc(alias = "get_wrap")] wrap(&self) -> WrapMode327 pub fn wrap(&self) -> WrapMode { 328 unsafe { from_glib(ffi::pango_layout_get_wrap(self.to_glib_none().0)) } 329 } 330 331 #[doc(alias = "pango_layout_index_to_line_x")] index_to_line_x(&self, index_: i32, trailing: bool) -> (i32, i32)332 pub fn index_to_line_x(&self, index_: i32, trailing: bool) -> (i32, i32) { 333 unsafe { 334 let mut line = mem::MaybeUninit::uninit(); 335 let mut x_pos = mem::MaybeUninit::uninit(); 336 ffi::pango_layout_index_to_line_x( 337 self.to_glib_none().0, 338 index_, 339 trailing.into_glib(), 340 line.as_mut_ptr(), 341 x_pos.as_mut_ptr(), 342 ); 343 let line = line.assume_init(); 344 let x_pos = x_pos.assume_init(); 345 (line, x_pos) 346 } 347 } 348 349 #[doc(alias = "pango_layout_index_to_pos")] index_to_pos(&self, index_: i32) -> Rectangle350 pub fn index_to_pos(&self, index_: i32) -> Rectangle { 351 unsafe { 352 let mut pos = Rectangle::uninitialized(); 353 ffi::pango_layout_index_to_pos(self.to_glib_none().0, index_, pos.to_glib_none_mut().0); 354 pos 355 } 356 } 357 358 #[doc(alias = "pango_layout_is_ellipsized")] is_ellipsized(&self) -> bool359 pub fn is_ellipsized(&self) -> bool { 360 unsafe { from_glib(ffi::pango_layout_is_ellipsized(self.to_glib_none().0)) } 361 } 362 363 #[doc(alias = "pango_layout_is_wrapped")] is_wrapped(&self) -> bool364 pub fn is_wrapped(&self) -> bool { 365 unsafe { from_glib(ffi::pango_layout_is_wrapped(self.to_glib_none().0)) } 366 } 367 368 #[doc(alias = "pango_layout_move_cursor_visually")] move_cursor_visually( &self, strong: bool, old_index: i32, old_trailing: i32, direction: i32, ) -> (i32, i32)369 pub fn move_cursor_visually( 370 &self, 371 strong: bool, 372 old_index: i32, 373 old_trailing: i32, 374 direction: i32, 375 ) -> (i32, i32) { 376 unsafe { 377 let mut new_index = mem::MaybeUninit::uninit(); 378 let mut new_trailing = mem::MaybeUninit::uninit(); 379 ffi::pango_layout_move_cursor_visually( 380 self.to_glib_none().0, 381 strong.into_glib(), 382 old_index, 383 old_trailing, 384 direction, 385 new_index.as_mut_ptr(), 386 new_trailing.as_mut_ptr(), 387 ); 388 let new_index = new_index.assume_init(); 389 let new_trailing = new_trailing.assume_init(); 390 (new_index, new_trailing) 391 } 392 } 393 394 #[doc(alias = "pango_layout_set_alignment")] set_alignment(&self, alignment: Alignment)395 pub fn set_alignment(&self, alignment: Alignment) { 396 unsafe { 397 ffi::pango_layout_set_alignment(self.to_glib_none().0, alignment.into_glib()); 398 } 399 } 400 401 #[doc(alias = "pango_layout_set_attributes")] set_attributes(&self, attrs: Option<&AttrList>)402 pub fn set_attributes(&self, attrs: Option<&AttrList>) { 403 unsafe { 404 ffi::pango_layout_set_attributes(self.to_glib_none().0, attrs.to_glib_none().0); 405 } 406 } 407 408 #[doc(alias = "pango_layout_set_auto_dir")] set_auto_dir(&self, auto_dir: bool)409 pub fn set_auto_dir(&self, auto_dir: bool) { 410 unsafe { 411 ffi::pango_layout_set_auto_dir(self.to_glib_none().0, auto_dir.into_glib()); 412 } 413 } 414 415 #[doc(alias = "pango_layout_set_ellipsize")] set_ellipsize(&self, ellipsize: EllipsizeMode)416 pub fn set_ellipsize(&self, ellipsize: EllipsizeMode) { 417 unsafe { 418 ffi::pango_layout_set_ellipsize(self.to_glib_none().0, ellipsize.into_glib()); 419 } 420 } 421 422 #[doc(alias = "pango_layout_set_font_description")] set_font_description(&self, desc: Option<&FontDescription>)423 pub fn set_font_description(&self, desc: Option<&FontDescription>) { 424 unsafe { 425 ffi::pango_layout_set_font_description(self.to_glib_none().0, desc.to_glib_none().0); 426 } 427 } 428 429 #[doc(alias = "pango_layout_set_height")] set_height(&self, height: i32)430 pub fn set_height(&self, height: i32) { 431 unsafe { 432 ffi::pango_layout_set_height(self.to_glib_none().0, height); 433 } 434 } 435 436 #[doc(alias = "pango_layout_set_indent")] set_indent(&self, indent: i32)437 pub fn set_indent(&self, indent: i32) { 438 unsafe { 439 ffi::pango_layout_set_indent(self.to_glib_none().0, indent); 440 } 441 } 442 443 #[doc(alias = "pango_layout_set_justify")] set_justify(&self, justify: bool)444 pub fn set_justify(&self, justify: bool) { 445 unsafe { 446 ffi::pango_layout_set_justify(self.to_glib_none().0, justify.into_glib()); 447 } 448 } 449 450 #[cfg(any(feature = "v1_44", feature = "dox"))] 451 #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))] 452 #[doc(alias = "pango_layout_set_line_spacing")] set_line_spacing(&self, factor: f32)453 pub fn set_line_spacing(&self, factor: f32) { 454 unsafe { 455 ffi::pango_layout_set_line_spacing(self.to_glib_none().0, factor); 456 } 457 } 458 459 #[doc(alias = "pango_layout_set_markup")] set_markup(&self, markup: &str)460 pub fn set_markup(&self, markup: &str) { 461 let length = markup.len() as i32; 462 unsafe { 463 ffi::pango_layout_set_markup(self.to_glib_none().0, markup.to_glib_none().0, length); 464 } 465 } 466 467 #[doc(alias = "pango_layout_set_markup_with_accel")] set_markup_with_accel(&self, markup: &str, accel_marker: char) -> char468 pub fn set_markup_with_accel(&self, markup: &str, accel_marker: char) -> char { 469 let length = markup.len() as i32; 470 unsafe { 471 let mut accel_char = mem::MaybeUninit::uninit(); 472 ffi::pango_layout_set_markup_with_accel( 473 self.to_glib_none().0, 474 markup.to_glib_none().0, 475 length, 476 accel_marker.into_glib(), 477 accel_char.as_mut_ptr(), 478 ); 479 let accel_char = accel_char.assume_init(); 480 std::convert::TryFrom::try_from(accel_char) 481 .expect("conversion from an invalid Unicode value attempted") 482 } 483 } 484 485 #[doc(alias = "pango_layout_set_single_paragraph_mode")] set_single_paragraph_mode(&self, setting: bool)486 pub fn set_single_paragraph_mode(&self, setting: bool) { 487 unsafe { 488 ffi::pango_layout_set_single_paragraph_mode(self.to_glib_none().0, setting.into_glib()); 489 } 490 } 491 492 #[doc(alias = "pango_layout_set_spacing")] set_spacing(&self, spacing: i32)493 pub fn set_spacing(&self, spacing: i32) { 494 unsafe { 495 ffi::pango_layout_set_spacing(self.to_glib_none().0, spacing); 496 } 497 } 498 499 #[doc(alias = "pango_layout_set_tabs")] set_tabs(&self, tabs: Option<&TabArray>)500 pub fn set_tabs(&self, tabs: Option<&TabArray>) { 501 unsafe { 502 ffi::pango_layout_set_tabs(self.to_glib_none().0, mut_override(tabs.to_glib_none().0)); 503 } 504 } 505 506 #[doc(alias = "pango_layout_set_text")] set_text(&self, text: &str)507 pub fn set_text(&self, text: &str) { 508 let length = text.len() as i32; 509 unsafe { 510 ffi::pango_layout_set_text(self.to_glib_none().0, text.to_glib_none().0, length); 511 } 512 } 513 514 #[doc(alias = "pango_layout_set_width")] set_width(&self, width: i32)515 pub fn set_width(&self, width: i32) { 516 unsafe { 517 ffi::pango_layout_set_width(self.to_glib_none().0, width); 518 } 519 } 520 521 #[doc(alias = "pango_layout_set_wrap")] set_wrap(&self, wrap: WrapMode)522 pub fn set_wrap(&self, wrap: WrapMode) { 523 unsafe { 524 ffi::pango_layout_set_wrap(self.to_glib_none().0, wrap.into_glib()); 525 } 526 } 527 528 #[doc(alias = "pango_layout_xy_to_index")] xy_to_index(&self, x: i32, y: i32) -> (bool, i32, i32)529 pub fn xy_to_index(&self, x: i32, y: i32) -> (bool, i32, i32) { 530 unsafe { 531 let mut index_ = mem::MaybeUninit::uninit(); 532 let mut trailing = mem::MaybeUninit::uninit(); 533 let ret = from_glib(ffi::pango_layout_xy_to_index( 534 self.to_glib_none().0, 535 x, 536 y, 537 index_.as_mut_ptr(), 538 trailing.as_mut_ptr(), 539 )); 540 let index_ = index_.assume_init(); 541 let trailing = trailing.assume_init(); 542 (ret, index_, trailing) 543 } 544 } 545 } 546 547 impl fmt::Display for Layout { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result548 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 549 f.write_str("Layout") 550 } 551 } 552