Struct duat_core::ui::FileBuilder

source ·
pub struct FileBuilder<'a, U>
where U: Ui,
{ /* private fields */ }
Expand description

A constructor helper for [Widget<U>]s.

When pushing [Widget<U>]s to the layout, this struct can be used to further actions to be taken. It is used in contexts where a widget has just been inserted to the screen, inside closures.

Here, [LineNumbers<U>][crate::widgets::LineNumbers] is pushed to the left of a widget (which in this case is a [FileWidget<U>]

fn file_fn<U>(mut mod_node: ModNode<U>, file: RoData<FileWidget<U>>)
where
    U: Ui,
{
    let specs = PushSpecs::left(Constraint::Length(1.0));
    mod_node.push_specd(LineNumbers::default_fn());
}

By using the file_fn() function as the constructor_hook argument for [Session::new()][crate::Session::new()], every file that is opened will have a [LineNumbers<U>][crate::widgets::LineNumbers] widget attached to it.

Implementations§

source§

impl<'a, U> FileBuilder<'a, U>
where U: Ui,

source

pub fn new( window: &'a mut Window<U>, mod_area: U::Area, context: Context<U>, ) -> Self

Creates a new FileBuilder<U>.

source

pub fn push<W: PassiveWidget<U>>(&mut self) -> (U::Area, Option<U::Area>)

Pushes a [Widget<U>] to [self], given [PushSpecs] and a constructor function.

Do note that this function will should change the index of [self], such that subsequent pushes are targeted at the parent.

§Returns

The first element is the area_index of the newly created [Widget<U>], you can use it to push new [Widget<U>]s. The second element, of type Option<usize> is [Some(..)] only when a new parent was created to accomodate the new [Widget<U>], and represents the new area_index of the old [Widget<U>], which has now become a child.

§Examples

Pushing on [Side::Left], when [self] has an index of 0:

╭────────0────────╮     ╭────────0────────╮
│                 │     │╭──2───╮╭───1───╮│
│                 │ --> ││      ││       ││
│                 │     ││      ││       ││
│                 │     │╰──────╯╰───────╯│
╰─────────────────╯     ╰─────────────────╯

So a subsequent use of [push_widget][Self::push_widget] on [Side::Bottom] would push to the bottom of “both 1 and 2”:

╭────────0────────╮     ╭────────0────────╮
│╭──2───╮╭───1───╮│     │╭──2───╮╭───1───╮│
││      ││       ││ --> │╰──────╯╰───────╯│
││      ││       ││     │╭───────3───────╮│
│╰──────╯╰───────╯│     │╰───────────────╯│
╰─────────────────╯     ╰─────────────────╯
source

pub fn push_cfg<W: PassiveWidget<U>>( &mut self, cfg: impl WidgetCfg<U, Widget = W>, ) -> (U::Area, Option<U::Area>)

Pushes a [Widget<U>] to [self], given [PushSpecs] and a constructor function.

Do note that this function will should change the index of [self], such that subsequent pushes are targeted at the parent.

§Returns

The first element is the area_index of the newly created [Widget<U>], you can use it to push new [Widget<U>]s. The second element, of type Option<usize> is [Some(..)] only when a new parent was created to accomodate the new [Widget<U>], and represents the new area_index of the old [Widget<U>], which has now become a child.

§Examples

Pushing on [Side::Left], when [self] has an index of 0:

╭────────0────────╮     ╭────────0────────╮
│                 │     │╭──2───╮╭───1───╮│
│                 │ --> ││      ││       ││
│                 │     ││      ││       ││
│                 │     │╰──────╯╰───────╯│
╰─────────────────╯     ╰─────────────────╯

So a subsequent use of [push_widget][Self::push_widget] on [Side::Bottom] would push to the bottom of “both 1 and 2”:

╭────────0────────╮     ╭────────0────────╮
│╭──2───╮╭───1───╮│     │╭──2───╮╭───1───╮│
││      ││       ││ --> │╰──────╯╰───────╯│
││      ││       ││     │╭───────3───────╮│
│╰──────╯╰───────╯│     │╰───────────────╯│
╰─────────────────╯     ╰─────────────────╯
source

pub fn push_to<W: PassiveWidget<U>>( &mut self, area: U::Area, ) -> (U::Area, Option<U::Area>)

Pushes a [Widget<U>] to a specific area, given [PushSpecs] and a constructor function.

§Examples

Given that [self] has an index of 0, and other widgets have already been pushed, one can push to a specific [Widget<U>], given an area index.

╭────────0────────╮ ╭────────0────────╮ │╭──2───╮╭───1───╮│ │╭──2───╮╭───1───╮│ ││ ││ ││ –> ││ │╰───────╯│ ││ ││ ││ ││ │╭───3───╮│ │╰──────╯╰───────╯│ │╰──────╯╰───────╯│ ╰─────────────────╯ ╰─────────────────╯

source

pub fn push_cfg_to<W: PassiveWidget<U>>( &mut self, cfg: impl WidgetCfg<U, Widget = W>, area: U::Area, ) -> (U::Area, Option<U::Area>)

Pushes a [Widget<U>] to a specific area, given [PushSpecs] and a constructor function.

§Examples

Given that [self] has an index of 0, and other widgets have already been pushed, one can push to a specific [Widget<U>], given an area index.

╭────────0────────╮ ╭────────0────────╮ │╭──2───╮╭───1───╮│ │╭──2───╮╭───1───╮│ ││ ││ ││ –> ││ │╰───────╯│ ││ ││ ││ ││ │╭───3───╮│ │╰──────╯╰───────╯│ │╰──────╯╰───────╯│ ╰─────────────────╯ ╰─────────────────╯

Auto Trait Implementations§

§

impl<'a, U> Freeze for FileBuilder<'a, U>
where <U as Ui>::Area: Freeze,

§

impl<'a, U> !RefUnwindSafe for FileBuilder<'a, U>

§

impl<'a, U> Send for FileBuilder<'a, U>

§

impl<'a, U> Sync for FileBuilder<'a, U>

§

impl<'a, U> Unpin for FileBuilder<'a, U>
where <U as Ui>::Area: Unpin,

§

impl<'a, U> !UnwindSafe for FileBuilder<'a, U>

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