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

Commit 385dcec

Browse files
Improve Attribute API
1 parent 44eca9d commit 385dcec

File tree

5 files changed

+94
-147
lines changed

5 files changed

+94
-147
lines changed

src/analysis.rs

+1-3
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

+1-1
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

-76
This file was deleted.

src/attribute.rs

+92-65
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,174 @@
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-
5-
use glib::translate::*;
6-
use pango_sys;
7-
use AttrClass;
81
use Attribute;
2+
use FontDescription;
93
use Gravity;
104
use GravityHint;
5+
use Language;
6+
use Rectangle;
117
use Stretch;
128
use Style;
139
use Underline;
14-
use Variant;
1510
use Weight;
1611

12+
use glib::translate::from_glib_full;
13+
use glib::translate::ToGlib;
14+
use glib::translate::ToGlibPtr;
15+
1716
impl Attribute {
1817
#[cfg(any(feature = "v1_38", feature = "dox"))]
19-
pub fn new_background_alpha(alpha: u16) -> Option<Attribute> {
18+
pub fn background_alpha_new(alpha: u16) -> Option<Attribute> {
2019
unsafe { from_glib_full(pango_sys::pango_attr_background_alpha_new(alpha)) }
2120
}
2221

23-
pub fn new_background(red: u16, green: u16, blue: u16) -> Option<Attribute> {
22+
pub fn background_new(red: u16, green: u16, blue: u16) -> Option<Attribute> {
2423
unsafe { from_glib_full(pango_sys::pango_attr_background_new(red, green, blue)) }
2524
}
2625

27-
pub fn new_fallback(enable_fallback: bool) -> Option<Attribute> {
26+
pub fn fallback_new(enable_fallback: bool) -> Option<Attribute> {
2827
unsafe {
2928
from_glib_full(pango_sys::pango_attr_fallback_new(
3029
enable_fallback.to_glib(),
3130
))
3231
}
3332
}
3433

35-
pub fn new_family(family: &str) -> Option<Attribute> {
34+
// TODO: available at 1.44
35+
// pub fn allow_breaks_new(allow_breaks: bool) -> Option<Attribute> {
36+
// unsafe {
37+
// from_glib_full(pango_sys::pango_attr_allow_breaks_new(
38+
// allow_breaks.to_glib(),
39+
// ))
40+
// }
41+
// }
42+
43+
// TODO: available at 1.44
44+
// pub fn insert_hyphens_new(insert_hyphens: bool) -> Option<Attribute> {
45+
// unsafe {
46+
// from_glib_full(pango_sys::pango_attr_insert_hyphens_new(
47+
// insert_hyphens.to_glib(),
48+
// ))
49+
// }
50+
// }
51+
52+
// TODO: available at 1.44, needs PangoShowFlags
53+
// pub fn show_new(flags: PangoShowFlags) -> Option<Attribute> {
54+
// unsafe {
55+
// from_glib_full(pango_sys::pango_attr_show_new(
56+
// flags.to_glib(),
57+
// ))
58+
// }
59+
// }
60+
61+
pub fn language_new(language: &Language) -> Option<Attribute> {
62+
unsafe {
63+
from_glib_full(pango_sys::pango_attr_language_new(
64+
language.to_glib_none().0,
65+
))
66+
}
67+
}
68+
69+
pub fn family_new(family: &str) -> Option<Attribute> {
3670
unsafe { from_glib_full(pango_sys::pango_attr_family_new(family.to_glib_none().0)) }
3771
}
3872

3973
#[cfg(any(feature = "v1_38", feature = "dox"))]
40-
pub fn new_foreground_alpha(alpha: u16) -> Option<Attribute> {
74+
pub fn font_features_new(features: &str) -> Option<Attribute> {
75+
unsafe {
76+
from_glib_full(pango_sys::pango_attr_font_features_new(
77+
features.to_glib_none().0,
78+
))
79+
}
80+
}
81+
82+
#[cfg(any(feature = "v1_38", feature = "dox"))]
83+
pub fn foreground_alpha_new(alpha: u16) -> Option<Attribute> {
4184
unsafe { from_glib_full(pango_sys::pango_attr_foreground_alpha_new(alpha)) }
4285
}
4386

44-
pub fn new_foreground(red: u16, green: u16, blue: u16) -> Option<Attribute> {
87+
pub fn foreground_new(red: u16, green: u16, blue: u16) -> Option<Attribute> {
4588
unsafe { from_glib_full(pango_sys::pango_attr_foreground_new(red, green, blue)) }
4689
}
4790

48-
pub fn new_gravity_hint(hint: GravityHint) -> Option<Attribute> {
91+
pub fn gravity_hint_new(hint: GravityHint) -> Option<Attribute> {
4992
unsafe { from_glib_full(pango_sys::pango_attr_gravity_hint_new(hint.to_glib())) }
5093
}
5194

52-
pub fn new_gravity(gravity: Gravity) -> Option<Attribute> {
95+
pub fn gravity_new(gravity: Gravity) -> Option<Attribute> {
5396
unsafe { from_glib_full(pango_sys::pango_attr_gravity_new(gravity.to_glib())) }
5497
}
5598

56-
pub fn new_letter_spacing(letter_spacing: i32) -> Option<Attribute> {
99+
pub fn letter_spacing_new(letter_spacing: i32) -> Option<Attribute> {
57100
unsafe { from_glib_full(pango_sys::pango_attr_letter_spacing_new(letter_spacing)) }
58101
}
59102

60-
pub fn new_rise(rise: i32) -> Option<Attribute> {
103+
pub fn rise_new(rise: i32) -> Option<Attribute> {
61104
unsafe { from_glib_full(pango_sys::pango_attr_rise_new(rise)) }
62105
}
63106

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_size(size: i32) -> Option<Attribute> {
107+
pub fn size_new(size: i32) -> Option<Attribute> {
69108
unsafe { from_glib_full(pango_sys::pango_attr_size_new(size)) }
70109
}
71110

72-
pub fn new_size_absolute(size: i32) -> Option<Attribute> {
111+
pub fn size_new_absolute(size: i32) -> Option<Attribute> {
73112
unsafe { from_glib_full(pango_sys::pango_attr_size_new_absolute(size)) }
74113
}
75114

76-
pub fn new_stretch(stretch: Stretch) -> Option<Attribute> {
115+
pub fn font_desc_new(desc: &FontDescription) -> Option<Attribute> {
116+
unsafe { from_glib_full(pango_sys::pango_attr_font_desc_new(desc.to_glib_none().0)) }
117+
}
118+
119+
pub fn pango_attr_shape_new(
120+
ink_rect: &Rectangle,
121+
logical_rect: &Rectangle,
122+
) -> Option<Attribute> {
123+
unsafe {
124+
from_glib_full(pango_sys::pango_attr_shape_new(
125+
ink_rect.to_glib_none().0,
126+
logical_rect.to_glib_none().0,
127+
))
128+
}
129+
}
130+
131+
pub fn scale_new(scale_factor: f64) -> Option<Attribute> {
132+
unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) }
133+
}
134+
135+
pub fn stretch_new(stretch: Stretch) -> Option<Attribute> {
77136
unsafe { from_glib_full(pango_sys::pango_attr_stretch_new(stretch.to_glib())) }
78137
}
79138

80-
pub fn new_strikethrough_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
139+
pub fn strikethrough_color_new(red: u16, green: u16, blue: u16) -> Option<Attribute> {
81140
unsafe {
82141
from_glib_full(pango_sys::pango_attr_strikethrough_color_new(
83142
red, green, blue,
84143
))
85144
}
86145
}
87146

88-
pub fn new_strikethrough(strikethrough: bool) -> Option<Attribute> {
147+
pub fn strikethrough_new(strikethrough: bool) -> Option<Attribute> {
89148
unsafe {
90149
from_glib_full(pango_sys::pango_attr_strikethrough_new(
91150
strikethrough.to_glib(),
92151
))
93152
}
94153
}
95154

96-
pub fn new_style(style: Style) -> Option<Attribute> {
155+
pub fn style_new(style: Style) -> Option<Attribute> {
97156
unsafe { from_glib_full(pango_sys::pango_attr_style_new(style.to_glib())) }
98157
}
99158

100-
pub fn new_underline_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
159+
pub fn underline_color_new(red: u16, green: u16, blue: u16) -> Option<Attribute> {
101160
unsafe { from_glib_full(pango_sys::pango_attr_underline_color_new(red, green, blue)) }
102161
}
103162

104-
pub fn new_underline(underline: Underline) -> Option<Attribute> {
163+
pub fn underline_new(underline: Underline) -> Option<Attribute> {
105164
unsafe { from_glib_full(pango_sys::pango_attr_underline_new(underline.to_glib())) }
106165
}
107166

108-
pub fn new_variant(variant: Variant) -> Option<Attribute> {
167+
/*pub fn attr_variant_new(variant: Variant) -> Option<Attribute> {
109168
unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) }
110-
}
169+
}*/
111170

112-
pub fn new_weight(weight: Weight) -> Option<Attribute> {
171+
pub fn weight_new(weight: Weight) -> Option<Attribute> {
113172
unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) }
114173
}
115-
116-
pub fn get_attr_class(&self) -> AttrClass {
117-
unsafe { from_glib_full((*self.to_glib_none().0).klass) }
118-
}
119-
120-
pub fn get_start_index(&self) -> u32 {
121-
unsafe {
122-
let stash = self.to_glib_none();
123-
(*stash.0).start_index
124-
}
125-
}
126-
127-
pub fn get_end_index(&self) -> u32 {
128-
unsafe {
129-
let stash = self.to_glib_none();
130-
(*stash.0).end_index
131-
}
132-
}
133-
134-
pub fn set_start_index(&mut self, index: u32) {
135-
unsafe {
136-
let stash = self.to_glib_none_mut();
137-
(*stash.0).start_index = index;
138-
}
139-
}
140-
141-
pub fn set_end_index(&mut self, index: u32) {
142-
unsafe {
143-
let stash = self.to_glib_none_mut();
144-
(*stash.0).end_index = index;
145-
}
146-
}
147174
}

src/lib.rs

-2
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)