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

Commit

Permalink
Merge pull request #821 from jf2048/more-ext
Browse files Browse the repository at this point in the history
Shorten and seal subclass traits, ExtManual traits
  • Loading branch information
GuillaumeGomez committed May 5, 2023
2 parents db377a7 + 063b0a8 commit 632273a
Show file tree
Hide file tree
Showing 55 changed files with 439 additions and 459 deletions.
7 changes: 6 additions & 1 deletion atk/src/editable_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::EditableText;
use glib::object::IsA;
use glib::translate::*;

pub trait EditableTextExtManual: IsA<EditableText> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::EditableText>> Sealed for T {}
}

pub trait EditableTextExtManual: IsA<EditableText> + sealed::Sealed + 'static {
#[doc(alias = "atk_editable_text_insert_text")]
fn insert_text(&self, string: &str, mut position: i32) -> i32 {
let length = string.len() as i32;
Expand Down
7 changes: 6 additions & 1 deletion atk/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::Table;
use glib::object::IsA;
use glib::translate::*;

pub trait TableExtManual: IsA<Table> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Table>> Sealed for T {}
}

pub trait TableExtManual: IsA<Table> + sealed::Sealed + 'static {
#[doc(alias = "atk_table_get_selected_columns")]
#[doc(alias = "get_selected_columns")]
fn selected_columns(&self) -> Vec<i32> {
Expand Down
7 changes: 6 additions & 1 deletion gdk/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ use glib::translate::*;
use std::mem;
use std::ptr;

pub trait DeviceExtManual: IsA<Device> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Device>> Sealed for T {}
}

pub trait DeviceExtManual: IsA<Device> + sealed::Sealed + 'static {
#[doc(alias = "gdk_device_get_axis")]
#[doc(alias = "get_axis")]
fn is_axis(&self, axes: &mut [f64], use_: AxisUse, value: &mut f64) -> bool {
Expand Down
7 changes: 6 additions & 1 deletion gdk/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ impl Backend {
}
}

pub trait DisplayExtManual: IsA<Display> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Display>> Sealed for T {}
}

pub trait DisplayExtManual: IsA<Display> + sealed::Sealed + 'static {
// rustdoc-stripper-ignore-next
/// Get the currently used display backend
fn backend(&self) -> Backend {
Expand Down
7 changes: 6 additions & 1 deletion gdk/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ impl Window {
}
}

pub trait WindowExtManual: IsA<Window> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Window>> Sealed for T {}
}

pub trait WindowExtManual: IsA<Window> + sealed::Sealed + 'static {
#[doc(alias = "gdk_window_set_user_data")]
unsafe fn set_user_data<T>(&self, user_data: &mut T) {
ffi::gdk_window_set_user_data(
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/accel_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use glib::object::{Cast, IsA};
use glib::translate::*;
use glib::ToValue;

pub trait AccelGroupExtManual: IsA<AccelGroup> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::AccelGroup>> Sealed for T {}
}

pub trait AccelGroupExtManual: IsA<AccelGroup> + sealed::Sealed + 'static {
fn connect_accel_group<F>(
&self,
accel_key: u32,
Expand Down
23 changes: 11 additions & 12 deletions gtk/src/app_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ glib::wrapper! {
}
}

pub trait AppChooserExt: 'static {
#[doc(alias = "gtk_app_chooser_get_app_info")]
#[doc(alias = "get_app_info")]
fn app_info(&self) -> Option<AppInfo>;

#[doc(alias = "gtk_app_chooser_get_content_type")]
#[doc(alias = "get_content_type")]
fn content_type(&self) -> Option<String>;

#[doc(alias = "gtk_app_chooser_refresh")]
fn refresh(&self);
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::AppChooser>> Sealed for T {}
}

impl<O: IsA<AppChooser>> AppChooserExt for O {
pub trait AppChooserExt: IsA<AppChooser> + sealed::Sealed + 'static {
#[doc(alias = "gtk_app_chooser_get_app_info")]
#[doc(alias = "get_app_info")]
fn app_info(&self) -> Option<AppInfo> {
unsafe {
from_glib_full(ffi::gtk_app_chooser_get_app_info(
Expand All @@ -35,6 +29,8 @@ impl<O: IsA<AppChooser>> AppChooserExt for O {
}
}

#[doc(alias = "gtk_app_chooser_get_content_type")]
#[doc(alias = "get_content_type")]
fn content_type(&self) -> Option<String> {
unsafe {
from_glib_full(ffi::gtk_app_chooser_get_content_type(
Expand All @@ -43,7 +39,10 @@ impl<O: IsA<AppChooser>> AppChooserExt for O {
}
}

#[doc(alias = "gtk_app_chooser_refresh")]
fn refresh(&self) {
unsafe { ffi::gtk_app_chooser_refresh(self.as_ref().to_glib_none().0) }
}
}

impl<O: IsA<AppChooser>> AppChooserExt for O {}
7 changes: 6 additions & 1 deletion gtk/src/buildable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::Buildable;
use glib::translate::*;
use glib::IsA;

pub trait BuildableExtManual: IsA<Buildable> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Buildable>> Sealed for T {}
}

pub trait BuildableExtManual: IsA<Buildable> + sealed::Sealed + 'static {
#[doc(alias = "gtk_buildable_get_name")]
#[doc(alias = "get_buildable_name")]
fn buildable_name(&self) -> Option<String> {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ impl Builder {
}
}

pub trait BuilderExtManual: IsA<Builder> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Builder>> Sealed for T {}
}

pub trait BuilderExtManual: IsA<Builder> + sealed::Sealed + 'static {
#[doc(alias = "gtk_builder_get_object")]
#[doc(alias = "get_object")]
fn object<T: IsA<Object>>(&self, name: &str) -> Option<T> {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/color_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use glib::object::IsA;
use glib::translate::*;
use std::mem;

pub trait ColorButtonExtManual: IsA<ColorButton> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::ColorButton>> Sealed for T {}
}

pub trait ColorButtonExtManual: IsA<ColorButton> + sealed::Sealed + 'static {
#[doc(alias = "gtk_color_button_new_with_color")]
fn with_color(color: &gdk::Color) -> ColorButton {
assert_initialized_main_thread!();
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/color_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use glib::object::IsA;
use glib::translate::*;
use libc::c_int;

pub trait ColorChooserExtManual: IsA<ColorChooser> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::ColorChooser>> Sealed for T {}
}

pub trait ColorChooserExtManual: IsA<ColorChooser> + sealed::Sealed + 'static {
#[doc(alias = "gtk_color_chooser_add_palette")]
fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &[RGBA]) {
unsafe {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::ComboBox;
use glib::object::IsA;
use glib::translate::*;

pub trait ComboBoxExtManual: IsA<ComboBox> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::ComboBox>> Sealed for T {}
}

pub trait ComboBoxExtManual: IsA<ComboBox> + sealed::Sealed + 'static {
#[doc(alias = "gtk_combo_box_set_active")]
fn set_active(&self, index_: Option<u32>) {
let index_ = match index_ {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::{Container, Widget};
use glib::translate::*;
use glib::{value::FromValue, IsA, ToValue};

pub trait ContainerExtManual: IsA<Container> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Container>> Sealed for T {}
}

pub trait ContainerExtManual: IsA<Container> + sealed::Sealed + 'static {
#[doc(alias = "gtk_container_child_get_property")]
fn child_property_value(&self, child: &impl IsA<Widget>, property_name: &str) -> glib::Value {
unsafe {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ impl Dialog {
}
}

pub trait DialogExtManual: IsA<Dialog> + IsA<Widget> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Dialog> + glib::IsA<crate::Widget>> Sealed for T {}
}

pub trait DialogExtManual: IsA<Dialog> + IsA<Widget> + sealed::Sealed + 'static {
#[doc(alias = "gtk_dialog_add_buttons")]
fn add_buttons(&self, buttons: &[(&str, ResponseType)]) {
for &(text, id) in buttons {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/drag_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::Widget;
use glib::object::IsA;
use glib::translate::*;

pub trait DragContextExtManual: IsA<gdk::DragContext> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<gdk::DragContext>> Sealed for T {}
}

pub trait DragContextExtManual: IsA<gdk::DragContext> + sealed::Sealed + 'static {
#[doc(alias = "gtk_drag_finish")]
fn drag_finish(&self, success: bool, del: bool, time_: u32) {
unsafe {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use std::convert::TryFrom;

use crate::Entry;

pub trait EntryExtManual: IsA<Entry> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Entry>> Sealed for T {}
}

pub trait EntryExtManual: IsA<Entry> + sealed::Sealed + 'static {
#[doc(alias = "gtk_entry_get_invisible_char")]
#[doc(alias = "get_invisible_char")]
fn invisible_char(&self) -> Option<char> {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/entry_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use glib::object::IsA;
use glib::translate::*;
use glib::Cast;

pub trait EntryCompletionExtManual: IsA<EntryCompletion> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::EntryCompletion>> Sealed for T {}
}

pub trait EntryCompletionExtManual: IsA<EntryCompletion> + sealed::Sealed + 'static {
#[doc(alias = "gtk_entry_completion_get_entry")]
#[doc(alias = "get_entry")]
fn entry(&self) -> Option<Entry> {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/file_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use glib::IsA;

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`FileChooser`](crate::FileChooser).
pub trait FileChooserExtManual: IsA<FileChooser> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::FileChooser>> Sealed for T {}
}

pub trait FileChooserExtManual: IsA<FileChooser> + sealed::Sealed + 'static {
#[cfg(any(feature = "v3_22", docsrs))]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_22")))]
#[doc(alias = "gtk_file_chooser_add_choice")]
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ fn has_widget<O: IsA<Fixed>, T: IsA<Widget>>(c: &O, item: &T) -> bool {
}
}

pub trait FixedExtManual: IsA<Fixed> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Fixed>> Sealed for T {}
}

pub trait FixedExtManual: IsA<Fixed> + sealed::Sealed + 'static {
#[doc(alias = "get_child_x")]
fn child_x<T: IsA<Widget>>(&self, item: &T) -> i32 {
assert!(
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/flow_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use glib::object::IsA;
use glib::translate::*;
use std::ptr;

pub trait FlowBoxExtManual: IsA<FlowBox> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::FlowBox>> Sealed for T {}
}

pub trait FlowBoxExtManual: IsA<FlowBox> + sealed::Sealed + 'static {
fn unbind_model(&self) {
unsafe {
ffi::gtk_flow_box_bind_model(
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/gesture_stylus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use gdk::AxisUse;
use glib::object::IsA;
use glib::translate::*;

pub trait GestureStylusExtManual: IsA<GestureStylus> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::GestureStylus>> Sealed for T {}
}

pub trait GestureStylusExtManual: IsA<GestureStylus> + sealed::Sealed + 'static {
#[cfg(any(feature = "v3_24", docsrs))]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
#[doc(alias = "gtk_gesture_stylus_get_axes")]
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/im_context_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use glib::translate::*;
use glib::IsA;
use std::path::Path;

pub trait IMContextSimpleExtManual: IsA<IMContextSimple> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::IMContextSimple>> Sealed for T {}
}

pub trait IMContextSimpleExtManual: IsA<IMContextSimple> + sealed::Sealed + 'static {
#[doc(alias = "gtk_im_context_simple_add_compose_file")]
fn add_compose_file<P: AsRef<Path>>(&self, compose_file: P) {
unsafe {
Expand Down
7 changes: 6 additions & 1 deletion gtk/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use glib::Cast;
use std::boxed::Box as Box_;
use std::mem::transmute;

pub trait ImageExtManual: IsA<Image> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Image>> Sealed for T {}
}

pub trait ImageExtManual: IsA<Image> + sealed::Sealed + 'static {
#[doc(alias = "icon-size")]
fn icon_size(&self) -> IconSize {
unsafe { from_glib(self.as_ref().property::<i32>("icon-size")) }
Expand Down
13 changes: 8 additions & 5 deletions gtk/src/invisible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use glib::translate::{from_glib_none, ToGlibPtr};
use glib::IsA;

// For some reasons, it's not generated...
pub trait InvisibleExtManual: 'static {
#[doc(alias = "gtk_invisible_get_screen")]
#[doc(alias = "get_screen")]
fn screen(&self) -> Option<gdk::Screen>;
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::Invisible>> Sealed for T {}
}

impl<T: IsA<Invisible>> InvisibleExtManual for T {
pub trait InvisibleExtManual: IsA<Invisible> + sealed::Sealed + 'static {
#[doc(alias = "gtk_invisible_get_screen")]
#[doc(alias = "get_screen")]
fn screen(&self) -> Option<gdk::Screen> {
unsafe {
from_glib_none(ffi::gtk_invisible_get_screen(
Expand All @@ -20,3 +21,5 @@ impl<T: IsA<Invisible>> InvisibleExtManual for T {
}
}
}

impl<T: IsA<Invisible>> InvisibleExtManual for T {}
7 changes: 6 additions & 1 deletion gtk/src/list_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use glib::object::IsA;
use glib::translate::*;
use std::ptr;

pub trait ListBoxExtManual: IsA<ListBox> + 'static {
mod sealed {
pub trait Sealed {}
impl<T: glib::IsA<crate::ListBox>> Sealed for T {}
}

pub trait ListBoxExtManual: IsA<ListBox> + sealed::Sealed + 'static {
fn unbind_model(&self) {
unsafe {
ffi::gtk_list_box_bind_model(
Expand Down

0 comments on commit 632273a

Please sign in to comment.