DDgui_spacer help

Previous topic - Next topic

FutureCow

Hi guys,
I started playing with DDgui today and I'm having trouble getting the spacer to work (I think it might be a bug but I'll post here first in case I'm missing something obvious).
The problem is down near the end. I have some text, then want a space before two buttons.
Instead the spacer widget, even though it is before the buttons, is inserting after the buttons.
i.e. The line "DDgui_spacer(0,100)" should move the "answer 1" and "answer 2" buttons down - at least, that's what I thought it should do.

Am I doing something wrong?

Code (glbasic) Select
FUNCTION Challenge2:
DDgui_pushdialog(100,100,300,400) // create main window
DDgui_set("", "TEXT", "Challenge 2 - Do I hear a bang?") // set window title

DDgui_widget("dtext1", "xxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.", 300,0)
DDgui_widget("dtext2", "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYYYYYYYYYYYY YYYYYYYYYY YYYYYYYYYYYYY.", 300,0)
DDgui_widget("dtext3", "\n\nZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZZZZZZZZZZZZZ.", 300,0)
DDgui_widget("dtext4", "\nAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.\n", 300,0)

DDgui_spacer(0,100)
DDgui_text("answer1","Answer 1")
DDgui_widget("dtext5", "and", 0,0)
DDgui_text("answer2","Answer 2")

// THE SPACER WIDGET ENDS UP HERE RATHER THAN BEFORE THE TWO BUTTONS

DDgui_widget("dtext6", "Your answer is currently : Incorrect", 0,0)
DDgui_spacer(0,40)
DDgui_button("id_button1", "Check Answer", 0,0)
DDgui_spacer(40,0)
DDgui_button("id_button2", "Main Menu", 0,0)


WHILE TRUE
DDgui_show(FALSE);
SHOWSCREEN
// check for user interaction
WEND

Quentin

hmm, looks like a "feature" ??

just change
Code (glbasic) Select

DDgui_spacer(0,100)


to
Code (glbasic) Select

DDgui_spacer(10000,50)


and it works as expected. Instead of 10.000 you can use any other value that is bigger than the current dialog width, but with 10.000 you're on the save side. If I remember well, I always used this value if I want to create line feed within the dialog.

Perhaps Gernot will bring some light to this behavior :)

Kitty Hello

Think of the spacer as an invisible "box". If the box is too wide to fit the line, the line gets wrapped.
If the spacer has a height, the spacer will make a newline with the given height, but the next widget will be too far right at the end of the spacer so it will do another line feed.

If you have spacers for newlines in a frame, be sure to match the spacer to the frame's size to get the line break, or the frame will "explode" to the full size of the dialog if you use 10000 as a spacer width.

Quentin

clear so far :)

but just take a look at the example of FutureCow:

Spacer is called with width = 0 and height = 100. The spacing is taking place after the following three widgets, not before as one should expect. This is an odd behavior.

FutureCow

Hi Gernot,
As Quentin wrote, the odd behaviour is where the space widget actually puts the space - it adds the spacer in the wrong place.

Quentin - setting the spacer to >= the size of the frame gets around the problem, thanks!

Kitty Hello

If you make a spacer (0,300), the spacer will not line wrap, but increase the current line of the widgets. Just replace the spacer with a button of that size to see what happens.

FutureCow

I want to have a button that when pressed, makes another button appear next to it. Is there a way to do this but centre the two buttons (ie. draw one button that when pressed moves the original one to the left and inserts a new one on its right so they're both the same distance from the centre?)

Kitty Hello

You can hide buttons with DDgui_hide() (or show them).
To center both, you uhm....
* Kitty Hello hides in a cave