orbtk icon indicating copy to clipboard operation
orbtk copied to clipboard

Generic widgets

Open kivimango opened this issue 5 years ago • 0 comments

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

  1. 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.

  1. 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>
});

More good example JavaFX's ListView and TableView

kivimango avatar Sep 06 '20 11:09 kivimango