Skip to content

Commit

Permalink
Change tab row to use selected param
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Oct 26, 2023
1 parent a883d28 commit c1c3a45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/tab_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fn app(cx: Scope) -> Element {
Theme {
TabRow {
onselect: |idx| log::info!("{}", idx),
selected: 0,
tabs: cx
.bump()
.alloc([
Expand Down
12 changes: 5 additions & 7 deletions src/tab_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ use std::{collections::HashMap, time::Duration};
pub fn TabRow<'a>(
cx: Scope<'a>,
tabs: &'a [Element<'a>],
selected: usize,
onselect: EventHandler<'a, usize>,
) -> Element<'a> {
let sizes = use_signal(cx, HashMap::new);
let selected = use_state(cx, || 0);


let width = sizes
.read()
.get(&**selected)
.get(selected)
.map(|rect: &Rect| rect.width() as f32)
.unwrap_or_default();
let left: f32 = (0..**selected)
let left: f32 = (0..*selected)
.map(|idx| {
sizes
.read()
Expand Down Expand Up @@ -48,10 +49,7 @@ pub fn TabRow<'a>(
render!(
div { position: "relative",
ul { display: "flex", flex_direction: "row", justify_content: "space-evenly", list_style: "none", margin: 0, padding: 0,
tabs.iter().enumerate().map(|(idx, tab)| render!(TabRowItem { index: idx, sizes: sizes, onselect: move |idx| {
onselect.call(idx);
selected.set(idx);
}, tab }))
tabs.iter().enumerate().map(|(idx, tab)| render!(TabRowItem { index: idx, sizes: sizes, onselect: move |idx| onselect.call(idx), tab }))
}
div { onmounted: move |event| animated_ref.onmounted(event) }
}
Expand Down

0 comments on commit c1c3a45

Please sign in to comment.