Skip to content

Commit

Permalink
Add interface bounds to Impls
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 23, 2024
1 parent 1626356 commit 8d2bf10
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 57 deletions.
7 changes: 5 additions & 2 deletions examples/composite_dialog/my_app_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#[allow(deprecated)]
mod imp;

use gtk::{glib, prelude::*, subclass::prelude::*};
use gtk::{gio, glib, prelude::*, subclass::prelude::*};

glib::wrapper! {
pub struct MyAppWindow(ObjectSubclass<imp::MyAppWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow;
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,
@implements gtk::Accessible, gio::ActionGroup, gio::ActionMap,
gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root,
gtk::ShortcutManager;
}

#[gtk::template_callbacks]
Expand Down
4 changes: 3 additions & 1 deletion examples/confetti_snapshot_animation/confetti_widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use gtk::{
use crate::{AnimatedExplosion, ExplosionParameters};

glib::wrapper! {
pub struct ConfettiWidget(ObjectSubclass<imp::ConfettiWidget>) @implements gtk::Widget;
pub struct ConfettiWidget(ObjectSubclass<imp::ConfettiWidget>)
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for ConfettiWidget {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_layout_manager/custom_layout_child/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::{gdk, glib};

glib::wrapper! {
pub struct CustomLayoutChild(ObjectSubclass<imp::CustomLayoutChild>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl CustomLayoutChild {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_layout_manager/simple_widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::custom_layout::CustomLayout;

glib::wrapper! {
pub struct SimpleWidget(ObjectSubclass<imp::SimpleWidget>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for SimpleWidget {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_orientable/custom_orientable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gtk::glib;
glib::wrapper! {
pub struct CustomOrientable(ObjectSubclass<imp::CustomOrientable>)
@extends gtk::Widget,
@implements gtk::Orientable;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
}

impl Default for CustomOrientable {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_widget/ex_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gtk::glib;
glib::wrapper! {
pub struct ExButton(ObjectSubclass<imp::ExButton>)
@extends gtk::Widget,
@implements gtk::Accessible;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for ExButton {
Expand Down
3 changes: 2 additions & 1 deletion examples/rotation_bin/rotation_bin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl From<Rotation> for f32 {

glib::wrapper! {
pub struct RotationBin(ObjectSubclass<imp::RotationBin>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for RotationBin {
Expand Down
3 changes: 2 additions & 1 deletion examples/scale_bin/scale_bin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::glib;

glib::wrapper! {
pub struct ScaleBin(ObjectSubclass<imp::ScaleBin>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for ScaleBin {
Expand Down
3 changes: 2 additions & 1 deletion examples/squares/squares_widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::glib;

glib::wrapper! {
pub struct SquaresWidget(ObjectSubclass<imp::SquaresWidget>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for SquaresWidget {
Expand Down
3 changes: 2 additions & 1 deletion examples/squeezer_bin/squeezer_bin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::glib;

glib::wrapper! {
pub struct SqueezerBin(ObjectSubclass<imp::SqueezerBin>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for SqueezerBin {
Expand Down
3 changes: 2 additions & 1 deletion examples/virtual_methods/base_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pub type PinnedFuture<T> = Pin<Box<dyn Future<Output = T>>>;
glib::wrapper! {
/// Public type for the `BaseButton` instances.
pub struct BaseButton(ObjectSubclass<imp::BaseButton>)
@extends gtk::Widget, gtk::Button;
@extends gtk::Widget, gtk::Button,
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for BaseButton {
Expand Down
3 changes: 2 additions & 1 deletion examples/virtual_methods/derived_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::glib;

glib::wrapper! {
pub struct DerivedButton(ObjectSubclass<imp::DerivedButton>)
@extends gtk::Widget, gtk::Button, crate::base_button::BaseButton;
@extends gtk::Widget, gtk::Button, crate::base_button::BaseButton,
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for DerivedButton {
Expand Down
12 changes: 9 additions & 3 deletions gtk4-macros/tests/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ mod imp {
}

glib::wrapper! {
pub struct MyWidget(ObjectSubclass<imp::MyWidget>) @extends gtk::Widget;
pub struct MyWidget(ObjectSubclass<imp::MyWidget>)
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

#[gtk::test]
Expand Down Expand Up @@ -145,7 +147,9 @@ mod imp2 {
}

glib::wrapper! {
pub struct MyWidget2(ObjectSubclass<imp2::MyWidget2>) @extends gtk::Widget;
pub struct MyWidget2(ObjectSubclass<imp2::MyWidget2>)
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

#[gtk::test]
Expand Down Expand Up @@ -192,7 +196,9 @@ mod imp3 {
}

glib::wrapper! {
pub struct MyWidget3(ObjectSubclass<imp3::MyWidget3>) @extends gtk::Widget;
pub struct MyWidget3(ObjectSubclass<imp3::MyWidget3>)
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

#[gtk::test]
Expand Down
4 changes: 3 additions & 1 deletion gtk4/src/subclass/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use crate::{prelude::*, subclass::prelude::*, ApplicationWindow};

pub trait ApplicationWindowImpl:
WindowImpl + ObjectSubclass<Type: IsA<ApplicationWindow>> + 'static
WindowImpl
+ ObjectSubclass<Type: IsA<ApplicationWindow> + IsA<gio::ActionGroup> + IsA<gio::ActionMap>>
+ 'static
{
}

Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Button};
use crate::{ffi, prelude::*, subclass::prelude::*, Actionable, Button};

pub trait ButtonImpl: WidgetImpl + ObjectSubclass<Type: IsA<Button>> {
pub trait ButtonImpl: WidgetImpl + ObjectSubclass<Type: IsA<Button> + IsA<Actionable>> {
fn activate(&self) {
self.parent_activate()
}
Expand Down
9 changes: 6 additions & 3 deletions gtk4/src/subclass/cell_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::mem;
use glib::{translate::*, ParamSpec, Value};

use crate::{
ffi, prelude::*, subclass::prelude::*, CellArea, CellAreaContext, CellRenderer,
CellRendererState, DirectionType, SizeRequestMode, Snapshot, TreeIter, TreeModel, Widget,
ffi, prelude::*, subclass::prelude::*, Buildable, CellArea, CellAreaContext, CellLayout,
CellRenderer, CellRendererState, DirectionType, SizeRequestMode, Snapshot, TreeIter, TreeModel,
Widget,
};

#[derive(Debug)]
Expand Down Expand Up @@ -63,7 +64,9 @@ impl CellCallbackAllocate {

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait CellAreaImpl: ObjectImpl + ObjectSubclass<Type: IsA<CellArea>> {
pub trait CellAreaImpl:
ObjectImpl + ObjectSubclass<Type: IsA<CellArea> + IsA<Buildable> + IsA<CellLayout>>
{
fn cell_properties() -> &'static [ParamSpec] {
&[]
}
Expand Down
2 changes: 1 addition & 1 deletion gtk4/src/subclass/cell_editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{ffi, prelude::*, subclass::prelude::*, CellEditable};

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait CellEditableImpl: ObjectImpl + ObjectSubclass<Type: IsA<CellEditable>> {
pub trait CellEditableImpl: WidgetImpl + ObjectSubclass<Type: IsA<CellEditable>> {
fn editing_done(&self) {
self.parent_editing_done()
}
Expand Down
6 changes: 4 additions & 2 deletions gtk4/src/subclass/check_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, CheckButton};
use crate::{ffi, prelude::*, subclass::prelude::*, Actionable, CheckButton};

pub trait CheckButtonImpl: WidgetImpl + ObjectSubclass<Type: IsA<CheckButton>> {
pub trait CheckButtonImpl:
WidgetImpl + ObjectSubclass<Type: IsA<CheckButton> + IsA<Actionable>>
{
fn toggled(&self) {
self.parent_toggled()
}
Expand Down
6 changes: 4 additions & 2 deletions gtk4/src/subclass/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

use glib::{translate::*, GString};

use crate::{ffi, prelude::*, subclass::prelude::*, ComboBox};
use crate::{ffi, prelude::*, subclass::prelude::*, CellEditable, CellLayout, ComboBox};

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait ComboBoxImpl: WidgetImpl + ObjectSubclass<Type: IsA<ComboBox>> {
pub trait ComboBoxImpl:
WidgetImpl + ObjectSubclass<Type: IsA<ComboBox> + IsA<CellEditable> + IsA<CellLayout>>
{
#[cfg(feature = "v4_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
fn activate(&self) {
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Entry};
use crate::{ffi, prelude::*, subclass::prelude::*, CellEditable, Entry};

pub trait EntryImpl: WidgetImpl + ObjectSubclass<Type: IsA<Entry>> {
pub trait EntryImpl: WidgetImpl + ObjectSubclass<Type: IsA<Entry> + IsA<CellEditable>> {
fn activate(&self) {
self.parent_activate()
}
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`Grid`].

use crate::{prelude::*, subclass::prelude::*, Grid};
use crate::{prelude::*, subclass::prelude::*, Grid, Orientable};

pub trait GridImpl: WidgetImpl + ObjectSubclass<Type: IsA<Grid>> {}
pub trait GridImpl: WidgetImpl + ObjectSubclass<Type: IsA<Grid> + IsA<Orientable>> {}

unsafe impl<T: GridImpl> IsSubclassable<T> for Grid {}
6 changes: 4 additions & 2 deletions gtk4/src/subclass/list_box_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, ListBoxRow};
use crate::{ffi, prelude::*, subclass::prelude::*, Actionable, ListBoxRow};

pub trait ListBoxRowImpl: WidgetImpl + ObjectSubclass<Type: IsA<ListBoxRow>> {
pub trait ListBoxRowImpl:
WidgetImpl + ObjectSubclass<Type: IsA<ListBoxRow> + IsA<Actionable>>
{
fn activate(&self) {
self.parent_activate()
}
Expand Down
5 changes: 4 additions & 1 deletion gtk4/src/subclass/media_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`MediaFile`].

use gdk::Paintable;
use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, MediaFile};

pub trait MediaFileImpl: MediaStreamImpl + ObjectSubclass<Type: IsA<MediaFile>> {
pub trait MediaFileImpl:
MediaStreamImpl + ObjectSubclass<Type: IsA<MediaFile> + IsA<Paintable>>
{
fn close(&self) {
self.parent_close()
}
Expand Down
5 changes: 4 additions & 1 deletion gtk4/src/subclass/media_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`MediaStream`].

use gdk::Paintable;
use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, MediaStream};

pub trait MediaStreamImpl: ObjectImpl + ObjectSubclass<Type: IsA<MediaStream>> {
pub trait MediaStreamImpl:
ObjectImpl + ObjectSubclass<Type: IsA<MediaStream> + IsA<Paintable>>
{
fn pause(&self) {
self.parent_pause()
}
Expand Down
6 changes: 4 additions & 2 deletions gtk4/src/subclass/popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Popover};
use crate::{ffi, prelude::*, subclass::prelude::*, Native, Popover, ShortcutManager};

pub trait PopoverImpl: WidgetImpl + ObjectSubclass<Type: IsA<Popover>> {
pub trait PopoverImpl:
WidgetImpl + ObjectSubclass<Type: IsA<Popover> + IsA<Native> + IsA<ShortcutManager>>
{
fn activate_default(&self) {
self.parent_activate_default()
}
Expand Down
2 changes: 1 addition & 1 deletion gtk4/src/subclass/print_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};

pub trait PrintOperationImpl:
PrintOperationPreviewImpl + ObjectSubclass<Type: IsA<PrintOperation>>
ObjectImpl + ObjectSubclass<Type: IsA<PrintOperation> + IsA<PrintOperationPreview>>
{
fn begin_print(&self, context: &PrintContext) {
self.parent_begin_print(context)
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Border, Range, ScrollType};
use crate::{ffi, prelude::*, subclass::prelude::*, Border, Orientable, Range, ScrollType};

pub trait RangeImpl: WidgetImpl + ObjectSubclass<Type: IsA<Range>> {
pub trait RangeImpl: WidgetImpl + ObjectSubclass<Type: IsA<Range> + IsA<Orientable>> {
fn adjust_bounds(&self, new_value: f64) {
self.parent_adjust_bounds(new_value)
}
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/subclass/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, Scale};
use crate::{ffi, prelude::*, subclass::prelude::*, Orientable, Scale};

pub trait ScaleImpl: RangeImpl + ObjectSubclass<Type: IsA<Scale>> {
pub trait ScaleImpl: RangeImpl + ObjectSubclass<Type: IsA<Scale> + IsA<Orientable>> {
#[doc(alias = "get_layout_offsets")]
fn layout_offsets(&self) -> (i32, i32) {
self.parent_layout_offsets()
Expand Down
6 changes: 4 additions & 2 deletions gtk4/src/subclass/scale_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

use glib::translate::*;

use crate::{ffi, prelude::*, subclass::prelude::*, ScaleButton};
use crate::{ffi, prelude::*, subclass::prelude::*, Orientable, ScaleButton};

pub trait ScaleButtonImpl: WidgetImpl + ObjectSubclass<Type: IsA<ScaleButton>> {
pub trait ScaleButtonImpl:
WidgetImpl + ObjectSubclass<Type: IsA<ScaleButton> + IsA<Orientable>>
{
fn value_changed(&self, new_value: f64) {
self.parent_value_changed(new_value)
}
Expand Down
6 changes: 3 additions & 3 deletions gtk4/src/subclass/text_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use glib::translate::*;

use crate::{
ffi, prelude::*, subclass::prelude::*, DeleteType, MovementStep, Snapshot, TextExtendSelection,
TextIter, TextView, TextViewLayer,
ffi, prelude::*, subclass::prelude::*, DeleteType, MovementStep, Scrollable, Snapshot,
TextExtendSelection, TextIter, TextView, TextViewLayer,
};

pub trait TextViewImpl: WidgetImpl + ObjectSubclass<Type: IsA<TextView>> {
pub trait TextViewImpl: WidgetImpl + ObjectSubclass<Type: IsA<TextView> + IsA<Scrollable>> {
fn backspace(&self) {
self.parent_backspace()
}
Expand Down
Loading

0 comments on commit 8d2bf10

Please sign in to comment.