BRT Community

General Category => Discussion - EVE => Topic started by: Cyrilou on April 06, 2021, 11:11:21 AM

Title: create an array of widgets
Post by: Cyrilou on April 06, 2021, 11:11:21 AM
Hi,

On ESD it's impossible to create an array of widgets, all widget of the same type must have a different name on design time.
Should I use custom source code to use them in array mode or in dynamic array mode (malloc)?
Title: Re: create an array of widgets
Post by: BRT Community on April 08, 2021, 05:09:44 PM
Hello,

ESD does have the way to create widget at run-time but it needs user code involved. 
I suggest you take a look at the ScrollPanel Example project under “Intermediate” folder as part of the ESD Toolchain.

Open the project and check the “ScrollContent” node and “MainPage_Add_New” node.

“ScrollContent” node is a linear layout widget which manages the newly created button and decide where to put them on screen.
“MainPage_Add_New” node is from user code in MainPage.c which creates the button widget when users clicks “Add New” button.

Here is the code:

Code: [Select]
// Add a button to the scroll panel
ESD_METHOD(MainPage_Add_New, Context = MainPage)
void MainPage_Add_New(MainPage *context)
{
                // Create the widget
                ButtonState *widget = malloc(sizeof(ButtonState));
                Ft_Esd_PushButton__Initializer(&widget->Button);
                Ft_Esd_Widget *esdWidget = &widget->Button.Widget;

                widget->Owner = context;
                esdWidget->Instanced = FT_TRUE; // Mark to be freed by parent End
                esdWidget->Owner = widget; // Self-owned

                // Create our user state
                sprintf(widget->Text, "Button %i", buttonNumber);
                ++buttonNumber;

                // Set user bindings
                widget->Button.Pushed = Button_Pushed;
                widget->Button.Text = Button_Text;

                // Start widget
                esdWidget->Slots->Start(esdWidget);
                esdWidget->Active = FT_TRUE;
                Ft_Esd_Widget_InsertBottom(esdWidget, &context->ScrollContent);
}

Open the MenuPage.page to see the node connections.

Best Regards,
BRT Community