How to change text of LabelWedget.

Author
ysaitoysaito
Super Member
  • Total Posts : 405
  • Reward points : 0
  • Joined: 2010/08/13 08:31:35
  • Location: 0
  • Status: offline
2018/11/07 07:02:47 (permalink)
0

How to change text of LabelWedget.


 How do you change the text of LabelWedget in Harmony v.2.06 graphics ?
 
  For example:
   The default text of the LabelWedget1  is  set  as  "Waiting".
  When the  Button Switch is clicked,  how do you change the text from "Waiting " to "Clicked" ?
 
 I need not to change font.
 
 Any advise make me pleased.
 
 
 ysaito
#1

6 Replies Related Threads

    Ed@Microchip
    Super Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/07 09:02:12 (permalink)
    0
    Hi ysaito,
     
    There are a couple of ways to do this:
     
    1. First, you will need to create a string asset for "Clicked".
    2. Then, in the button's Pressed event function, call:
        laLabelWidget_SetText(LabelWidget1, laString_CreateFromID(string_Clicked));
     Where string_Clicked is the ID of the string asset for Clicked.
     
    OR, you can use the Event Manager in MHGC:
     
    1. First, create the string asset for "Clicked".
    2. Next, select the Button and in the Button's events properties, check "Pressed" and click the button "..." to the right to open the Event Editor window.
    3. In the Event Editor window, click the "+New" button to create a new event.
    4. In the Action Edit Dialog, select "Template" and click "Next"
    5. In the next window, select "LabelWidget1" in the Active Screen, then click "Next".
    6. In the next window, select "Set Text", then click "Next"
    7. In the next window, select the "Clicked" string from the list in the "String" arguments drop down list, and click "Finish"
    8. Close the Event Editor window by clicking "Ok"
    9. Regenerate.
     
    After regeneration, you should see in the libaria_events.c the call to laLabelWdiget_SetText() in the button's pressed event callback.
     
    Thanks,
     
    Ed @ Microchip
    #2
    ysaitoysaito
    Super Member
    • Total Posts : 405
    • Reward points : 0
    • Joined: 2010/08/13 08:31:35
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/07 17:51:38 (permalink)
    0
    Dear Ed @ Microchip

    Thank you very much for quick and kind advice.  I understood Both 2 ways.
     I am sorry.  But your 2 ways cannot satisfy my demand.  I know well that my question was not so suitable for my demand.  I would like to change the texts(strings), which  are, for examle, texts from UART,  File name string in SD card and characters from keyboard, etc.   Namely I would like to change the text, which are unknown when I make a program.

     And I would like to konw the way to change the texts of not only LabelWidget but also TextFieldWidget concernig unknown tests at the stage of programing.
     
     Best regards
     ysaito
    #3
    Ed@Microchip
    Super Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/08 11:57:27 (permalink)
    0
    Hi ysaito,
     
         To show dynamic or run-time generated text, it will need to be converted to an laString object, then passed to laLabelWidget_SetText().
     
         Refer to the sample GFX application aria_counter, open app.c and look at the function APP_DecrementCount(). In that function, the number tickCount is converted to a character array using sprint(), then converted to laString using laString_CreateFromCharBuffer, then used in laLabelWidget_SetText().
     
        The second parameter to GFXU_StringFontIndexLookup is the ID of the superset string that contains all the characters of the dynamic text, in this case "0123456789" since the text is a number. If the text can be any word, the superset string will need to contain all the characters in the alphabet.
     
      static char charBuff[10];
        laString str;
         sprintf(charBuff, "%u", tickCount--);
        
        str = laString_CreateFromCharBuffer(charBuff,
                GFXU_StringFontIndexLookup(&stringTable, string_NewTxt, 0));
        
        laLabelWidget_SetText(labelWidget, str);

     
     
     
    Thanks,
     
     
    Ed
    #4
    ysaitoysaito
    Super Member
    • Total Posts : 405
    • Reward points : 0
    • Joined: 2010/08/13 08:31:35
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/09 08:54:09 (permalink)
    0
    Dear Ed @ Microchip

     Thank you very much for excellent advice.   I could display and change the dynamic text in LabelWidge and TextFieldWidget.
    I attached the pictures. 
      note: Upper is  LabelWidget and Lower is TextFieldWidget.  Both texts are the same.


    Below is my code.
    SYS_TMR_HANDLE handleTimer3;
    bool notFirst;
    bool Flag;
    char charBuff1[32];
    char charBuff2[32];

    laString str1,str2;
      
    char Hellow_World[] = "Hellow\r\nWorld\r\n";
    char Fine_Today[] = "Fine\r\nToday\r\n";
    int Count;

    void Func1(void) //
    {
        Count++;
        sprintf(charBuff1, "%s N=%d",Fine_Today,Count );
        
        str1 = laString_CreateFromCharBuffer(charBuff1,
                GFXU_StringFontIndexLookup(&stringTable, string_LabelStr1, 0));
        
        laLabelWidget_SetText(LabelWidget1, str1);
        
        laTextFieldWidget_SetText(TextFieldWidget1, str1);
    }

    void Func2(void) //
    {
        Count++;
        sprintf(charBuff2, "%s N=%d", Hellow_World, Count);
        
        str1 = laString_CreateFromCharBuffer(charBuff2,
                            GFXU_StringFontIndexLookup(&stringTable, string_LabelStr1, 0));
        laLabelWidget_SetText(LabelWidget1, str1);
     
        laTextFieldWidget_SetText(TextFieldWidget1, str1);
    }

    void Timer_Callback3 ( uintptr_t context, uint32_t currTick )
    {
        if(Flag == false)
        {
            Flag = true;
            Func1();
        }
        else
        {
            Flag = false;
            Func2();
        }
    }
    ....
    ....



    I have some question.

    1. How do you line feed ?
       I tried to line feed by using \r\n. But I cannot.
       
    2. Concerningn TextFieldWidget, How do you arrange the Vertical Arignment ?

    3. What is the differrece between LabelWidget and TextFieldWidget ?
       What case do yo use TextFieldWidget ?
       
       
       
    Best regards

    ysaito   
      

    Attached Image(s)

    #5
    Ed@Microchip
    Super Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/09 09:27:21 (permalink)
    0
    Hi ysaito,
     
        Good to know that you are now able to display dynamic text. Multi-line should work by adding '\n' between lines of text. It should be supported in buttons and label widgets.
     
         Textfield widget is useful if you need text input from the user using the keypad widget, like putting in a password. If you only need to show text, you can just use the label widget.
     
    Thanks,
     
    Ed @ Microchip
    #6
    ysaitoysaito
    Super Member
    • Total Posts : 405
    • Reward points : 0
    • Joined: 2010/08/13 08:31:35
    • Location: 0
    • Status: offline
    Re: How to change text of LabelWedget. 2018/11/10 00:06:08 (permalink)
    0
    Dear Ed @ Microchip

     Thank you very much for advice.
     
      I found the reason Why Multi-line does not work by adding '\n' between lines of text.  To tell the truth, at the present moment I use Harmony v2.04,  because my own making graphics driver of the conventional Graphics LCD is for Harmony v2.04.
      I checked whether Multi-line works or not by adding '\n' between lines of text in 2 conditions, namely  Harmony 2.04 and 2.06,  by using  the sample GFX application  v2.04 aria_counter and the v2.06 aria_counter.   And I found  that '\n' is useful  for Harmony v2.06  but '\n' is not useful  for Harmony v2.04.
     
      On this occcasion , I start to update my own making graphics driver.
     
     
      Best regards
     
      ysaito
    #7
    Jump to:
    © 2018 APG vNext Commercial Version 4.5