JFLib

Docking: panels at the sides, tab groups, floating tool windows#

Source: lib/ui/dock.rs

dock -- a docking area: the app's panels at the sides of a document area (left, right,
bottom) in tab groups with splitters, dragged to other places with drop markers, floating in
tool windows and docked again, hidden, collapsed to a rail; the layout is the app's DockState

  dock_begin(id, &mut st, panels)   the area takes the next place (without next_size it fills
                                    the box); panels describe every panel each frame
                                    (DockPanel: id != 0, title, icon, DP_* flags, first place)
  dock_next(&mut st) -> Some(id)    the next place to fill: DOCK_CENTER (the document area)
                                    first, then the shown panel of every group, the floating
                                    windows last; emit its content (a vertical box that clips)
                                    and call it again until None
  dock_end(&mut st) -> changed      true when the user changed the layout (save it then)
  DockState                         the layout, kept by the app: save() -> text, load(text),
                                    reset, show / hide / toggle / focus / activate, float /
                                    dock_to, float_group / dock_group_to (a whole group),
                                    collapse / collapsed, size / set_size, groups /
                                    floats / hidden_panels, side / visible / front / shown

Places: a side holds tab groups (left / right: one above the other, bottom: side by side)
with splitters between them and towards the document area; a collapsed side is a rail of
icon buttons.  Left and right are the start and the end side: the layout is logical, so a
mirrored (RTL) window shows the left side at the right like everything else.
A press on a tab (or on the empty part of a tab strip: the whole group) can drag only after it
was held for DOCK_HOLD_MS: then the tab shows it (DOCK_TAB_HOLD, the move cursor; a timer gives
the pass while the pointer rests), and the drag starts when the pointer moves past the usual
threshold from where it is at that moment.  Movement during the hold cancels nothing and never
counts (a slip or a tremor starts nothing), a release without a drag is a click if it is over
the tab.  Clicks, double clicks, the menu and the splitters need no hold.
A drag shows drop markers at the three edges of the area (a new group on that side) and on the
group under the pointer (as a tab, before, after it); a release over a tab strip inserts it
there; anywhere else -- also outside the window -- the panel floats in a tool window at the
pointer (WF_TOOL, window ids dock_float_id(id, window, k): id + 1 .. id + DOCK_FLOAT_MAX in the
main window, ids of their own in any other).  Tabs of a floating window drag the
same way onto the main window's markers (the pointer stays with the floating window); its pin
button or a double click docks it where it came from, its close button hides its panels.  Esc
cancels a hold and a drag (the release is no click then).
Keyboard: the tab strip of a group is one focus stop (Left / Right / Home / End switch tabs,
the menu key or Shift+F10 open the group's menu with every move), Ctrl+PgDn / Ctrl+PgUp switch
tabs while the focus is anywhere in the group, DockState::focus(id) brings a panel forward
and gives its tab strip the focus (the app binds it to its commands).
Structural changes (clicks, drops, menu rows) are applied at dock_end, followed by another
pass; splitters change the sizes at once.  Widget ids are parts of the area id (pid).
Every window keeps the state of its dock areas (WinParts::dock): an area of the same id in two
windows lays out, drags and floats by itself, in floating windows of its own (dock_float_id
hashes the area and the window outside the main window).
/// the sides of a dock area (DockPanel::at, DockState::side); left / right are the start / end
/// side (a mirrored window shows them the other way round)
DOCK_LEFT: u8 = 0
DOCK_RIGHT: u8 = 1
DOCK_BOTTOM: u8 = 2
/// a floating tool window
DOCK_FLOAT: u8 = 3
/// dock_next: the document area in the middle
DOCK_CENTER: u32 = 0
/// DockPanel flags: no hide button or menu row (the app shows and hides it)
DP_NOCLOSE: u32 = 1
/// never floats (a drop outside the markers does nothing)
DP_NOFLOAT: u32 = 2
/// starts hidden (until DockState::show / focus); later the layout remembers it
DP_HIDDEN: u32 = 4
/// its group moves as a whole: when it is the shown tab, the group menu's "Links / Rechts /
/// Unten andocken" and "Lösen" and a double click on the strip's empty part take every tab of
/// the group (panels that belong together, such as an app's developer tools;
/// DockState::dock_group_to / float_group)
DP_GROUP: u32 = 8
/// floating windows of one dock area at most (fixed: each is a window, WIN_MAX)
DOCK_FLOAT_MAX: usize = 6
  • const fn dock_float_id(area: u32, win: u32, k: usize) -> u32 The window id of floating window k (0 .. DOCK_FLOAT_MAX) of the dock area area in the app window win (0 = the main window): area + 1 + k in the main window; in any other window an id of its own hashed from area and win (ID_HASH_BASE and up, like ui.id), so an area of the same id in two windows floats its panels in windows of their own.
/// drop marker kinds (StyleShell::dock_marker, sp.value): the part of the place it fills
DOCK_MK_LEFT: i32 = 0
DOCK_MK_RIGHT: i32 = 1
DOCK_MK_TOP: i32 = 2
DOCK_MK_BOTTOM: i32 = 3
DOCK_MK_CENTER: i32 = 4
/// a press on a tab or on the empty part of a tab strip can drag only after this many ms with
/// the button down, so that a slip of the hand during a click neither moves nor floats a panel;
/// clicks, double clicks (they float), the menu and the splitters need no hold
DOCK_HOLD_MS: u32 = 300
/// StyleShell::dock_tab, sp.flags: the press was held long enough, the tab can be moved now (a
/// press on the strip's empty part: every tab of the group, they would all move)
DOCK_TAB_HOLD: u32 = 1
  • struct DockPanel<'a> a panel as the app describes it to dock_begin every frame
    • id: u32 -- != 0 and stable (the saved layout refers to it)
    • title: &'a str
    • icon: u32 -- IC_* of its tab and of the rail of a collapsed side (0 = none)
    • flags: u32 -- DP_*
    • side: u8 -- where it goes the first time: DOCK_LEFT / DOCK_RIGHT / DOCK_BOTTOM / DOCK_FLOAT
    • group: u8 -- panels of one side with the same group number start as tabs of one group; the groups in the order of their numbers

impl<'a> DockPanel<'a>

  • const fn new(id: u32, title: &'a str, icon: u32) -> DockPanel<'a> a panel that starts in group 0 of the left side

  • const fn at(mut self, side: u8, group: u8) -> DockPanel<'a> its first place: side (DOCK_*) and group number

  • const fn flags(mut self, f: u32) -> DockPanel<'a> add DP_* flags

  • struct DockState the layout of a dock area: kept by the app and passed to dock_begin / dock_next / dock_end. save() / load() turn it into a few lines of text: \dock 1\\, then \side S SIZE COLLAPSED, group S TAG SIZE ACTIVE PANEL..., float SLOT X Y W H HOME HOMETAG ACTIVE PANEL...\\, \hidden PANEL S TAG POS X Y W H HOME HOMETAG [ORDER...]\\ (ORDER: its group's tab order when it left; unknown lines are skipped).

impl DockState

  • fn new() -> DockState the empty layout: every panel goes to its DockPanel place in the first frame
  • fn reset(&mut self) forget the layout: every panel goes to its DockPanel place in the next frame
  • fn show(&mut self, id: u32) show a hidden panel where it was, as the shown tab of its group
  • fn hide(&mut self, id: u32) hide a panel (show brings it back to the same place)
  • fn toggle(&mut self, id: u32) show a hidden panel, hide a visible one
  • fn focus(&mut self, id: u32) show the panel as the shown tab (a collapsed side expands) and give its tab strip the keyboard focus in the next pass (a floating window comes to the front)
  • fn activate(&mut self, id: u32) make the panel the shown tab of its group (a collapsed side expands)
  • fn float(&mut self, id: u32, rect: Option<[i32; 4]>) -> bool float the panel in a tool window: rect = x, y (DIP from the main window's client origin), client width, height; None: cascaded from the top left -> false when every floating window of the area is in use
  • fn dock_to(&mut self, id: u32, side: u8) dock the panel to a side, as a new group at its end
  • fn dock_group_to(&mut self, id: u32, side: u8) dock the whole group of the panel to a side, as a new group at its end: every tab in its order, the shown one stays shown (a floating window's group too; a group already on that side stays where it is)
  • fn float_group(&mut self, id: u32, rect: Option<[i32; 4]>) -> bool float the whole group of the panel in a tool window (rect as for float; its pin button docks it back on its side) -> false when every floating window of the area is in use or the panel is hidden; a group that floats already only moves to rect
  • fn collapse(&mut self, side: u8, on: bool) collapse a side to a rail of icon buttons, or expand it
  • fn collapsed(&self, side: u8) -> bool the side is collapsed
  • fn size(&self, side: u8) -> i32 the width (left / right) or the height (bottom) of a side in DIP
  • fn set_size(&mut self, side: u8, dip: i32) set the width / height of a side (DIP)
  • fn groups(&self, side: u8) -> Vec<Vec<u32>> the tab groups of a side from start to end, each with its panels in tab order
  • fn floats(&self) -> Vec<Vec<u32>> the panels of every floating window
  • fn hidden_panels(&self) -> Vec<u32> the hidden panels
  • fn side(&self, id: u32) -> Option<u8> where the panel is: DOCK_LEFT / DOCK_RIGHT / DOCK_BOTTOM / DOCK_FLOAT (None: hidden or unknown)
  • fn visible(&self, id: u32) -> bool docked or floating (not hidden)
  • fn front(&self, id: u32) -> bool the shown tab of its group (also on a collapsed side)
  • fn shown(&self, id: u32) -> bool its content is on the screen: the front tab, on a side that is not collapsed (or floating)
  • fn save(&self) -> String the layout as text (see DockState)
  • fn load(text: &str) -> Option<DockState> a layout saved with save -> None when the text is no dock layout (version 1)

impl Ui

  • fn dock_begin(&mut self, id: u32, st: &mut DockState, panels: &[DockPanel]) dock_begin(id, &mut st, panels): open the dock area (always pair with dock_end; fill it with dock_next). It takes the next place of the box (the whole rest when no size was set); panels: every panel the app has, each frame (titles and icons may change).
  • fn dock_next(&mut self, st: &mut DockState) -> Option<u32> dock_next(&mut st) -> the next place to fill (None: done): DOCK_CENTER, then the id of a shown panel; its content goes into a vertical box (it clips) until the next call
  • fn dock_end(&mut self, st: &mut DockState) -> bool dock_end(&mut st) -> the user changed the layout in this pass (store st.save() then)

Source: docs/API.md in the JFLib repository.