-
-
Notifications
You must be signed in to change notification settings - Fork 24
Allow to get Color from Analysis #168
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
// Copyright 2017, The Gtk-rs Project Developers. | ||
// See the COPYRIGHT file at the top-level directory of this distribution. | ||
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> | ||
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> | ||
|
||
use glib::translate::*; | ||
use pango_sys; | ||
use AttrClass; | ||
use Attribute; | ||
use FontDescription; | ||
use Gravity; | ||
use GravityHint; | ||
use Language; | ||
use Rectangle; | ||
use Stretch; | ||
use Style; | ||
use Underline; | ||
use Variant; | ||
use Weight; | ||
|
||
use glib::translate::from_glib_full; | ||
use glib::translate::ToGlib; | ||
use glib::translate::ToGlibPtr; | ||
|
||
impl Attribute { | ||
#[cfg(any(feature = "v1_38", feature = "dox"))] | ||
pub fn new_background_alpha(alpha: u16) -> Option<Attribute> { | ||
|
@@ -32,10 +36,54 @@ impl Attribute { | |
} | ||
} | ||
|
||
// TODO: available at 1.44 | ||
// pub fn new_allow_breaks(allow_breaks: bool) -> Option<Attribute> { | ||
// unsafe { | ||
// from_glib_full(pango_sys::pango_attr_allow_breaks_new( | ||
// allow_breaks.to_glib(), | ||
// )) | ||
// } | ||
// } | ||
|
||
// TODO: available at 1.44 | ||
// pub fn new_insert_hyphens(insert_hyphens: bool) -> Option<Attribute> { | ||
// unsafe { | ||
// from_glib_full(pango_sys::pango_attr_insert_hyphens_new( | ||
// insert_hyphens.to_glib(), | ||
// )) | ||
// } | ||
// } | ||
|
||
// TODO: available at 1.44, needs PangoShowFlags | ||
// pub fn new_show(flags: PangoShowFlags) -> Option<Attribute> { | ||
// unsafe { | ||
// from_glib_full(pango_sys::pango_attr_show_new( | ||
// flags.to_glib(), | ||
// )) | ||
// } | ||
// } | ||
|
||
pub fn new_language(language: &Language) -> Option<Attribute> { | ||
unsafe { | ||
from_glib_full(pango_sys::pango_attr_language_new( | ||
language.to_glib_none().0, | ||
)) | ||
} | ||
} | ||
|
||
pub fn new_family(family: &str) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_family_new(family.to_glib_none().0)) } | ||
} | ||
|
||
#[cfg(any(feature = "v1_38", feature = "dox"))] | ||
pub fn new_font_features(features: &str) -> Option<Attribute> { | ||
unsafe { | ||
from_glib_full(pango_sys::pango_attr_font_features_new( | ||
features.to_glib_none().0, | ||
)) | ||
} | ||
} | ||
|
||
#[cfg(any(feature = "v1_38", feature = "dox"))] | ||
pub fn new_foreground_alpha(alpha: u16) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_foreground_alpha_new(alpha)) } | ||
|
@@ -61,18 +109,34 @@ impl Attribute { | |
unsafe { from_glib_full(pango_sys::pango_attr_rise_new(rise)) } | ||
} | ||
|
||
pub fn new_scale(scale_factor: f64) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) } | ||
} | ||
|
||
pub fn new_size(size: i32) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_size_new(size)) } | ||
} | ||
|
||
pub fn new_size_absolute(size: i32) -> Option<Attribute> { | ||
pub fn new_absolute_size(size: i32) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_size_new_absolute(size)) } | ||
} | ||
|
||
pub fn new_font_desc(desc: &FontDescription) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_font_desc_new(desc.to_glib_none().0)) } | ||
} | ||
|
||
pub fn new_shape( | ||
ink_rect: &Rectangle, | ||
logical_rect: &Rectangle, | ||
) -> Option<Attribute> { | ||
unsafe { | ||
from_glib_full(pango_sys::pango_attr_shape_new( | ||
ink_rect.to_glib_none().0, | ||
logical_rect.to_glib_none().0, | ||
)) | ||
} | ||
} | ||
|
||
pub fn new_scale(scale_factor: f64) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) } | ||
} | ||
|
||
pub fn new_stretch(stretch: Stretch) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_stretch_new(stretch.to_glib())) } | ||
} | ||
|
@@ -105,9 +169,9 @@ impl Attribute { | |
unsafe { from_glib_full(pango_sys::pango_attr_underline_new(underline.to_glib())) } | ||
} | ||
|
||
pub fn new_variant(variant: Variant) -> Option<Attribute> { | ||
/*pub fn attr_variant_new(variant: Variant) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) } | ||
} | ||
}*/ | ||
|
||
pub fn new_weight(weight: Weight) -> Option<Attribute> { | ||
unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) } | ||
|
@@ -117,31 +181,31 @@ impl Attribute { | |
unsafe { from_glib_full((*self.to_glib_none().0).klass) } | ||
} | ||
|
||
pub fn get_start_index(&self) -> u32 { | ||
pub fn get_end_index(&self) -> u32 { | ||
unsafe { | ||
let stash = self.to_glib_none(); | ||
(*stash.0).start_index | ||
(*stash.0).end_index | ||
} | ||
} | ||
|
||
pub fn get_end_index(&self) -> u32 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two getters at least seem useful, the setters maybe not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Don't remember why I removed them... |
||
pub fn set_end_index(&mut self, index: u32) { | ||
unsafe { | ||
let stash = self.to_glib_none(); | ||
(*stash.0).end_index | ||
let stash = self.to_glib_none_mut(); | ||
(*stash.0).end_index = index; | ||
} | ||
} | ||
|
||
pub fn set_start_index(&mut self, index: u32) { | ||
pub fn get_start_index(&self) -> u32 { | ||
unsafe { | ||
let stash = self.to_glib_none_mut(); | ||
(*stash.0).start_index = index; | ||
let stash = self.to_glib_none(); | ||
(*stash.0).start_index | ||
} | ||
} | ||
|
||
pub fn set_end_index(&mut self, index: u32) { | ||
pub fn set_start_index(&mut self, index: u32) { | ||
unsafe { | ||
let stash = self.to_glib_none_mut(); | ||
(*stash.0).end_index = index; | ||
(*stash.0).start_index = index; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at the auto impl maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I thought there's only the manual impl of it. Ok then |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2018, The Gtk-rs Project Developers. | ||
// See the COPYRIGHT file at the top-level directory of this distribution. | ||
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> | ||
|
||
use glib::translate::*; | ||
use Color; | ||
|
||
impl Color { | ||
pub fn red(&self) -> u16 { | ||
unsafe { | ||
let stash = self.to_glib_none(); | ||
(*stash.0).red | ||
} | ||
} | ||
|
||
pub fn green(&self) -> u16 { | ||
unsafe { | ||
let stash = self.to_glib_none(); | ||
(*stash.0).green | ||
} | ||
} | ||
|
||
pub fn blue(&self) -> u16 { | ||
unsafe { | ||
let stash = self.to_glib_none(); | ||
(*stash.0).blue | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and all the others too) should probably return an
AttributeBackgrondAlpha
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's all casted as
Attribute
in the source code. Also, it's not really supposed to be "used" so better not give access to the fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack