Skip to main content

Layout

Struct Layout 

Source
pub struct Layout {
    pub areas: Vec<(Area, Node)>,
    pub auxiliary: Vec<Auxiliary>,
    pub hidden: Vec<PanelId>,
    pub folded: Vec<Area>,
    pub over: Vec<Area>,
    pub flyouts: BTreeMap<PanelId, f32>,
    pub floating: Vec<FloatingGroup>,
    pub docked_groups: Vec<FloatingGroup>,
    pub closed: BTreeMap<PanelId, DormantPlace>,
    pub instances: Vec<PanelInstance>,
    pub windows: Vec<WindowAreas>,
}

Fields§

§areas: Vec<(Area, Node)>§auxiliary: Vec<Auxiliary>§hidden: Vec<PanelId>

Panels the user closed: not put back as new ones are.

§folded: Vec<Area>

Areas folded to their strip: their panels stay, unshown.

§over: Vec<Area>

Side areas lying over the centre (Placement::Over): their folded strip keeps their room, the centre its width.

§flyouts: BTreeMap<PanelId, f32>

The width each panel was given as a flyout over the centre, out of its folded side area’s strip, in points.

§floating: Vec<FloatingGroup>

Panels floating over the interface (palettes), each group as one unit (a palette alone is a group of one).

§docked_groups: Vec<FloatingGroup>

Groups docked whole in an area (their members there as tabs), kept so that floating one of them out again gives the group back.

§closed: BTreeMap<PanelId, DormantPlace>

The place each closed panel had when it closed (Layout::hide), where opening it puts it back (Layout::last_place); kept only for panels in hidden.

§instances: Vec<PanelInstance>

The instances of panels declared with several (PanelSpec::instances): each <kind>#<n> open, its title when renamed and the application’s payload for it; the panel declared (instance 1) only when it holds a payload. A layout saved without them reads as one with none.

§windows: Vec<WindowAreas>

The areas of the application windows other than the main one, each window’s own workbench (WindowAreas); areas are the main window’s. A layout saved before them reads as one with none.

Implementations§

Source§

impl Layout

Source

pub fn default_for(panels: &Panels) -> Layout

Every declared panel in its default area, as tabs.

Source

pub fn placement(&self, area: Area) -> Placement

Where a side area lies (the centre and the bottom area always lie beside).

Source

pub fn set_placement(&mut self, area: Area, placement: Placement)

Lays a side area over the centre or beside it.

Source

pub fn placed(&self) -> Vec<&PanelId>

Every panel placed, docked, detached or floating.

Source

pub fn window_areas(&self, window: &str) -> Option<&WindowAreas>

An application window’s areas, if it has any.

Source

pub fn window_folded(&self, window: &str, area: Area) -> bool

Whether an application window’s area is folded (WindowAreas::folded).

Source

pub fn fold_in_window(&mut self, window: &str, area: Area, folded: bool) -> bool

Folds an application window’s area (true) or unfolds it; a window without areas has nothing to fold. false when nothing changed.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::Layout;
use egui_pop_model::panels::Area;

let outline = PanelId::from_static("app.outline");
let mut layout = Layout::default();
layout.place_in_window(&outline, "library", Area::StartSide);
assert!(layout.fold_in_window("library", Area::StartSide, true));
assert!(layout.window_folded("library", Area::StartSide));
assert!(layout.shows(&outline));
Source

pub fn window_place(&self, panel: &PanelId) -> Option<(&str, Area)>

The application window (other than the main one) a panel is docked in, and its area there.

Source

pub fn panels_in_window(&self, window: &str) -> Vec<&PanelId>

Every panel an application window holds: for MAIN_WINDOW those in its areas, its detached windows and its floating groups; for another, those docked in its own areas (Layout::windows).

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{Layout, MAIN_WINDOW};
use egui_pop_model::panels::Area;

let [tree, log] = [PanelId::from_static("app.tree"), PanelId::from_static("app.log")];
let mut layout = Layout::default();
layout.place(&tree, Area::StartSide);
layout.place_in_window(&log, "activity", Area::Bottom);
assert_eq!(layout.panels_in_window(MAIN_WINDOW), [&tree]);
assert_eq!(layout.panels_in_window("activity"), [&log]);
Source

pub fn with_window_from(&self, from: &Layout, window: &str) -> Layout

This layout with one application window’s part taken from from, every other window left as it is here: what a change made to one window (a place switched in it) puts in.

The part of MAIN_WINDOW is its areas, its detached windows, its floating groups and what goes with them (folded and overlaid areas, flyouts, docked groups); another window’s part is its own areas. A panel this layout shows in another window stays there: from cannot take it, show it or close it. Closed panels follow the window they were closed in, and instances the window that holds them.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{Layout, MAIN_WINDOW};
use egui_pop_model::panels::Area;

let [tree, log] = [PanelId::from_static("app.tree"), PanelId::from_static("app.log")];
// Shown: the log docked in a second window.
let mut shown = Layout::default();
shown.place(&tree, Area::StartSide);
shown.place_in_window(&log, "activity", Area::Bottom);
// A place's layout for the main window, which had the log there.
let mut place = Layout::default();
place.place(&tree, Area::EndSide);
place.place(&log, Area::Bottom);
let merged = shown.with_window_from(&place, MAIN_WINDOW);
assert_eq!(merged.area_of(&tree), Some(Area::EndSide));
assert_eq!(merged.window_place(&log), Some(("activity", Area::Bottom)));
assert_eq!(merged.area_of(&log), None);
Source

pub fn place_in_window(&mut self, panel: &PanelId, window: &str, area: Area)

Docks a panel in an area of an application window other than the main one (taken out of where it was, opened if closed), as the shown tab of the area’s first tabs.

Source

pub fn set_window_areas(&mut self, window: &str, areas: Vec<(Area, Node)>)

Sets an application window’s areas as drawn (its tabs reordered, split, moved between its areas); empty areas are dropped, and the window with them when it has none left.

Source

pub fn window_of(&self, panel: &PanelId) -> Option<&Auxiliary>

The window a detached panel is in, if it is detached (alone or as one of its tabs).

Source

pub fn join_window( &mut self, panel: &PanelId, window: &PanelId, ) -> Result<(), String>

Moves a panel into the window holding window (a panel of it), as its last tab, shown; taken out of where it was, opened if closed. A panel in that window already is only shown.

Source

pub fn group_of(&self, panel: &PanelId) -> Option<(Vec<PanelId>, usize)>

The tab group holding a docked or detached panel: its panels in order and the index of the shown one (an area’s tabs holding it, or its window’s tabs).

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{Layout, Node};
use egui_pop_model::panels::Area;

let [a, b] = [PanelId::from_static("app.a"), PanelId::from_static("app.b")];
let mut layout = Layout::default();
layout.areas.push((Area::Bottom, Node::Tabs { panels: vec![a.clone(), b.clone()], active: 1 }));
assert_eq!(layout.group_of(&a), Some((vec![a, b], 1)));
Source

pub fn join_window_group( &mut self, panel: &PanelId, window: &PanelId, ) -> Result<(), String>

Moves the tab group holding panel (Layout::group_of) into the window holding window, after its tabs, in order; the group’s shown panel is shown there. A group already in that window stays.

Source

pub fn detach_group( &mut self, panel: &PanelId, screen: &str, rect: [f32; 4], ) -> Result<(), String>

Moves the tab group holding panel (Layout::group_of) into a window of its own at rect on screen, in order, its shown panel shown. A group that is a window already stays.

Source

pub fn float_tabs( &mut self, panel: &PanelId, pos: [f32; 2], ) -> Result<Vec<PanelId>, String>

Floats the docked tab group holding panel (Layout::group_of) over the interface at pos, whole: one floating group of tabs, in order, its shown tab shown. The panels floated.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{Arrangement, Layout, Node};
use egui_pop_model::panels::Area;

let [a, b] = [PanelId::from_static("app.a"), PanelId::from_static("app.b")];
let mut layout = Layout::default();
layout.areas.push((Area::Bottom, Node::Tabs { panels: vec![a.clone(), b.clone()], active: 1 }));
assert_eq!(layout.float_tabs(&a, [8.0, 8.0]).unwrap(), [a.clone(), b.clone()]);
let g = layout.floating_of(&a).unwrap();
assert_eq!(g.arrangement, Arrangement::Tabs);
assert_eq!(g.shown(), &b);
assert_eq!(layout.area_of(&a), None);
Source

pub fn floating_of(&self, panel: &PanelId) -> Option<&FloatingGroup>

The group a floating panel floats in, if it floats.

Source

pub fn floating_mut(&mut self, panel: &PanelId) -> Option<&mut FloatingGroup>

The group a floating panel floats in, to change it.

Source

pub fn float(&mut self, panel: &PanelId, pos: [f32; 2])

Floats a panel over the interface at pos (taken out of where it was, opened if it was closed); a panel floating already moves there with its group, keeping its state. A panel docked with the group it was docked in whole (Layout::dock_group) floats with the members still docked beside it: the group comes back.

Source

pub fn group( &mut self, panels: &[PanelId], into: &PanelId, at: Join, ) -> Result<(), String>

Moves floating panels into the group of another floating panel, into, and says where:

  • Join::Above or Join::Below it: the group is then a stack. Beside a group of tabs, the tabs stay tabs, as one member of the stack (a nested tab group).
  • Join::Tab: as tabs of it, the first of them shown. In a group of tabs or with a palette alone, the group turns to tabs; on a member of a stack, that member alone becomes a tab group.

A nested tab group whose tabs all move keeps them, unless it joins as tabs; each moved member keeps whether it is rolled up; groups left empty go.

Source

pub fn ungroup(&mut self, panel: &PanelId, pos: [f32; 2]) -> Result<(), String>

Takes a floating panel out of its group, alone at pos (it keeps whether it is rolled up); out of a nested tab group, the group’s other tabs stay.

Source

pub fn ungroup_tabs( &mut self, panel: &PanelId, pos: [f32; 2], ) -> Result<(), String>

Takes the tab group a floating panel is a tab of, nested in a stack, out of the stack whole: a group of tabs at pos. A palette that is not in a nested tab group comes out alone, as Layout::ungroup takes it.

Source

pub fn dock_group(&mut self, panel: &PanelId, area: Area) -> Vec<PanelId>

Docks every member of a floating panel’s group in an area, as tabs, the group’s shown member shown; the group is kept (Layout::docked_groups) so that floating one of them out again gives it back. The panels docked.

Source

pub fn area_of(&self, panel: &PanelId) -> Option<Area>

The area a panel is docked in, if it is.

Source

pub fn shows(&self, panel: &PanelId) -> bool

Whether a panel is docked or detached, and not closed.

Source

pub fn remove(&mut self, panel: &PanelId) -> bool

Takes a panel out of its area, its window or its float (out of its group, the others staying together; it stays known: not closed). Whether it was placed.

Source

pub fn place(&mut self, panel: &PanelId, area: Area)

Docks a panel in an area (taken out of where it was), as the shown tab of the area’s first tabs.

Source

pub fn docked_place(&self, panel: &PanelId) -> Option<DormantPlace>

Where a docked panel is: its area, the other panels of its tabs and its index among them (a DormantPlace::Docked); None when it is not docked.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{DormantPlace, Layout, Node};
use egui_pop_model::panels::Area;

let [a, b] = [PanelId::from_static("app.a"), PanelId::from_static("app.b")];
let mut layout = Layout::default();
layout.areas.push((Area::Bottom, Node::Tabs { panels: vec![a.clone(), b.clone()], active: 0 }));
let place = layout.docked_place(&b).unwrap();
assert_eq!(place, DormantPlace::Docked { area: Area::Bottom, beside: vec![a.clone()], index: 1 });
layout.float(&b, [0.0, 0.0]);
layout.dock_at(&b, &place);
assert_eq!(layout.group_of(&b), Some((vec![a, b], 1)));
Source

pub fn in_window_place(&self, panel: &PanelId) -> Option<DormantPlace>

Where a panel docked in an application window other than the main one is (a DormantPlace::InWindow); None when it is not there.

Source

pub fn dock_at(&mut self, panel: &PanelId, place: &DormantPlace) -> bool

Docks a panel at a place Layout::docked_place gave (taken out of where it is, opened if closed), shown: at its index in the tabs holding one of the panels it was beside, else in its area’s first tabs. A place that is not DormantPlace::Docked changes nothing; whether it was docked.

Source

pub fn join_tabs( &mut self, panel: &PanelId, into: &PanelId, ) -> Result<(), String>

Docks a panel in the tabs holding into, after them and shown (taken out of where it is: floating, detached or docked, opened if closed). into is docked; a panel already there is only shown.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{Layout, Node};
use egui_pop_model::panels::Area;

let [a, b] = [PanelId::from_static("app.a"), PanelId::from_static("app.b")];
let mut layout = Layout::default();
layout.areas.push((Area::Bottom, Node::tab(a.clone())));
layout.float(&b, [0.0, 0.0]);
layout.join_tabs(&b, &a).unwrap();
assert_eq!(layout.group_of(&b), Some((vec![a, b], 1)));
Source

pub fn place_of(&self, panel: &PanelId) -> Option<DormantPlace>

Where a panel is: docked (its area, the tabs beside it and its index, Layout::docked_place), detached (its window’s screen and rectangle) or floating (its group’s corner); None when it is not placed.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{DormantPlace, Layout};

let tools = PanelId::from_static("app.tools");
let mut layout = Layout::default();
layout.float(&tools, [16.0, 24.0]);
assert_eq!(layout.place_of(&tools), Some(DormantPlace::Floating { pos: [16.0, 24.0] }));
Source

pub fn last_place(&self, panel: &PanelId) -> Option<&DormantPlace>

The place a closed panel had when it closed (Layout::hide): None when it is open, or closed with no place known.

use egui_pop_model::ids::PanelId;
use egui_pop_model::layout::{DormantPlace, Layout, Node};
use egui_pop_model::panels::Area;

let [a, b] = [PanelId::from_static("app.a"), PanelId::from_static("app.b")];
let mut layout = Layout::default();
layout.areas.push((Area::Bottom, Node::Tabs { panels: vec![a.clone(), b.clone()], active: 1 }));
layout.hide(&b);
let place = layout.last_place(&b).cloned().unwrap();
assert_eq!(place, DormantPlace::Docked { area: Area::Bottom, beside: vec![a.clone()], index: 1 });
layout.dock_at(&b, &place);
assert_eq!(layout.group_of(&b), Some((vec![a, b], 1)));
Source

pub fn instance(&self, id: &PanelId) -> Option<&PanelInstance>

An instance’s record (Layout::instances).

Source

pub fn instance_mut(&mut self, id: &PanelId) -> &mut PanelInstance

An instance’s record, made (without payload) when it has none.

Source

pub fn instances_of(&self, kind: &PanelId) -> Vec<PanelId>

The instances of kind this layout knows (open, closed or kept for a panel no longer declared), the panel declared included when placed or closed, in number order.

Source

pub fn next_instance(&self, kind: &PanelId) -> PanelId

The id a new instance of kind takes: the number after the highest this layout knows, from 2.

Source

pub fn drop_instance(&mut self, id: &PanelId) -> bool

Drops an instance (<kind>#<n>): out of where it is, its record and payload gone, not kept closed (closing the panel declared keeps its place, Layout::hide). Whether it was known.

Source

pub fn hide(&mut self, panel: &PanelId)

Closes a panel: out of its area or window, and kept closed, its place kept for when it opens again (Layout::last_place).

Source

pub fn activate(&mut self, panel: &PanelId) -> bool

Makes a docked panel the shown tab of its tabs; whether it is docked.

Source

pub fn active_in(&self, area: Area) -> Vec<&PanelId>

The shown panels of an area, in order (the shown tab of each tabs node).

Source

pub fn repair(self, panels: &Panels, screens: &[&str]) -> (Layout, Vec<String>)

Brings a saved layout in line with today’s panels and screens: panels no longer declared leave it, new ones go to their default area, so do panels in an area they may no longer be in, a window on a screen that is gone comes back docked. Says what it changed. Layout::repair_dormant also keeps the places of the panels that leave.

Source

pub fn repair_dormant( self, dormant: Vec<Dormant>, panels: &Panels, screens: &[&str], ) -> (SavedLayout, Vec<String>)

Layout::repair, keeping the places of panels no longer declared (ADR 0028): dormant, the places kept so far, comes back with those of the panels leaving now; a panel declared again goes back to its place (docked at its index beside the same tabs, detached, floating, or closed) instead of to its default area.

Source

pub fn to_json(&self) -> String

The document’s text.

Source

pub fn from_json(text: &str) -> Result<Layout, String>

Reads a layout document of any known version.

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Layout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Layout

Source§

fn default() -> Layout

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Layout

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Layout

Source§

fn eq(&self, other: &Layout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Layout

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Layout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,