• AVR Freaks

HGC duplicating parts of a screen to multiple screens

Author
jack012161
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2012/01/25 12:47:41
  • Location: 0
  • Status: offline
2019/07/02 08:12:34 (permalink)
0

HGC duplicating parts of a screen to multiple screens

Is there a way in HGC to have parts of a screen common to multiple screens?  I'm using Harmony 2.06.  I have about ten screens that share the identical areas of a screen. 
#1

2 Replies Related Threads

    Ed@Microchip
    Super Member
    • Total Posts : 141
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: HGC duplicating parts of a screen to multiple screens 2019/07/03 15:51:29 (permalink)
    0
    MHGC does not have options within the tool to make a widget persistent across different screens.
     
    However, you can modify the generated code to make widgets persistent, and reuse them to screens when the screens are shown.
     
    To do this:
    1. In MHGC, create a 'template' screen with the widgets that you would like to reuse across different screens.
    2. In MHGC, for each of the screen that will have this widget, enable the 'On Show' and 'On Hide' screen events. You can do this in the Event Manager (Tools -> Event Manager), Screen Events, check the On Show and On Hide Events for the relevant screens. For each On Show/On Hide event, enable a Custom Action.

    3. Regenerate the project.

    4. Now in libaria_init.c, in the ScreenCreate_*() function for the template screen, CUT (not copy) the code that creates the widgets that you want to reuse in different screens. PASTE that code into the libaria_initialize() function in libaria_init.c. Remove/Comment out the laWidget_AddChild() calls for each of those widgets. The code would look something like this :

        //Create persistent widgets
        LogoWidget = laImageWidget_New();
        laWidget_SetPosition((laWidget*)LogoWidget, 151, 48);
        laWidget_SetSize((laWidget*)LogoWidget, 184, 136);
        laWidget_SetBackgroundType((laWidget*)LogoWidget, LA_WIDGET_BACKGROUND_NONE);
        laWidget_SetBorderType((laWidget*)LogoWidget, LA_WIDGET_BORDER_NONE);
        laImageWidget_SetImage(LogoWidget, &NewHarmonyLogo_Small);
    // laWidget_AddChild((laWidget*)layer0, (laWidget*)LogoWidget);
        TitleLabel = laLabelWidget_New();
        laWidget_SetPosition((laWidget*)TitleLabel, 71, 18);
        laWidget_SetSize((laWidget*)TitleLabel, 343, 25);
        laWidget_SetBackgroundType((laWidget*)TitleLabel, LA_WIDGET_BACKGROUND_NONE);
        laWidget_SetBorderType((laWidget*)TitleLabel, LA_WIDGET_BORDER_NONE);
        laLabelWidget_SetText(TitleLabel, laString_CreateFromID(string_TitleString));
    // laWidget_AddChild((laWidget*)layer0, (laWidget*)TitleLabel);

    5. Now for each screen where you want to show these widgets, add the widgets as child to the screen by calling laWidget_AddChild() in the *_ShowEvent() function for each screen. This function is in the libaria_events.c file. It would look like the code below if adding the widgets to the first layer (layers[0]) in the screen. Change the layers index if adding to a different layer in a multi-layer design.

    // screen1 - ShowEvent
    void screen1_ShowEvent(laScreen* scr)
    {
        // Custom Action
        laWidget_AddChild((laWidget*)scr->layers[0], (laWidget*)LogoWidget);
        laWidget_AddChild((laWidget*)scr->layers[0], (laWidget*)TitleLabel);  
    }


    6. The widgets will need to be removed as child to the parent screen when the screen is hidden. This is important to preserve the widgets, otherwise they will be deleted/destroyed when their parent screen is hidden. To remove the widget from the parent screen, call the laWidget_RemoveChild() function in the *_HideEvent() function for the relevant screen. It would look like this:

    // screen1 - HideEvent
    void screen1_HideEvent(laScreen* scr)
    {
        // Custom Action
        laWidget_RemoveChild((laWidget*)scr->layers[0], (laWidget*)LogoWidget);
        laWidget_RemoveChild((laWidget*)scr->layers[0], (laWidget*)TitleLabel);
    }


    The process above lets you create persistent widgets that you can add/remove from screens to make them appear in each of those screens. Note that the widgets are 'reused', not duplicated. So the states and memory used for those widgets are preserved even when changing screens. A widget that has changed in one screen will retain those changes when shown on another screen. Also, the memory used by those widgets are not freed during screen transitions and will carve out a persistent allocation from the project heap.
    #2
    jack012161
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2012/01/25 12:47:41
    • Location: 0
    • Status: offline
    Re: HGC duplicating parts of a screen to multiple screens 2019/07/09 08:41:37 (permalink)
    0
    Thank You for response Ed.  I am surprised that MHGC does not support this directly.  I'm sure many graphic Apps require common widgets across several screens.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5