Bug introduced in 8 or earlier and persists through 12.0
Edit 16. IV 2016 I've received an answer from WRI Support:
[...] It does appear that
CellMarginsis not interacting correctly withWindowSize->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[]]
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
]
Answer
There is a straightforward way to set CellMargins to be zero:
DialogInput[
DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 8],
CellMargins -> 0]}]]
Instead of ImageMargins we can rely on CellFrameMargins:
DialogInput[
DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 8,
CellFrame -> True, CellFrameColor -> None]}]]
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]}]]

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]
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]
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.






Comments
Post a Comment