What is the best way to right align a button in a dialog window, regardless of the window's WindowSize?
Here is a resizable window to test on:
CreateDialog[
Column[{"Here's some text text text text text text text",
ChoiceButtons[]}],
WindowFrameElements -> {"ResizeArea"},
WindowFrame -> "Normal"]
I would like the button to always be right aligned.
Some unsatisfactory solutions I thought of:
Put the button in an
Itemand right align. Then the right margin is determined by theColumnsize which can't easily be set in pixels.Put the button in a
Panel, right align it, and set a fixed size on the panel. Again, the size is determined by the panel size, not the window size.
Use case:
Suppose we need to create an alternative to MessageDialog. This new function, myMessageDialog, should take the WindowSize option, and the created notebook should respond to SetOptions[nb, WindowSize -> ...] The dialog buttons should always be aligned to the right edge of the window regardless of the window size.
Item. Could you useSpacerto set a margin after converting pixels to printer's points? – Mr.Wizard Jul 27 '12 at 11:54Itemsizes can only be set in ems, not pixels. I use theItemapproach in the image uploader's history dialog, and on a Chinese version of Windows, the sizes are all messed up because of the unpredictability of the em width (different system font). – Szabolcs Jul 27 '12 at 11:56Spaceruses pixels. An em is the width of the letter M, or something like that ... – Szabolcs Jul 27 '12 at 12:01Spacerworks as desired you can use that to set the margin, can you not? That's one problem down if so. – Mr.Wizard Jul 27 '12 at 12:03MessageDialogdoes it: it always has the button aligned to the right edge of the window. – Szabolcs Jul 27 '12 at 12:04Item[Row[{ChoiceButtons[], Spacer[7]}], Alignment -> Right]-- you said "right margin" so I assume you want something like this? Also, have you tried usingDynamic@CurrentValue["WindowSize"]to set the size of aRow/Grid/whatever? – Mr.Wizard Jul 27 '12 at 12:08Dynamic@CurrentValue["WindowSize"]is an excellent suggestion! It is possible to useCreateDialog[..., WindowSize -> Dynamic[sz]], but that is very messy, especially becauseszcan't be properly localized with aDynamicModule. Your suggestion to useCurrentValueis much better. Unfortunately I'm not sure how to set theGridsize with this as it is specified inItemSizeunits. But it's a step forward nevertheless. – Szabolcs Jul 27 '12 at 12:22