Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 82d96e9

Browse files
Improve Attribute API
1 parent 44eca9d commit 82d96e9

File tree

5 files changed

+87
-103
lines changed

5 files changed

+87
-103
lines changed

src/analysis.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ impl Analysis {
4949
}
5050

5151
pub fn extra_attrs(&self) -> Vec<Attribute> {
52-
unsafe {
53-
FromGlibPtrContainer::from_glib_none(self.0.extra_attrs)
54-
}
52+
unsafe { FromGlibPtrContainer::from_glib_none(self.0.extra_attrs) }
5553
}
5654
}
5755

src/attr_class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// See the COPYRIGHT file at the top-level directory of this distribution.
33
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
44

5-
use AttrType;
65
use glib::translate::from_glib;
76
use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, Stash, ToGlibPtr};
87
use pango_sys;
8+
use AttrType;
99

1010
#[doc(hidden)]
1111
impl<'a> ToGlibPtr<'a, *mut pango_sys::PangoAttrClass> for &'a AttrClass {

src/attr_color.rs

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/attribute.rs

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
// Copyright 2017, The Gtk-rs Project Developers.
22
// 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>
44

5-
use glib::translate::*;
6-
use pango_sys;
75
use AttrClass;
86
use Attribute;
7+
use FontDescription;
98
use Gravity;
109
use GravityHint;
10+
use Language;
11+
use Rectangle;
1112
use Stretch;
1213
use Style;
1314
use Underline;
14-
use Variant;
1515
use Weight;
1616

17+
use glib::translate::from_glib_full;
18+
use glib::translate::ToGlib;
19+
use glib::translate::ToGlibPtr;
20+
1721
impl Attribute {
1822
#[cfg(any(feature = "v1_38", feature = "dox"))]
1923
pub fn new_background_alpha(alpha: u16) -> Option<Attribute> {
@@ -32,10 +36,54 @@ impl Attribute {
3236
}
3337
}
3438

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+
3574
pub fn new_family(family: &str) -> Option<Attribute> {
3675
unsafe { from_glib_full(pango_sys::pango_attr_family_new(family.to_glib_none().0)) }
3776
}
3877

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+
3987
#[cfg(any(feature = "v1_38", feature = "dox"))]
4088
pub fn new_foreground_alpha(alpha: u16) -> Option<Attribute> {
4189
unsafe { from_glib_full(pango_sys::pango_attr_foreground_alpha_new(alpha)) }
@@ -61,18 +109,34 @@ impl Attribute {
61109
unsafe { from_glib_full(pango_sys::pango_attr_rise_new(rise)) }
62110
}
63111

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-
68112
pub fn new_size(size: i32) -> Option<Attribute> {
69113
unsafe { from_glib_full(pango_sys::pango_attr_size_new(size)) }
70114
}
71115

72-
pub fn new_size_absolute(size: i32) -> Option<Attribute> {
116+
pub fn new_absolute_size(size: i32) -> Option<Attribute> {
73117
unsafe { from_glib_full(pango_sys::pango_attr_size_new_absolute(size)) }
74118
}
75119

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+
76140
pub fn new_stretch(stretch: Stretch) -> Option<Attribute> {
77141
unsafe { from_glib_full(pango_sys::pango_attr_stretch_new(stretch.to_glib())) }
78142
}
@@ -105,9 +169,9 @@ impl Attribute {
105169
unsafe { from_glib_full(pango_sys::pango_attr_underline_new(underline.to_glib())) }
106170
}
107171

108-
pub fn new_variant(variant: Variant) -> Option<Attribute> {
172+
/*pub fn attr_variant_new(variant: Variant) -> Option<Attribute> {
109173
unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) }
110-
}
174+
}*/
111175

112176
pub fn new_weight(weight: Weight) -> Option<Attribute> {
113177
unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) }
@@ -117,31 +181,31 @@ impl Attribute {
117181
unsafe { from_glib_full((*self.to_glib_none().0).klass) }
118182
}
119183

120-
pub fn get_start_index(&self) -> u32 {
184+
pub fn get_end_index(&self) -> u32 {
121185
unsafe {
122186
let stash = self.to_glib_none();
123-
(*stash.0).start_index
187+
(*stash.0).end_index
124188
}
125189
}
126190

127-
pub fn get_end_index(&self) -> u32 {
191+
pub fn set_end_index(&mut self, index: u32) {
128192
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;
131195
}
132196
}
133197

134-
pub fn set_start_index(&mut self, index: u32) {
198+
pub fn get_start_index(&self) -> u32 {
135199
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
138202
}
139203
}
140204

141-
pub fn set_end_index(&mut self, index: u32) {
205+
pub fn set_start_index(&mut self, index: u32) {
142206
unsafe {
143207
let stash = self.to_glib_none_mut();
144-
(*stash.0).end_index = index;
208+
(*stash.0).start_index = index;
145209
}
146210
}
147211
}

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ pub mod analysis;
3131
pub use analysis::Analysis;
3232
pub mod attr_class;
3333
pub use attr_class::AttrClass;
34-
pub mod attr_color;
35-
pub use attr_color::AttrColor;
3634
pub mod attr_iterator;
3735
pub mod attr_list;
3836
pub mod attribute;

0 commit comments

Comments
 (0)