understanding handling of nested widgets

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

understanding handling of nested widgets

Post 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.
Attachments
map tab
map tab
genworld_map.png (63.16 KiB) Viewed 2352 times
ai tab (still empty)
ai tab (still empty)
genworld_ai.png (26.05 KiB) Viewed 2352 times
genmap.diff
diff
(24.76 KiB) Downloaded 77 times
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: understanding handling of nested widgets

Post 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
Attachments
separated_tab_button.png
separated_tab_button.png (56.85 KiB) Viewed 2284 times
seperate_buttons.diff
diff which gives the layout as shown in attached image
(24.84 KiB) Downloaded 106 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: understanding handling of nested widgets

Post 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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: understanding handling of nested widgets

Post 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.
Attachments
screenshot.png
screenshot.png (15.43 KiB) Viewed 2176 times
Last edited by ChillCore on 13 May 2010 13:58, edited 1 time in total.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: understanding handling of nested widgets

Post 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 ?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: understanding handling of nested widgets

Post 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
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: understanding handling of nested widgets

Post 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.

Image
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: understanding handling of nested widgets

Post 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.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 55 guests