4
$\begingroup$

I have a palette containing a Grid with dynamics. As it runs it jiggles horizontally. Here's a minimal example:

CreatePalette[
 Dynamic[Grid[{{"Some text of unknown length", 
     DateString["SecondShort"]}}, BaseStyle -> 15], 
  UpdateInterval -> 1], Saveable -> False]

width of palette wiggles back and forth and depends on the text presented in it

I don't want to just set WindowSize because I don't know the size before it's run, and unfortunately Grid doesn't have like an ImageMargins or ImagePadding or anything like that. I'm sure there must be some simple way of doing this.

$\endgroup$
5
  • $\begingroup$ If you don't know the size before it's run, than I think you're out of luck. No matter what size the initial window is, at some point it is possible for the contents to be bigger than the window. $\endgroup$
    – Carl Woll
    Commented Nov 20, 2019 at 23:08
  • $\begingroup$ Would placing your variable width content in Panes of fixed widths help? e.g. Pane[DateString["SecondShort"], 20, FrameMargins -> 0, ImageMargins -> 0, ContentPadding -> False] $\endgroup$
    – Greg Hurst
    Commented Nov 21, 2019 at 0:36
  • $\begingroup$ Or perhaps a fixed width font. e.g. Style[DateString["SecondShort"], FontFamily -> "Courier"] $\endgroup$
    – Greg Hurst
    Commented Nov 21, 2019 at 0:38
  • $\begingroup$ @ChipHurst that almost works, but the palette changes size when it wraps around from 59 back to 0... I tried getting the padding form right, but I can't avoid the jiggle :( $\endgroup$
    – M.R.
    Commented Nov 21, 2019 at 1:04
  • $\begingroup$ Which one? I don't see the jiggle with Pane. For the Style idea, padding the string prevents the 59 -> 0 jiggle. Style[StringPadRight[DateString["SecondShort"], 2, " "], FontFamily -> "Courier"] $\endgroup$
    – Greg Hurst
    Commented Nov 21, 2019 at 1:21

1 Answer 1

3
$\begingroup$

Let's assume that the content's size is unknown up front but stays more or less the same later. You can adjust the size after it appears by using current value of WindowSize or to do this up front by using Rasterize[whatever, "RasterSize"].

Let's try with the former one as Rasterize needs to be adjusted to use palettes' styles anyway.

CreatePalette[
 DynamicModule[{},
  Pane[
   Dynamic[
    Grid[{{"Some text of unknown length", DateString["SecondShort"]}},
      BaseStyle -> 15], UpdateInterval -> 1],
   Full,
   FrameMargins -> 5,
   Alignment -> {Left, Center}
   ],
  SynchronousInitialization -> False,
  Initialization :> (
    CurrentValue[EvaluationNotebook[], WindowSize] = 
     1.05 AbsoluteCurrentValue[EvaluationNotebook[], WindowSize]
    )
  ]
 , Saveable -> False

 ]

Does it fit your needs?

$\endgroup$
1
  • 1
    $\begingroup$ Almost, this stops the window of the palette from jiggling. But two things: if I set SynchronousInitialization->False, then for some reason some of my FE`oneOfMyDyamicModuleSymbols do not format for a few seconds, which looks bad, and still the numbers in the Grid columns continue to jiggle... $\endgroup$
    – M.R.
    Commented Jan 15, 2020 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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