2020-12-12 18:53:04 +00:00
|
|
|
|
pub struct FontBook {
|
|
|
|
|
standard: bool,
|
|
|
|
|
emojis: bool,
|
|
|
|
|
filter: String,
|
2020-12-29 12:40:11 +00:00
|
|
|
|
text_style: egui::TextStyle,
|
2020-12-12 18:53:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for FontBook {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
standard: false,
|
|
|
|
|
emojis: true,
|
|
|
|
|
filter: Default::default(),
|
2020-12-29 12:40:11 +00:00
|
|
|
|
text_style: egui::TextStyle::Button,
|
2020-12-12 18:53:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FontBook {
|
2020-12-29 12:40:11 +00:00
|
|
|
|
fn characters_ui(&self, ui: &mut egui::Ui, characters: &[(u32, char, &str)]) {
|
|
|
|
|
use egui::{Button, Label};
|
2020-12-12 18:53:04 +00:00
|
|
|
|
for &(_, chr, name) in characters {
|
2020-12-13 19:37:44 +00:00
|
|
|
|
if self.filter.is_empty()
|
|
|
|
|
|| name.contains(&self.filter)
|
|
|
|
|
|| self.filter == chr.to_string()
|
|
|
|
|
{
|
|
|
|
|
let button = Button::new(chr).text_style(self.text_style).frame(false);
|
2020-12-12 18:53:04 +00:00
|
|
|
|
|
2020-12-29 12:40:11 +00:00
|
|
|
|
let tooltip_ui = |ui: &mut egui::Ui| {
|
2020-12-13 19:37:44 +00:00
|
|
|
|
ui.add(Label::new(chr).text_style(self.text_style));
|
|
|
|
|
ui.label(format!("{}\nU+{:X}\n\nClick to copy", name, chr as u32));
|
|
|
|
|
};
|
2020-12-12 18:53:04 +00:00
|
|
|
|
|
2021-01-25 17:50:19 +00:00
|
|
|
|
if ui.add(button).on_hover_ui(tooltip_ui).clicked() {
|
2020-12-13 19:37:44 +00:00
|
|
|
|
ui.output().copied_text = chr.to_string();
|
|
|
|
|
}
|
2020-12-12 18:53:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 16:11:05 +00:00
|
|
|
|
impl super::Demo for FontBook {
|
2021-02-20 08:18:23 +00:00
|
|
|
|
fn name(&self) -> &'static str {
|
2020-12-12 18:53:04 +00:00
|
|
|
|
"🔤 Font Book"
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 12:40:11 +00:00
|
|
|
|
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
|
|
|
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
2021-01-01 16:11:05 +00:00
|
|
|
|
use super::View;
|
2020-12-12 18:53:04 +00:00
|
|
|
|
self.ui(ui);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 16:11:05 +00:00
|
|
|
|
impl super::View for FontBook {
|
2020-12-29 12:40:11 +00:00
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
2021-01-01 16:11:05 +00:00
|
|
|
|
use super::font_contents_emoji::FULL_EMOJI_LIST;
|
|
|
|
|
use super::font_contents_ubuntu::UBUNTU_FONT_CHARACTERS;
|
2020-12-12 18:53:04 +00:00
|
|
|
|
|
|
|
|
|
ui.label(format!(
|
2021-05-11 12:56:27 +00:00
|
|
|
|
"The default egui fonts supports {} standard characters and {} emojis.",
|
2020-12-12 18:53:04 +00:00
|
|
|
|
UBUNTU_FONT_CHARACTERS.len(),
|
|
|
|
|
FULL_EMOJI_LIST.len(),
|
|
|
|
|
));
|
|
|
|
|
|
2021-05-11 12:56:27 +00:00
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
|
|
|
|
ui.spacing_mut().item_spacing.x = 0.0;
|
|
|
|
|
ui.label("You can add more characters by installing additional fonts with ");
|
|
|
|
|
ui.add(
|
|
|
|
|
egui::Hyperlink::from_label_and_url(
|
|
|
|
|
"Context::set_fonts",
|
|
|
|
|
"https://docs.rs/egui/latest/egui/struct.Context.html#method.set_fonts",
|
|
|
|
|
)
|
|
|
|
|
.text_style(egui::TextStyle::Monospace),
|
|
|
|
|
);
|
|
|
|
|
ui.label(".");
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-12 18:53:04 +00:00
|
|
|
|
ui.separator();
|
|
|
|
|
|
2021-03-27 09:35:40 +00:00
|
|
|
|
egui::ComboBox::from_label("Text style")
|
|
|
|
|
.selected_text(format!("{:?}", self.text_style))
|
|
|
|
|
.show_ui(ui, |ui| {
|
|
|
|
|
for style in egui::TextStyle::all() {
|
|
|
|
|
ui.selectable_value(&mut self.text_style, style, format!("{:?}", style));
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-12-12 18:53:04 +00:00
|
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.label("Show:");
|
|
|
|
|
ui.checkbox(&mut self.standard, "Standard");
|
|
|
|
|
ui.checkbox(&mut self.emojis, "Emojis");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.label("Filter:");
|
|
|
|
|
ui.text_edit_singleline(&mut self.filter);
|
|
|
|
|
self.filter = self.filter.to_lowercase();
|
2021-01-25 17:50:19 +00:00
|
|
|
|
if ui.button("x").clicked() {
|
2020-12-12 18:53:04 +00:00
|
|
|
|
self.filter.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
2020-12-29 12:40:11 +00:00
|
|
|
|
egui::ScrollArea::auto_sized().show(ui, |ui| {
|
2020-12-12 18:53:04 +00:00
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
2021-02-01 15:55:40 +00:00
|
|
|
|
ui.spacing_mut().item_spacing = egui::Vec2::splat(2.0);
|
2020-12-12 18:53:04 +00:00
|
|
|
|
|
|
|
|
|
if self.standard {
|
|
|
|
|
self.characters_ui(ui, UBUNTU_FONT_CHARACTERS);
|
|
|
|
|
}
|
|
|
|
|
if self.emojis {
|
|
|
|
|
self.characters_ui(ui, FULL_EMOJI_LIST);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|