Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Example of ListView #476

Open
mjehrhart opened this issue Jan 17, 2022 · 2 comments
Open

Simple Example of ListView #476

mjehrhart opened this issue Jan 17, 2022 · 2 comments
Assignees

Comments

@mjehrhart
Copy link

I tried running the ListView example but ran into errors.

Is it possible to create a very simple demo where developers could essentially copy and past a ListView example to see a working demo? Or perhaps could I get some assistance in running the demo?

I am currently adding a gui to a simple search project I wrote. As far as I can tell, I cannot create a dynamic set of widgets unless I use the ListView - is this correct?

I like this project and like where its going. Amazing job to all involved.

@rzerres rzerres self-assigned this Jan 31, 2022
@rzerres
Copy link
Contributor

rzerres commented Jan 31, 2022

Hey @mjehrhart

Try to summarize the needed blocks ... (which should go into orbtk-book

In general we try to implement reference code inside the example subdirectory of the orbtk crate. In concrete, the showcase code is designed to implement all common components, structured to group related widgets inside dedicated tabs.

You can find a reference section consuming the ListView widget around line 338.
The macro instantiates an ItemsView widget (which is used to represent a ListView. It defines a variable items consuming a List type. The List is constructed via a regular rust Vector creation macro [vec!], where its members are constructed from the given strings.

You are completely free, to construct your List/vector from a file io or socket/stream call.

// Represents an overview of list widgets like ListView, ItemsWidget and ComboBox.
widget!(ItemsView {
    /// Active seleced index of combo box.
    selected_index: i32,

    /// Valid list of items.
    items: List
});


impl Template for ItemsView {
    fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
        let items = vec![
            "Item 1".to_string(),
            "Item 2".to_string(),
            "Item 3".to_string(),
            "Item 4".to_string(),
            "Item 5".to_string(),
        ];
        let items_count = items.len();

given Codeline 401 a ListView widget will consume the items_builder method, which itself is using a closure to iterate its index.

BuildContext is mutable and will assign the text variable, that will take the context of the vector string, that is addressed via its index position. Each text-index is rendered inside a TextBlock, aligned in the center of that widget.

Finally calling the build method will trigger the rendering pipeline. Compare to orbtk-book Ingredients, that visualizes the state workflow.

Hope that clarifies your question.

@rzerres
Copy link
Contributor

rzerres commented Feb 17, 2022

@mjehrhart does that solve your issue? Can i close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants