Retain widget state against incoming panes

We can associate each state with a `Pane` and compare
that against the new panes to remove states w/ respective
panes which no longer exist.

Because we always increment `Pane`, new states are always
added to the end, so this retain + add new state approach
will ensure continuity when panes are added & removed
This commit is contained in:
Cory Forsstrom 2024-10-04 11:31:14 -07:00 committed by Héctor Ramón Jiménez
parent 415fd4f643
commit 9ac3318357
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 135 additions and 125 deletions

View file

@ -343,7 +343,7 @@ impl<T> State<T> {
/// [`PaneGrid`]: super::PaneGrid
#[derive(Debug, Clone)]
pub struct Internal {
layout: Node,
pub(super) layout: Node,
last_id: usize,
}
@ -397,11 +397,12 @@ impl Internal {
/// The current action of a [`PaneGrid`].
///
/// [`PaneGrid`]: super::PaneGrid
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Action {
/// The [`PaneGrid`] is idle.
///
/// [`PaneGrid`]: super::PaneGrid
#[default]
Idle,
/// A [`Pane`] in the [`PaneGrid`] is being dragged.
///
@ -441,9 +442,8 @@ impl Action {
}
}
impl Internal {
/// The layout [`Node`] of the [`Internal`] state
pub fn layout(&self) -> &Node {
&self.layout
}
#[derive(Default)]
pub(super) struct Widget {
pub action: Action,
pub panes: Vec<Pane>,
}