orbtk
orbtk copied to clipboard
Generic widgets
Context
(My issue is related to #272) The current syntax of declaring widgets does not allow adding properties with generics (like Vec<T>), and you need to use type aliasing:
(does not compile, the compiler complains:
no rules expected this token in macro call)
widget!(MyWidget {
items: Vec<MyStruct>
});
This works:
#[derive(Debug, Clone, PartialEq)]
pub struct MyStruct;
type MyList = Vec<MyStruct>;
widget!(MyWidget {
items: MyList
});
Problem description & Solution
- Change the syntax of the widget!() macro to allow passing a generic type when declaring widgets, like:
widget!(ListView<T>);
or
widget!(TableView<TableViewState, T>);
where T is a generic type, like MyStruct.
- Refactor ListView to allow a generic type.
Developers working with ListViews or other generic widgets could work with their own struct when developing UIs.
Examples and MockUps
#[derive(Debug, Clone, PartialEq)]
pub struct MyStruct;
widget!(MyWidget<MyState, MyStruct{
items: Vec<MyStruct>
});