Skip to content

Macro for generating signals() and emit_/connect_ functions for subclass #214

@ids1024

Description

@ids1024

When defining a GObject type in Rust, it is necessary to define a ObjectImpl::signals() function, and useful to define the emit_ and connect_ functions like the ones generated by gir.

Considering a few things, this seems like a reasonable API for it, which I think would work:

glib::wrapper! {
    signals {
        fn signal_without_params();
        fn signal_with_params(i32, String);
        fn signal_with_params_and_return(i32, String) -> bool;       
    }
    pub struct FooObject(ObjectSubclass<FooObjectInner>);
}

I guess it would be necessary for the caller to define ObjectImpl::signals() to call a function generated by the macro. Kind of similar to the boilerplate required with composite templates. I can't think of a way to avoid a slight complication like this.

Alternately to making this part of glib::wrapper!, it could be a separate macro, or an attribute macro on something. Given glib::wrapper! is necessary, it seems cleaner to add it here. It could also generate the connect_/emit_ functions for types other than ObjectSubclass (code currently generated in gir).

Properties should be handled in a similar way, but that's more complicated since it would be good for it to automatically store a value if there is no custom getter/setter, while also supporting custom getters and setters. And then there's a need to define nick, blurb, and default value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions