Class Slider
[min, max]. Drag the thumb or
click the track to jump; keyboard arrows nudge by the step (Home/End jump to the ends, PageUp/PageDown by ten steps). A continuous
slider (step == 0) nudges by 1% of the range. The filled portion,
thumb and focus ring all come from the Theme; the thumb grows on hover
and the focus ring fades in through the shared Transition animator.
Slider volume = new Slider(0, 100).setStep(5).setValue(30);
volume.onChange(v -> audio.setGain(v / 100f));
Sizes follow the ControlSize resolved on this widget. This control's height
derives from a focus-ring constant, 2 * (knobHover + FOCUS_GAP_SLIDER + border),
rather than from a font or a design height, so it must not be rounded onto the shared
control-height ramp. It is also the one place Strokes.MIN_HIT_TARGET binds: at the
densest step the natural height falls below the floor, because the ring needs absolute room
the knob ramp does not predict.
The preferred length is free: 220 at every step, equal to
ProgressBar's so the two stack in a settings panel without a ragged column. Only
the thickness moves with the step.
The value axis follows the resolved layout direction: reading right to left, min is at the right end of the track, the fill grows
leftwards from it, and Left/Right nudge the value the way the thumb visibly moves. Up/Down are a
vertical pair and keep their meaning in both directions, and Home/End/PageUp/PageDown name a
value rather than a side, so they never mirror either. The track rectangle itself does not move:
the pad is reserved at both ends, so only the meaning of each end changes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatmax()Upper bound, inclusive.floatmin()Lower bound, inclusive.Called with the new value on user changes only, not onsetValue(float).Called with the value the user settled on: once when a drag ends, and after each change made with the keyboard.protected voidCalled when this widget takes keyboard focus.protected voidCalled when this widget loses keyboard focus.protected voidonKeyEvent(KeyEvent event) Key events (focused widget first, then ancestors).protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidonMouseEvent(MouseEvent event) Mouse events (bubbling); callevent.consume()when handled.protected voidWidget's own background/content, in local coordinates.setStep(float newStep) Sets the discrete increment (0= continuous).setValue(float newValue) Sets the value programmatically (clamped + snapped to the step); does not fireonChange.floatvalue()The current value, always within[min, max].Methods inherited from class limn.scene.Widget
acceptsTextInput, add, baselineOffset, baselineOffsetOf, caretRect, children, clipboard, clipsChildren, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedByTraversal, height, hitTest, imageCursor, invalidate, invalidate, isEnabled, isFocusable, isFocused, isShowing, isVisible, layoutBox, layoutDirection, locale, localToSceneX, localToSceneY, markNeedsContainedLayout, markNeedsLayout, measure, moveChild, neutralBase, onAttached, onCharTyped, onDetached, onFileDrop, onLayout, onPaintOverlay, onPreedit, overlayPassesPointer, paintChildren, paintOutset, paintWidget, parent, remove, requestFocus, revealInView, scene, sceneToLocalX, sceneToLocalY, setControlSize, setCursor, setEnabled, setFocusable, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, width, x, y
-
Constructor Details
-
Slider
public Slider(float min, float max) A slider over[min, max], starting atmin.
-
-
Method Details
-
setValue
Sets the value programmatically (clamped + snapped to the step); does not fireonChange. -
value
public float value()The current value, always within[min, max]. -
min
public float min()Lower bound, inclusive. -
max
public float max()Upper bound, inclusive. -
setStep
Sets the discrete increment (0= continuous). Re-snaps the current value. -
onChange
Called with the new value on user changes only, not onsetValue(float). -
onCommit
Called with the value the user settled on: once when a drag ends, and after each change made with the keyboard.onChangefires continuously while a drag is in progress and this fires once at the end of it, which is the difference between a preview and a decision.For anything a value change starts that should not be started per pixel: a decode, a request, a recomputation. A control bound only to
onChangedoes that work for every position the thumb passes through; one bound to both can show something cheap on the way and do the real work here.Fires on a drag that ends where it began, because the user still chose that value, and does not fire for
setValue(float), which is not a user change at all. -
onMeasure
Description copied from class:WidgetReports the size this widget wants withinconstraints. 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
ControlSizeand theLayoutDirectiononce each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, andI18n.locale()answers it wherever text is resolved. -
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
onMouseEvent
Description copied from class:WidgetMouse events (bubbling); callevent.consume()when handled.- Overrides:
onMouseEventin classWidget
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget
-