pub struct DockLayout { /* private fields */ }Expand description
The arrangement of a DockArea: which panel is where, the sizes, and what
is collapsed or closed. It holds ids only, so it can be kept in a State, compared and saved;
what a panel shows comes from the app, by id, each time it is drawn.
use ravenrs_widgets::{DockDrop, DockLayout, DockNode, DockSide};
let mut layout = DockLayout::new()
.center(DockNode::tabs(["photo"]))
.left(DockNode::tabs(["folders", "search"]), 240.0);
layout.move_panel("search", DockDrop::Side(DockSide::Center));
assert_eq!(layout.side_of("search"), Some(DockSide::Center));
let saved = layout.to_text();
assert_eq!(DockLayout::parse(&saved), Ok(layout));
assert!(DockLayout::parse("not a layout").is_err());Implementations§
Source§impl DockLayout
impl DockLayout
Sourcepub fn left(self, node: DockNode, size: f32) -> Self
pub fn left(self, node: DockNode, size: f32) -> Self
Puts this in the left dock, size logical pixels wide.
Sourcepub fn right(self, node: DockNode, size: f32) -> Self
pub fn right(self, node: DockNode, size: f32) -> Self
Puts this in the right dock, size logical pixels wide.
Sourcepub fn bottom(self, node: DockNode, size: f32) -> Self
pub fn bottom(self, node: DockNode, size: f32) -> Self
Puts this in the bottom dock, size logical pixels tall.
Sourcepub fn closed<S: Into<String>>(
self,
panels: impl IntoIterator<Item = S>,
place: DockSide,
) -> Self
pub fn closed<S: Into<String>>( self, panels: impl IntoIterator<Item = S>, place: DockSide, ) -> Self
Starts with these panels closed, ready to be reopened in place.
Sourcepub fn size(&self, side: DockSide) -> f32
pub fn size(&self, side: DockSide) -> f32
The size of a dock in logical pixels, kept while it is collapsed. The center has none.
Sourcepub fn set_size(&mut self, side: DockSide, size: f32)
pub fn set_size(&mut self, side: DockSide, size: f32)
Sets the size of a dock. A size that is no number is ignored.
Sourcepub fn set_open(&mut self, side: DockSide, open: bool)
pub fn set_open(&mut self, side: DockSide, open: bool)
Shows or collapses a dock. It keeps its size and its panels for when it comes back.
Sourcepub fn contains(&self, id: &str) -> bool
pub fn contains(&self, id: &str) -> bool
Whether a panel is in the tree, whether or not it is what shows.
Sourcepub fn side_of(&self, id: &str) -> Option<DockSide>
pub fn side_of(&self, id: &str) -> Option<DockSide>
The place a panel is in, if it is not closed.
Sourcepub fn closed_panels(&self) -> Vec<&str>
pub fn closed_panels(&self) -> Vec<&str>
The ids closed, in the order they closed.
Sourcepub fn activate(&mut self, id: &str) -> bool
pub fn activate(&mut self, id: &str) -> bool
Brings a panel to the front of its group, and shows its dock if that was collapsed. It
says whether the panel is there at all; for one that was closed, see Self::reopen.
Sourcepub fn close(&mut self, id: &str) -> bool
pub fn close(&mut self, id: &str) -> bool
Closes a panel, remembering where it was for Self::reopen. A group left empty goes
away, and a split left with one part gives way to it. The last panel can close too: an
arrangement with nothing open is still valid.
Sourcepub fn reopen(&mut self, id: &str) -> bool
pub fn reopen(&mut self, id: &str) -> bool
Brings a closed panel back to the group it was in, or to the place if that group is gone, and shows it. It says whether there was such a panel to bring back.
Sourcepub fn move_panel(&mut self, id: &str, target: DockDrop) -> bool
pub fn move_panel(&mut self, id: &str, target: DockDrop) -> bool
Sends a panel somewhere: into a group, beside it, or into a place; a closed one reopens there. It says whether anything changed, which it does not if the target is gone, or the panel is already what it would become.
Sourcepub fn reconcile(&mut self, known: &[&str]) -> bool
pub fn reconcile(&mut self, known: &[&str]) -> bool
Fits the arrangement to the panels that exist: an id not among them is left out, as if it had never been saved, and one of them that is nowhere becomes closed, ready to be reopened. It says whether anything changed.
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Writes it as text to keep, in a versioned format: JSON with a version at the top.
Sourcepub fn parse(text: &str) -> Result<Self, DockLayoutError>
pub fn parse(text: &str) -> Result<Self, DockLayoutError>
Reads a text from Self::to_text. What makes no sense but does no harm, such as a panel
twice, an empty group or a share below zero, is put right; what cannot be read is an error,
never a panic.
Trait Implementations§
Source§impl Clone for DockLayout
impl Clone for DockLayout
Source§fn clone(&self) -> DockLayout
fn clone(&self) -> DockLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more