pub struct DockArea { /* private fields */ }Expand description
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.
The panels are the dock’s children, added with DockArea::add_panel and removed with
DockArea::remove_panel (a panel removed from the Ui directly is forgotten at the
dock’s next event). The dock owns their styles, which place and hide them, so style what
goes inside a panel rather than the panel itself, and leave the dock’s own padding at
zero. A hidden panel keeps its state, scroll positions included. Give the dock
DockArea::style.
The arrangement of panels added with keys (DockPanel::with_key) is saved with
DockArea::layout and put back, in this run or the next, with
DockArea::restore_layout; a DockLayout reads and writes itself as a line of text.
use densa_core::Size;
use densa_paragraph::TextSystem;
use densa_ui::Ui;
use densa_widgets::{DockArea, DockAt, DockPanel, DockSide, Label, Panel};
let mut ui = Ui::new(TextSystem::new()?);
ui.resize(Size::new(1200.0, 800.0));
let dock = ui.add(ui.root(), DockArea::new(), DockArea::style())?;
let quotes = DockArea::add_panel(&mut ui, dock, Panel::new(), "Quotes", DockAt::First)?;
let right = DockAt::Beside(quotes, DockSide::Right);
let chart = DockPanel::new("Chart").with_key("chart");
let chart = DockArea::add_panel(&mut ui, dock, Panel::new(), chart, right)?;
DockArea::add_panel(&mut ui, dock, Panel::new(), "Trades", DockAt::With(quotes))?;
ui.add(chart, Label::new("Panel content goes inside the panel"), Default::default())?;
ui.layout();
let area = ui.widget::<DockArea>(dock).unwrap();
assert_eq!(area.group_count(), 2);
assert!(!area.is_shown(quotes), "Trades, added last, is the tab shown");
assert_eq!(area.panel_with_key("chart"), Some(chart));It reports ActionKind::Selected with the panel’s
position in DockArea::panels (valid until a panel is removed) when a click shows a
panel, and ActionKind::Changed when a drag moved a tab
or a divider.
Implementations§
Source§impl DockArea
impl DockArea
Sourcepub fn layout(&self) -> Option<DockLayout>
pub fn layout(&self) -> Option<DockLayout>
How the panels with keys are arranged now; None if none has a key. Panels without
a key are left out, and a group with none of them with them.
Sourcepub fn restore_layout(
ui: &mut Ui,
dock: WidgetId,
layout: &DockLayout,
) -> Result<(), UiError>
pub fn restore_layout( ui: &mut Ui, dock: WidgetId, layout: &DockLayout, ) -> Result<(), UiError>
Arranges dock’s panels as layout says, matching them by key; see
set_layout.
§Errors
UiError::NoSuchWidget if dock is gone or is not a DockArea.
Sourcepub fn set_layout(&mut self, cx: &mut EventCx<'_>, layout: &DockLayout)
pub fn set_layout(&mut self, cx: &mut EventCx<'_>, layout: &DockLayout)
Arranges the panels as layout says (from an Ui::update on the dock): each key
takes the next panel with that key. Keys without a panel are passed over (a group
left empty goes, its space to its neighbor), and panels the layout does not name
(without a key, or added since it was saved) join the first group, so none is lost.
Ratios are kept from 0 to 1, and a group shows its first tab if its shown one is
missing. Either part of a split keeps at least 1% of it, so no group vanishes. A drag
in progress ends, and the keyboard stays with the group of the panel it was on.
Source§impl DockArea
impl DockArea
Sourcepub fn style() -> Style
pub fn style() -> Style
A dock filling its parent’s free space, allowed to be smaller than its panels’ content and clipping them.
Sourcepub fn add_panel(
ui: &mut Ui,
dock: WidgetId,
widget: impl Widget,
panel: impl Into<DockPanel>,
at: DockAt,
) -> Result<WidgetId, UiError>
pub fn add_panel( ui: &mut Ui, dock: WidgetId, widget: impl Widget, panel: impl Into<DockPanel>, at: DockAt, ) -> Result<WidgetId, UiError>
Adds widget to dock as a panel (a title, or a DockPanel), placed at, and
shows it.
§Errors
UiError::NoSuchWidget if dock is gone or is not a DockArea, or if at
names a widget that is not one of its panels; UiError::TooManyWidgets as for
Ui::add.
Sourcepub fn remove_panel(
ui: &mut Ui,
dock: WidgetId,
panel: WidgetId,
) -> Result<(), UiError>
pub fn remove_panel( ui: &mut Ui, dock: WidgetId, panel: WidgetId, ) -> Result<(), UiError>
Removes panel from dock and from the Ui; its group shows its next tab, and an
emptied group’s space goes to its neighbor.
§Errors
UiError::NoSuchWidget if dock is gone or is not a DockArea, or panel is
not one of its panels.
Sourcepub fn show_panel(
ui: &mut Ui,
dock: WidgetId,
panel: WidgetId,
) -> Result<(), UiError>
pub fn show_panel( ui: &mut Ui, dock: WidgetId, panel: WidgetId, ) -> Result<(), UiError>
Shows panel in its group.
§Errors
UiError::NoSuchWidget if dock is gone or is not a DockArea, or panel is
not one of its panels.
Sourcepub fn panels(&self) -> impl ExactSizeIterator<Item = WidgetId> + '_
pub fn panels(&self) -> impl ExactSizeIterator<Item = WidgetId> + '_
The panels’ widgets, in the order they were added (removals close the gaps).
Sourcepub fn show(&mut self, cx: &mut EventCx<'_>, panel: WidgetId) -> bool
pub fn show(&mut self, cx: &mut EventCx<'_>, panel: WidgetId) -> bool
Shows panel in its group (from an Ui::update on the dock); false if it is not
one of the dock’s panels.
Sourcepub fn set_title(
&mut self,
cx: &mut EventCx<'_>,
panel: WidgetId,
title: impl Into<String>,
) -> bool
pub fn set_title( &mut self, cx: &mut EventCx<'_>, panel: WidgetId, title: impl Into<String>, ) -> bool
Changes panel’s tab title (from an Ui::update on the dock); false if it is not
one of the dock’s panels.
Sourcepub fn panel_with_key(&self, key: &str) -> Option<WidgetId>
pub fn panel_with_key(&self, key: &str) -> Option<WidgetId>
The first panel added with key.
Sourcepub fn group_count(&self) -> usize
pub fn group_count(&self) -> usize
How many groups the panels are in.
Trait Implementations§
Source§impl Widget for DockArea
impl Widget for DockArea
Source§fn accepts_focus(&self) -> bool
fn accepts_focus(&self) -> bool
Reachable by Tab, as a tab list; clicks on panels do not focus it (a tab press does).
Source§fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
node, which starts as a
Role::Group with the widget’s rectangle. Called only while
assistive technology is listening; it may allocate.