Re: Creating dialogs, right-aligning buttons
- To: mathgroup at smc.vnet.net
- Subject: [mg123940] Re: Creating dialogs, right-aligning buttons
- From: Szabolcs HorvÃt <szhorvat at gmail.com>
- Date: Mon, 2 Jan 2012 02:40:43 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201201010728.CAA28407@smc.vnet.net> <CAEtRDSebnrLfE-DTG6bXY77faNOcS7Z6E6ROMowhh6AjMvdtRA@mail.gmail.com>
Thank you!
In the meantime I also found Pane[], which I wasn't familiar with before.
This is what I use right now:
screenHeight[] := -Subtract @@
Part[ScreenRectangle /. Options[$FrontEnd, ScreenRectangle], 2];
preview[img_Image] :=
CreateDialog[
Column[{
Style["Do you want to do this?", Bold],
Pane[
Image[img, Magnification -> 1], {Automatic,
Min[screenHeight[] - 140, 1 + ImageDimensions[img][[2]]]},
Scrollbars -> Automatic, AppearanceElements -> {},
ImageMargins -> 0
],
Item[
ChoiceButtons[{"Do stuff"}, {doStuff[
img]; DialogReturn[]}], Alignment -> Right]
}]
];
Points to note:
* screenHeight[] return the vertical usable screens space (screen
height, minus things like the taskbar on Windows, Mathematica menu,
etc.)
* I needed to make the Pane[] 1 pixel taller than the image itself,
otherwise I'd occasionally get rendering artefacts as I move the mouse
across the screen
* AppearanceElements -> {} removes the resize grip
* my images are never wider than the screen, so I didn't protect
against horizontal overflow
2012/1/1 Bob Hanlon <hanlonr357 at gmail.com>:
> image = Rasterize[
> ExampleData[{"AerialImage", "Earth"}],
> ImageSize -> 1024]; {* oversize image *)
>
> itemWidth = Min[512,
> {ImageSize /. AbsoluteOptions[image, ImageSize]}[[1]]];
>
> CreateDialog[
> Column[{
> Panel[
> "Some message here",
> ImageSize -> itemWidth],
> Pane[image,
> ImageSize -> {itemWidth, itemWidth},
> Scrollbars -> True],(*this is obtained from Rasterize*)
> ChoiceButtons[
> {"Do it!"},
> {doIt[]; DialogReturn[]}]},
> Alignment -> Right]];
>
> or, if you prefer, put the panel around the buttons
>
> CreateDialog[
> Column[{
> "Some message here",
> Pane[image,
> ImageSize -> {itemWidth, itemWidth},
> Scrollbars -> True],(*this is obtained from Rasterize*)
> Panel[
> ChoiceButtons[
> {"Do it!"},
> {doIt[]; DialogReturn[]}],
> ImageSize -> itemWidth,
> Alignment -> Right]}]];
>
> or put a panel around both (not shown).
>
>
> Bob Hanlon
>
> 2012/1/1 Szabolcs Horv=C3=A1t <szhorvat at gmail.com>:
>>
>> Hello,
>>
>> What is the best way to create dialogs and align the different UI
>> elements in them?
>>
>> In particular, how can I create a dialog with right-aligned OK and
>> Cancel buttons?
>>
>> Here's a simplified model of what I'm actually doing:
>>
>> image = Rasterize@ExampleData[{"AerialImage", "Earth"}]
>>
>> CreateDialog[
>> Column[
>> {"Some message here",
>> image, (* this is obtained from Rasterize *)
>> ChoiceButtons[{"Do it!"}, {doIt[]; DialogReturn[]}]}
>> ]
>> ]
>>
>> Problems with this approach:
>>
>> * How can I right-align the buttons without
>> right-aligning all other elements?
>>
>> * I do not know the size of the image beforehand. It may be
>> taller than the screen in my application. In this cas=
e
>> it will push the buttons off-screen.
>> How can I protect against this?
>>
>>
>> There seem to be many ways to create dialogs in Mathematica. There's
>> CreateDialog (shown here), MessageDialog (which makes ugly small buttons
>> where there's more than one button, and I'm having problems controlling
>> the window size), ChoiceDialog (the buttons return values instead of
>> doing something).
>>
>>
>> Can you show me example code based on the model above, with its problems
>> fixed?
>>
>>
>> --
>> Szabolcs Horv=C3=A1t
>> Mma QA site proposal: http://area51.stackexchange.com/proposals/37304
>>
--
Szabolcs Horv=C3=A1t
Mma QA site proposal: http://area51.stackexchange.com/proposals/37304
- References:
- Creating dialogs, right-aligning buttons
- From: Szabolcs Horvát <szhorvat@gmail.com>
- Creating dialogs, right-aligning buttons