Struct FileBuilder

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

A constructor helper for File initiations

This helper is used primarily to push widgets around the file in question, and is only obtainable in a OnFileOpen hook:

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

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

In the example above, I pushed a LineNumbers widget to the File. By default, this widget will go on the left, but you can change that:

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

fn setup() {
    hook::add::<OnFileOpen>(|pa, builder| {
        let line_numbers_cfg = LineNumbers::cfg().relative().on_the_right();
        builder.push(pa, line_numbers_cfg);
    });
}

Note that I also made another change to the widget, it will now show relative numbers, instead of absolute, like it usually does.

By default, there already exists a hook group that adds widgets to a file, the "FileWidgets" group. If you want to get rid of this group in order to create your own widget layout, you should use hook::remove:

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

fn setup() {
    hook::remove("FileWidgets");
    hook::add::<OnFileOpen>(|pa, builder| {
        let line_numbers_cfg = LineNumbers::cfg().relative().on_the_right();
        builder.push(pa, line_numbers_cfg);
        // Push a StatusLine to the bottom.
        builder.push(pa, StatusLine::cfg());
        // Push a PromptLine to the bottom.
        builder.push(pa, PromptLine::cfg());
    });
}

Implementations§

Source§

impl<U: Ui> FileBuilder<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 the main area of this File

This widget will be a satellite of the file. This means that, if the file is destroyed, the widget will be destroyed as well, if it is moved, the widget will be moved with it, etc.

When you push a widget, it is placed on the edge of the file. The next widget is placed on the edge of the area containing the file and the previous widget, and so on.

This means that, if you push widget A to the left of the file, then you push widget B to the bottom of the window, you will get this layout:

╭───┬──────────╮
│   │          │
│ A │   File   │
│   │          │
├───┴──────────┤
│      B       │
╰──────────────╯

Here’s an example of such a layout:

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

fn setup() {
    hook::remove("FileWidgets");
    hook::add::<OnFileOpen>(|pa, builder| {
        let line_numbers_cfg = LineNumbers::cfg().rel_abs();
        builder.push(pa, line_numbers_cfg);

        let status_line_cfg = status!("{file_fmt} {selections_fmt} {main_fmt}");
        builder.push(pa, status_line_cfg);
    });
}

In this case, each file will have LineNumbers with relative/absolute numbering, and a StatusLine showing the file’s name and how many selections are in it.

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 around a File

This method can be used to get some more advanced layouts, where you have multiple widgets parallel to each other, yet on the same edge.

One of the main ways in which this is used is when using a hidden Notifications widget alongside the PromptLine widget.

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

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

        let status_cfg = status!("{file_fmt} {selections_fmt} {main_fmt}");
        let (child, _) = builder.push(pa, status_cfg);
        let prompt_cfg = PromptLine::cfg().left_ratioed(3, 5);
        let (child, _) = builder.push_to(pa, child, prompt_cfg);
        builder.push_to(pa, child, Notifications::cfg());
    });
}

Pushing directly to the PromptLine’s U::Area means that they’ll share a parent that holds only them.

Source

pub fn add_reader(&mut self, pa: &mut Pass, reader_cfg: impl ReaderCfg<U>)

Adds a Reader to this File

Readers read changes to Text and can act accordingly by adding or removing Tags from it. They can also be accessed via a public API, in order to be used for other things, like the treesitter Reader, which, internally, creates the syntax tree and does syntax highlighting, but externally it can also be used for indentation of Text by Modes

Source

pub fn read<Ret>( &mut self, pa: &Pass, f: impl FnOnce(&File<U>, &U::Area) -> Ret, ) -> Ret

The File that this hook is being applied to

Source

pub fn write<Ret>( &mut self, pa: &mut Pass, f: impl FnOnce(&mut File<U>, &U::Area) -> Ret, ) -> Ret

Mutable reference to the File that this hooks is being applied to

Trait Implementations§

Source§

impl<U: Ui> UiBuilder<U> for FileBuilder<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 FileBuilder<U>

§

impl<U> !RefUnwindSafe for FileBuilder<U>

§

impl<U> !Send for FileBuilder<U>

§

impl<U> !Sync for FileBuilder<U>

§

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

§

impl<U> !UnwindSafe for FileBuilder<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>,

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.