Skip to content

Commit ec12e47

Browse files
committed
added file for list functions
1 parent fac1e3e commit ec12e47

File tree

25 files changed

+465
-151
lines changed

25 files changed

+465
-151
lines changed

Cargo.toml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ repository = "https://github.com/togglebyte/anathema"
1313
publish = true
1414

1515
[dependencies]
16-
anathema-default-widgets = { path = "./anathema-default-widgets", version = "0.2.2" }
17-
anathema-backend = { path = "./anathema-backend", version = "0.2.2" }
18-
anathema-runtime = { path = "./anathema-runtime", version = "0.2.2" }
19-
anathema-state = { path = "./anathema-state", version = "0.2.2" }
20-
anathema-state-derive = { path = "./anathema-state-derive", version = "0.2.2" }
21-
anathema-store = { path = "./anathema-store", version = "0.2.2" }
22-
anathema-templates = { path = "./anathema-templates", version = "0.2.2" }
23-
anathema-widgets = { path = "./anathema-widgets", version = "0.2.2" }
24-
anathema-geometry = { path = "./anathema-geometry", version = "0.2.2" }
25-
anathema-value-resolver = { path = "./anathema-value-resolver", version = "0.2.2" }
16+
anathema-backend = { workspace = true }
17+
anathema-default-widgets = { workspace = true }
18+
anathema-geometry = { workspace = true }
19+
anathema-runtime = { workspace = true }
20+
anathema-state = { workspace = true }
21+
anathema-state-derive = { workspace = true }
22+
anathema-store = { workspace = true }
23+
anathema-templates = { workspace = true }
24+
anathema-value-resolver = { workspace = true }
25+
anathema-widgets = { workspace = true }
26+
27+
[dev-dependencies]
28+
# anathema-debug = { path = "anathema-debug" }
29+
anathema-testutils = { path = "anathema-testutils" }
2630

2731
[features]
2832
default = []
29-
profile = ["anathema-runtime/profile", "anathema-widgets/profile", "anathema-backend/profile"]
30-
# filelog = ["anathema-debug/filelog"]
33+
# profile = ["anathema-runtime/profile", "anathema-widgets/profile", "anathema-backend/profile"]
34+
# filelog = ["anathema-debug/filelog", "anathema-widgets/filelog", "anathema-runtime/filelog"]
3135

3236
[lints]
3337
workspace = true
@@ -42,13 +46,21 @@ crossterm = "0.28.1"
4246
unicode-width = "0.1.11"
4347
flume = "0.11.0"
4448
notify = "6.1.1"
45-
anathema-debug = { path = "anathema-testutils" }
49+
anathema-default-widgets = { path = "./anathema-default-widgets", version = "0.2.2" }
50+
anathema-backend = { path = "./anathema-backend", version = "0.2.2" }
51+
anathema-runtime = { path = "./anathema-runtime", version = "0.2.2" }
52+
anathema-state = { path = "./anathema-state", version = "0.2.2" }
53+
anathema-state-derive = { path = "./anathema-state-derive", version = "0.2.2" }
54+
anathema-store = { path = "./anathema-store", version = "0.2.2" }
55+
anathema-templates = { path = "./anathema-templates", version = "0.2.2" }
56+
anathema-widgets = { path = "./anathema-widgets", version = "0.2.2" }
57+
anathema-geometry = { path = "./anathema-geometry", version = "0.2.2" }
58+
anathema-value-resolver = { path = "./anathema-value-resolver", version = "0.2.2" }
4659

4760
[workspace]
4861
members = [
4962
"anathema-backend",
5063
"anathema-runtime",
51-
"anathema-debug",
5264
"anathema-default-widgets",
5365
"anathema-geometry",
5466
"anathema-state",
@@ -71,9 +83,6 @@ type_complexity = "allow"
7183
too_many_arguments = "allow"
7284
wrong_self_convention = "allow"
7385

74-
[dev-dependencies]
75-
anathema-testutils = { path = "anathema-testutils" }
76-
7786
[package.metadata.release]
7887
shared-version = true
7988
dependent-version = "upgrade"

anathema-backend/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ homepage = "https://github.com/togglebyte/anathema"
99
repository = "https://github.com/togglebyte/anathema"
1010

1111
[dependencies]
12-
anathema-geometry = { path = "../anathema-geometry", version = "0.2.2" }
13-
anathema-state = { path = "../anathema-state", version = "0.2.2" }
14-
anathema-store = { path = "../anathema-store", version = "0.2.2" }
15-
anathema-strings = { path = "../anathema-strings", version = "0.2.2" }
16-
anathema-templates = { path = "../anathema-templates", version = "0.2.2" }
17-
anathema-value-resolver = { path = "../anathema-value-resolver", version = "0.2.2" }
18-
anathema-widgets = { path = "../anathema-widgets", version = "0.2.2" }
12+
anathema-geometry = { workspace = true }
13+
anathema-state = { workspace = true }
14+
anathema-store = { workspace = true }
15+
anathema-templates = { workspace = true }
16+
anathema-value-resolver = { workspace = true }
17+
anathema-widgets = { workspace = true }
1918
crossterm = { workspace = true }
2019
unicode-width = { workspace = true }
2120
bitflags = { workspace = true }

anathema-backend/src/testing/events.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ impl EventsMut<'_> {
1212
self
1313
}
1414

15+
pub fn next_frames(self, count: usize) -> Self {
16+
for _ in 0..count {
17+
self.event_queue.push_back(None);
18+
}
19+
self
20+
}
21+
1522
pub fn stop(self) -> Self {
1623
self.event_queue.push_back(Some(Event::Stop));
1724
self

anathema-debug/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub mod macros {
5454
#[macro_export]
5555
macro_rules! debug_tree {
5656
($tree:expr) => {
57-
let mut d = $crate::tree::debug::DebugTree::new();
57+
let mut d = anathema_widgets::tree::debug::DebugTree::new();
5858
$tree.apply_visitor(&mut d);
5959
$crate::debug_to_file!("{}", d.output);
6060
};

anathema-default-widgets/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ homepage = "https://github.com/togglebyte/anathema"
99
repository = "https://github.com/togglebyte/anathema"
1010

1111
[dependencies]
12-
anathema-backend = { path = "../anathema-backend", version = "0.2.2" }
13-
anathema-geometry = { path = "../anathema-geometry", version = "0.2.2" }
14-
anathema-state = { path = "../anathema-state", version = "0.2.2" }
15-
anathema-store = { path = "../anathema-store", version = "0.2.2" }
16-
anathema-templates = { path = "../anathema-templates", version = "0.2.2" }
17-
anathema-value-resolver = { path = "../anathema-value-resolver", version = "0.2.2" }
18-
anathema-widgets = { path = "../anathema-widgets", version = "0.2.2" }
12+
anathema-backend = { workspace = true }
13+
anathema-geometry = { workspace = true }
14+
anathema-state = { workspace = true }
15+
anathema-store = { workspace = true }
16+
anathema-templates = { workspace = true }
17+
anathema-value-resolver = { workspace = true }
18+
anathema-widgets = { workspace = true }
1919
bitflags = { workspace = true }
2020
unicode-width = { workspace = true }
2121

anathema-runtime/Cargo.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ homepage = "https://github.com/togglebyte/anathema"
99
repository = "https://github.com/togglebyte/anathema"
1010

1111
[dependencies]
12-
anathema-geometry = { path = "../anathema-geometry", version = "0.2.2" }
13-
anathema-debug = { path = "../anathema-debug", version = "0.2.2" }
14-
anathema-default-widgets = { path = "../anathema-default-widgets", version = "0.2.2" }
15-
anathema-backend = { path = "../anathema-backend", version = "0.2.2" }
16-
anathema-state = { path = "../anathema-state", version = "0.2.2" }
17-
anathema-store = { path = "../anathema-store", version = "0.2.2" }
18-
anathema-strings = { path = "../anathema-strings", version = "0.2.2" }
19-
anathema-templates = { path = "../anathema-templates", version = "0.2.2" }
20-
anathema-widgets = { path = "../anathema-widgets", version = "0.2.2" }
21-
anathema-value-resolver = { path = "../anathema-value-resolver", version = "0.2.2" }
12+
anathema-geometry = { workspace = true }
13+
anathema-default-widgets = { workspace = true }
14+
anathema-backend = { workspace = true }
15+
anathema-state = { workspace = true }
16+
anathema-store = { workspace = true }
17+
anathema-templates = { workspace = true }
18+
anathema-widgets = { workspace = true }
19+
anathema-value-resolver = { workspace = true }
2220
flume = { workspace = true }
2321
notify = { workspace = true }
2422
puffin = { version = "0.19.1", features = ["web"], optional = true }
@@ -27,6 +25,7 @@ puffin_http = { version = "0.16.1", optional = true }
2725
[features]
2826
default = []
2927
profile = ["puffin", "puffin_http"]
28+
filelog = []
3029

3130
[lints]
3231
workspace = true

anathema-runtime/src/runtime/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<G: GlobalEventHandler> Runtime<G> {
138138

139139
loop {
140140
frame.tick(backend)?;
141-
if frame.stop {
141+
if frame.layout_ctx.stop_runtime {
142142
return Err(Error::Stop);
143143
}
144144

@@ -191,7 +191,6 @@ impl<G: GlobalEventHandler> Runtime<G> {
191191

192192
dt: &mut self.dt,
193193
needs_layout: true,
194-
stop: false,
195194

196195
global_event_handler: &self.global_event_handler,
197196
tabindex: None,
@@ -231,7 +230,6 @@ pub struct Frame<'rt, 'bp, G> {
231230
message_receiver: &'rt flume::Receiver<ViewMessage>,
232231
dt: &'rt mut Instant,
233232
needs_layout: bool,
234-
stop: bool,
235233
global_event_handler: &'rt G,
236234
pub tabindex: Option<Index>,
237235
}
@@ -280,7 +278,7 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
280278

281279
let Some(event) = self.handle_global_event(event) else { return };
282280
if let Event::Stop = event {
283-
self.stop = true;
281+
self.layout_ctx.stop_runtime = true;
284282
return;
285283
}
286284

@@ -327,18 +325,21 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
327325
puffin::GlobalProfiler::lock().new_frame();
328326

329327
let now = Instant::now();
330-
self.cycle(backend)?;
331328
self.init_new_components();
332-
self.tick_components(self.dt.elapsed());
333329
let elapsed = self.handle_messages(now);
334330
self.poll_events(elapsed, now, backend);
335331
self.drain_deferred_commands();
336332
self.drain_assoc_events();
333+
334+
// TODO:
335+
// this secondary call is here to deal with changes causing changes
336+
// which happens when values are removed or inserted and indices needs updating
337337
self.apply_changes()?;
338-
// TODO: this secondary call is here to deal with changes causing changes
339-
// which happens when values are removed or inserted and indices needs updating
340338
self.apply_changes()?;
341339

340+
self.tick_components(self.dt.elapsed());
341+
self.cycle(backend)?;
342+
342343
*self.dt = Instant::now();
343344

344345
match self.layout_ctx.stop_runtime {
@@ -405,6 +406,11 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
405406
backend.resize(size, self.layout_ctx.glyph_map);
406407
}
407408

409+
if let Event::Stop = event {
410+
self.layout_ctx.stop_runtime = true;
411+
break;
412+
}
413+
408414
self.event(event);
409415

410416
// Make sure event handling isn't holding up the rest of the event loop.
@@ -491,8 +497,8 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
491497
self.with_component(widget_id, state_id, |comp, children, ctx| {
492498
comp.dyn_component.any_message(children, ctx, msg);
493499
});
500+
break;
494501
}
495-
break;
496502
}
497503
}
498504
}
@@ -564,16 +570,6 @@ impl<'rt, 'bp, G: GlobalEventHandler> Frame<'rt, 'bp, G> {
564570
let widget_id = value_id.key();
565571

566572
if let Some(widget) = tree.get_mut(widget_id) {
567-
let kind = &widget.kind;
568-
match kind {
569-
WidgetKind::Element(_element) => {}
570-
WidgetKind::For(_forloop) => {}
571-
WidgetKind::Iteration(_) => {}
572-
_ => (), // WidgetKind::ControlFlow(control_flow) => todo!(),
573-
// WidgetKind::ControlFlowContainer(_) => todo!(),
574-
// WidgetKind::Component(component) => todo!(),
575-
// WidgetKind::Slot => todo!(),
576-
}
577573
if let WidgetKind::Element(element) = &mut widget.kind {
578574
element.invalidate_cache();
579575
}

anathema-state/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ homepage = "https://github.com/togglebyte/anathema"
99
repository = "https://github.com/togglebyte/anathema"
1010

1111
[dependencies]
12-
anathema-debug = { path = "../anathema-debug", version = "0.2.2" }
13-
anathema-state-derive = { path = "../anathema-state-derive", version = "0.2.2" }
14-
anathema-store = { path = "../anathema-store", version = "0.2.2" }
12+
anathema-state-derive = { workspace = true }
13+
anathema-store = { workspace = true }
1514

1615
[lints]
1716
workspace = true

anathema-state/src/states.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ impl State for Box<dyn State> {
159159
}
160160
}
161161

162-
pub trait AnyMap {
162+
pub trait AnyMap: 'static {
163163
fn lookup(&self, key: &str) -> Option<PendingValue>;
164164

165165
fn is_empty(&self) -> bool;
166166
}
167167

168-
pub trait AnyList {
168+
pub trait AnyList: 'static {
169169
fn lookup(&self, index: usize) -> Option<PendingValue>;
170170

171171
fn len(&self) -> usize;
@@ -175,6 +175,13 @@ pub trait AnyList {
175175
}
176176
}
177177

178+
impl dyn AnyList {
179+
pub fn iter(&self) -> impl Iterator<Item = PendingValue> {
180+
let len = self.len();
181+
(0..len).filter_map(|i| self.lookup(i))
182+
}
183+
}
184+
178185
pub trait AnyMaybe {
179186
fn get(&self) -> Option<PendingValue>;
180187
}

anathema-state/src/value/mod.rs

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl PendingValue {
443443
/// Try to get access to the underlying value as a `dyn AnyState`.
444444
/// This will return `None` if the `Value<T>` behind this `ValueRef` has
445445
/// been dropped.
446-
pub fn as_state(&self) -> Option<SharedState<'_>> {
446+
pub fn as_state<'a>(&'a self) -> Option<SharedState<'a>> {
447447
let (key, value) = try_make_shared(self.0.owned())?;
448448
let shared = SharedState::new(key, value);
449449
Some(shared)
@@ -469,6 +469,75 @@ impl PendingValue {
469469
pub fn key(&self) -> ValueKey {
470470
self.0
471471
}
472+
473+
pub fn pending_eq(&self, rhs: PendingValue) -> bool {
474+
let lhs = self;
475+
// -----------------------------------------------------------------------------
476+
// - Composite -
477+
// If two keys are the same it's the same value.
478+
// This is mostly for composite values
479+
// -----------------------------------------------------------------------------
480+
if lhs.key() == rhs.key() {
481+
return true;
482+
}
483+
484+
let lhs_type = lhs.type_info();
485+
let rhs_type = rhs.type_info();
486+
487+
// -----------------------------------------------------------------------------
488+
// - Maybe -
489+
// -----------------------------------------------------------------------------
490+
if let Type::Maybe = lhs_type {
491+
let Some(lhs) = lhs.as_state() else { return false };
492+
let lhs = lhs.as_maybe().expect("type checked");
493+
if let Some(lhs) = lhs.get() {
494+
return lhs.pending_eq(rhs);
495+
}
496+
}
497+
498+
if let Type::Maybe = rhs_type {
499+
let Some(rhs) = rhs.as_state() else { return false };
500+
let rhs = rhs.as_maybe().expect("type checked");
501+
502+
if let Some(rhs) = rhs.get() {
503+
return lhs.pending_eq(rhs);
504+
}
505+
}
506+
507+
let Some(lhs) = lhs.as_state() else { return false };
508+
let Some(rhs) = rhs.as_state() else { return false };
509+
510+
match (lhs_type, rhs_type) {
511+
(Type::Int, Type::Int) => lhs.as_int() == rhs.as_int(),
512+
(Type::Float, Type::Float) => lhs.as_float() == rhs.as_float(),
513+
(Type::Char, Type::Char) => lhs.as_char() == rhs.as_char(),
514+
(Type::String, Type::String) => lhs.as_str() == rhs.as_str(),
515+
(Type::Bool, Type::Bool) => lhs.as_bool() == rhs.as_bool(),
516+
(Type::Hex, Type::Hex) => lhs.as_hex() == rhs.as_hex(),
517+
(Type::Map, Type::Map) => false,
518+
(Type::Unit, Type::Unit) => true,
519+
(Type::List, Type::List) => {
520+
let lhs = lhs.as_any_list().expect("type checked");
521+
let rhs = rhs.as_any_list().expect("type checked");
522+
523+
if lhs.len() != rhs.len() {
524+
return false;
525+
}
526+
527+
for (lhs, rhs) in lhs.iter().zip(rhs.iter()) {
528+
if !lhs.pending_eq(rhs) {
529+
return false;
530+
}
531+
}
532+
533+
true
534+
}
535+
(Type::Color, Type::Color) => lhs.as_color() == rhs.as_color(),
536+
(Type::Maybe, Type::Maybe) => true, // both are None
537+
538+
_ => false,
539+
}
540+
}
472541
}
473542

474543
#[derive(Debug, Copy, Clone)]

0 commit comments

Comments
 (0)