Class ThemePreview

java.lang.Object
limn.scene.Widget
limn.themeeditor.ThemePreview

public final class ThemePreview extends Widget
A miniature window, painted from a palette that is not the process-wide one.

That is the whole point of it, and the reason it draws itself instead of holding real widgets. Every widget in this toolkit reads Theme.current() as it paints, so a preview built out of a Button and a Label would show whichever palette the application is wearing, which is either the one being edited (in which case the preview says nothing the surrounding window does not) or the wrong one entirely.

It also shows what a running application does not: the hover and pressed states of the accent, a disabled control, a popover above a card, and all four semantic tones, all at once and without having to be interacted with. Those are the tones a palette author cannot see while choosing them, and they are where a hand-built palette goes wrong.

Not a rendering of the toolkit's real chrome, and it does not try to be: it is a swatch board with the shapes of a window, held deliberately simple so that a change to a component's paint cannot silently make the preview a lie.

  • Constructor Details

    • ThemePreview

      public ThemePreview(Theme theme)
      A preview of theme, which is never read from Theme.current().
  • Method Details

    • theme

      public Theme theme()
      The palette being previewed.
    • setTheme

      public ThemePreview setTheme(Theme value)
      Shows another palette. Repaints; never re-lays out, since the geometry is fixed.
    • onMeasure

      protected Size onMeasure(Constraints constraints)
      Description copied from class: Widget
      Reports the size this widget wants within constraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.

      Resolve the ControlSize and the LayoutDirection once each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, and I18n.locale() answers it wherever text is resolved.

      Specified by:
      onMeasure in class Widget
    • onPaint

      protected void onPaint(Canvas canvas)
      Description copied from class: Widget
      Widget's own background/content, in local coordinates.
      Overrides:
      onPaint in class Widget