Class TitleControl

java.lang.Object
dev.myriadclient.api.ui.TitleControl

public final class TitleControl extends Object
A control in a window's title bar, beside its own float and close buttons: a switch (a control panel's on/off) or an icon button (Addons' "check for updates"). Return them from Panel.titleControls(); make them once (a field) and return the same ones, so a switch's slide carries on between frames. Hovering shows the tooltip. In a narrow window the controls that would crowd the title out are left off.
private final List<TitleControl> controls = List.of(
    TitleControl.toggle(module::isEnabled, module::setEnabled, () -> "Turn " + module.name() + " on or off"),
   TitleControl.button(() -> Icons.REFRESH, this::reload, () -> "Reload"));

@Override
public List<TitleControl> titleControls() { return controls; }
  • Method Details

    • toggle

      public static TitleControl toggle(BooleanSupplier on, Consumer<Boolean> set, Supplier<@Nullable String> tooltip)
      An on/off switch showing on; clicking it calls set with the opposite. The suppliers are read every frame. tooltip may return null for none.
    • button

      public static TitleControl button(Supplier<String> icon, Runnable action, Supplier<@Nullable String> tooltip)
      A Nerd Font icon (Icons) that runs action when clicked. The suppliers are read every frame, so the icon can change (a spinner while busy). tooltip may return null for none.
    • visible

      public TitleControl visible(BooleanSupplier visible)
      Shown only while visible says so (read every frame). Returns this control.
    • isToggle

      @Internal public boolean isToggle()
      Core's: whether this is a switch rather than a button.
    • isVisible

      @Internal public boolean isVisible()
      Core's: whether it shows this frame.
    • isOn

      @Internal public boolean isOn()
      Core's: a switch's state.
    • icon

      @Internal public String icon()
      Core's: a button's glyph, empty for a switch.
    • tooltip

      @Internal public @Nullable String tooltip()
      Core's: the tooltip, or null.
    • width

      @Internal public float width()
      Core's: its width in the title bar, in UI units.
    • knob

      @Internal public Animated knob()
      Core's: a switch's knob animation.
    • click

      @Internal public void click()
      Core's: a click on it.