pango/
attribute.rs

1// Copyright 2017, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use glib::translate::*;
6use pango_sys;
7use AttrClass;
8use Attribute;
9use Gravity;
10use GravityHint;
11use Stretch;
12use Style;
13use Underline;
14use Variant;
15use Weight;
16
17impl Attribute {
18    #[cfg(any(feature = "v1_38", feature = "dox"))]
19    pub fn new_background_alpha(alpha: u16) -> Option<Attribute> {
20        unsafe { from_glib_full(pango_sys::pango_attr_background_alpha_new(alpha)) }
21    }
22
23    pub fn new_background(red: u16, green: u16, blue: u16) -> Option<Attribute> {
24        unsafe { from_glib_full(pango_sys::pango_attr_background_new(red, green, blue)) }
25    }
26
27    pub fn new_fallback(enable_fallback: bool) -> Option<Attribute> {
28        unsafe {
29            from_glib_full(pango_sys::pango_attr_fallback_new(
30                enable_fallback.to_glib(),
31            ))
32        }
33    }
34
35    pub fn new_family(family: &str) -> Option<Attribute> {
36        unsafe { from_glib_full(pango_sys::pango_attr_family_new(family.to_glib_none().0)) }
37    }
38
39    #[cfg(any(feature = "v1_38", feature = "dox"))]
40    pub fn new_foreground_alpha(alpha: u16) -> Option<Attribute> {
41        unsafe { from_glib_full(pango_sys::pango_attr_foreground_alpha_new(alpha)) }
42    }
43
44    pub fn new_foreground(red: u16, green: u16, blue: u16) -> Option<Attribute> {
45        unsafe { from_glib_full(pango_sys::pango_attr_foreground_new(red, green, blue)) }
46    }
47
48    pub fn new_gravity_hint(hint: GravityHint) -> Option<Attribute> {
49        unsafe { from_glib_full(pango_sys::pango_attr_gravity_hint_new(hint.to_glib())) }
50    }
51
52    pub fn new_gravity(gravity: Gravity) -> Option<Attribute> {
53        unsafe { from_glib_full(pango_sys::pango_attr_gravity_new(gravity.to_glib())) }
54    }
55
56    pub fn new_letter_spacing(letter_spacing: i32) -> Option<Attribute> {
57        unsafe { from_glib_full(pango_sys::pango_attr_letter_spacing_new(letter_spacing)) }
58    }
59
60    pub fn new_rise(rise: i32) -> Option<Attribute> {
61        unsafe { from_glib_full(pango_sys::pango_attr_rise_new(rise)) }
62    }
63
64    pub fn new_scale(scale_factor: f64) -> Option<Attribute> {
65        unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) }
66    }
67
68    pub fn new_stretch(stretch: Stretch) -> Option<Attribute> {
69        unsafe { from_glib_full(pango_sys::pango_attr_stretch_new(stretch.to_glib())) }
70    }
71
72    pub fn new_strikethrough_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
73        unsafe {
74            from_glib_full(pango_sys::pango_attr_strikethrough_color_new(
75                red, green, blue,
76            ))
77        }
78    }
79
80    pub fn new_strikethrough(strikethrough: bool) -> Option<Attribute> {
81        unsafe {
82            from_glib_full(pango_sys::pango_attr_strikethrough_new(
83                strikethrough.to_glib(),
84            ))
85        }
86    }
87
88    pub fn new_style(style: Style) -> Option<Attribute> {
89        unsafe { from_glib_full(pango_sys::pango_attr_style_new(style.to_glib())) }
90    }
91
92    pub fn new_underline_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
93        unsafe { from_glib_full(pango_sys::pango_attr_underline_color_new(red, green, blue)) }
94    }
95
96    pub fn new_underline(underline: Underline) -> Option<Attribute> {
97        unsafe { from_glib_full(pango_sys::pango_attr_underline_new(underline.to_glib())) }
98    }
99
100    pub fn new_variant(variant: Variant) -> Option<Attribute> {
101        unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) }
102    }
103
104    pub fn new_weight(weight: Weight) -> Option<Attribute> {
105        unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) }
106    }
107
108    pub fn get_attr_class(&self) -> AttrClass {
109        unsafe { from_glib_full((*self.to_glib_none().0).klass) }
110    }
111
112    pub fn get_start_index(&self) -> u32 {
113        unsafe {
114            let stash = self.to_glib_none();
115            (*stash.0).start_index
116        }
117    }
118
119    pub fn get_end_index(&self) -> u32 {
120        unsafe {
121            let stash = self.to_glib_none();
122            (*stash.0).end_index
123        }
124    }
125
126    pub fn set_start_index(&mut self, index: u32) {
127        unsafe {
128            let stash = self.to_glib_none_mut();
129            (*stash.0).start_index = index;
130        }
131    }
132
133    pub fn set_end_index(&mut self, index: u32) {
134        unsafe {
135            let stash = self.to_glib_none_mut();
136            (*stash.0).end_index = index;
137        }
138    }
139}