Skip to content
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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions xilem/examples/emoji_picker.rs
Copy link
Member

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)

Copy link
Contributor Author

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.
image

Copy link
Member

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)

Copy link
Contributor Author

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.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(|| {
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
Loading