Skip to content

We should have named views #51

@museun

Description

@museun

After some thinking, I think I came up with a solution:
At

pub(in crate::view) fn begin_view<V>(&self, args: V::Args<'_>, ui: &Ui) -> (ViewId, V::Response)

and
fn update_view<V>(&self, parent: ViewId, args: V::Args<'_>, ui: &Ui) -> (ViewId, V::Response)

We can pass in something like

enum Id {
    Anonymous,
    Named(Str)
}

which could be stored on

too/src/view/view_nodes.rs

Lines 277 to 284 in 162a548

pub struct ViewNode {
/// Your parents id, if you have one.
pub parent: Option<ViewId>,
/// Your childrens ids, if you have any
pub children: Vec<ViewId>,
pub(in crate::view) view: Lock<Slot>,
pub(in crate::view) next: usize,
}

By default, views will have be Id::Anonymous. This'll also require duplicating:

pub fn show<'v, B>(&self, args: B) -> Response<<B::View as View>::Response>

and
pub fn show_children<'v, B, R>(

to have a show_named(view, Id) and a show_named_children(view, Id, impl FnOnce(&Ui) -> R)

With this, then the logic here:

if type_id != TypeId::of::<V>() {
could be changed to compare the self.nodes.borrow()[id].view.borrow().id() with the provided Id, if it doesn't match then we can remove/replace it as if the type didn't match.

Doing this will allow for a tab/screen view type to actually replace its content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions