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

[FEATURE REQUEST] Automatic ObjectSubclass #1412

Open
DaKnig opened this issue May 24, 2024 · 2 comments
Open

[FEATURE REQUEST] Automatic ObjectSubclass #1412

DaKnig opened this issue May 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@DaKnig
Copy link
Contributor

DaKnig commented May 24, 2024

every class needs this tiny bit of boilerplate (from the book):

// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for Window {
    // `NAME` needs to match `class` attribute of template
    const NAME: &'static str = "MyGtkAppWindow";
    type Type = super::Window;
    type ParentType = gtk::ApplicationWindow;

    fn class_init(klass: &mut Self::Class) {
        klass.bind_template();
        klass.bind_template_callbacks();
    }

    fn instance_init(obj: &InitializingObject<Self>) {
        obj.init_template();
    }
}

from what I understand we need that because in some cases we may or may not want to call klass.bind_template_callbacks(). every single widget I have contains this much boilerplate... and most of them do nothing interesting besides that.

suggestions:

  • klass.bind_template() could call klass.bind_template_callbacks() always, with a default empty function for bind_template_callbacks
  • default implementation of the whole thing when deriving CompositeTemplate with impl ... for T where T : <has derived CompositeTemplate?> or something
  • other ideas?
@DaKnig DaKnig added the enhancement New feature or request label May 24, 2024
@DaKnig
Copy link
Contributor Author

DaKnig commented May 24, 2024

this is by far the most annoying bit of the boilerplate. I always get it wrong. I always forget something. with this we could just have impl ObjectSubclass for DewYtItemList {} or something just like we have for everything else.

@bilelmoussaoui
Copy link
Member

The issue itself is not really actionable. Instead, it should mention having a way to inject something into class_init / instance_init automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants