Struct penrose::pure::Stack

source ·
pub struct Stack<T> { /* private fields */ }
Expand description

A Stack can be thought of as a linked list with a hole punched in it to mark a single element that currently holds focus (though in practice it is implemented using a VecDeque for efficiency purposes). By convention, the main element is the first element in the stack (regardless of focus). Focusing operations do not reorder the elements of the stack or the resulting Vec that can be obtained from calling Stack::flatten.

This is a zipper over a VecDeque. Many of the methods that mutate the structure of the Stack return back a mutable reference so that they are able to be chained.

Implementations§

source§

impl Stack<Box<dyn Layout>>

source

pub fn run_and_replace<F>(&mut self, f: F) -> Vec<(Xid, Rect)>
where F: FnOnce(&mut Box<dyn Layout>) -> (Option<Box<dyn Layout>>, Vec<(Xid, Rect)>),

Run the currently focused Layout and return the positions it generates.

If the layout being run wants to be replaced with a new layout, swap it out for the new one in its current position in the Stack.

source

pub fn handle_message<M>(&mut self, m: M)
where M: IntoMessage,

Send the given Message to the currently active Layout.

source

pub fn broadcast_message<M>(&mut self, m: M)
where M: IntoMessage,

Send the given Message to every Layout in this stack rather that just the currently active one.

source§

impl<T> Stack<T>

source

pub fn new<I, J>(up: I, focus: T, down: J) -> Self
where I: IntoIterator<Item = T>, J: IntoIterator<Item = T>,

Create a new Stack specifying the focused element and and elements above and below it.

source

pub fn try_from_iter<I>(iter: I) -> Option<Self>
where I: IntoIterator<Item = T>,

For an iterator of at least one element, the first element will be focused and all remaining elements will be placed after it. For an empty iterator, return None.

source

pub fn len(&self) -> usize

The number of elements in this Stack.

source

pub fn is_empty(&self) -> bool

Always false: a Stack always has at least one focused element.

source

pub fn iter(&self) -> Iter<'_, T>

Provide an iterator over this stack iterating over up, focus and then down.

source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Provide an iterator over this stack iterating over up, focus and then down with mutable references.

source

pub fn unravel(&self) -> impl Iterator<Item = &T>

Iterate over the clients in this stack from the the focused element down through the stack.


let unraveled: Vec<u8> = stack!([1, 2], 3, [4, 5]).unravel().copied().collect();
assert_eq!(unraveled, vec![3, 4, 5, 1, 2]);
source

pub fn flatten(self) -> Vec<T>

Flatten a Stack into a Vector, losing the information of which element is focused.

source

pub fn head(&self) -> &T

Return a reference to the first element in this Stack

source

pub fn focused(&self) -> &T

Return a reference to the focused element in this Stack

source

pub fn last(&self) -> &T

Return a reference to the last element in this Stack

source

pub fn swap_focus_and_head(&mut self) -> &mut Self

Swap the current head element with the focused element in the stack order. Focus stays with the original focused element.

source

pub fn rotate_focus_to_head(&mut self) -> &mut Self

Rotate the Stack until the current focused element is in the head position

source

pub fn focus_head(&mut self) -> &mut Self

Move focus to the element in the head position

source

pub fn insert(&mut self, t: T) -> &mut Self

Insert the given element in place of the current focus, pushing the current focus down the Stack.

source

pub fn insert_at(&mut self, pos: Position, t: T) -> &mut Self

Insert the given element at the requested position in the Stack. See Position for the semantics of each case. For all cases, the existing elements in the Stack are pushed down to make room for the new one.

source

pub fn remove_focused(self) -> (T, Option<Self>)

Remove the focused element of this Stack. If this was the only element then the stack is dropped and None is returned.

source

pub fn remove(self, t: &T) -> (Option<T>, Option<Self>)
where T: PartialEq,

Remove an element from the stack.

If the element was present it is returned along with the rest of the Stack. If this was the last element in the stack, the stack is dropped and None is returned.

source

pub fn map<F, U>(self, f: F) -> Stack<U>
where F: Fn(T) -> U,

Map a function over all elements in this Stack, returning a new one.

source

pub fn filter<F>(self, f: F) -> Option<Self>
where F: Fn(&T) -> bool,

Retain only elements which satisfy the given predicate. If the focused element is removed then focus shifts to the first remaining element after it, if there are no elements after then focus moves to the first remaining element before. If no elements satisfy the predicate then None is returned.

source

pub fn reverse(&mut self) -> &mut Self

Reverse the ordering of a Stack (up becomes down) while maintaining focus.

source

pub fn focus_up(&mut self) -> &mut Self

Move focus from the current element up the stack, wrapping to the bottom if focus is already at the top.

source

pub fn focus_down(&mut self) -> &mut Self

Move focus from the current element down the stack, wrapping to the top if focus is already at the bottom.

source

pub fn focus_element_by<F>(&mut self, f: F)
where F: Fn(&T) -> bool,

Focus the first element found matching the given predicate function.

If no matching elements are found, the Stack will be left in its original state.

source

pub fn swap_up(&mut self) -> &mut Self

Swap the focused element with the one above, wrapping from top to bottom. The currently focused element is maintained by this operation.

source

pub fn swap_down(&mut self) -> &mut Self

Swap the focused element with the one below, wrapping from top to bottom. The currently focused element is maintained by this operation.

source

pub fn rotate_up(&mut self) -> &mut Self

Rotate all elements of the stack forward, wrapping from top to bottom. The currently focused element in the stack is maintained by this operation.

source

pub fn rotate_down(&mut self) -> &mut Self

Rotate all elements of the stack back, wrapping from bottom to top. The currently focused element in the stack is maintained by this operation.

source§

impl<T: Clone> Stack<T>

source

pub fn from_filtered<F>(&self, f: F) -> Option<Self>
where F: Fn(&T) -> bool,

Attempt to create a new Stack from this one by filtering the existing elements using a predicate function. This will return None if no elements match the predicate.

source

pub fn extract<F>(&self, f: F) -> (Option<Self>, Vec<T>)
where F: Fn(&T) -> bool,

Extract elements satisfying a predicate into a Vec, leaving remaining elements in their original stack position.

source§

impl<T: PartialEq> Stack<T>

source

pub fn contains(&self, t: &T) -> bool

Check whether a given element is in this Stack

source

pub fn focus_element(&mut self, t: &T)

Attempt to focus a given element in the Stack if it is present.

If the requested element is not found, the Stack will be left in its original state.

Trait Implementations§

source§

impl<T: Clone> Clone for Stack<T>

source§

fn clone(&self) -> Stack<T>

Returns a copy 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<T: Debug> Debug for Stack<T>

source§

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

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

impl<T: Default> Default for Stack<T>

source§

fn default() -> Stack<T>

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

impl<T: Display> Display for Stack<T>

source§

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

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

impl<'a, T> IntoIterator for &'a Stack<T>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<'a, T> IntoIterator for &'a mut Stack<T>

§

type Item = &'a mut T

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IterMut<'a, T>

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Stack<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more
source§

impl<T: PartialEq> PartialEq for Stack<T>

source§

fn eq(&self, other: &Stack<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Stack<T>

source§

impl<T> StructuralPartialEq for Stack<T>

Auto Trait Implementations§

§

impl<T> Freeze for Stack<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Stack<T>
where T: RefUnwindSafe,

§

impl<T> Send for Stack<T>
where T: Send,

§

impl<T> Sync for Stack<T>
where T: Sync,

§

impl<T> Unpin for Stack<T>
where T: Unpin,

§

impl<T> UnwindSafe for Stack<T>
where T: UnwindSafe,

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,