Right aligned button
-
Hi,
I'd like to place one button at the right side of a row of the window, and the rest of the buttons to the left side of the same row.
like this:__________________________________________ | b1 b2 b3 b4 .... bn-1 bn| | | | | | |
I put the first n-1 buttons to a group, and the last button the another group, and I thought applying BFH_RIGHT flag to the right group and the last button could help me get the expected result, however, I found the button n is always right after button n-1 instead of at the very right side of the row.
The actual result is as below:__________________________________________ | b1 b2 b3 b4 .... bn-1 bn | | | | | | |
The code I used is similar to below:
// parent group GroupBegin(100, BFH_SCALEFIT, <n>, 0, ""_s, 0, 0, 0); // group at the left side GroupBegin(200,BFH_LEFT|BFV_FIT,<n-1>,0,""_s,0); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "b1", BFH_FIT|BFV_FIT, minw, 0,customdata); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "b2", BFH_FIT|BFV_FIT, minw, 0,customdata); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "b3", BFH_FIT|BFV_FIT, minw, 0,customdata); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "b4", BFH_FIT|BFV_FIT, minw, 0,customdata); ... AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "bn-1", BFH_FIT|BFV_FIT, minw, 0,customdata); GroupEnd() // group at the right side GroupBegin(300, BFH_RIGHT | BFV_FIT, 1, 0, ""_s, 0); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "bn", BFH_RIGHT|BFV_FIT, minw, 0,customdata); GroupEnd() GroupEnd()
Could you please help me find out what's going wrong?
Note: I need the last button always at the right side of the row after user resizes the window width. -
Hi @BruceC,
The layout options in our API can sometimes be a little counter-intuitive. However, in your scenario (assuming you're talking about normal window layout, not the toolbar scope), the solution would be in adding an empty static text, which scale-fits the empty space and pushes the last button to the right. For this you'd need to use BFH_SCALEFIT on the static text.
Note: in this case you also need to use BFH_SCALEFIT on the parent group of the buttons. Also note, that grouping left buttons (as well as right ones) is not necessary, but if you do so, you shouldn't use BFH_SCALEFIT there.
It can look for example something like the code snippet below.
Cheers,
IliaThe C++ code snippet for layouting:
// parent group GroupBegin(100, BFH_SCALEFIT, 0, 1, ""_s, 0, 0, 0); // group at the left side GroupBegin(200, BFH_LEFT, 0, 1, ""_s, 0); AddCustomGui(201, CUSTOMGUI_BITMAPBUTTON, "b1", BFH_FIT | BFV_FIT, minw, 0, customdata); AddCustomGui(202, CUSTOMGUI_BITMAPBUTTON, "b2", BFH_FIT | BFV_FIT, minw, 0, customdata); AddCustomGui(203, CUSTOMGUI_BITMAPBUTTON, "b3", BFH_FIT | BFV_FIT, minw, 0, customdata); AddCustomGui(204, CUSTOMGUI_BITMAPBUTTON, "b4", BFH_FIT | BFV_FIT, minw, 0, customdata); GroupEnd() // group left side // add the hidden stretching static text AddStaticText(0, BFH_SCALEFIT, 0, 0, ""_s, 0); // group at the right side GroupBegin(300, BFH_RIGHT | BFV_FIT, 0, 1, ""_s, 0); AddCustomGui(301, CUSTOMGUI_BITMAPBUTTON, "bn", BFH_RIGHT | BFV_FIT, minw, 0, customdata); GroupEnd() // group right side GroupEnd() // parent group
-
This works! Thank you very much, @i_mazlov.