Skip to main content

CamoScrollbar

Concept​

Milestone: M16 (v0.2), raised by Graft (srctool/camouflage#78)

1. Why​

On desktop and the web every scrolling component (lists, trees, tables, text) shows a scrollbar, and the platform's default does not match the skin: a wide classic bar next to a Carbon table, or none at all in Compose. Desktop apps expect a thin overlay bar that appears on scroll and widens on hover, drawn in the skin's colours, usable by dragging the thumb and clicking the track. Touch platforms keep their native indicators.

2. Shape​

Skin mapping preview: Material: a 12 dp track with a rounded thumb that widens on hover. Cupertino: an 8 dp overlay thumb with no track. Fluent: a thin 2 dp line that expands to 12 on hover, with arrows off. Carbon: a 6 dp thumb on a transparent track that grows to 10 on hover. Minimal: a 4 dp thumb. Every skin: a minimum thumb of 32 dp.

3. API​

Contract​

fun CamoScrollbar(
adapter: CamoScrollAdapter, // how far and how much the content scrolls
orientation: Orientation = Vertical,
visibility: ScrollbarVisibility = Auto, // Auto (the skin's default), OnScroll, Always
modifier,
)

fun CamoScrollArea(content: Slot, vertical: CamoScrollAdapter? = null, horizontal: CamoScrollAdapter? = null) // a box with the bars laid over the content

interface CamoScrollAdapter { val viewport: Float; val content: Float; val offset: Float; fun scrollTo(offset: Float) }

Adapters come from the platform's scroll states (Kotlin: ScrollState, LazyListState, LazyGridState; Flutter: a ScrollController).

Where it applies. Automatically inside Camouflage's own scrolling components (tree, data table, paged list, menu panel, select list), only when CamoEnvironment.input is Pointer and the platform is desktop or web; and explicitly in an app's own scroll container through CamoScrollArea. Touch input shows nothing.

State → renderer: ScrollbarState(orientation, thumbStart, thumbLength, hovered, dragging, visible). The renderer draws the track and thumb; core owns the geometry, the drag, the track click (page up or down), the fade timing and the hit area.

Tokens used​

  • colors.onSurfaceVariant at low alpha for the thumb, higher on hover and drag; shapes.full
  • motion.durationShort and durationLong (fade in and out); none with reduced motion

Component theme​

theme.components.scrollbar: ScrollbarTheme?.

FieldTypeCarbon defaultWhat it's for
thickness / hoverThicknessDp6 / 10the thumb width idle and under the pointer
minThumbDp32the shortest thumb
visibilityScrollbarVisibilityOnScrollwhen it shows
hideDelayDuration1200 mshow long it stays after scrolling stops (OnScroll)
colorsScrollbarColors(thumb, thumbHover, thumbDrag, track)see the skinevery colour it uses

Accessibility​

  • A scrollbar is not a focus stop and is hidden from the accessibility tree: assistive technology scrolls the content through its own scroll actions, and a keyboard user scrolls with the content's keys (Page Up and Down, Home, End, arrows).
  • It never takes focus or captures the wheel: wheel and trackpad events go to the content.
  • The thumb has a minimum size and, while dragged, a larger hit area, so it stays usable at 200% text.

4. Build steps​

  1. The geometry as pure functions (thumb length and start from viewport, content and offset; offset from a thumb position; track click paging), with unit tests that need no window.
  2. CamoScrollbar, the adapters, CamoScrollArea and the pointer-input check in core; the fade state machine.
  3. ScrollbarRenderer in the five skins and the debug skin; ScrollbarTheme.
  4. Wire it into CamoTree, CamoDataTable, CamoPagedList, CamoMenuPanel and CamoSelect's list.
  5. Tests: geometry; drag and track click; fade timing and Always; hidden with touch input; hover thickness; RTL (a vertical bar sits on the end edge); goldens per skin in light and dark.

Done when

  • Lists, trees and tables in the desktop sample show the skin's scrollbar, usable by drag and track click, on Kotlin and Flutter, with a renderer in every skin.

5. Edge cases​

CaseDecided behavior
Content shorter than the viewportNo thumb is drawn.
A very long list (lazy content)The thumb length follows the average item size seen so far; the drag maps to a fraction, so it stays smooth.
Nested scrollablesEach has its own bar; the inner one wins under the pointer.
Touch platformsNothing is drawn (native indicators stay).
The OS setting ("show scroll bars": automatically, when scrolling, always on macOS)Not in the first cut. The skin and the theme decide visibility. Reading the macOS setting is a later capability.

Implementation​

1. Why​

Compose Multiplatform's VerticalScrollbar and HorizontalScrollbar exist only in the desktop (JVM) source set and are not themeable by a skin; wasmJs has none. Core draws its own from a ScrollAdapter, in commonMain, so desktop and web both follow the skin.

2. Shape​

3. API​

@Composable public fun CamoScrollbar(adapter: CamoScrollAdapter, orientation: Orientation = Orientation.Vertical, visibility: ScrollbarVisibility = ScrollbarVisibility.Auto, modifier: Modifier = Modifier)
@Composable public fun CamoScrollArea(modifier: Modifier = Modifier, vertical: CamoScrollAdapter? = null, horizontal: CamoScrollAdapter? = null, content: @Composable () -> Unit)
@Composable public fun rememberCamoScrollAdapter(state: ScrollState): CamoScrollAdapter
@Composable public fun rememberCamoScrollAdapter(state: LazyListState): CamoScrollAdapter
@Composable public fun rememberCamoScrollAdapter(state: LazyGridState): CamoScrollAdapter
  • Adapters: ScrollState gives exact value and maxValue; LazyListState and LazyGridState estimate the content from the items laid out so far (the average item size times the item count), as Compose's own scrollbar does.
  • Input mode: the bar is composed only when CamoEnvironment.input == Pointer and the platform is not Android or iOS; Android and iOS draw nothing.
  • Drag and click: pointerInput on the track (detectDragGestures on the thumb, a tap on the track pages by a viewport); the wheel is not consumed.
  • Fade: an Animatable alpha; OnScroll shows the bar when the adapter's offset changes and hides it hideDelay later; reduced motion makes it instant.

4. Build steps​

As the base note's §4. Module: camouflage-core (package scrollbar); renderer parts in the skin modules; ABI dump updated.

Done when

  • Lists, trees and tables in the desktop sample show the skin's scrollbar, usable by drag and track click, with a renderer in every skin.

5. Edge cases​

CaseDecided behavior
wasmJsSame code; the page's own scrollbars are hidden inside Camouflage's scroll containers (the canvas has none).
A scrolling component inside CamoScrollAreaThe component's own automatic bar is suppressed (a local flag), so two bars never overlap.