Skip to content

Commit a4fb539

Browse files
committed
new border style and feature
1 parent d1cd163 commit a4fb539

File tree

8 files changed

+43
-17
lines changed

8 files changed

+43
-17
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* 0.2.9
2+
* New border style: "rounded"
3+
* Hex and Color can now be serialized / deserialized if the `serde` feature
4+
is enabled.
15
* 0.2.8
26
* An emitter can be created before the runtime
37
* Messages can be emitted to both widget ids and component ids

anathema-default-widgets/src/border.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ pub const DEFAULT_THICK_EDGES: [Glyph; 8] = [
131131
Glyph::from_char('║', 1),
132132
];
133133

134+
pub const DEFAULT_ROUNDED_EDGES: [Glyph; 8] = [
135+
Glyph::from_char('╭', 1),
136+
Glyph::from_char('─', 1),
137+
Glyph::from_char('╮', 1),
138+
Glyph::from_char('│', 1),
139+
Glyph::from_char('╯', 1),
140+
Glyph::from_char('─', 1),
141+
Glyph::from_char('╰', 1),
142+
Glyph::from_char('│', 1),
143+
];
144+
134145
/// The style of the border.
135146
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
136147
pub enum BorderStyle {
@@ -152,6 +163,7 @@ pub enum BorderStyle {
152163
/// 7hello3
153164
/// 6555554
154165
/// ```
166+
Rounded,
155167
Custom([Glyph; 8]),
156168
}
157169

@@ -160,6 +172,7 @@ impl BorderStyle {
160172
match self {
161173
BorderStyle::Thin => DEFAULT_SLIM_EDGES,
162174
BorderStyle::Thick => DEFAULT_THICK_EDGES,
175+
BorderStyle::Rounded => DEFAULT_ROUNDED_EDGES,
163176
BorderStyle::Custom(edges) => *edges,
164177
}
165178
}
@@ -429,6 +442,7 @@ impl Widget for Border {
429442
match s {
430443
Some("thin") | None => BorderStyle::default(),
431444
Some("thick") => BorderStyle::Thick,
445+
Some("rounded") => BorderStyle::Rounded,
432446
Some(s) => {
433447
let mut glyphs = Glyphs::new(s);
434448
while let Some(g) = glyphs.next(ctx.glyph_map) {

anathema-state/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ repository = "https://github.com/togglebyte/anathema"
1111
[dependencies]
1212
anathema-state-derive = { workspace = true }
1313
anathema-store = { workspace = true }
14+
serde = { version = "1.0", optional = true, features = ["derive"] }
15+
16+
[features]
17+
default = []
18+
serde = ["dep:serde"]
1419

1520
[lints]
1621
workspace = true

anathema-state/src/colors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub trait FromColor {
1111
///
1212
/// [ANSI color table](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
1313
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Default)]
14+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1415
pub enum Color {
1516
#[default]
1617
Reset,

anathema-state/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl<'a> From<&'a str> for Path<'a> {
4545
}
4646

4747
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
48+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4849
pub struct Hex {
4950
pub r: u8,
5051
pub g: u8,

anathema-templates/src/components.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,26 @@ impl ComponentTemplates {
219219

220220
pub(crate) fn load(
221221
&mut self,
222-
parent_id: ComponentBlueprintId,
222+
component_id: ComponentBlueprintId,
223223
variables: &mut Variables,
224224
slots: SmallMap<StringId, Vec<Blueprint>>,
225225
strings: &mut Strings,
226226
) -> Result<Vec<Blueprint>> {
227-
let ticket = self.components.checkout(parent_id);
227+
let ticket = self.components.checkout(component_id);
228228
let (_, component_src) = &*ticket;
229229

230-
if self.dependencies.contains(&parent_id) {
230+
if self.dependencies.contains(&component_id) {
231231
let path = component_src.path();
232232
self.components.restore(ticket);
233233
return Err(Error::new(path, ErrorKind::CircularDependency));
234234
}
235235

236-
self.dependencies.push(parent_id);
236+
self.dependencies.push(component_id);
237237

238238
// NOTE
239239
// The ticket has to be restored to the component store,
240240
// this is why the error is returned rather than using `?` on `self.compile`.
241-
let ret = self.compile(component_src, variables, slots, strings, parent_id);
241+
let ret = self.compile(component_src, variables, slots, strings, component_id);
242242
self.components.restore(ticket);
243243
self.dependencies.pop();
244244
ret

anathema-templates/src/statements/eval.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,19 @@ impl Scope {
222222

223223
// If the next statement is NOT a slot id then assume $children
224224
// and still try to take the scope
225-
if !scope.is_next_slot() {
226-
let slot_id = ctx.strings.children();
227-
let scope = Scope::new(scope);
228-
let body = scope.eval(ctx)?;
229-
slots.set(slot_id, body);
230-
} else {
231-
// for each slot take the scope and associate it with the slot id
232-
while let Some(slot_id) = scope.next_slot() {
233-
let scope = Scope::new(scope.take_scope());
225+
if !scope.is_empty() {
226+
if !scope.is_next_slot() {
227+
let slot_id = ctx.strings.children();
228+
let scope = Scope::new(scope);
234229
let body = scope.eval(ctx)?;
235230
slots.set(slot_id, body);
231+
} else {
232+
// for each slot take the scope and associate it with the slot id
233+
while let Some(slot_id) = scope.next_slot() {
234+
let scope = Scope::new(scope.take_scope());
235+
let body = scope.eval(ctx)?;
236+
slots.set(slot_id, body);
237+
}
236238
}
237239
}
238240

anathema-templates/src/statements/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ impl Context<'_> {
5252

5353
fn load_component(
5454
&mut self,
55-
parent_component_id: ComponentBlueprintId,
55+
component_id: ComponentBlueprintId,
5656
slots: SmallMap<StringId, Vec<Blueprint>>,
5757
) -> Result<Vec<Blueprint>> {
58-
self.components
59-
.load(parent_component_id, self.variables, slots, self.strings)
58+
self.components.load(component_id, self.variables, slots, self.strings)
6059
}
6160
}
6261

0 commit comments

Comments
 (0)