Board index FlightGear Development Canvas

Canvas Widget use  Topic is solved

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Re: Canvas Widget use

Postby Necolatis » Mon Jul 14, 2014 1:30 am

.clear() works, except for nested elements. I will do some kind of hack to get it to work.
Thanks.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby Hooray » Mon Jul 14, 2014 1:36 am

note that the posted link is just the FG side of things, the underlying base classes should be defined in SG IIRC - so if you miss any methods, check there first
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Canvas Widget use

Postby TheTom » Mon Jul 14, 2014 2:47 pm

Necolatis wrote in Mon Jul 14, 2014 1:30 am:.clear() works, except for nested elements. I will do some kind of hack to get it to work.

clear() should also work with nested elements. You need to make sure that there are no references around to the according elements. (eg. vars in a func are not cleaned up after executing a function...)
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Tue Jul 15, 2014 1:58 pm

I have some further questions:

In this line what does the second parameter do: vbox.addItem(scroll, 1)

In this line, what does the number signify: .addStretch(1)

Can I hide/show a layout item? So that when it is hidden, its size is not factored into the layout. I need to switch between two different items in the same layout space.
I figure I can make a new canvas group, and show and hide that. But then the items would still take up layout space. If I could make a VBoxLayout take up 0 size temporarily then maybe I could solve it that way..
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Tue Jul 15, 2014 3:11 pm

Necolatis wrote in Tue Jul 15, 2014 1:58 pm:In this line what does the second parameter do: vbox.addItem(scroll, 1)

Its the stretch factor (works the same as in Qt): http://qt-project.org/doc/qt-5/qboxlayout.html

Necolatis wrote in Tue Jul 15, 2014 1:58 pm:In this line, what does the number signify: .addStretch(1)

Space in excess of the prefered space of each item is distributed proporitional to the assigned stretch factors. Layouting works basically the same as with Qt: http://qt-project.org/doc/qt-5/layout.html You can use addSpacing(<num>) to add a spacing with a fixed size of <num> pixels.

Necolatis wrote in Tue Jul 15, 2014 1:58 pm:Can I hide/show a layout item?

No, (not yet). Currently you can just remove and add items. Use layout.takeAt(<index>) to remove the item with given index, and layout.insertItem(<index>, <widget/layout>) to insert an item at the given index. It should also work to set a maximum (or fixed size) of (0, 0). To reset to the automatic size reset to minimumSize and sizeHint (0, 0) and maximumSize (gui.Widget._MAX_SIZE, gui.Widget._MAX_SIZE).
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Wed Jul 16, 2014 3:56 am

That seems to work, except for the stretchfactor, which I cannot figure out how to set after an item has been added.

item.setStretchFactor(widget, 0) does not seem to work. Any other way of doing that?
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Wed Jul 16, 2014 10:55 am

Should work now. I just forgot to expose it to Nasal. You can have a look at https://gitorious.org/fg/flightgear/sou ... s.cxx#L475 to see what is available in Nasal.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Wed Jul 16, 2014 1:33 pm

Nice, thanks. That semi works now. When setting a layout to maximum/hint size 0,0 and stretchfactor to 0, it now gets smaller, but does not get size zero.
Anything else I can do?

Also in aircraft-center I wonder why these lines have move and size, since its size and position is determined by layout: (has it any effect?)

var scroll = gui.widgets.ScrollArea.new(m._root, style, {size: [96, 128]})
.move(20, 100);
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Wed Jul 16, 2014 1:50 pm

Necolatis wrote in Wed Jul 16, 2014 1:33 pm:Nice, thanks. That semi works now. When setting a layout to maximum/hint size 0,0 and stretchfactor to 0, it now gets smaller, but does not get size zero.
Anything else I can do?

Ah, thats the padding/spacing. For now try to add a negative spacing before or after the "hidden" item.

Necolatis wrote in Wed Jul 16, 2014 1:33 pm:Also in aircraft-center I wonder why these lines have move and size, since its size and position is determined by layout: (has it any effect?)

It has no effect. Just a leftover from earlier experiments without the layouting system :-)
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Wed Jul 16, 2014 2:36 pm

If I insert any negative spacing, it appears they do not get smaller at all.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Wed Jul 16, 2014 2:44 pm

Strange. Maybe I've limited somewhere the size to 0. You can then try it the other way round. Set the spacing of the layout to 0 and manually add spacing between items as required.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Wed Jul 16, 2014 3:10 pm

Not sure I understand.

Are you refering to setSpacing(0) ? Does that set a spacing for all its items at once?

As for add spacing as required, since I seem to need negative spacing, not sure how to do that.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Wed Jul 16, 2014 3:19 pm

The spacing set with setSpacing is added between every two items of the layout and defaults to 5. So with setSpacing(0) there will be no spacing any more. If you then want to add spacing between items you need to add it with addSpacing/insertSpacing, eg:

Code: Select all
box.addItem(...);
box.addSpacing(5);
box.addItem(...);
box.addSpacing(5);
box.addItem(...);


With box.takeAt(<index>) you can also remove spacing by the index inside the layout.

If you don't need it now or for 3.2. just wait a few days and I will add the possibility to hide elements to git.
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Canvas Widget use

Postby Necolatis » Wed Jul 16, 2014 3:22 pm

It is for 3.4, so I will wait for that then. :)
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas Widget use

Postby TheTom » Mon Jul 21, 2014 2:22 pm

I've just pushed it. You can now use the following methods on every LayoutItem (Widget/Layout):

Code: Select all
setVisible(bool visible)
isVisible()
isExplicitlyHidden()
show()
hide()
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

PreviousNext

Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests