392 views
in GUI Development by
Hi,

 

I have a variable of type: Views::Text on my screen

I have a slot function which fires when I press the simple touch handler

In the slot, I execute the following code:

txt = new Views::Text;

   txt.Visible = true;
   txt.Color = #FF0000FF;
   txt.String = "TXTFFFF";
   txt.Font = Resources::FontArial24;
   txt.Bounds.origin.x = 50;
   txt.textSize.x = 40;
   txt.textSize.y = 24;
   txt.Bounds.origin.y = 50;
   Add(txt, 0);

But I find that nothing is displayed.

Can anyone perhaps wee where I am going wrong with this?

 

Kind Regards,

Rob

2 Answers

0 votes
by
 
Best answer
Bounds was set to <50, 50, 50, 50>, which means that width and height were zero. As soon as I changed that, it worked.
0 votes
by

Hello Rob,

the reason is, you specify the position but not size for the view. Try following:

txt = new Views::Text;

   txt.Visible = true;
   txt.Color = #FF0000FF;
   txt.String = "TXTFFFF";
   txt.Font = Resources::FontArial24;

   // The view should appear at position 50,50 with 200x100 pixel size
   txt.Bounds = <50,50,250,150>;

   Add(txt, 0);

Best regards

Paul Banach

by
Hello, I am new to this tell. I am trying to perform same steps as mentioned above. But I am getting error as
[8.4.2019 14:29:07] Error Application::fourthProduct.cust (2:1) : Unknown identifier 'txt' found.
 

I want to change txt value base on some selection.
by

Hello,

according to the thread owner txt was an existing variable. In your case the variable is probably not defined. Try following:

var Views::Text txt = new Views::Text;

txt.Visible = true;
txt.Color = #FF0000FF;
txt.String = "TXTFFFF";
txt.Font = Resources::FontArial24;

// The view should appear at position 50,50 with 200x100 pixel size
txt.Bounds = <50,50,250,150>;

Add(txt, 0);

See also the section Compose the component programmatically.

Best regards

Paul Banach

by

Thanks for reply it works. I do not really under what exactly happen, I need to go through more on document.

I have one more question what is 

Add(txt, 0);

and I want to replace existing text with new text string

 

by

Hello,

yes, the best would be if you start with our Quick Tour. It explains the basic ideas how to create GUIs. After processing Quick Tour I would recommend you to evaluate a little bit the chapters in the section Working with Embedded Wizard.

Concerning your concrete question, the method Add() adds a new view to a the tree of views. This tree reflects what you see on the screen. The method Add() is also described in our documentation. The link from my answer above points to a section explaining its usage.

Concerning text display I would recommend you the section Text View. Superficially explained the displayed text is determined by a string stored in the text view's property String. Changing this property will has the effect of anther text being shown on the screen. But the best would be to start with Quick Tour :o)

Best regards

Paul Banach

by

After adding text using below code. Is there any way or method to remove and empty string then add new text.

var Views::Text txt = new Views::Text;

txt.Visible = true;
txt.Color = #FF0000FF;
txt.String = "TXTFFFF";
txt.Font = Resources::FontArial24;

// The view should appear at position 50,50 with 200x100 pixel size
txt.Bounds = <50,50,250,150>;

Add(txt, 0);

When I try to empty string before add method it does not work.

txt.String = "" ; //this line will not work. 

by

Hello,

what do you mean with 'does not work'? If you are doing following, the text view will remain empty:

var Views::Text txt = new Views::Text;

txt.Visible = true;
txt.Color = #FF0000FF;
txt.String = "";
txt.Font = Resources::FontArial24;

// The view should appear at position 50,50 with 200x100 pixel size
txt.Bounds = <50,50,250,150>;

Add(txt, 0);

This is because every time the above code is executed a new instance of a text view is added. If there was already an instance added in the preceding step, this instance will not be affected -> it will still show its old text. 

Is there a particular reason why you want to create the text view programmatically? Usually you can compose the GUI 'visually'. In this manner its is simple to access and modofy the properties of existing views. If it is essential to create the view dynamically, store the view within a variable and next time when you want to change the text access the view via this variable.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...