How can one convert between the implicit units used by Grid
(ems and line height for horizontal and vertical dimensions) and printers points (in GraphicsGrid
and Graphics
)?
Grid[{{"sample", "text"}}, Frame -> All,
ItemSize -> {{4, 7}, Automatic}]
Row@{Framed["sample", ImageSize -> 60, FrameMargins -> 0],
Framed["sample", ImageSize -> 100, FrameMargins -> 0]}
GraphicsGrid[{{"sample", "text"}}, Frame -> All, ItemSize -> 7]
GraphicsGrid[{{Item["sample", ItemSize -> 4],
Item["text", ItemSize -> 7]}}, Frame -> All(*,ImageSize->160*)]
The last two examples show that, while the documentation of ItemSize
states that "In GraphicsGrid, w and h are both measured in absolute printer's points", ItemSize
cannot be used as an option for GraphicsGrid
and it doesn't do anything as an option for an internal object wrapped in Item
.
Realistic example
Here is a particular problem, that presents the issue of different units in the same object. The task is to automatically scroll a Pane
to a certain line in a dataset.
Updated: Improved code according to Heike, to keep the line in focus at the top.
data = Range@200;
lineHeight = 1.5;
conversion = 14; (* magic number *)
paneHeight = 120;
update[n_] := (scrollToThis = n;
pos = (scrollToThis - 1)*lineHeight*conversion);
update@1;
Row@{Slider[Dynamic[scrollToThis, (update@#) &], {1, Length@data, 1}],
" line: ", Dynamic@scrollToThis, " at position: ", Dynamic@pos}
Dynamic[Framed[
Pane[Grid[List /@ data, Frame -> All, ItemSize -> {5, lineHeight},
Background -> {White, {scrollToThis -> Red}}],
ImageSize -> {100, paneHeight}, Scrollbars -> {False, True},
ScrollPosition -> {0, pos}, ImageMargins -> 0, FrameMargins -> 0],
ImageMargins -> 0, FrameMargins -> 0],
TrackedSymbols :> {scrollToThis, pos}]
Question
Is there a way to convert between different units (ems / lineheight <--> printers points) in a foolproof way?
22.77
on my machine. $\endgroup$ScrollPosition
only accepts pixel measurements as briefly skimming the help suggests I don't see how this can be done reliably. $\endgroup$