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,
impl<'a, U> FileBuilder<'a, U>where
U: Ui,
sourcepub fn new(
window: &'a mut Window<U>,
mod_area: U::Area,
context: Context<U>,
) -> Self
pub fn new( window: &'a mut Window<U>, mod_area: U::Area, context: Context<U>, ) -> Self
Creates a new FileBuilder<U>.
sourcepub fn push<W: PassiveWidget<U>>(&mut self) -> (U::Area, Option<U::Area>)
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───────╮│
│╰──────╯╰───────╯│ │╰───────────────╯│
╰─────────────────╯ ╰─────────────────╯
sourcepub fn push_cfg<W: PassiveWidget<U>>(
&mut self,
cfg: impl WidgetCfg<U, Widget = W>,
) -> (U::Area, Option<U::Area>)
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───────╮│
│╰──────╯╰───────╯│ │╰───────────────╯│
╰─────────────────╯ ╰─────────────────╯
sourcepub fn push_to<W: PassiveWidget<U>>(
&mut self,
area: U::Area,
) -> (U::Area, Option<U::Area>)
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───╮│ │╰──────╯╰───────╯│ │╰──────╯╰───────╯│ ╰─────────────────╯ ╰─────────────────╯
sourcepub fn push_cfg_to<W: PassiveWidget<U>>(
&mut self,
cfg: impl WidgetCfg<U, Widget = W>,
area: U::Area,
) -> (U::Area, Option<U::Area>)
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───╮│ │╰──────╯╰───────╯│ │╰──────╯╰───────╯│ ╰─────────────────╯ ╰─────────────────╯