bodil / vgtk

A declarative desktop UI framework for Rust built on GTK and Gtk-rs
http://bodil.lol/vgtk/
Other
1.05k stars 37 forks source link

Implement Notebook::tab_label_text child property. #44

Closed nt8r closed 4 years ago

nt8r commented 4 years ago

This is not the most flexible interface, but handles the simple case of notebooks with textual tab labels.

I'd appreciate review about object::Cast; I couldn't get a simple usage setting Notebook::tab_label_text to a string literal to typecheck with a <P: IsA<...>> bound of Object or Widget for the child parameter. Am I missing things or is the flexibility of dynamic casting necessary here?

LiHRaM commented 4 years ago

I got it working with the current codebase by wrapping the inner element in a Box, if that helps.

<Notebook show_tabs=true show_border=false>
    <Box Notebook::tab_label="filename">
        <@CustomComponent />
    </Box>
</Notebook>
nt8r commented 4 years ago

@LiHRaM thanks for the investigation. I think I understand the problem now: the attribute needs to be placed on widget the inside the component's view function, not on the component itself. I wonder if vgtk could be modified so that the latter worked too? The status quo makes it hard to reuse components in multiple contexts, since contextual properties have to be set inside the component definition. This PR should probably be closed, but I'll file an issue on this question.

nt8r commented 4 years ago

It turns out, child properties are silently ignored on the top-level widget of the component's view function, so @LiHRaM 's workaround works but the workaround of moving the child property inside the component does not. I'll mention this in the issue.