10
$\begingroup$

Bug introduced in 8 or earlier and persists through 11.3


Edit 16. IV 2016 I've received an answer from WRI Support:

[...] It does appear that CellMargins is not interacting correctly with WindowSize->All, and I have forwarded an incident report to our developers with the information you provided. I have also included your contact information so that you can be notified once this gets resolved. [...]

Which I believe confirms that this is a bug. I'd appreciate checking that in earlier versions of MMA.


DialogInput has by default those annoying margins settings (missing a bottom one):

DialogInput[Pane@RandomImage[]]

enter image description here

What is the best/shortest way to make them even.

Let's not touch stylesheets here.

It seems that the problem is more general. I was suspecting that somwhere deep in definitions of DialogInput some options are prepended but here I'm just using basic code to generate the issue:

NotebookPut @ Notebook[
  List @ Cell @ BoxData @ ToBoxes @ Pane[
    RandomImage[], ImageMargins -> 0, FrameMargins -> 0
  ],
  WindowSize -> All, 
  WindowElements -> None, 
  "CellInsertionPointCell" -> None, 
  WindowFrameElements -> {"CloseBox"},
  ShowCellBracket -> False, 
  CellMargins -> 10
]

enter image description here

$\endgroup$
8
$\begingroup$

There is a straightforward way to set CellMargins to be zero:

DialogInput[
 DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 8], 
    CellMargins -> 0]}]]

screenshot

Instead of ImageMargins we can rely on CellFrameMargins:

DialogInput[
 DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 8, 
    CellFrame -> True, CellFrameColor -> None]}]]

screenshot

On my system (Windows 7 x64) with Mathematica 10.4 the CellFrameMargins method gives more accurate results than ImageMargins (compare the screenshots):

DialogInput[
 DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 1], 
    CellMargins -> 0]}]]

DialogInput[
 DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 1, 
    CellFrame -> True, CellFrameColor -> None]}]]

screenshot with ImageMargins -> 1 screenshot with CellFrameMargins -> 1


From your second example in the question I believe that this behavior is determined by the WindowSize -> All Notebook option which makes the window

large enough to fit all visible contents

(emphasis mine).

It seems that FrontEnd crops CellMargins because they "aren't visible". But with this explanation the inconsistency is that it crops them only at the bottom but not on the right even if we switch off displaying of the cell bracket:

NotebookPut@
 Notebook[{Cell@
    BoxData@ToBoxes@Pane[RandomImage[], ImageMargins -> 0, FrameMargins -> 0]}, 
  WindowSize -> All, WindowElements -> None, ShowCellBracket -> False, 
  WindowFrameElements -> {"CloseBox"}, CellMargins -> 10]

screenshot

If we add another cell we can see that CellMargins are actually respected:

NotebookPut@
 Notebook[Table[
   Cell@BoxData@ToBoxes@Pane[RandomImage[], ImageMargins -> 0, FrameMargins -> 0], {2}], 
  WindowSize -> All, WindowElements -> None, ShowCellBracket -> False, 
  WindowFrameElements -> {"CloseBox"}, CellMargins -> 10]

screenshot

So I'm inclined to think that we have a bug in handling of the WindowSize -> All option: the expected behavior for this option is to treat CellMargins as visible contents and make the window to be sufficiently large to include the whole CellMargins.

$\endgroup$
  • $\begingroup$ Yep, that's shorter than mine. I believe I've used something like that once but I forgot due to the confusion about all those DialogNotebook/CreateWindow/Notebook and friends. Do you possibly have any idea what's the root of the problem? $\endgroup$ – Kuba Apr 15 '16 at 6:31
  • $\begingroup$ @Kuba I think it's a bug. I have read the Dialog.nb stylesheet but haven't found anything what could explain this. I also wasn't able to reproduce this with the default stylesheet (but I haven't spend much time on this). $\endgroup$ – Alexey Popkov Apr 15 '16 at 8:24
  • $\begingroup$ The second example in the question includes the default.nb stylesheet. I just had to get rid of some elements to make this effect visible. I've sent a support question, CASE:3579534 created, will keep you informed. $\endgroup$ – Kuba Apr 15 '16 at 8:29
  • $\begingroup$ @Kuba Thanks, I overlooked the second example. I have updated the answer with new findings. $\endgroup$ – Alexey Popkov Apr 15 '16 at 8:51
  • $\begingroup$ @Kuba Added CellFrameMargins-based workaround and the comparison. $\endgroup$ – Alexey Popkov Apr 15 '16 at 9:08
6
$\begingroup$

I gave up looking for neat solution. Here's brute force.

Since the bottom CellMargins are not respected then let's not use any! :) We can use Pane and its ImageMargins to take control over padding.

DialogInput[
   DynamicModule[{},
      Pane[RandomImage[], ImageMargins -> 8],
      Initialization :> (SetOptions[EvaluationCell[], CellMargins -> 0])
   ]
]

enter image description here

So in general instead of RandomImage[] put the code you would have used in DialogInput.

$\endgroup$
  • 1
    $\begingroup$ I love brute force solutions :) $\endgroup$ – M.R. Apr 15 '16 at 0:21
3
$\begingroup$

It really expects that you have some buttons along the bottom.

DialogInput[Column[{Pane @ RandomImage[], Button["OK", DialogReturn[0]]}]]

dialog1

but you can do it this way

DialogInput[Column[{Pane @ RandomImage[], ""}]]

dialog2

Update

I Think it looks better with the bottom margin a bit larger than the top, but if you are being picky about equal margins, try

DialogInput[Column[{Pane@RandomImage[], ""}, Spacings -> 0]]

dialog3

$\endgroup$
  • $\begingroup$ But I don't have any Buttons. Both you examples have the bottom margin different than the rest of them. $\endgroup$ – Kuba Apr 14 '16 at 15:39
  • $\begingroup$ @Kuba. see update $\endgroup$ – m_goldberg Apr 14 '16 at 15:51
  • $\begingroup$ Yes, that's good quick fix thanks. Unfortunately it doesn't give a precision/control, over those margins, that I'm after. $\endgroup$ – Kuba Apr 15 '16 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.