Skip to content

UXSlider

UXSlider is a knob on a track. The value maps linearly to the knob position and back, so a click or drag sets the value and the value places the knob. The value↔position arithmetic is pure and unit-testable without a window. Drawing and click conversion go through the UXControl seam. On backends with a native slider (macOS NSSlider, Win32 trackbar, iOS UISlider, Android SeekBar, GTK GtkScale) the driver realizes one and this object holds its state. On GEM and the web the control draws itself from the theme’s slider.htrack and slider.knob sprites.

#use <UXKit>
UXSlider* s = new UXSlider();
s.setRange(0, 255);
s.setValue(128);
s.setAction(&controller.onLevel); // fires on every value change
content.addSubview(s, UXGeom.make(8, 8, 180, 20));

The action fires as the value moves: once per click or drag step on the self-drawn path, and whenever the native control reports a user change elsewhere. The handler reads the value from the sender:

void onLevel(UXControl* sender) {
i32 level = ((UXSlider* ?)sender).intValue();
...
}
  • Inherits UXControl: the weak: bound-method action, enable/disable, the fire path.

Value · setRange · setValue · intValue Geometry · knobX · valueForX Realization · kind

void setRange(i32 lo, i32 hi)

Sets the bounds and clamps the current value into them. A degenerate range is repaired (hi becomes lo + 1), so the position arithmetic never divides by zero.

void setValue(i32 v)

Sets the value programmatically, clamped to the range. Does not fire the action. Actions report the user’s changes; code that sets the value already knows it.

i32 intValue(void)

The current value. The neutral object holds it, whatever realized the control.

i32 knobX(i16 trackW)

The knob’s left edge for the current value within a track trackW wide. Pure arithmetic; the tests call it without a window.

i32 valueForX(i16 lx, i16 trackW)

The value for a local x (the click or drag point), centring the knob under the pointer, clamped to the track.

UXKind kind(void)

UXKindSlider: native where the backend has one, themed sprites elsewhere. The driver decides; the control does not know which.

UXSlider on the web backend

The theme’s slider.htrack groove and round slider.knob, the same Aristo art GEM draws, on canvas.

A brightness control that applies live while dragging:

UXSlider* bright = new UXSlider();
bright.setRange(0, 100);
bright.setValue(80);
bright.setAction(&controller.onBrightness);
content.addSubview(bright, UXGeom.make(8, 8, 200, 20));
void onBrightness(UXControl* sender) {
display.setBrightness(((UXSlider* ?)sender).intValue());
}