Skip to main content

CamoSplitPane

Concept​

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

1. Why​

Desktop tools lay out two or more panes side by side or stacked (a list, a detail, a log) and let the user drag the divider. The canonical layouts are plain composition (Canonical Layouts (List-Detail, Feed, Supporting Pane)), but the draggable, accessible divider is real work that every desktop app repeats: pointer drag, minimum sizes, keyboard resize, collapse, semantics and a layout the app can save. CamoSplitPane is that, and the dock layout (a later item) is built on it.

2. Shape​

Skin mapping preview: Material: a 1 dp outlineVariant line with an 8 dp hit area. Cupertino: a hairline. Fluent: a 1 dp neutralStroke2 line that thickens on hover. Carbon: 1 px border-subtle, the accent colour while dragging. Minimal: a hairline. All draw a focus ring on the keyboard-focused divider.

3. API​

Contract​

fun CamoSplitPane(
axis: Axis, // Horizontal: panes side by side (start to end); Vertical: stacked
panes: List<CamoPane>, // two or more
state: CamoSplitState, // app-owned: sizes and which panes are collapsed
modifier,
)

data class CamoPane(
val minSize: Dp = 80.dp,
val maxSize: Dp? = null,
val collapsible: Boolean = false,
val content: Slot,
)

class CamoSplitState(initial: List<Float>) { // the pane sizes as fractions of the container, summing to 1
val fractions: List<Float>
val collapsed: Set<Int>
fun resize(divider: Int, deltaPx: Float) // moves space between the two neighbours of a divider
fun collapse(pane: Int); fun restore(pane: Int); fun reset()
fun snapshot(): CamoSplitSnapshot // plain data (fractions, collapsed) the app can persist
}

Sizes. The state stores fractions (a saved layout restores on a different window size); minSize and maxSize are dp (a pane never gets too small to use). Nested splits are composition: a pane's content is another CamoSplitPane.

Layout rule. A divider moves space between its two neighbours only, clamped by both neighbours' min and max. When the container resizes the fractions are kept and then clamped, and the excess goes to the nearest panes. A collapsible pane dragged below half its minSize snaps to zero (collapsed); a collapsed pane restores to its previous fraction.

State → renderer: SplitDividerState(axis, hovered, focused, dragging, collapsedBefore, collapsedAfter). Slots: none. Core owns the layout, the hit area and the interaction; the renderer draws the line (and an optional grip).

Tokens used​

  • colors.outlineVariant (idle), colors.outline (hover), colors.primary (dragging and focus)
  • spacing for the key step, motion.durationShort for a collapse and restore animation (none with reduced motion)

Component theme​

theme.components.splitPane: SplitPaneTheme? (nullable fields, filled by the skin's defaults(theme)).

FieldTypeDefaultWhat it's for
thicknessDp1the drawn line
hitSizeDp8the grab area, centred on the line
keyStep / keyStepLargeDp16 / 64arrow and Shift+arrow resize
colorsSplitPaneColors(line, hover, dragging, focus)outlineVariant, outline, primary, primaryevery colour it uses
gripBooleanfalsea small grip in the middle (some skins)

Accessibility​

  • A divider is focusable and exposes the platform's adjustable value ("Resize panel, 35 percent"), with increase and decrease actions, because the platforms have no splitter role (the WAI-ARIA window splitter pattern is exposed as a slider-like value).
  • Keyboard: Left and Right (Up and Down when stacked) move the divider by keyStep, with Shift by keyStepLarge; Home and End go to the minimum and maximum; Enter collapses or restores a collapsible neighbour; Tab moves between dividers.
  • Pointer: a resize cursor over the hit area; drag; double-click resets the two neighbours to their initial sizes.
  • Right to left mirrors a horizontal split (the first pane is on the right), and Left and Right keep their visual meaning.

4. Build steps​

  1. CamoSplitState and the layout rule as pure functions (clamping, redistribution, collapse), with unit tests that need no window.
  2. The CamoSplitPane layout and the divider interaction in core (drag, keys, double-click, cursor, semantics).
  3. SplitPaneRenderer in the five skins and the debug skin; SplitPaneTheme in CamoComponentThemes.
  4. Sample: a three-pane layout (list, detail, log) with a collapsible log; the saved layout restored on launch.
  5. Tests: sizes from fractions; min and max respected; collapse and restore; resize by key and by accessibility action; double-click reset; nested splits; RTL; a restored snapshot on a different window width; goldens in light and dark per skin.

Done when

  • A three-pane layout resizes by mouse, keyboard and screen reader, respects minimum sizes and restores saved fractions, on Kotlin and Flutter, with a renderer in every skin.

5. Edge cases​

CaseDecided behavior
The container is smaller than the sum of the minimumsThe panes shrink below minSize in proportion, so nothing is cut off; dividers stay usable.
A pane's content has an intrinsic sizeThe split gives it exactly its size; the content scrolls or clips (the app's choice).
Collapsed paneIts content leaves the composition (not just hidden), its divider stays so it can be restored.
Touch inputThe hit area grows to 24 dp; dragging works with a finger.
Many panesAny number; dividers are numbered in order. More than four is a design smell.
PersistingThe app saves snapshot(); the state accepts it back. Camouflage stores nothing itself.

Implementation​

1. Why​

Compose has no split pane in common code (JetBrains' SplitPane lives in the desktop-only Compose Desktop libraries and is not themeable or accessible). Core builds one from Layout, pointer input and key handling, so it works on desktop and web and follows the skin.

2. Shape​

3. API​

@Composable
public fun CamoSplitPane(
axis: Orientation,
panes: List<CamoPane>,
state: CamoSplitState = rememberCamoSplitState(panes.size),
modifier: Modifier = Modifier,
)
public class CamoPane(val minSize: Dp = 80.dp, val maxSize: Dp? = null, val collapsible: Boolean = false, val content: @Composable () -> Unit)
@Stable public class CamoSplitState(initial: List<Float>) { /* fractions, collapsed, resize, collapse, restore, reset, snapshot */ }
@Composable public fun rememberCamoSplitState(count: Int, initial: List<Float>? = null): CamoSplitState // rememberSaveable
  • Layout: a custom Layout measures each pane with a fixed main-axis size from the state (converted to px with the container's size) and the full cross size. The clamping and redistribution are pure functions in SplitMath.kt.
  • Drag: detectDragGestures on the divider's hit box; state.resize(divider, delta) on each move. onDoubleTap resets.
  • Keys: onKeyEvent on the focusable divider; Left and Right swap in RTL (LayoutDirection).
  • Semantics: progressBarRangeInfo (the current fraction and its range), setProgress (increase and decrease), stateDescription = "35 percent", contentDescription = "Resize panel"; the role is the nearest adjustable one, since Compose has no splitter role.
  • Cursor: Modifier.pointerHoverIcon with a small expect/actual ResizeCursor (AWT Cursor.E_RESIZE_CURSOR and S_RESIZE_CURSOR on the JVM, CSS on wasm); Android and iOS draw none.
  • Saving: rememberCamoSplitState uses rememberSaveable with a Saver over the snapshot; apps that persist across launches keep their own copy of snapshot().

4. Build steps​

As the base note's §4. Module: camouflage-core (package splitpane); renderer part in each skin module; ABI dump updated (updateKotlinAbi).

Done when

  • A three-pane layout resizes by mouse, keyboard and screen reader, respects minimum sizes and restores saved fractions, with Material, Cupertino, Fluent, Carbon and Minimal.

5. Edge cases​

CaseDecided behavior
Recomposition while draggingThe drag reads the latest state through rememberUpdatedState; the gesture is keyed on the divider index only (a scene rebuilt per hover would restart every gesture, found in M11).
Pointer capture leaving the windowThe drag ends on onDragEnd and onDragCancel.
wasmJsThe same code; the cursor comes from CSS.