Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit b10a29d

Browse files
authored
Merge pull request #212 from sophie-h/pango-new-attributes
Add new pango attributes
2 parents 991981e + a3162c9 commit b10a29d

File tree

2 files changed

+89
-29
lines changed

2 files changed

+89
-29
lines changed

examples/src/bin/pango_attributes.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,21 @@ fn build_ui(application: &gtk::Application) {
1818
let label = gtk::Label::new(Some("Some text"));
1919
let attr_list = pango::AttrList::new();
2020

21-
let mut attr =
22-
pango::Attribute::new_background(65535, 0, 0).expect("Couldn't create new background");
21+
let mut attr = pango::Attribute::new_background(65535, 0, 0);
2322
attr.set_start_index(0);
2423
attr.set_end_index(2);
2524
attr_list.insert(attr);
2625

27-
let mut attr = pango::Attribute::new_underline(pango::Underline::Single)
28-
.expect("Couldn't create new underline");
26+
let mut attr = pango::Attribute::new_underline(pango::Underline::Single);
2927
attr.set_start_index(1);
3028
attr.set_end_index(4);
3129
attr_list.insert(attr);
3230

33-
let mut attr =
34-
pango::Attribute::new_strikethrough(true).expect("Couldn't create new strikethrough");
31+
let mut attr = pango::Attribute::new_strikethrough(true);
3532
attr.set_start_index(5);
3633
attr_list.insert(attr);
3734

38-
let mut attr = pango::Attribute::new_scale(1.2).expect("Couldn't create new scale");
35+
let mut attr = pango::Attribute::new_scale(1.2);
3936
attr.set_start_index(6);
4037
attr_list.insert(attr);
4138

pango/src/attribute.rs

+85-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ use crate::AttrClass;
66
use crate::Attribute;
77
use crate::Gravity;
88
use crate::GravityHint;
9+
#[cfg(any(feature = "v1_46", feature = "dox"))]
10+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
11+
use crate::Overline;
12+
#[cfg(any(feature = "v1_44", feature = "dox"))]
13+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
14+
use crate::ShowFlags;
915
use crate::Stretch;
1016
use crate::Style;
1117
use crate::Underline;
@@ -14,97 +20,154 @@ use crate::Weight;
1420
use glib::translate::*;
1521

1622
impl Attribute {
23+
#[cfg(any(feature = "v1_44", feature = "dox"))]
24+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
25+
#[doc(alias = "pango_attr_allow_breaks_new")]
26+
pub fn new_allow_breaks(allow_breaks: bool) -> Attribute {
27+
unsafe { from_glib_full(ffi::pango_attr_allow_breaks_new(allow_breaks.to_glib())) }
28+
}
29+
1730
#[cfg(any(feature = "v1_38", feature = "dox"))]
1831
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_38")))]
19-
pub fn new_background_alpha(alpha: u16) -> Option<Attribute> {
32+
#[doc(alias = "pango_attr_background_alpha_new")]
33+
pub fn new_background_alpha(alpha: u16) -> Attribute {
2034
unsafe { from_glib_full(ffi::pango_attr_background_alpha_new(alpha)) }
2135
}
2236

23-
pub fn new_background(red: u16, green: u16, blue: u16) -> Option<Attribute> {
37+
#[doc(alias = "pango_attr_background_new")]
38+
pub fn new_background(red: u16, green: u16, blue: u16) -> Attribute {
2439
unsafe { from_glib_full(ffi::pango_attr_background_new(red, green, blue)) }
2540
}
2641

27-
pub fn new_fallback(enable_fallback: bool) -> Option<Attribute> {
42+
#[doc(alias = "pango_attr_fallback_new")]
43+
pub fn new_fallback(enable_fallback: bool) -> Attribute {
2844
unsafe { from_glib_full(ffi::pango_attr_fallback_new(enable_fallback.to_glib())) }
2945
}
3046

31-
pub fn new_family(family: &str) -> Option<Attribute> {
47+
#[doc(alias = "pango_attr_family_new")]
48+
pub fn new_family(family: &str) -> Attribute {
3249
unsafe { from_glib_full(ffi::pango_attr_family_new(family.to_glib_none().0)) }
3350
}
3451

3552
#[cfg(any(feature = "v1_38", feature = "dox"))]
3653
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_38")))]
37-
pub fn new_font_features(features: &str) -> Option<Attribute> {
54+
#[doc(alias = "pango_attr_font_features_new")]
55+
pub fn new_font_features(features: &str) -> Attribute {
3856
unsafe { from_glib_full(ffi::pango_attr_font_features_new(features.to_glib_none().0)) }
3957
}
4058

4159
#[cfg(any(feature = "v1_38", feature = "dox"))]
4260
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_38")))]
43-
pub fn new_foreground_alpha(alpha: u16) -> Option<Attribute> {
61+
#[doc(alias = "pango_attr_foreground_alpha_new")]
62+
pub fn new_foreground_alpha(alpha: u16) -> Attribute {
4463
unsafe { from_glib_full(ffi::pango_attr_foreground_alpha_new(alpha)) }
4564
}
4665

47-
pub fn new_foreground(red: u16, green: u16, blue: u16) -> Option<Attribute> {
66+
#[doc(alias = "pango_attr_foreground_new")]
67+
pub fn new_foreground(red: u16, green: u16, blue: u16) -> Attribute {
4868
unsafe { from_glib_full(ffi::pango_attr_foreground_new(red, green, blue)) }
4969
}
5070

51-
pub fn new_gravity_hint(hint: GravityHint) -> Option<Attribute> {
71+
#[doc(alias = "pango_attr_gravity_hint_new")]
72+
pub fn new_gravity_hint(hint: GravityHint) -> Attribute {
5273
unsafe { from_glib_full(ffi::pango_attr_gravity_hint_new(hint.to_glib())) }
5374
}
5475

55-
pub fn new_gravity(gravity: Gravity) -> Option<Attribute> {
76+
#[doc(alias = "pango_attr_gravity_new")]
77+
pub fn new_gravity(gravity: Gravity) -> Attribute {
5678
unsafe { from_glib_full(ffi::pango_attr_gravity_new(gravity.to_glib())) }
5779
}
5880

59-
pub fn new_letter_spacing(letter_spacing: i32) -> Option<Attribute> {
81+
#[cfg(any(feature = "v1_44", feature = "dox"))]
82+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
83+
#[doc(alias = "pango_attr_insert_hyphens_new")]
84+
pub fn new_insert_hyphens(insert_hyphens: bool) -> Attribute {
85+
unsafe { from_glib_full(ffi::pango_attr_insert_hyphens_new(insert_hyphens.to_glib())) }
86+
}
87+
88+
#[doc(alias = "pango_attr_letter_spacing_new")]
89+
pub fn new_letter_spacing(letter_spacing: i32) -> Attribute {
6090
unsafe { from_glib_full(ffi::pango_attr_letter_spacing_new(letter_spacing)) }
6191
}
6292

63-
pub fn new_rise(rise: i32) -> Option<Attribute> {
93+
#[cfg(any(feature = "v1_46", feature = "dox"))]
94+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
95+
#[doc(alias = "pango_attr_overline_color_new")]
96+
pub fn new_overline_color(red: u16, green: u16, blue: u16) -> Attribute {
97+
unsafe { from_glib_full(ffi::pango_attr_overline_color_new(red, green, blue)) }
98+
}
99+
100+
#[cfg(any(feature = "v1_46", feature = "dox"))]
101+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_46")))]
102+
#[doc(alias = "pango_attr_overline_new")]
103+
pub fn new_overline(overline: Overline) -> Attribute {
104+
unsafe { from_glib_full(ffi::pango_attr_overline_new(overline.to_glib())) }
105+
}
106+
107+
#[doc(alias = "pango_attr_rise_new")]
108+
pub fn new_rise(rise: i32) -> Attribute {
64109
unsafe { from_glib_full(ffi::pango_attr_rise_new(rise)) }
65110
}
66111

67-
pub fn new_scale(scale_factor: f64) -> Option<Attribute> {
112+
#[doc(alias = "pango_attr_scale_new")]
113+
pub fn new_scale(scale_factor: f64) -> Attribute {
68114
unsafe { from_glib_full(ffi::pango_attr_scale_new(scale_factor)) }
69115
}
70116

71-
pub fn new_size(size: i32) -> Option<Attribute> {
117+
#[cfg(any(feature = "v1_44", feature = "dox"))]
118+
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
119+
#[doc(alias = "pango_attr_show_new")]
120+
pub fn new_show(flags: ShowFlags) -> Attribute {
121+
unsafe { from_glib_full(ffi::pango_attr_show_new(flags.to_glib())) }
122+
}
123+
124+
#[doc(alias = "pango_attr_size_new")]
125+
pub fn new_size(size: i32) -> Attribute {
72126
unsafe { from_glib_full(ffi::pango_attr_size_new(size)) }
73127
}
74128

75-
pub fn new_size_absolute(size: i32) -> Option<Attribute> {
129+
#[doc(alias = "pango_attr_size_new_absolute")]
130+
pub fn new_size_absolute(size: i32) -> Attribute {
76131
unsafe { from_glib_full(ffi::pango_attr_size_new_absolute(size)) }
77132
}
78133

79-
pub fn new_stretch(stretch: Stretch) -> Option<Attribute> {
134+
#[doc(alias = "pango_attr_stretch_new")]
135+
pub fn new_stretch(stretch: Stretch) -> Attribute {
80136
unsafe { from_glib_full(ffi::pango_attr_stretch_new(stretch.to_glib())) }
81137
}
82138

83-
pub fn new_strikethrough_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
139+
#[doc(alias = "pango_attr_strikethrough_color_new")]
140+
pub fn new_strikethrough_color(red: u16, green: u16, blue: u16) -> Attribute {
84141
unsafe { from_glib_full(ffi::pango_attr_strikethrough_color_new(red, green, blue)) }
85142
}
86143

87-
pub fn new_strikethrough(strikethrough: bool) -> Option<Attribute> {
144+
#[doc(alias = "pango_attr_strikethrough_new")]
145+
pub fn new_strikethrough(strikethrough: bool) -> Attribute {
88146
unsafe { from_glib_full(ffi::pango_attr_strikethrough_new(strikethrough.to_glib())) }
89147
}
90148

91-
pub fn new_style(style: Style) -> Option<Attribute> {
149+
#[doc(alias = "pango_attr_style_new")]
150+
pub fn new_style(style: Style) -> Attribute {
92151
unsafe { from_glib_full(ffi::pango_attr_style_new(style.to_glib())) }
93152
}
94153

95-
pub fn new_underline_color(red: u16, green: u16, blue: u16) -> Option<Attribute> {
154+
#[doc(alias = "pango_attr_underline_color_new")]
155+
pub fn new_underline_color(red: u16, green: u16, blue: u16) -> Attribute {
96156
unsafe { from_glib_full(ffi::pango_attr_underline_color_new(red, green, blue)) }
97157
}
98158

99-
pub fn new_underline(underline: Underline) -> Option<Attribute> {
159+
#[doc(alias = "pango_attr_underline_new")]
160+
pub fn new_underline(underline: Underline) -> Attribute {
100161
unsafe { from_glib_full(ffi::pango_attr_underline_new(underline.to_glib())) }
101162
}
102163

103-
pub fn new_variant(variant: Variant) -> Option<Attribute> {
164+
#[doc(alias = "pango_attr_variant_new")]
165+
pub fn new_variant(variant: Variant) -> Attribute {
104166
unsafe { from_glib_full(ffi::pango_attr_variant_new(variant.to_glib())) }
105167
}
106168

107-
pub fn new_weight(weight: Weight) -> Option<Attribute> {
169+
#[doc(alias = "pango_attr_weight_new")]
170+
pub fn new_weight(weight: Weight) -> Attribute {
108171
unsafe { from_glib_full(ffi::pango_attr_weight_new(weight.to_glib())) }
109172
}
110173

0 commit comments

Comments
 (0)