Skip to main content

CamoDocumentTabs

Editor-style tabs for open documents: a close button on hover and on the selected tab (a dot while the document is modified), middle-click to close, drag to reorder (Alt+Left and Alt+Right with the keyboard), pinned tabs at the start, and a row that scrolls with a "show all tabs" menu when the tabs don't fit.

documents and selected (a document id) are the app's; so is closing: onClose says the user asked, and the app removes the document and picks the next selection. The order and pins live in state. onContextMenu returns the entries of a tab's right-click menu ("Close others", "Close to the right", "Pin"). Ctrl+W is the app's key. Screen readers get the tab-list semantics of CamoTabs plus "Close", "Move earlier", "Move later" and "Pin" actions on every tab, and hear "modified" and "pinned" in its state.

Built from the skin's tab bar (every skin draws it), so it needs no renderer of its own.

Usage​

val state = remember { CamoDocumentTabsState() } // order and pins; snapshot() and apply() to save them
var selected by remember { mutableStateOf<Any>(documents.first().id) }

CamoDocumentTabs(
documents = documents.map { CamoDocument(it.id, it.name, modified = it.unsaved) },
selected = selected,
onSelect = { selected = it },
onClose = { id -> closeDocument(id) }, // the app removes it and picks the next tab
state = state,
)

API​

public fun CamoDocumentTabs(
documents: List<CamoDocument>,
selected: Any,
onSelect: (Any) -> Unit,
onClose: (Any) -> Unit,
state: CamoDocumentTabsState,
modifier: Modifier = Modifier,
onContextMenu: ((CamoDocument) -> List<CamoMenuEntry>)? = null,
appearance: Appearance? = null,
)
NameTypeDefault
documentsList<CamoDocument>required
selectedAnyrequired
onSelect(Any) -> Unitrequired
onClose(Any) -> Unitrequired
stateCamoDocumentTabsStaterequired
modifierModifierModifier
onContextMenu((CamoDocument) -> List<CamoMenuEntry>)?null
appearanceAppearance?null
Design notes

Why CamoDocumentTabs works this way, its states and its edge cases: contributor docs.