App: add element selection
This commit is contained in:
parent
93190e99da
commit
a60624884a
5 changed files with 41 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
use sycamore::{prelude::*, web::tags::div};
|
||||
use web_sys::KeyboardEvent;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
|
|
@ -21,6 +22,9 @@ pub fn Outline() -> View {
|
|||
Keyed(
|
||||
list=elements_sorted,
|
||||
view=|elt| {
|
||||
let class = create_memo(move ||
|
||||
if elt.selected.get() { "selected" } else { "" }
|
||||
);
|
||||
let label = elt.label.clone();
|
||||
let rep_components = elt.rep.iter().map(|u| {
|
||||
let u_coord = u.to_string().replace("-", "\u{2212}");
|
||||
|
|
@ -29,7 +33,19 @@ pub fn Outline() -> View {
|
|||
view! {
|
||||
/* [TO DO] switch to integer-valued parameters whenever
|
||||
that becomes possible again */
|
||||
li(tabindex="0") {
|
||||
li(
|
||||
class=class.get(),
|
||||
tabindex="0",
|
||||
on:click=move |_| {
|
||||
elt.selected.set_fn(|sel| !sel);
|
||||
},
|
||||
on:keydown=move |event: KeyboardEvent| {
|
||||
if event.key() == "Enter" {
|
||||
elt.selected.set_fn(|sel| !sel);
|
||||
event.prevent_default();
|
||||
}
|
||||
}
|
||||
) {
|
||||
div(class="elt-label") { (label) }
|
||||
div(class="elt-rep") { (rep_components) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue