Small improvements to the demo app
This commit is contained in:
parent
49b0b06739
commit
357f62e136
6 changed files with 41 additions and 34 deletions
|
@ -21,19 +21,20 @@ impl Default for FontBook {
|
|||
impl FontBook {
|
||||
fn characters_ui(&self, ui: &mut Ui, characters: &[(u32, char, &str)]) {
|
||||
for &(_, chr, name) in characters {
|
||||
if !self.filter.is_empty() && !name.contains(&self.filter) {
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
|
||||
let button = Button::new(chr).text_style(self.text_style).frame(false);
|
||||
let tooltip_ui = |ui: &mut Ui| {
|
||||
ui.add(Label::new(chr).text_style(self.text_style));
|
||||
ui.label(format!("{}\nU+{:X}\n\nClick to copy", name, chr as u32));
|
||||
};
|
||||
|
||||
let tooltip_ui = |ui: &mut Ui| {
|
||||
ui.add(Label::new(chr).text_style(self.text_style));
|
||||
ui.label(format!("{}\nU+{:X}\n\nClick to copy", name, chr as u32));
|
||||
};
|
||||
|
||||
if ui.add(button).on_hover_ui(tooltip_ui).clicked {
|
||||
ui.output().copied_text = chr.to_string();
|
||||
if ui.add(button).on_hover_ui(tooltip_ui).clicked {
|
||||
ui.output().copied_text = chr.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,9 +89,9 @@ fn toggle_compact(ui: &mut Ui, on: &mut bool) -> Response {
|
|||
}
|
||||
|
||||
pub fn demo(ui: &mut Ui, on: &mut bool) {
|
||||
ui.label("It's easy to create your own widgets!");
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Like this toggle switch:");
|
||||
ui.horizontal_wrapped_for_text(TextStyle::Button, |ui| {
|
||||
ui.label("It's easy to create your own widgets!");
|
||||
ui.label("This toggle switch is just one function of 20 lines of code:");
|
||||
toggle(ui, on).on_hover_text("Click to toggle");
|
||||
ui.add(__egui_github_link_file!());
|
||||
});
|
||||
|
|
|
@ -49,19 +49,21 @@ impl Widgets {
|
|||
ui.add(__egui_github_link_file_line!());
|
||||
|
||||
ui.horizontal_wrapped_for_text(TextStyle::Body, |ui| {
|
||||
ui.label("Long text will wrap, just as you would expect.");
|
||||
ui.add(Label::new("Text can have").text_color(srgba(110, 255, 110, 255)));
|
||||
ui.colored_label(srgba(128, 140, 255, 255), "color"); // Shortcut version
|
||||
ui.label("and tooltips.").on_hover_text(
|
||||
"This is a multiline tooltip that demonstrates that you can easily add tooltips to any element.\nThis is the second line.\nThis is the third.",
|
||||
);
|
||||
|
||||
ui.label("You can mix in other widgets into text, like this");
|
||||
let _ = ui.small_button("button");
|
||||
ui.label("You can mix in other widgets into text, like");
|
||||
let _ = ui.small_button("this button");
|
||||
ui.label(".");
|
||||
|
||||
ui.label("There is also (limited) non-ASCII support: Ευρηκα! τ = 2×π")
|
||||
.on_hover_text("The current font supports only a few non-latin characters and Egui does not currently support right-to-left text.");
|
||||
ui.label("The default font supports all latin and cyrillic characters (ИÅđ…), common math symbols (∫√∞²⅓…), and many emojis (💓🌟🖩…).")
|
||||
.on_hover_text("There is currently no support for right-to-left languages.");
|
||||
ui.label("See the 🔤 Font Book for more!");
|
||||
|
||||
ui.monospace("There is also a monospace font.");
|
||||
});
|
||||
|
||||
let tooltip_ui = |ui: &mut Ui| {
|
||||
|
@ -97,7 +99,7 @@ impl Widgets {
|
|||
{
|
||||
self.count += 1;
|
||||
}
|
||||
ui.label(format!("The button has been clicked {} times", self.count));
|
||||
ui.label(format!("The button has been clicked {} times.", self.count));
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
@ -119,15 +121,18 @@ impl Widgets {
|
|||
self.sliders.ui(ui);
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
{
|
||||
ui.label("An angle stored as radians, but edited in degrees:");
|
||||
ui.horizontal(|ui| {
|
||||
ui.style_mut().spacing.item_spacing.x = 0.0;
|
||||
ui.drag_angle(&mut self.angle);
|
||||
ui.label(format!(" = {} radians", self.angle));
|
||||
});
|
||||
}
|
||||
|
||||
ui.horizontal_for_text(TextStyle::Body, |ui| {
|
||||
ui.label("An angle:");
|
||||
ui.drag_angle(&mut self.angle);
|
||||
ui.label(format!("≈ {:.3}τ", self.angle / std::f32::consts::TAU))
|
||||
.on_hover_text("Each τ represents one turn (τ = 2π)");
|
||||
})
|
||||
.1
|
||||
.on_hover_text("The angle is stored in radians, but presented in degrees");
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
|
|
|
@ -44,6 +44,7 @@ pub enum FontFamily {
|
|||
VariableWidth,
|
||||
}
|
||||
|
||||
/// This is how you tell Egui which fonts and font sizes to use.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FontDefinitions {
|
||||
/// The dpi scale factor. Needed to get pixel perfect fonts.
|
||||
|
@ -59,8 +60,8 @@ pub struct FontDefinitions {
|
|||
/// Which fonts (names) to use for each `FontFamily`.
|
||||
///
|
||||
/// The list should be a list of keys into `font_data`.
|
||||
/// When looking for a character glyph,
|
||||
/// Egui will start will the first font and then move to the second, and so on.
|
||||
/// When looking for a character glyph Egui will start with
|
||||
/// the first font and then move to the second, and so on.
|
||||
/// So the first font is the primary, and then comes a list of fallbacks in order of priority.
|
||||
pub fonts_for_family: BTreeMap<FontFamily, Vec<String>>,
|
||||
|
||||
|
|
|
@ -913,10 +913,10 @@ impl Ui {
|
|||
self.horizontal_with_main_wrap(true, add_contents)
|
||||
}
|
||||
|
||||
/// Like `horizontal_wrapped`, but will set up spacing so that
|
||||
/// the line size and matches that for a normal label.
|
||||
/// Like `horizontal_wrapped`, but will set up the spacing and
|
||||
/// line size to match that of a normal label.
|
||||
///
|
||||
/// In particular, the space between widgets is the same with as the space character
|
||||
/// In particular, the space between widgets is the same width as the space character
|
||||
/// and the line spacing is the same as that for text.
|
||||
///
|
||||
/// You can still add any widgets to the layout (not only Labels).
|
||||
|
|
|
@ -146,7 +146,7 @@ impl<'a> Widget for DragValue<'a> {
|
|||
.sense(Sense::click_and_drag())
|
||||
.text_style(TextStyle::Monospace);
|
||||
let response = ui.add(button);
|
||||
let response = response.on_hover_text("Drag to edit, click to enter a value");
|
||||
let response = response.on_hover_text("Drag to edit or click to enter a value");
|
||||
if response.clicked {
|
||||
ui.memory().request_kb_focus(kb_edit_id);
|
||||
ui.memory().temp_edit_string = None; // Filled in next frame
|
||||
|
|
Loading…
Reference in a new issue