Struct WindowBuilder

Source
pub struct WindowBuilder<U: Ui> { /* private fields */ }
Expand description

A constructor helper for window initiations

This helper is used primarily to push widgets around the window, surrounding the “main area” which contains all Files and widgets added via the OnFileOpen hook.

It is used whenever the OnWindowOpen hook is triggered, which happens whenever a new window is opened:

setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    hook::add::<OnWindowOpen>(|pa, builder| {
        // Push a StatusLine to the bottom.
        builder.push(pa, StatusLine::cfg());
        // Push a PromptLine to the bottom.
        builder.push(pa, PromptLine::cfg());
    });
}

Contrast this with the example in the FileBuilder docs, where a similar hook is added, but with OnFileOpen instead of OnWindowOpen. In that scenario, the widgets are added to each file that is opened, while in this one, only one instance of these widgets will be created per window.

The existence of these two hooks lets the user make some more advanced choices on the layout:

setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    hook::remove("FileWidgets");
    hook::add::<OnFileOpen>(|pa, builder| {
        builder.push(pa, LineNumbers::cfg());
        builder.push(pa, StatusLine::cfg());
    });

    hook::remove("WindowWidgets");
    hook::add::<OnWindowOpen>(|pa, builder| {
        builder.push(pa, PromptLine::cfg());
    });
}

In this case, each file gets a StatusLine, and the window will get one PromptLine, after all, what is the point of having more than one command line?

You can go further with this idea, like a status line on each file, that shows different information from the status line for the whole window, and so on and so forth.

Implementations§

Source§

impl<U: Ui> WindowBuilder<U>

Source

pub fn push<W: WidgetAlias<U, impl BuilderDummy>>( &mut self, pa: &mut Pass, widget: W, ) -> (U::Area, Option<U::Area>)

Pushes a widget to an edge of the window, given a cfg

This widget will be pushed to the “main” area, i.e., the area that contains all other widgets. After that, the widget’s parent will become the main area, which can be pushed onto again.

This means that, if you push widget A to the right of the window, then you push widget B to the bottom of the window, and then you push widget C to the left of the window,you will end up with something like this:

╭───┬───────────┬───╮
│   │           │   │
│   │ main area │ A │
│ C │           │   │
│   ├───────────┴───┤
│   │       B       │
╰───┴───────────────╯

This method returns the Area created for this widget, as well as an Area for the parent of the two widgets, if a new one was created.

Source

pub fn push_to<W: WidgetCfg<U>>( &mut self, pa: &mut Pass, area: U::Area, cfg: W, ) -> (U::Area, Option<U::Area>)

Pushes a widget to a specific area

Unlike push, this method will push the widget to an area that is not the main area. This can be used to create more intricate layouts.

For example, let’s say I push a StatusLine below the main area, and then I push a PromptLine on the left of the status’s area:

setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    hook::add::<OnWindowOpen>(|pa, builder| {
        // StatusLine goes below by default
        let (status_area, _) = builder.push(pa, StatusLine::cfg());
        let prompt_cfg = PromptLine::cfg().left_ratioed(3, 5);
        builder.push_to(pa, status_area, prompt_cfg);
    });
}

The following would happen:

╭────────────────────────────────────╮
│                                    │
│              main area             │
│                                    │
├─────────────┬──────────────────────┤
│ PromptLine  │      StatusLine      │
╰─────────────┴──────────────────────╯

This is the layout that Kakoune uses by default, and is also avaliable as commented option in the default config.

Trait Implementations§

Source§

impl<U: Ui> UiBuilder<U> for WindowBuilder<U>

Source§

fn push_cfg<W: WidgetCfg<U>>( &mut self, pa: &mut Pass, cfg: W, ) -> (U::Area, Option<U::Area>)

Pushes a Widget to this UiBuilder, on its main U::Area
Source§

fn push_cfg_to<W: WidgetCfg<U>>( &mut self, pa: &mut Pass, area: U::Area, cfg: W, ) -> (U::Area, Option<U::Area>)

Pushes a Widget to this UiBuilder, on a given U::Area

Auto Trait Implementations§

§

impl<U> Freeze for WindowBuilder<U>
where <U as Ui>::Area: Freeze,

§

impl<U> RefUnwindSafe for WindowBuilder<U>
where <U as Ui>::Area: RefUnwindSafe,

§

impl<U> Send for WindowBuilder<U>
where <U as Ui>::Area: Send,

§

impl<U> Sync for WindowBuilder<U>
where <U as Ui>::Area: Sync,

§

impl<U> Unpin for WindowBuilder<U>
where <U as Ui>::Area: Unpin,

§

impl<U> UnwindSafe for WindowBuilder<U>
where <U as Ui>::Area: 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, 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>,

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.