-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emoji picker example improvements #833
Changes from all commits
880edad
64245a4
53af04e
2ed5742
8377dda
e25de83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,9 +57,12 @@ fn picker(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> { | |
}; | ||
let view = flex(( | ||
// TODO: Expose that this button corresponds to the label below for accessibility? | ||
sized_box(button(emoji.display, move |data: &mut EmojiPagination| { | ||
data.last_selected = Some(idx); | ||
})) | ||
sized_box(button( | ||
label(emoji.display).text_size(200.0 / data.size as f32), | ||
move |data: &mut EmojiPagination| { | ||
data.last_selected = Some(idx); | ||
}, | ||
)) | ||
.expand_width(), | ||
sized_box( | ||
prose(emoji.name) | ||
|
@@ -84,26 +87,33 @@ fn picker(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> { | |
data.size.try_into().unwrap(), | ||
data.size.try_into().unwrap(), | ||
) | ||
.spacing(10.0) | ||
} | ||
|
||
fn paginate( | ||
current_start: usize, | ||
count_per_page: usize, | ||
max_count: usize, | ||
) -> impl WidgetView<usize> { | ||
let percentage = (current_start * 100) / max_count; | ||
let current_end = (current_start + count_per_page).min(max_count); | ||
let percentage_start = (current_start * 100) / max_count; | ||
let percentage_end = (current_end * 100) / max_count; | ||
|
||
flex(( | ||
// TODO: Expose that this is a previous page button to accessibility | ||
button("<-", move |data| { | ||
*data = current_start.saturating_sub(count_per_page); | ||
(current_start != 0).then(|| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we'd disable the button instead of hiding it, but that's not currently exposed to Xilem (it will likely end up looking similar to transform) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the same thought. Hopefully it won't be too much overhead to implement disabling widgets in the future. |
||
button(label("⬅️").text_size(24.0), move |data| { | ||
*data = current_start.saturating_sub(count_per_page); | ||
}) | ||
}), | ||
label(format!("{percentage}%")), | ||
button("->", move |data| { | ||
let new_idx = current_start + count_per_page; | ||
if new_idx < max_count { | ||
*data = new_idx; | ||
} | ||
label(format!("{percentage_start}% - {percentage_end}%")), | ||
(current_end < max_count).then(|| { | ||
button(label("➡️").text_size(24.0), move |data| { | ||
let new_idx = current_start + count_per_page; | ||
if new_idx < max_count { | ||
*data = new_idx; | ||
} | ||
}) | ||
}), | ||
)) | ||
.direction(Axis::Horizontal) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst we're here, could we increase the font size on the buttons (which is possible since #797)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It looked bad so I got the idea of using emoji. This isn't great for universal compatibility, but of all examples this is the most appropriate. This may even help with default accessibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I also meant the buttons associated with each option)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Pushed. It's definitely even better now.