Widgets

/

interact

Slider

A labelled range slider.

A value on a range

Slider picks a number between min and max in steps of step. .fnc { … } runs with the new value while it is dragged, so what depends on it follows the thumb.

LAYROpen in playground
Page(
  .name(Hours)
  .route('/')
  var int hours = 2
  Scaffold(
    .config(color: canvas)
    .body(
      Column(
        .config(w: 320, gap: 12, padding: all(24))
        Slider(
          .config(label: 'Hours', max: 8, min: 1, step: 1, value: hours)
          .fnc { hours = value }
        )
        Text(
          .config(size: 18, weight: semibold)
          .obj('$hours hours · €${hours * 24}')
        )
        Container(
          .config(w: hours * 40, h: 10, color: accent, cornerRadius: 999)
        )
      )
    )
  )
)

Config keys

KeyTypeDefaultMeaning
valuenumCurrent value.
minnum0Minimum.
maxnum100Maximum.
stepnum1Step.
labeltxtLabel.
disabledboolDisabled.
w (width)len | fill | hugWidth: a length, fill (share the remaining space) or hug (fit content, default).
h (height)len | fill | hugHeight: a length, fill or hug (default).
size (s)sizeWidth and height together: size: 200 or size: (200, 120).
minW (minWidth)lenMinimum width.
maxW (maxWidth)lenMaximum width.
minH (minHeight)lenMinimum height.
maxH (maxHeight)lenMaximum height.
aspect (aspectRatio)numAspect ratio (width / height), e.g. 16/9.
margininsetsSpace outside the object: all(8), sym(x: 8, y: 4), only(top: 8).
opacitynumOpacity from 0 to 1.
hide (hidden)boolRemoves the object from layout and the accessibility tree.
shrinknum1Shrink priority when space runs out. Lower shrinks first; 0 never shrinks.
flexnum1Share of remaining space for fill sizes.
cursorauto | pointer | text | grab | grabbing | move | notAllowed | crosshair | nonePointer cursor.
className (class)txtExtra CSS class names: styling hooks for your own stylesheet (hover rules, third-party CSS).

Events

.fnc runs on change. .on(...) accepts tap, press, hover, hoverEnd, focus, blur, key, drag, swipe, mount, unmount, visible.