Board index FlightGear Development

Howto toggle a Button label depending on porperty ?

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Howto toggle a Button label depending on porperty ?

Postby mhab » Fri Jun 26, 2015 5:53 pm

Hello

Can I change the label of a button in a GUI dialog, depending on a property ?

I tried to use <visible> tag to hide/show two different buttons, but the invisible button still consumes empty space instead of disappearing.

Thanks for any advice

Mike-DE
mhab
 
Posts: 410
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2019.1.1
OS: Win10

Re: Howto toggle a Button label depending on porperty ?

Postby Jabberwocky » Sat Jun 27, 2015 2:10 pm

If those buttons are objects in an .ac, just do select animations on them depending on which one you want.
The other option is to have a button-object without a label at all and just do a texttranslate with a condition based on your property.

Code: Select all
    <animation>
        <type>select</type>
        <object-name>button_visible</object-name>
        <condition>
            <property>whatever your property is</property>
        </condition>
    </animation> 

    <animation>
        <type>select</type>
        <object-name>button_invisible</object-name>
        <condition>
            <not>
               <property>whatever your property is</property>
            </not>
        </condition>
    </animation>
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Howto toggle a Button label depending on porperty ?

Postby mhab » Sat Jun 27, 2015 3:27 pm

Thanks for the reply,
but I did say --> "button in a GUI dialog"

So that's a different thing
mhab
 
Posts: 410
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2019.1.1
OS: Win10

Re: Howto toggle a Button label depending on porperty ?

Postby Thorsten » Sat Jun 27, 2015 4:53 pm

The GUI dialog has an equivalent in the property tree (I guess you would usually specify that where you define the dialog pointer in Nasal) and the label is represented as a property there - which you can change runtime using setprop() .
Thorsten
 
Posts: 11086
Joined: Mon Nov 02, 2009 8:33 am

Re: Howto toggle a Button label depending on porperty ?

Postby mhab » Sat Jun 27, 2015 6:38 pm

OK

I was thinking of that, and I searched "sim/gui/dialogs/..." in the property tree but I cannot find the dialog there.
I have no idea where I can find e.g. the "formation" dialog, which is a standard FG dialog from "FG_HOME/data/gui/dialogs/formation.xml" and is opened through "dialog-show" command.

It seems not to be anywhere in the property tree ...

Thanks
Mike-DE
Last edited by mhab on Sat Jun 27, 2015 7:33 pm, edited 2 times in total.
mhab
 
Posts: 410
Joined: Thu Apr 18, 2013 10:59 pm
Callsign: D-MIKE
Version: 2019.1.1
OS: Win10

Re: Howto toggle a Button label depending on porperty ?

Postby Hooray » Sat Jun 27, 2015 7:10 pm

Please see $FG_ROOT/Docs/README.gui (live properties) and refer to $FG_ROOT/gui/dialogs for examples.
The Nasal route mentioned above is unnecessarily complicated in this case, and would involve using a few gui related fgcommands (as per README.commands).
GUI dialogs don't generally reside in the global property tree, but a non-global/private object.
Obviously, Nasal/Canvas is a much more flexible method.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11340
Joined: Tue Mar 25, 2008 8:40 am

Re: Howto toggle a Button label depending on porperty ?

Postby Thorsten » Sun Jun 28, 2015 6:29 am

Please see $FG_ROOT/Docs/README.gui (live properties) and refer to $FG_ROOT/gui/dialogs for examples.


Well, I couldn't find how to change a button label runtime that way.
Thorsten
 
Posts: 11086
Joined: Mon Nov 02, 2009 8:33 am

Re: Howto toggle a Button label depending on porperty ?

Postby Hooray » Sun Jun 28, 2015 9:14 am

correct, like I said, the dialog's property tree is not live once it is loaded (which is why only a few tags support property/live tags), so you have to manipulate the tree (like you said), but need to re-create the dialog as per the APIs in README.commands

For examples, you can refer to GUI dialogs that need to be very dynamic, e.g. the performance monitor or the multiplayer pilot list.

The aircraft generation wizard I once created is using this method to dynamically create a multi-page wizard with arbitrary pages - but this does involve re-initializing the dialog every time you modify it (via the props.nas module).

Personally, I would probably just use Nasal/Canvas for these things meanwhile
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11340
Joined: Tue Mar 25, 2008 8:40 am

Re: Howto toggle a Button label depending on porperty ?

Postby Red Leader » Tue Jun 30, 2015 8:42 pm

Hi mhab,

As Hooray has said, you could do it via Canvas GUI. However, that would be time-consuming. Canvas GUI is alright, but it needs a few more widgets before it can fully replace the current PLIB PUI.

Assuming that you want to change the button's label when it is clicked, this XML code should help:

Code: Select all
<?xml version="1.0"?>

<PropertyList>

<!-- ... -->

<nasal>
   <open>
      var dlg_root = cmdarg();
      var n = props.Node.new({ "dialog-name": "test" });
      var toggle_label = func {
         if(dlg_root.getNode("button[1]/legend").getValue() == "Number 1"){
            dlg_root.getNode("button[1]/legend").setValue("Number 2");
         }else{
            dlg_root.getNode("button[1]/legend").setValue("Number 1");
         }
         fgcommand("dialog-close", n);
         fgcommand("dialog-show", n);
      }
   </open>
</nasal>

<!-- ... -->

<button>
   <legend>Number 1</legend>
   <binding>
      <command>nasal</command>
      <script>update_label();</script>
   </binding>
</button>

<!-- ... -->

</PropertyList>

All you need to do is change:
  1. "dialog-name": "test" to match the name of your dialog.
  2. the if condition.
  3. the index of the button (in this case 1) to the correct (zero-based) index.
  4. the labels used (obviously).

I hope that helps, :)
Red Leader
For once you have tasted flight you will walk the earth with your eyes turned skywards, for there you have been and there you will long to return.
Leonardo da Vinci

Projects:
BAe Sea Harrier FA2Scripted AI Objects frameworkDocumenting Nasal
Red Leader
 
Posts: 22
Joined: Sat Oct 25, 2014 7:52 pm
Location: United Kingdom
Callsign: Red-Led
Version: 2017.3.1
OS: Microsoft Windows 10

Re: Howto toggle a Button label depending on porperty ?

Postby Hooray » Wed Jul 01, 2015 7:21 pm

note that this will dynamically modify/re-create the dialog using the aforementioned props.nas APIs and the corresponding GUI related fgcommands
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11340
Joined: Tue Mar 25, 2008 8:40 am


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest