BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: create an array of widgets  (Read 5869 times)

Cyrilou

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
create an array of widgets
« 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)?
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 732
    • View Profile
Re: create an array of widgets
« Reply #1 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
Logged