Pantrix UI

Toolbar

A row of what a screen or a part of it can do, as a document's: buttons with words, buttons with an icon, buttons that open a menu, and lines between their groups, which keeps what has no room in a menu behind a "…" button at its end.

import com.pantrixui.components.container.toolbar.PantrixToolbar

Examples

A document's actions

A document's actions, at the width chosen: in a wide bar all of them with their words; as it narrows, the button of the lowest priority is drawn as its icon first, then falls into the "…" menu, and then the next one. The copy button is of the highest priority and falls last.

var width by rememberSaveable { mutableStateOf(640) }
var pressed by rememberSaveable { mutableStateOf("") }
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    PantrixSegmentButton(
        options = listOf(
            SegmentOption(value = 640, label = "640 dp", tagKey = "640"),
            SegmentOption(value = 360, label = "360 dp", tagKey = "360"),
            SegmentOption(value = 200, label = "200 dp", tagKey = "200")
        ),
        selected = width,
        onSelect = { width = it },
        tagKey = "width"
    )
    PantrixToolbar(
        start = listOf(
            ToolbarItem.Button(
                key = "format",
                label = "Format",
                onClick = { pressed = "Format" },
                variant = ButtonVariant.Solid,
                priority = 3
            ),
            ToolbarItem.Button(
                key = "minify",
                label = "Minify",
                onClick = { pressed = "Minify" },
                icon = PantrixIcons.Minus
            ),
            ToolbarItem.Divider(key = "made"),
            ToolbarItem.Button(
                key = "convert",
                label = "Convert",
                onClick = { pressed = "Convert" },
                icon = PantrixIcons.Code
            ),
            ToolbarItem.Button(
                key = "history",
                label = "History",
                onClick = { pressed = "History" },
                icon = PantrixIcons.History,
                priority = 1
            )
        ),
        end = listOf(
            ToolbarItem.IconButton(
                key = "copy",
                icon = PantrixIcons.Copy,
                label = "Copy",
                onClick = { pressed = "Copy" },
                priority = 5
            )
        ),
        modifier = Modifier.widthIn(max = width.dp).fillMaxWidth(),
        contentDescription = "Document",
        tagKey = "document"
    )
    PantrixText(
        text = if (pressed.isEmpty()) "No action pressed yet." else "Last pressed: $pressed",
        color = PantrixTheme.colors.textSecondary,
        tagKey = "pressed"
    )
}

A choice's menu, and the menu's own rows

A choice's menu: the document's format, the one chosen marked. The menu's own rows, sharing and closing the document, are behind the "…" button at every width; in a narrow bar the format's button falls there too, and opens its rows in the menu's place.

The format's button writes the chosen format alone, "JSON"; a screen reader reads it as "The document's format", by its contentDescription. So does "Validate": "Validate the document", in the bar and in the "…" menu alike.

var format by rememberSaveable { mutableStateOf("json") }
var narrow by rememberSaveable { mutableStateOf(false) }
var said by rememberSaveable { mutableStateOf("") }
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    PantrixSegmentButton(
        options = listOf(
            SegmentOption(value = false, label = "Wide", tagKey = "wide"),
            SegmentOption(value = true, label = "Narrow", tagKey = "narrow")
        ),
        selected = narrow,
        onSelect = { narrow = it },
        tagKey = "room"
    )
    PantrixToolbar(
        start = listOf(
            ToolbarItem.Menu(
                key = "format",
                label = FORMATS.getValue(format),
                items = FORMATS.map { (key, name) ->
                    ToolbarMenuItem(key = key, label = name, onClick = { format = key }, selected = key == format)
                },
                priority = 2,
                contentDescription = "The document's format"
            ),
            ToolbarItem.Divider(key = "line"),
            ToolbarItem.Button(
                key = "validate",
                label = "Validate",
                onClick = { said = "Validated" },
                contentDescription = "Validate the document"
            )
        ),
        menuItems = listOf(
            ToolbarMenuItem(
                key = "share",
                label = "Share",
                onClick = { said = "Shared" },
                icon = PantrixIcons.Share
            ),
            ToolbarMenuItem(
                key = "close",
                label = "Close the document",
                onClick = { said = "Closed" },
                icon = PantrixIcons.Delete,
                destructive = true
            )
        ),
        modifier = Modifier.widthIn(max = if (narrow) 120.dp else 480.dp),
        tagKey = "editor"
    )
    PantrixText(
        text = "Format: ${FORMATS.getValue(format)}" + if (said.isEmpty()) "" else " · $said",
        color = PantrixTheme.colors.textSecondary,
        tagKey = "format"
    )
}

private val FORMATS = linkedMapOf("json" to "JSON", "yaml" to "YAML", "toml" to "TOML")

The button of the view shown

A document's views: each a button, the one shown selected. The selected button is drawn in Soft's pale fill whatever its variant, and a screen reader is told it is selected, as a tab is; in a narrow bar it is a checked row of the "…" menu. A button that is not selected is read as the others are.

var view by rememberSaveable { mutableStateOf("tree") }
PantrixToolbar(
    start = VIEWS.map { (key, name) ->
        ToolbarItem.Button(key = key, label = name, onClick = { view = key }, selected = key == view)
    },
    tagKey = "views"
)

private val VIEWS = linkedMapOf("tree" to "Tree", "table" to "Table", "raw" to "Raw text")

Its own style and colour

In its own style: small buttons, less room between them, and a shorter line in the app's colour.

PantrixToolbar(
    start = listOf(
        ToolbarItem.IconButton(key = "undo", icon = PantrixIcons.ArrowBack, label = "Undo", onClick = {}),
        ToolbarItem.IconButton(key = "redo", icon = PantrixIcons.ArrowForward, label = "Redo", onClick = {}),
        ToolbarItem.Divider(key = "line"),
        ToolbarItem.Button(key = "settings", label = "Settings", onClick = {}, icon = PantrixIcons.Settings)
    ),
    buttonSize = ButtonSize.Small,
    style = ToolbarStyle(gap = 2.dp, dividerHeight = 16.dp),
    colors = ToolbarColors(divider = PantrixTheme.colors.primary.color),
    tagKey = "own"
)

API

start

A row of what a screen or a part of it can do, as a document's: buttons with words, buttons with an icon, buttons that open a menu, and lines between their groups, which keeps what has no room in a menu behind a "…" button at its end.

ParameterTypeDefaultWhat it is
startList<ToolbarItem>the items at the bar's start, in order.
modifierModifierModifierthe bar's modifier.
endList<ToolbarItem>emptyList()the items at the bar's end, before the "…" button, in order.
menuItemsList<ToolbarMenuItem>emptyList()the rows the "…" menu holds whatever the room, under the items that had none.
buttonSizeButtonSizeButtonSize.Mediumhow large the bar's buttons are: ButtonSize.Medium by default.
contentDescriptionString?nullwhat a screen reader calls the bar, or null for a bar it hears only the buttons of.
styleToolbarStyle?nullthis call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform.
colorsToolbarColors?nullthis call's own colours, where they are not the theme's.
tagKeyString?nullthe bar's automation key: it is Toolbar_<tagKey>, and its items, in the bar and in the menu alike, are Action_<key> inside it; its "…" button is More_actions.

ToolbarStyle

PantrixToolbar's geometry: the room between two of its items and how tall a line between two groups is. A bar used by touch has less room between its buttons, which take the platform's touch target, and taller lines.

ParameterTypeDefaultWhat it is
gapDpDp.UnspecifiedThe room between two items, and between the last item and the "…" button.
dividerHeightDpDp.UnspecifiedHow tall a ToolbarItem.Divider is drawn.

ToolbarColors

A PantrixToolbar's own colours, where they are not the theme's. The bar has no fill of its own, and its buttons are drawn in their variants' colours.

ParameterTypeDefaultWhat it is
dividerColorColor.UnspecifiedThe line between two groups: the theme's divider.

Accessibility