Skip to content

Commit 84e49c4

Browse files
committed
BUGFIX: remove components when truncating the tree
1 parent d6343cc commit 84e49c4

14 files changed

Lines changed: 34 additions & 58 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* `Backend::full_screen()` convenience function
44
* `to_float` template function
55
* `PathBuf`s can now be used as templates
6+
* BUGFIX: tick events no longer tries to use removed components
67
* 0.2.5
78
* BUGFIX: component reuse in if / else
89
* `with` statement

anathema-backend/src/tui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl TuiBackend {
117117
}
118118

119119
/// Convenience function this is the same as calling
120-
/// ```
120+
/// ```no_run
121121
/// # use anathema_backend::tui::TuiBackend;
122122
/// # use anathema_backend::Backend;
123123
/// let mut backend = TuiBackend::builder()

anathema-runtime/src/runtime/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
327327
let now = Instant::now();
328328
self.init_new_components();
329329
let elapsed = self.handle_messages(now);
330+
// Pre cycle events
330331
self.poll_events(elapsed, now, backend);
331332
self.drain_deferred_commands();
332333
self.drain_assoc_events();
@@ -340,6 +341,7 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
340341
self.tick_components(self.dt.elapsed());
341342
self.cycle(backend)?;
342343

344+
// Post cycle events
343345
*self.dt = Instant::now();
344346

345347
match self.layout_ctx.stop_runtime {

anathema-state/src/value/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ mod test {
132132
}
133133
impl Drop for DM {
134134
fn drop(&mut self) {
135-
eprintln!("- drop: {}", self.0);
135+
// eprintln!("- drop: {}", self.0);
136136
}
137137
}
138138

anathema-store/src/slab/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<I, T> Entry<I, T> {
6969
// Insert an Occupied entry in place of a vacant one.
7070
fn swap(&mut self, value: T) {
7171
debug_assert!(matches!(self, Entry::Vacant(_)));
72-
std::mem::swap(self, &mut Entry::Occupied(value));
72+
*self = Entry::Occupied(value);
7373
}
7474

7575
// Create a new occupied entry

anathema-store/src/slab/generational.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<T> Entry<T> {
144144
// Insert an Occupied entry in place of a vacant one.
145145
fn swap(&mut self, value: T, generation: Gen) {
146146
debug_assert!(matches!(self, Entry::Vacant(_)));
147-
std::mem::swap(self, &mut Entry::Occupied(value, generation));
147+
*self = Entry::Occupied(value, generation);
148148
}
149149

150150
// Create a new occupied entry
@@ -437,7 +437,7 @@ where
437437
Entry::Vacant(key) => {
438438
let _ = write!(&mut s, "{idx}: vacant ");
439439
match key {
440-
Some(key) => writeln!(&mut s, "next key: {:?}", key),
440+
Some(key) => writeln!(&mut s, "next key: {key:?}"),
441441
None => writeln!(&mut s, "no next id"),
442442
}
443443
}
@@ -451,7 +451,7 @@ where
451451
let _ = writeln!(&mut s, "---- next id ----");
452452

453453
let _ = match self.next_id {
454-
Some(key) => writeln!(&mut s, "next key: {:?}", key),
454+
Some(key) => writeln!(&mut s, "next key: {key:?}"),
455455
None => writeln!(&mut s, "no next id"),
456456
};
457457

anathema-store/src/slab/shared/arc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<I, T> Entry<I, T> {
4646
.expect("Arc strong count is always one here")
4747
.replace(inner_value);
4848

49-
swap(self, &mut Entry::Occupied(storage_cell));
49+
*self = Entry::Occupied(storage_cell);
5050
}
5151
_ => unreachable!(),
5252
}
@@ -70,7 +70,7 @@ impl<I, T> Entry<I, T> {
7070
.expect("strong count is always one")
7171
.take()
7272
.expect("occupied variant never contains a None");
73-
swap(self, &mut Entry::Vacant(next_id.take(), store));
73+
*self = Entry::Vacant(next_id.take(), store);
7474
Some(value)
7575
}
7676
_ => unreachable!(),

anathema-store/src/slab/shared/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<I, T> Entry<I, T> {
4444
.expect("Rc strong count is always one here")
4545
.replace(inner_value);
4646

47-
swap(self, &mut Entry::Occupied(storage_cell));
47+
*self = Entry::Occupied(storage_cell);
4848
}
4949
_ => unreachable!(),
5050
}
@@ -68,7 +68,7 @@ impl<I, T> Entry<I, T> {
6868
.expect("strong count is always one")
6969
.take()
7070
.expect("occupied variant never contains a None");
71-
swap(self, &mut Entry::Vacant(next_id.take(), store));
71+
*self = Entry::Vacant(next_id.take(), store);
7272
Some(value)
7373
}
7474
_ => unreachable!(),

anathema-value-resolver/src/functions/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn round<'bp>(args: &[ValueKind<'bp>]) -> ValueKind<'bp> {
6464
};
6565

6666
match &args[0] {
67-
ValueKind::Float(f) => ValueKind::Str(format!("{f:.*}", precision).into()),
67+
ValueKind::Float(f) => ValueKind::Str(format!("{f:.precision$}").into()),
6868
_ => ValueKind::Null,
6969
}
7070
}

anathema-widgets/src/layout/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'frame, 'bp> LayoutCtx<'frame, 'bp> {
8282
}
8383

8484
pub(crate) fn truncate_children(&mut self, tree: &mut TreeView<'_, WidgetContainer<'bp>>) {
85-
tree.truncate_children(&mut &mut |widget| {
85+
tree.truncate_children(&mut |widget| {
8686
self.return_component(widget);
8787
});
8888
}
@@ -95,6 +95,7 @@ impl<'frame, 'bp> LayoutCtx<'frame, 'bp> {
9595

9696
fn return_component(&mut self, widget: WidgetContainer<'_>) {
9797
let WidgetKind::Component(comp) = widget.kind else { return };
98+
self.components.try_remove(comp.widget_id);
9899
let id = comp.component_id;
99100
let state = self.states.remove(comp.state_id).take();
100101
self.component_registry.return_component(id, comp.dyn_component, state);

0 commit comments

Comments
 (0)