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 24, 2024
1 parent 1626356 commit 4bea9f4
Show file tree
Hide file tree
Showing 45 changed files with 137 additions and 72 deletions.
3 changes: 2 additions & 1 deletion examples/column_view_datagrid/grid_cell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub struct Entry {

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

impl Default for GridCell {
Expand Down
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
3 changes: 2 additions & 1 deletion examples/composite_template/ex_application_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use gtk::{gio, glib, prelude::*, subclass::prelude::*};
glib::wrapper! {
pub struct ExApplicationWindow(ObjectSubclass<imp::ExApplicationWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget,
gtk::Native, gtk::Root, gtk::ShortcutManager, gio::ActionMap, gio::ActionGroup;
}

impl ExApplicationWindow {
Expand Down
3 changes: 2 additions & 1 deletion examples/composite_template/ex_menu_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ use gtk::glib;

glib::wrapper! {
pub struct ExMenuButton(ObjectSubclass<imp::ExMenuButton>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}
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
2 changes: 1 addition & 1 deletion examples/custom_buildable/custom_buildable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gtk::{glib, prelude::*, subclass::prelude::*};
glib::wrapper! {
pub struct CustomBuildable(ObjectSubclass<imp::CustomBuildable>)
@extends gtk::Widget,
@implements gtk::Buildable;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl CustomBuildable {
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_editable/custom_editable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::custom_tag::CustomTag;
glib::wrapper! {
pub struct CustomEditable(ObjectSubclass<imp::CustomEditable>)
@extends gtk::Widget,
@implements gtk::Editable;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Editable;
}

impl Default for CustomEditable {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_editable/custom_tag/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 CustomTag(ObjectSubclass<imp::CustomTag>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl CustomTag {
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/gif_paintable/gif_paintable_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::gif_paintable::GifPaintable;
glib::wrapper! {
pub struct GifPaintableWindow(ObjectSubclass<imp::GifPaintableWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget,
gtk::Native, gtk::Root, gtk::ShortcutManager, gio::ActionMap, gio::ActionGroup;
}

impl GifPaintableWindow {
Expand Down
3 changes: 2 additions & 1 deletion examples/list_box_model/list_box_row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::row_data::RowData;

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

impl ListBoxRow {
Expand Down
3 changes: 2 additions & 1 deletion examples/list_view_apps_launcher/application_row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::{gio, glib, prelude::*, subclass::prelude::*};

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

impl Default for ApplicationRow {
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/video_player/video_player_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use gtk::{gio, glib, prelude::*, subclass::prelude::*};
glib::wrapper! {
pub struct VideoPlayerWindow(ObjectSubclass<imp::VideoPlayerWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup;
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget,
gtk::Native, gtk::Root, gtk::ShortcutManager, gio::ActionMap, gio::ActionGroup;
}

impl VideoPlayerWindow {
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/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ pub fn include_blueprint(input: TokenStream) -> TokenStream {
/// }
///
/// glib::wrapper! {
/// pub struct MyWidget(ObjectSubclass<imp::MyWidget>) @extends gtk::Widget, gtk::Box;
/// pub struct MyWidget(ObjectSubclass<imp::MyWidget>)
/// @extends gtk::Widget, gtk::Box,
/// @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
/// }
///
/// impl MyWidget {
Expand Down Expand Up @@ -197,7 +199,9 @@ pub fn include_blueprint(input: TokenStream) -> TokenStream {
/// }
///
/// 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;
/// }
/// ```
#[proc_macro_derive(CompositeTemplate, attributes(template, template_child))]
Expand Down Expand Up @@ -351,7 +355,9 @@ pub fn composite_template_derive(input: TokenStream) -> TokenStream {
/// }
///
/// glib::wrapper! {
/// pub struct MyWidget(ObjectSubclass<imp::MyWidget>) @extends gtk::Widget, gtk::Box;
/// pub struct MyWidget(ObjectSubclass<imp::MyWidget>)
/// @extends gtk::Widget, gtk::Box,
/// @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
/// }
///
/// #[gtk::template_callbacks]
Expand Down
20 changes: 15 additions & 5 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 Expand Up @@ -248,7 +254,9 @@ mod imp4 {

#[cfg(feature = "blueprint")]
glib::wrapper! {
pub struct MyWidget4(ObjectSubclass<imp4::MyWidget4>) @extends gtk::Widget;
pub struct MyWidget4(ObjectSubclass<imp4::MyWidget4>)
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

#[gtk::test]
Expand Down Expand Up @@ -295,7 +303,9 @@ mod imp5 {

#[cfg(feature = "blueprint")]
glib::wrapper! {
pub struct MyWidget5(ObjectSubclass<imp5::MyWidget5>) @extends gtk::Widget;
pub struct MyWidget5(ObjectSubclass<imp5::MyWidget5>)
@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
Loading

0 comments on commit 4bea9f4

Please sign in to comment.