How might I construct a function called EmToPX[p] such that the following 2 InputFields would be the same width. If not please explain why doing such isn't possible.

InputField["a", ImageSize -> 100]
InputField["a", FieldSize -> EmToPX[100]]

After some trial an error ~7.2 appears to be the proper number of EMs above( InputField["a", FieldSize -> 7.2]), but after trying to convert to a function using proper ratios it appears such technique doesn't work very well.

EmToPX[p_] := (N[
    p (1.888888 + CurrentValue[EvaluationNotebook[], "FontSize"]) ]);
   InputField["a", ImageSize -> EmToPX[a]],
   InputField["a", FieldSize -> a],
 , {a, 1, 100}

Background: Ultimately I am working with Grid elements and would like an easy way to switch back and froth between CellSize,ImageSize,ItemSize,FieldSize.

  • $\begingroup$ You might want to also read this $\endgroup$ – rm -rf Sep 16 '13 at 22:52
  • $\begingroup$ I believe this is effectively a duplicate but I cannot find the original. Can anyone help? $\endgroup$ – Mr.Wizard Sep 17 '13 at 0:32
  • 2
    $\begingroup$ If you're working with Grid, then for the love of all that is good and holy, don't do it this way. Use Pane to define your constraints, and let Grid just snap itself to the Pane elements. $\endgroup$ – John Fultz Sep 17 '13 at 5:17
  • $\begingroup$ @JohnFultz You are quit right. That does solve my most immediate problem. I think it would be beneficial though if there there was a way to seamlessly add, and subtract between the EMs and pixels. At minimum a reason why such can't be done. $\endgroup$ – William Sep 17 '13 at 11:21
  • 1
    $\begingroup$ @Mr.Wizard See above comment. $\endgroup$ – István Zachar Sep 18 '13 at 6:49

Browse other questions tagged or ask your own question.