Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface bounds to Impls #1883

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
bilelmoussaoui marked this conversation as resolved.
Show resolved Hide resolved
}

#[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;
}
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/femtovg_area/femtovg_area/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 FemtoVGArea(ObjectSubclass<imp::FemtoVGArea>)
@extends gtk::Widget, gtk::GLArea;
@extends gtk::Widget, gtk::GLArea,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}

impl Default for FemtoVGArea {
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/glium_gl_area/glium_gl_area/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::{gdk, glib, prelude::*};

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

impl Default for GliumGLArea {
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::Actionable, gtk::Buildable, gtk::ConstraintTarget;
}

impl ListBoxRow {
Expand Down
22 changes: 7 additions & 15 deletions examples/list_box_model/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,13 @@ fn build_ui(application: &gtk::Application) {
// The gtk::ListBoxRow can contain any possible widgets.

let listbox = gtk::ListBox::new();
listbox.bind_model(
Some(&model),
clone!(
#[weak]
window,
#[upgrade_or_panic]
move |item| {
ListBoxRow::new(
item.downcast_ref::<RowData>()
.expect("RowData is of wrong type"),
)
.upcast::<gtk::Widget>()
}
),
);
listbox.bind_model(Some(&model), move |item| {
ListBoxRow::new(
item.downcast_ref::<RowData>()
.expect("RowData is of wrong type"),
)
.upcast::<gtk::Widget>()
});

let scrolled_window = gtk::ScrolledWindow::builder()
.hscrollbar_policy(gtk::PolicyType::Never) // Disable horizontal scrolling
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
23 changes: 17 additions & 6 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 Expand Up @@ -348,5 +358,6 @@ mod imp6 {

glib::wrapper! {
pub struct TestWidget(ObjectSubclass<imp6::TestWidget>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}
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
Loading
Loading