Page 1 of 1
understanding handling of nested widgets
Posted: 12 May 2010 09:30
by planetmaker
I'm currently trying to get a nice handling of a tab view into place. Attached is a diff where I don't quite understand the behaviour (see the attached two screenshots). In both cases, I expect a behaviour as shown in the 2nd one (with AI having the same colour as the empty panel, the other buttons showing the pressed state). Any pointers of what I'm missing?
The diff actually looks larger than it is as I changed the indentation of the nested widget array (due to introducing the selection widget).
EDIT: it's not a big thing that the random seed doesn't show (in the screen), that's solved in the diff.
Re: understanding handling of nested widgets
Posted: 12 May 2010 16:54
by planetmaker
Maybe just to clearify why I'm so puzzled in particular: If I move the 4 tab buttons out of the switched plane, the behaviour works as I expect it to work, the buttons are properly drawn. Attached screenshot and diff for that behaviour. The backdraw is that in that case there's a separation line between the tab label and the big panel
Re: understanding handling of nested widgets
Posted: 12 May 2010 20:37
by Zuu
Some comments regarding the first patch:
* Don't put tabs at lines without code. This actually makes the patch a bit longer at at least one place than it would need to be.
* At the beginning of the patch you have a code line with a tab at the end. This is boring stuff but they shouldn't be there and I get that sometimes too. The best way to handle it is to run some regex searches on your patches after you created them with your common mistakes. I usually scan for "if(" and "for(" as well, as I use that coding style for another project.
Re: understanding handling of nested widgets
Posted: 13 May 2010 12:25
by ChillCore
Hello planetmaker,
I did not get to solve your problem but I hope the attached patch suits your needs.
The first patch introduces a wigdet for centering a simple text string, WWT_CENTERED_TEXT. I will use it myself for rearranging the load heightmap gui in another patch.
The second patch is your first posted, using the centered text widget.
! No need to apply both at the same time ! The second includes the first.
I have outcommented the 'SetWidgetLoweredState' code in 'virtual void OnPaint()' and replaced the colourcodes for not selected tabs.
I could not find the correct colour code for light brown, to use for (fake) pressed down tabs, so I have used yellow for now. See attached picture.
I tried COLOUR_LIGHT_BROWN but it 'is not defined in this scope' and I do not feel like searching for now, Sorry about that.
Also I have removed the tabs on empty lines and a few spaces on line endings.
(You may want to disable auto indent in your text editor to prevent the tabs on empty lines.)
Loading heightmaps crashes the game but I assume you already knew that as the heightmap gui is not yet extended.
To reproduce click load heightmap, on selecting the heightmap to play the game exits with a segmentation fault.
Edit:
Removed patches. There is already a widget for centering simple text and planetmaker already has an updated version. Read below.
Re: understanding handling of nested widgets
Posted: 13 May 2010 13:32
by Alberth
ChillCore wrote:The first patch introduces a wigdet for centering a simple text string, WWT_CENTERED_TEXT. I will use it myself for rearranging the load heightmap gui in another patch.
Euhm, what's wrong with WWT_LABEL ?
Re: understanding handling of nested widgets
Posted: 13 May 2010 13:42
by planetmaker
Thanks Zuu & Chillcore for your input, very much appreciated
After a discussion with Alberth it turns out that the error I had been doing was to use the same widgetID twice; that must even be avoided, if both widgets are not displayed at the same time, even if they are on different 'planes' of the same window.
I continued to play around with it, a slightly boilt-down version is
attached to FS
Re: understanding handling of nested widgets
Posted: 13 May 2010 13:49
by Zuu
Actually after having looked at many different attempts I think this one below is the one that best resambles with the OpenTTD-style. At least if you reverse it so that you have one lowered button and all other are raised.

Re: understanding handling of nested widgets
Posted: 13 May 2010 13:50
by ChillCore
Alberth wrote:
ChillCore wrote:
The first patch introduces a wigdet for centering a simple text string, WWT_CENTERED_TEXT. I will use it myself for rearranging the load heightmap gui in another patch.
Euhm, what's wrong with WWT_LABEL ?
Other then me being to lazy to find out what all the widgets do? Nothing I guess.
Updated version in the making. (Edit: No need I see. Will check in a bit planetmaker)
Thank you Alberth.