Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Update Floem version
Browse files Browse the repository at this point in the history
- Rewrite radio group to use `h_stack_from_iter`
  • Loading branch information
pieterdd committed Jan 12, 2024
1 parent 5737d27 commit 86c25b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]

[dependencies]
embed-doc-image = "0.1.4"
floem = { git = "https://github.com/lapce/floem", rev = "e795021bfb28cd15a6d499349e547c435ceb8520" }
floem = { git = "https://github.com/lapce/floem", rev = "9fc98fd6789beb1accc7af25291321ae3d0d9542" }
im = "15.1.0"
num = "0.4.1"
strum = { version = "0.25.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Its [README](https://github.com/lapce/floem) and [documentation](http://lapce.de
Since Floem does not have a published release, you can install it as a Git dependency:

```toml
floem = { git = "https://github.com/lapce/floem", rev = "e795021bfb28cd15a6d499349e547c435ceb8520" }
floem = { git = "https://github.com/lapce/floem", rev = "9fc98fd6789beb1accc7af25291321ae3d0d9542" }
```

Crates.io does not allow Git dependencies, so Floem UI Kit is not available on crates.io yet. When Floem publishes to crates.io, Floem UI Kit will publish as well. In the meantime, you can install Floem UI Kit as a Git dependency.
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
floem-ui-kit = { path = "../.." }
floem = { git = "https://github.com/lapce/floem", rev = "e795021bfb28cd15a6d499349e547c435ceb8520" }
floem = { git = "https://github.com/lapce/floem", rev = "9fc98fd6789beb1accc7af25291321ae3d0d9542" }
2 changes: 1 addition & 1 deletion examples/showcase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
floem-ui-kit = { path = "../.." }
floem = { git = "https://github.com/lapce/floem", rev = "e795021bfb28cd15a6d499349e547c435ceb8520" }
floem = { git = "https://github.com/lapce/floem", rev = "9fc98fd6789beb1accc7af25291321ae3d0d9542" }
strum = { version = "0.25.0", features = ["derive"] }
47 changes: 16 additions & 31 deletions src/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use floem::{
style::AlignItems,
style_class,
view::View,
views::{container, h_stack, label, svg, virtual_list, Decorators, VirtualListDirection},
views::{container, h_stack, h_stack_from_iter, label, svg, v_stack_from_iter, Decorators},
};
use strum::IntoEnumIterator;

Expand Down Expand Up @@ -172,37 +172,22 @@ impl Theme {
T: IntoEnumIterator + Copy + Clone + PartialEq + Eq + Display + std::hash::Hash + 'static,
{
let variants: im::Vector<T> = T::iter().collect();
let last_variant = *(variants
.last()
.expect("Cannot pass empty enum to radio group"));
let (variants_signal, _set_variant) = create_signal(variants);

container(
virtual_list(
match variant {
RadioGroupVariant::Horizontal => VirtualListDirection::Horizontal,
RadioGroupVariant::Vertical => VirtualListDirection::Vertical,
},
floem::views::VirtualListItemSize::Fixed(Box::new(|| 20.0)),
move || variants_signal.get(),
move |item| *item,
move |item| {
container(self.radio_button(item, read_signal, write_signal)).style(move |s| {
s.apply_if(
item != last_variant && variant == RadioGroupVariant::Vertical,
|s| s.margin_bottom(gap_between_items),
)
.apply_if(
item != last_variant && variant == RadioGroupVariant::Horizontal,
|s| s.margin_right(gap_between_items),
)
})
},
)
.style(move |s| {
s.apply_if(variant == RadioGroupVariant::Vertical, |s| s.flex_col())
.apply_if(variant == RadioGroupVariant::Horizontal, |s| s.flex_row())
}),
)
// These are not reactive. This is a consequence of how items are passed to `h_stack_from_iter`. Since
// the enum values are known at compile time, this is not an issue.
let group_items = variants_signal
.get()
.into_iter()
.map(|item| container(self.radio_button(item, read_signal, write_signal)));

container(match variant {
RadioGroupVariant::Horizontal => {
h_stack_from_iter(group_items).style(move |s| s.gap(gap_between_items, 0.))
}
RadioGroupVariant::Vertical => {
v_stack_from_iter(group_items).style(move |s| s.gap(0., gap_between_items))
}
})
}
}

0 comments on commit 86c25b3

Please sign in to comment.