1
1
// Copyright 2017, The Gtk-rs Project Developers.
2
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>
3
+ // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
4
5
- use glib:: translate:: * ;
6
- use pango_sys;
7
5
use AttrClass ;
8
6
use Attribute ;
7
+ use FontDescription ;
9
8
use Gravity ;
10
9
use GravityHint ;
10
+ use Language ;
11
+ use Rectangle ;
11
12
use Stretch ;
12
13
use Style ;
13
14
use Underline ;
14
- use Variant ;
15
15
use Weight ;
16
16
17
+ use glib:: translate:: from_glib_full;
18
+ use glib:: translate:: ToGlib ;
19
+ use glib:: translate:: ToGlibPtr ;
20
+
17
21
impl Attribute {
18
22
#[ cfg( any( feature = "v1_38" , feature = "dox" ) ) ]
19
23
pub fn new_background_alpha ( alpha : u16 ) -> Option < Attribute > {
@@ -32,10 +36,54 @@ impl Attribute {
32
36
}
33
37
}
34
38
39
+ // TODO: available at 1.44
40
+ // pub fn new_allow_breaks(allow_breaks: bool) -> Option<Attribute> {
41
+ // unsafe {
42
+ // from_glib_full(pango_sys::pango_attr_allow_breaks_new(
43
+ // allow_breaks.to_glib(),
44
+ // ))
45
+ // }
46
+ // }
47
+
48
+ // TODO: available at 1.44
49
+ // pub fn new_insert_hyphens(insert_hyphens: bool) -> Option<Attribute> {
50
+ // unsafe {
51
+ // from_glib_full(pango_sys::pango_attr_insert_hyphens_new(
52
+ // insert_hyphens.to_glib(),
53
+ // ))
54
+ // }
55
+ // }
56
+
57
+ // TODO: available at 1.44, needs PangoShowFlags
58
+ // pub fn new_show(flags: PangoShowFlags) -> Option<Attribute> {
59
+ // unsafe {
60
+ // from_glib_full(pango_sys::pango_attr_show_new(
61
+ // flags.to_glib(),
62
+ // ))
63
+ // }
64
+ // }
65
+
66
+ pub fn new_language ( language : & Language ) -> Option < Attribute > {
67
+ unsafe {
68
+ from_glib_full ( pango_sys:: pango_attr_language_new (
69
+ language. to_glib_none ( ) . 0 ,
70
+ ) )
71
+ }
72
+ }
73
+
35
74
pub fn new_family ( family : & str ) -> Option < Attribute > {
36
75
unsafe { from_glib_full ( pango_sys:: pango_attr_family_new ( family. to_glib_none ( ) . 0 ) ) }
37
76
}
38
77
78
+ #[ cfg( any( feature = "v1_38" , feature = "dox" ) ) ]
79
+ pub fn new_font_features ( features : & str ) -> Option < Attribute > {
80
+ unsafe {
81
+ from_glib_full ( pango_sys:: pango_attr_font_features_new (
82
+ features. to_glib_none ( ) . 0 ,
83
+ ) )
84
+ }
85
+ }
86
+
39
87
#[ cfg( any( feature = "v1_38" , feature = "dox" ) ) ]
40
88
pub fn new_foreground_alpha ( alpha : u16 ) -> Option < Attribute > {
41
89
unsafe { from_glib_full ( pango_sys:: pango_attr_foreground_alpha_new ( alpha) ) }
@@ -61,18 +109,34 @@ impl Attribute {
61
109
unsafe { from_glib_full ( pango_sys:: pango_attr_rise_new ( rise) ) }
62
110
}
63
111
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
112
pub fn new_size ( size : i32 ) -> Option < Attribute > {
69
113
unsafe { from_glib_full ( pango_sys:: pango_attr_size_new ( size) ) }
70
114
}
71
115
72
- pub fn new_size_absolute ( size : i32 ) -> Option < Attribute > {
116
+ pub fn new_absolute_size ( size : i32 ) -> Option < Attribute > {
73
117
unsafe { from_glib_full ( pango_sys:: pango_attr_size_new_absolute ( size) ) }
74
118
}
75
119
120
+ pub fn new_font_desc ( desc : & FontDescription ) -> Option < Attribute > {
121
+ unsafe { from_glib_full ( pango_sys:: pango_attr_font_desc_new ( desc. to_glib_none ( ) . 0 ) ) }
122
+ }
123
+
124
+ pub fn new_shape (
125
+ ink_rect : & Rectangle ,
126
+ logical_rect : & Rectangle ,
127
+ ) -> Option < Attribute > {
128
+ unsafe {
129
+ from_glib_full ( pango_sys:: pango_attr_shape_new (
130
+ ink_rect. to_glib_none ( ) . 0 ,
131
+ logical_rect. to_glib_none ( ) . 0 ,
132
+ ) )
133
+ }
134
+ }
135
+
136
+ pub fn new_scale ( scale_factor : f64 ) -> Option < Attribute > {
137
+ unsafe { from_glib_full ( pango_sys:: pango_attr_scale_new ( scale_factor) ) }
138
+ }
139
+
76
140
pub fn new_stretch ( stretch : Stretch ) -> Option < Attribute > {
77
141
unsafe { from_glib_full ( pango_sys:: pango_attr_stretch_new ( stretch. to_glib ( ) ) ) }
78
142
}
@@ -105,9 +169,9 @@ impl Attribute {
105
169
unsafe { from_glib_full ( pango_sys:: pango_attr_underline_new ( underline. to_glib ( ) ) ) }
106
170
}
107
171
108
- pub fn new_variant ( variant : Variant ) -> Option < Attribute > {
172
+ /* pub fn attr_variant_new (variant: Variant) -> Option<Attribute> {
109
173
unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) }
110
- }
174
+ }*/
111
175
112
176
pub fn new_weight ( weight : Weight ) -> Option < Attribute > {
113
177
unsafe { from_glib_full ( pango_sys:: pango_attr_weight_new ( weight. to_glib ( ) ) ) }
@@ -117,31 +181,31 @@ impl Attribute {
117
181
unsafe { from_glib_full ( ( * self . to_glib_none ( ) . 0 ) . klass ) }
118
182
}
119
183
120
- pub fn get_start_index ( & self ) -> u32 {
184
+ pub fn get_end_index ( & self ) -> u32 {
121
185
unsafe {
122
186
let stash = self . to_glib_none ( ) ;
123
- ( * stash. 0 ) . start_index
187
+ ( * stash. 0 ) . end_index
124
188
}
125
189
}
126
190
127
- pub fn get_end_index ( & self ) -> u32 {
191
+ pub fn set_end_index ( & mut self , index : u32 ) {
128
192
unsafe {
129
- let stash = self . to_glib_none ( ) ;
130
- ( * stash. 0 ) . end_index
193
+ let stash = self . to_glib_none_mut ( ) ;
194
+ ( * stash. 0 ) . end_index = index ;
131
195
}
132
196
}
133
197
134
- pub fn set_start_index ( & mut self , index : u32 ) {
198
+ pub fn get_start_index ( & self ) -> u32 {
135
199
unsafe {
136
- let stash = self . to_glib_none_mut ( ) ;
137
- ( * stash. 0 ) . start_index = index ;
200
+ let stash = self . to_glib_none ( ) ;
201
+ ( * stash. 0 ) . start_index
138
202
}
139
203
}
140
204
141
- pub fn set_end_index ( & mut self , index : u32 ) {
205
+ pub fn set_start_index ( & mut self , index : u32 ) {
142
206
unsafe {
143
207
let stash = self . to_glib_none_mut ( ) ;
144
- ( * stash. 0 ) . end_index = index;
208
+ ( * stash. 0 ) . start_index = index;
145
209
}
146
210
}
147
211
}
0 commit comments