Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion anathema-default-widgets/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,53 @@ impl Widget for Expand {

#[cfg(test)]
mod test {
use crate::testing::TestRunner;

#[test]
fn expand() {}
fn hstack_expand_nospace() {
let tpl = "
border
container [width:12]
hstack
expand
text 'this is text'
";

let expected = "
╔══════════════╗
║┌────────────┐║
║│this is text│║
║│ │║
║└────────────┘║
╚══════════════╝
";

let mut runner = TestRunner::new(tpl, (14, 4));
let mut runner = runner.instance();
runner.render_assert(expected);
}

#[test]
fn vstack_expand_nospace() {
let tpl = "
border
container [height:1]
vstack
expand
text 'this is text'
";

let expected = "
╔═════════════════╗
║┌───────────────┐║
║│this is text │║
║└───────────────┘║
║ ║
╚═════════════════╝
";

let mut runner = TestRunner::new(tpl, (17, 4));
let mut runner = runner.instance();
runner.render_assert(expected);
}
}
10 changes: 1 addition & 9 deletions anathema-default-widgets/src/layout/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ const DEFAULT_FACTOR: u16 = 1;
/// Panics when called with more weights than the total number of available size.
/// Allocates a minimum of one to each weight.
fn distribute_size(weights: &[u16], mut total: u16) -> Vec<u16> {
assert!(
total >= weights.len() as u16,
"{total} is not larger than {}",
weights.len()
);

let mut indexed = weights
.iter()
.copied()
.enumerate()
.map(|(i, w)| (i, w, 1u16))
.map(|(i, w)| (i, w, 0u16))
.collect::<Vec<_>>();

total -= weights.len() as u16;

fn pop(n: &mut u16) -> bool {
if let Some(nn) = n.checked_sub(1) {
*n = nn;
Expand Down
17 changes: 7 additions & 10 deletions anathema-default-widgets/src/layout/many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,13 @@ impl Many {
}
})?;

// Apply spacer and expand if the layout is constrained and we have remaining space
if !self.unconstrained && !self.used_size.no_space_left() {
let constraints = self.used_size.to_constraints();
let expanded_size = expand::layout_all_expansions(&mut children, constraints, self.axis, ctx)?;
self.used_size.apply(expanded_size);

let constraints = self.used_size.to_constraints();
let spacer_size = spacers::layout_all_spacers(&mut children, constraints, self.axis, ctx)?;
self.used_size.apply(spacer_size);
}
let constraints = self.used_size.to_constraints();
let expanded_size = expand::layout_all_expansions(&mut children, constraints, self.axis, ctx)?;
self.used_size.apply(expanded_size);

let constraints = self.used_size.to_constraints();
let spacer_size = spacers::layout_all_spacers(&mut children, constraints, self.axis, ctx)?;
self.used_size.apply(spacer_size);

size.width = self.used_size.inner.width.max(max_constraints.min_width);
size.height = (self.used_size.inner.height).max(max_constraints.min_height);
Expand Down
53 changes: 53 additions & 0 deletions anathema-default-widgets/src/spacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,56 @@ impl Widget for Spacer {
// The spacer widget has no children
}
}

#[cfg(test)]
mod test {
use crate::testing::TestRunner;

#[test]
fn hstack_spacer_nospace() {
let tpl = "
border
container [width:12]
hstack
spacer
text 'this is text'
";

let expected = "
╔══════════════╗
║┌────────────┐║
║│this is text│║
║└────────────┘║
║ ║
╚══════════════╝
";

let mut runner = TestRunner::new(tpl, (14, 4));
let mut runner = runner.instance();
runner.render_assert(expected);
}

#[test]
fn vstack_spacer_nospace() {
let tpl = "
border
container [height:1]
vstack
spacer
text 'this is text'
";

let expected = "
╔═════════════════╗
║┌────────────┐ ║
║│this is text│ ║
║└────────────┘ ║
║ ║
╚═════════════════╝
";

let mut runner = TestRunner::new(tpl, (17, 4));
let mut runner = runner.instance();
runner.render_assert(expected);
}
}
6 changes: 3 additions & 3 deletions anathema-runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, Instant};

use anathema_backend::{Backend, WidgetCycle};
use anathema_geometry::Size;
use anathema_state::{clear_all_changes, clear_all_subs, drain_changes, Changes, StateId, States};
use anathema_state::{Changes, StateId, States, clear_all_changes, clear_all_subs, drain_changes};
use anathema_store::tree::root_node;
use anathema_templates::blueprints::Blueprint;
use anathema_templates::{Document, Globals};
Expand All @@ -17,8 +17,8 @@ use anathema_widgets::layout::{LayoutCtx, Viewport};
use anathema_widgets::query::Children;
use anathema_widgets::tabindex::{Index, TabIndex};
use anathema_widgets::{
eval_blueprint, update_widget, Component, Components, Factory, FloatingWidgets, GlyphMap, WidgetContainer,
WidgetId, WidgetKind, WidgetTree,
Component, Components, Factory, FloatingWidgets, GlyphMap, WidgetContainer, WidgetId, WidgetKind, WidgetTree,
eval_blueprint, update_widget,
};
use flume::Receiver;
use notify::RecommendedWatcher;
Expand Down
8 changes: 4 additions & 4 deletions anathema-state/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub use self::list::List;
pub use self::map::Map;
pub use self::maybe::{Maybe, Nullable};
use crate::states::State;
use crate::store::subscriber::{subscribe, unsubscribe, SubKey};
use crate::store::subscriber::{SubKey, subscribe, unsubscribe};
use crate::store::values::{
drop_value, get_unique, make_shared, new_value, return_owned, return_shared, try_make_shared, OwnedValue,
OwnedValue, drop_value, get_unique, make_shared, new_value, return_owned, return_shared, try_make_shared,
};
use crate::store::watchers::{monitor, queue_monitor, Watcher};
use crate::store::{changed, ValueKey};
use crate::store::watchers::{Watcher, monitor, queue_monitor};
use crate::store::{ValueKey, changed};
use crate::{Change, Subscriber};

mod list;
Expand Down
7 changes: 1 addition & 6 deletions anathema-store/src/tree/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ impl<'tree, T> TreeView<'tree, T> {
}

pub fn view_mut(&mut self) -> TreeView<'_, T> {
TreeView::new(
self.offset,
&mut self.layout,
&mut self.values,
&mut self.removed_values,
)
TreeView::new(self.offset, self.layout, self.values, self.removed_values)
}

pub fn get_mut(&mut self, value_id: ValueId) -> Option<&mut T> {
Expand Down
2 changes: 1 addition & 1 deletion anathema-templates/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anathema_store::smallmap::SmallMap;
use anathema_store::stack::Stack;
use anathema_store::storage::Storage;

use crate::Lexer;
use crate::blueprints::Blueprint;
use crate::error::{Error, Result};
use crate::statements::eval::Scope;
Expand All @@ -14,7 +15,6 @@ use crate::statements::{Context, Statements};
use crate::strings::{StringId, Strings};
use crate::token::Tokens;
use crate::variables::Variables;
use crate::Lexer;

pub trait ToSourceKind {
fn to_path(self) -> SourceKind;
Expand Down
2 changes: 1 addition & 1 deletion anathema-templates/src/statements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use anathema_store::smallmap::SmallMap;

use crate::ComponentBlueprintId;
use crate::blueprints::Blueprint;
use crate::components::{AssocEventMapping, ComponentTemplates};
use crate::error::Result;
use crate::expressions::Expression;
use crate::strings::{StringId, Strings};
use crate::variables::Variables;
use crate::ComponentBlueprintId;

mod const_eval;
pub(crate) mod eval;
Expand Down
Loading