Question about tag LAYOUT_EvenSize
I'm creating a window that looks like this
The buttons "Ok" and "Cancel" at the bottom are in their own horizontal layout:
LAYOUT_AddChild, NewObject(LAYOUT_GetClass(), NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_EvenSize, FALSE,
LAYOUT_AddChild, m_ppGadgets[GID_BTN_OK] = NewObject(BUTTON_GetClass(), NULL,
GA_ID, GID_BTN_OK,
GA_RelVerify, TRUE,
GA_Text, (ULONG)"Ok",
BUTTON_TextPadding, TRUE,
TAG_DONE),
LAYOUT_AddChild, m_ppGadgets[GID_BTN_CANCEL] = NewObject(BUTTON_GetClass(), NULL,
GA_ID, GID_BTN_CANCEL,
GA_RelVerify, TRUE,
GA_Text, (ULONG)"Cancel",
BUTTON_TextPadding, TRUE,
TAG_DONE),
TAG_DONE),
Because LAYOUT_EvenSize, TRUE,
they should have the same width, but smaller as they are. From the autodocs:
(BOOL) Use the minimum size of the largest child for all children. Default FALSE.
So they both should only be as wide as the "Cancel" button
So my main question is: Is there a way to have both buttons in this horizontal layout so that they have the same (small) width and one is aligned left an the other aligned on the right? Like its done in the Amiga system requesters?
As SamuraiCrow mentioned, you should put a space gadget between the two and give CHILD_WeightedWidth of 100. Set CHILD_WeightedWidth to 0 for the two button gadgets. This should give you what you want.
Also give the buttons BUTTON_TextPadding, TRUE for the authentic 3.2 look.
Actually don't put a space.gadget - A space.gadget dispite its name is not a simple spacer - A space gadget is a canvas (aka space) where a hook can render.
You will get the right look if you use space.gadget, but it is overkill. A simple empty label.image used as a gadget will work just as well, The idea is to have a lightweight class that doesn't render anything.
The reason I propose a label.image is that it is already loaded in memory and thus takes up less memory. You could also use a gadgetclass, which would be even more basic, but you can only get that using the string and not a class pointer, and so it will be a bit slower to create.
Thank you all for your answers! While playing around with the layout, I found that setting CHILD_WeightedWidth, 0
for each button was enough to make it work. So, the working variant now looks like this:
LAYOUT_AddChild, NewObject(LAYOUT_GetClass(), NULL,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_EvenSize, TRUE,
LAYOUT_AddChild, m_ppGadgets[GID_BTN_OK] = NewObject(BUTTON_GetClass(), NULL,
GA_ID, GID_BTN_OK,
GA_RelVerify, TRUE,
GA_Text, (ULONG)"Ok",
BUTTON_TextPadding, TRUE,
TAG_DONE),
CHILD_WeightedWidth, 0,
LAYOUT_AddChild, m_ppGadgets[GID_BTN_CANCEL] = NewObject(BUTTON_GetClass(), NULL,
GA_ID, GID_BTN_CANCEL,
GA_RelVerify, TRUE,
GA_Text, (ULONG)"Cancel",
BUTTON_TextPadding, TRUE,
TAG_DONE),
CHILD_WeightedWidth, 0,
TAG_DONE)
Online Status
Coming from an MUI background so I may have the terminology wrong but if you put a space between the buttons, that should fix the layout. On some platforms you have to make sure it isn't an absolute sized space, on Hollywood's RapaGUI plug-in it's called a "rectangle".