Skip to main content

DockLayout

Struct DockLayout 

Source
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

Source

pub fn new() -> Self

Nothing anywhere yet, with the docks at their usual sizes.

Source

pub fn center(self, node: DockNode) -> Self

Puts this in the center.

Source

pub fn left(self, node: DockNode, size: f32) -> Self

Puts this in the left dock, size logical pixels wide.

Source

pub fn right(self, node: DockNode, size: f32) -> Self

Puts this in the right dock, size logical pixels wide.

Source

pub fn bottom(self, node: DockNode, size: f32) -> Self

Puts this in the bottom dock, size logical pixels tall.

Source

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.

Source

pub fn node(&self, side: DockSide) -> Option<&DockNode>

What is in this place.

Source

pub fn size(&self, side: DockSide) -> f32

The size of a dock in logical pixels, kept while it is collapsed. The center has none.

Source

pub fn set_size(&mut self, side: DockSide, size: f32)

Sets the size of a dock. A size that is no number is ignored.

Source

pub fn is_open(&self, side: DockSide) -> bool

Whether a dock shows; the center always does.

Source

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.

Source

pub fn contains(&self, id: &str) -> bool

Whether a panel is in the tree, whether or not it is what shows.

Source

pub fn side_of(&self, id: &str) -> Option<DockSide>

The place a panel is in, if it is not closed.

Source

pub fn panels(&self) -> Vec<&str>

The ids in the tree, center first.

Source

pub fn closed_panels(&self) -> Vec<&str>

The ids closed, in the order they closed.

Source

pub fn is_active(&self, id: &str) -> bool

Whether this panel is the one its group shows.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn to_text(&self) -> String

Writes it as text to keep, in a versioned format: JSON with a version at the top.

Source

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

Source§

fn clone(&self) -> DockLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DockLayout

Source§

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

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

impl Default for DockLayout

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for DockLayout

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 DockLayout

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for DockLayout

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 DockLayout

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
§

impl<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more