Skip to content

Field types created by impl_singleton! are opaque #15

Open
@dhardy

Description

@dhardy

When creating a widget with make_widget!{ .. }, fields cannot be accessed from outside the defining macro due to the anonymous type.

I had hoped this could be fixed with some type of type alias feature, but alas, this appears limited to trait implementations.

To some extent this can be worked around with traits, e.g. from the stopwatch example:

#[widget] display: impl HasText = make_widget!{
    frame => EmptyMsg;
    struct {
        #[widget] display: Label = Label::from("0.000"),
    }
    impl HasText {
        fn get_text(&self) -> &str {
            self.display.get_text()
        }
        fn set_string(&mut self, tk: &mut dyn TkWindow, text: String) {
            self.display.set_text(tk, text);
        }
    }
},

allowing self.display.set_text(tk, &self.dur_buf); to be called from the outer widget later.

Ideally in the above, it would be possible to directly call self.display.display.set_text(tk, ..).


Proposal: build_widget! macro

Move most of the make_widget! code into a separate macro, defining the type, and allow direct use of this.

Issue: implicit typing within make_widget! uses generics, thus the resulting type requires parameterisation on use. Ideally, we would not have to use generics but could use some type of "magic type alias".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions