Skip to content

Commit

Permalink
gtk: Generate new v4.10 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Oct 27, 2022
1 parent 7c76d1e commit e70c716
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 14 deletions.
1 change: 1 addition & 0 deletions gtk4/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ generate = [
"Gtk.CellRendererState",
"Gtk.CenterBox",
"Gtk.CenterLayout",
"Gtk.Collation",
"Gtk.ColorButton",
"Gtk.ColorChooserDialog",
"Gtk.ColorChooserWidget",
Expand Down
105 changes: 105 additions & 0 deletions gtk4/src/auto/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,111 @@ impl ToValue for CellRendererMode {
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GtkCollation")]
pub enum Collation {
#[doc(alias = "GTK_COLLATION_NONE")]
None,
#[doc(alias = "GTK_COLLATION_UNICODE")]
Unicode,
#[doc(alias = "GTK_COLLATION_FILENAME")]
Filename,
#[doc(hidden)]
__Unknown(i32),
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
impl fmt::Display for Collation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Collation::{}",
match *self {
Self::None => "None",
Self::Unicode => "Unicode",
Self::Filename => "Filename",
_ => "Unknown",
}
)
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
#[doc(hidden)]
impl IntoGlib for Collation {
type GlibType = ffi::GtkCollation;

fn into_glib(self) -> ffi::GtkCollation {
match self {
Self::None => ffi::GTK_COLLATION_NONE,
Self::Unicode => ffi::GTK_COLLATION_UNICODE,
Self::Filename => ffi::GTK_COLLATION_FILENAME,
Self::__Unknown(value) => value,
}
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
#[doc(hidden)]
impl FromGlib<ffi::GtkCollation> for Collation {
unsafe fn from_glib(value: ffi::GtkCollation) -> Self {
skip_assert_initialized!();
match value {
ffi::GTK_COLLATION_NONE => Self::None,
ffi::GTK_COLLATION_UNICODE => Self::Unicode,
ffi::GTK_COLLATION_FILENAME => Self::Filename,
value => Self::__Unknown(value),
}
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
impl StaticType for Collation {
fn static_type() -> Type {
unsafe { from_glib(ffi::gtk_collation_get_type()) }
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
impl glib::value::ValueType for Collation {
type Type = Self;
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
unsafe impl<'a> FromValue<'a> for Collation {
type Checker = glib::value::GenericValueTypeChecker<Self>;

unsafe fn from_value(value: &'a glib::Value) -> Self {
skip_assert_initialized!();
from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
}
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
impl ToValue for Collation {
fn to_value(&self) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
unsafe {
glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
}
value
}

fn value_type(&self) -> glib::Type {
Self::static_type()
}
}

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GtkConstraintAttribute")]
Expand Down
3 changes: 3 additions & 0 deletions gtk4/src/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,9 @@ pub use self::enums::BuilderError;
pub use self::enums::ButtonsType;
pub use self::enums::CellRendererAccelMode;
pub use self::enums::CellRendererMode;
#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
pub use self::enums::Collation;
pub use self::enums::ConstraintAttribute;
pub use self::enums::ConstraintRelation;
pub use self::enums::ConstraintStrength;
Expand Down
46 changes: 32 additions & 14 deletions gtk4/src/auto/string_sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
use crate::Collation;
use crate::Expression;
use crate::Sorter;
use glib::object::Cast;
Expand Down Expand Up @@ -44,13 +47,13 @@ impl StringSorter {
StringSorterBuilder::default()
}

//#[cfg(any(feature = "v4_10", feature = "dox"))]
//#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
//#[doc(alias = "gtk_string_sorter_get_collation")]
//#[doc(alias = "get_collation")]
//pub fn collation(&self) -> /*Ignored*/Collation {
// unsafe { TODO: call ffi:gtk_string_sorter_get_collation() }
//}
#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
#[doc(alias = "gtk_string_sorter_get_collation")]
#[doc(alias = "get_collation")]
pub fn collation(&self) -> Collation {
unsafe { from_glib(ffi::gtk_string_sorter_get_collation(self.to_glib_none().0)) }
}

#[doc(alias = "gtk_string_sorter_get_expression")]
#[doc(alias = "get_expression")]
Expand All @@ -68,12 +71,14 @@ impl StringSorter {
}
}

//#[cfg(any(feature = "v4_10", feature = "dox"))]
//#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
//#[doc(alias = "gtk_string_sorter_set_collation")]
//pub fn set_collation(&self, collation: /*Ignored*/Collation) {
// unsafe { TODO: call ffi:gtk_string_sorter_set_collation() }
//}
#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
#[doc(alias = "gtk_string_sorter_set_collation")]
pub fn set_collation(&self, collation: Collation) {
unsafe {
ffi::gtk_string_sorter_set_collation(self.to_glib_none().0, collation.into_glib());
}
}

#[doc(alias = "gtk_string_sorter_set_expression")]
pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
Expand Down Expand Up @@ -177,7 +182,9 @@ impl Default for StringSorter {
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct StringSorterBuilder {
//collation: /*Unknown type*/,
#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
collation: Option<Collation>,
expression: Option<Expression>,
ignore_case: Option<bool>,
}
Expand All @@ -194,6 +201,10 @@ impl StringSorterBuilder {
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> StringSorter {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
#[cfg(any(feature = "v4_10", feature = "dox"))]
if let Some(ref collation) = self.collation {
properties.push(("collation", collation));
}
if let Some(ref expression) = self.expression {
properties.push(("expression", expression));
}
Expand All @@ -203,6 +214,13 @@ impl StringSorterBuilder {
glib::Object::new::<StringSorter>(&properties)
}

#[cfg(any(feature = "v4_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))]
pub fn collation(mut self, collation: Collation) -> Self {
self.collation = Some(collation);
self
}

pub fn expression(mut self, expression: impl AsRef<Expression>) -> Self {
self.expression = Some(expression.as_ref().clone());
self
Expand Down

0 comments on commit e70c716

Please sign in to comment.