Skip to main content

Crate densa_widgets

Crate densa_widgets 

Source
Expand description

Standard widgets for densa_ui: Label, Button, TextInput (with undo and the clipboard), ScrollView, Splitter, Panel, DockArea (panels in tab groups the user rearranges, the arrangement saved and restored as a DockLayout), DataGrid (rows of a model, scrolled, selected, copied and sorted), Chart (time series, candles and volume, panned and zoomed), and Menu and MenuBar (commands in menus that pop up, with submenus, check marks and keyboard navigation).

Each is a Widget: add it to a Ui with a Style, and read what the user did from the actions it reports. They take their colors and text size from the Theme, and paint and handle input without allocating (editing text re-lays it out, which does).

use densa_core::Size;
use densa_paragraph::TextSystem;
use densa_ui::{Align, Style, Ui};
use densa_widgets::{Button, Label, Panel, TextInput};

let mut ui = Ui::new(TextSystem::new()?);
ui.resize(Size::new(640.0, 480.0));
let bar = ui.add(
    ui.root(),
    Panel::new(),
    Style::row().gap(6.0).padding(8.0).align_items(Align::Center),
)?;
ui.add(bar, Label::new("Symbol"), Style::row())?;
let filter = ui.add(bar, TextInput::new("").with_placeholder("Filter"), Style::row())?;
let run = ui.add(bar, Button::new("Run").primary(), Style::row())?;
ui.layout();
assert!(ui.rect(run).unwrap().left() > ui.rect(filter).unwrap().right());

Structs§

Button
A push button: reports ActionKind::Clicked when released over itself, or when Enter or Space is pressed while it has focus.
Chart
A chart of a ChartModel: its panes stacked top to bottom on one horizontal axis, labelled under the lowest, each scaled to what it shows.
DataGrid
A grid of rows from a GridModel: the user scrolls it (wheel, touchpad, scroll bar, keys), selects a row (click, arrow keys, Page Up and Down, Home, End) or a range of rows (the same with Shift; Ctrl+A, or Cmd+A on macOS, for all), copies them (Ctrl+C or Ctrl+Insert, Cmd+C: tab-separated, see selected_text), sorts it by clicking a column’s title (again to reverse), and resizes columns by dragging the edges between titles. Leading columns can stay in place while the rest scroll sideways (with_frozen_columns).
DockArea
Panels in tab groups, side by side or stacked, that the user rearranges: click a tab to show its panel, drag it along its bar to reorder, onto another group to join that group, or near a group’s edge to split the group, and drag the gaps between groups to resize them. Tabs that do not fit their bar shrink, and the shown tab always stays in view.
DockLayoutError
Why text is not a DockLayout, and where reading stopped.
DockPanel
What a dock shows for a panel: its tab’s title and, for saving and restoring workspaces, a key that stays the same across runs (widget ids do not, and titles need not be unique).
Label
Text, on one line or wrapped to its width, vertically centered in its rectangle.
Menu
A list of commands that pops up: open it with Ui::open_popup (a context menu) or from a MenuBar.
MenuBar
A row of menu titles: a press on one opens its Menu below it, and while one is open the pointer coming over another title switches to it. Left and Right switch menus from the keyboard. The bar is not in the Tab order: give it the keyboard with MenuBar::activate (on F10, say).
MenuItem
An entry of a Menu: a command, a submenu or a separator.
Panel
A container that paints a background (the theme’s surface color by default) and, optionally, a border. Lay out its children with its style.
ScrollView
Scrolls its children with the wheel, a touchpad or by dragging its scroll bars.
Splitter
Two panes side by side (or one above the other) with a draggable divider between them.
TextInput
A single line of editable text. Reports ActionKind::Changed after every edit and ActionKind::Submitted on Enter.

Enums§

DockAt
Where DockArea::add_panel puts a panel.
DockAxis
Which way a split’s two parts sit.
DockLayout
How a dock’s panels are arranged, naming panels by their keys (DockPanel::with_key): what DockArea::layout saves and DockArea::restore_layout puts back, for example when an application starts again.
DockLayoutErrorKind
What was wrong with a layout’s text.
DockSide
A side of a dock group.

Constants§

MAX_LAYOUT_DEPTH
How deeply splits may nest in a layout: far more than any workspace has, few enough that reading a damaged or hostile layout cannot exhaust the stack. DockArea::layout keeps within it (deeper groups are saved as one), and reading refuses deeper text.