532 views
in GUI Development by
Hello,

i have set up a multiLingual system that is displaing a speed value in Knots. i have manage to make the language change. now i want to set up this to change units from Knots to MPH to Km/h. what is the best practice to do that?

1 Answer

0 votes
by

Hello,

if the conversion depends on the actually selected language, you can evaluate the global variable language. Acccording to its actual value you convert the original speed value in MPH, Km/h or even Knots. To convert from Knots to Km/h:
 

if ( language == SomeLanguage )
{
  var int32 speedInKnots = ...
  var int32 speedInKmh   = int32( float( speedInKnots ) * 1.852 );

  [...]
}

Best regards

Paul Banach
 

by
Dear Paul,

thank you for your quick answer.  my question was more about how to display the unit types in diferent languages together. Might not be so clear with my question so let me explain a little more about what i am tring to do here.

i have a Value display that i have assigned a constand in the "unit" section. this costant type is a string. i am displaying  "knots"in english "nodi'in italian "knoten" in german and "nudos"in spanish. for this i took advantage of the multiligual option in your system.

i have a settin in my system that controls if you are see the screen in daylight of in the night to change the the color from white to black. this i did it using styles and making a viriant of value display configuration.

i have also set up a button that let you chose what unit system you are using and also lets you pick for your self individually if you want to afect only temperature presuure speed or any other value i have. i can do metric of imperial system.

i was thinking about doing a variant in the costan that gange the language an do the changes oh the displayed units there with styles. is this the correct approche? i saw that i can only have 32 styles to use. is there a better way to manage this that i didnt find in the documantation?

thank you!
by

Hello,

thank you for the detailed explication. Now I have understood your application case. As you have noticed yourself, you can manage this by deriving variants from the respective string constants. For example:

Step 1: Asuming the metric system is the default system, initialize all affected constants with the metric units. 

Step 2: Add a new Style to your project. It will represent the imperial system.

Step 3: Derive a variant from each constant containing a unit.

Step 4: Configure the Variant Condition of the derived variants to depend on the Style (step 2).

Step 5: At the runtime when the user activates the button, switch on/off the style.

Please note, switching on/off the styles affectes GUI components created/initialized afterwards. If you have already a GUI component showing a unit, the switch will not affect it unless you evaluate the expession referering to the constant again (unless you initialize the property of Value display again). See also Control the selection of dynamic variants. It is also true, that the number of Styles is limited to 32. 

The approach with variants is just one possibility. You can also manage the different unit systems as separate constants. At the runtime you initialize the Value display widgets manually with the right constant depending on your actual setting.

Does it help you?

Best regards

Paul Banach

by
Dear Paul,

Thanks again your answer was very hepful! one last question is there a way to reinitialaze all the graphics at once? i have several dislpays and some graphics that needs to be changed when i add a style and i was wondering if there is a way to do it with one comand?

Thank you again!
by

Hello,

if you want to refresh existing GUI components after switching on/off a style, you have to notify all affected GUI components explicitly. Because variants may affect the inheritance of classes, there is no automatic 'update' of already existing objects possible. Already instantiated classes or evaluated expressions involving multi-variant constants or resources will retain their actual value. If you want some value to be updated after a Style has been switched on/off you have to handle this operation explicitly.

How to achieve this?

The application component (the root GUI component of your application) contains a property Styles. This property is in fact a copy of the global built-in variable styles. Modifying the property causes the styles variable also to be modified. Doing this however via the application component will broadcast an event Core::StylesEvent to all GUI components belonging to the view tree. The GUI components can react to this alternation.

To react to such event you have to to override within the affected GUI component its inherited method HandleEvent(). Implement the method with following code:

var Core::StylesEvent event = (Core::StylesEvent)aEvent;

// Is this the 'Styles' event?
if ( event != null )
{
  // Assign again the constant containing the unit name
  SomeValueDisplay.Unit = Example::SomeConstantWithUnitName;  
}

// Give the inherited functionality a chance to process all events
return super( aEvent );

This approach has a problem. If you change the language afterwards, the modification from the HandleEvent() method is discarded. You would thus need to react also to language alternation, which is reported via event Core::LanguageEvent:

var Core::StylesEvent   event1 = (Core::StylesEvent)aEvent;
var Core::LanguageEvent event2 = (Core::LanguageEvent)aEvent;

// Is this the 'Styles' or 'Language' event?
if (( event1 != null ) || ( event2 != null ))
{
  // Assign again the constant containing the unit name
  SomeValueDisplay.Unit = Example::SomeConstantWithUnitName;  
}

// Give the inherited functionality a chance to process all events
return super( aEvent );

The appliocation component implements for this purpose also the property Language. Similarly to the above explained Styles property, Language contains a copy of the global built-in variable language. Changing the language via this property will broadcast the Core::LanguageEvent.

This is just one of the possible approaches. You can of course implement your own functionality to notify the affected GUI components after the style has been changed. If you know the GUI components, you can call some methods implemented in the components. Or you use the observer infrastructure. In any case it is necessary to notify the GUI component in order to force their update.

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

...