Rename tooltip_text to on_hover_text
This commit is contained in:
parent
5cba44eaa8
commit
7a71ac1a95
15 changed files with 55 additions and 39 deletions
2
TODO.md
2
TODO.md
|
@ -5,7 +5,7 @@ TODO-list for the Egui project. If you looking for something to do, look here.
|
|||
* Widgets
|
||||
* [ ] Tooltips:
|
||||
* [ ] Tooltip widget: Something that looks like this: (?) :that shows text on hover.
|
||||
* [ ] ui.info_button().tooltip_text("More info here");
|
||||
* [ ] ui.info_button().on_hover_text("More info here");
|
||||
* [ ] Allow adding multiple tooltips to the same widget, showing them all one after the other.
|
||||
* [ ] Text input
|
||||
* [x] Input
|
||||
|
|
|
@ -553,7 +553,7 @@ impl Context {
|
|||
|
||||
if ui
|
||||
.add(Button::new("Reset all"))
|
||||
.tooltip_text("Reset all Egui state")
|
||||
.on_hover_text("Reset all Egui state")
|
||||
.clicked
|
||||
{
|
||||
*self.memory() = Default::default();
|
||||
|
@ -629,9 +629,9 @@ impl paint::PaintOptions {
|
|||
impl PaintStats {
|
||||
pub fn ui(&self, ui: &mut Ui) {
|
||||
ui.add(label!("Jobs: {}", self.num_jobs))
|
||||
.tooltip_text("Number of separate clip rectangles");
|
||||
.on_hover_text("Number of separate clip rectangles");
|
||||
ui.add(label!("Primitives: {}", self.num_primitives))
|
||||
.tooltip_text("Boxes, circles, text areas etc");
|
||||
.on_hover_text("Boxes, circles, text areas etc");
|
||||
ui.add(label!("Vertices: {}", self.num_vertices));
|
||||
ui.add(label!("Triangles: {}", self.num_triangles));
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ impl FrameHistory {
|
|||
"Mean CPU usage per frame: {:.2} ms / frame",
|
||||
1e3 * self.frame_times.average().unwrap_or_default()
|
||||
))
|
||||
.tooltip_text(
|
||||
.on_hover_text(
|
||||
"Includes Egui layout and tesselation time.\n\
|
||||
Does not include GPU usage, nor overhead for sending data to GPU.",
|
||||
);
|
||||
|
@ -366,9 +366,9 @@ impl DemoApp {
|
|||
let run_mode = &mut self.run_mode;
|
||||
ui.label("Run mode:");
|
||||
ui.radio_value("Continuous", run_mode, RunMode::Continuous)
|
||||
.tooltip_text("Repaint everything each frame");
|
||||
.on_hover_text("Repaint everything each frame");
|
||||
ui.radio_value("Reactive", run_mode, RunMode::Reactive)
|
||||
.tooltip_text("Repaint when there are animations or input (e.g. mouse movement)");
|
||||
.on_hover_text("Repaint when there are animations or input (e.g. mouse movement)");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ fn show_menu_bar(ui: &mut Ui, windows: &mut OpenWindows, env: &DemoEnvironment)
|
|||
}
|
||||
if ui
|
||||
.add(Button::new("Clear entire Egui memory"))
|
||||
.tooltip_text("Forget scroll, collapsibles etc")
|
||||
.on_hover_text("Forget scroll, collapsibles etc")
|
||||
.clicked
|
||||
{
|
||||
*ui.ctx().memory() = Default::default();
|
||||
|
|
|
@ -78,7 +78,7 @@ impl ColorTest {
|
|||
let texel_offset = 0.5 / (g.0.len() as f32);
|
||||
let uv = Rect::from_min_max(pos2(texel_offset, 0.0), pos2(1.0 - texel_offset, 1.0));
|
||||
ui.add(Image::new(tex, GRADIENT_SIZE).tint(vertex_color).uv(uv))
|
||||
.tooltip_text(format!("A texture that is {} texels wide", g.0.len()));
|
||||
.on_hover_text(format!("A texture that is {} texels wide", g.0.len()));
|
||||
ui.label("GPU result");
|
||||
});
|
||||
});
|
||||
|
@ -233,7 +233,7 @@ impl ColorTest {
|
|||
let texel_offset = 0.5 / (gradient.0.len() as f32);
|
||||
let uv = Rect::from_min_max(pos2(texel_offset, 0.0), pos2(1.0 - texel_offset, 1.0));
|
||||
ui.add(Image::new(tex, GRADIENT_SIZE).bg_fill(bg_fill).uv(uv))
|
||||
.tooltip_text(format!(
|
||||
.on_hover_text(format!(
|
||||
"A texture that is {} texels wide",
|
||||
gradient.0.len()
|
||||
));
|
||||
|
@ -246,7 +246,7 @@ impl ColorTest {
|
|||
return;
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
vertex_gradient(ui, bg_fill, gradient).tooltip_text(format!(
|
||||
vertex_gradient(ui, bg_fill, gradient).on_hover_text(format!(
|
||||
"A triangle mesh that is {} vertices wide",
|
||||
gradient.0.len()
|
||||
));
|
||||
|
|
|
@ -415,7 +415,7 @@ impl LayoutDemo {
|
|||
}
|
||||
if ui
|
||||
.add(RadioButton::new(self.align == None, "Justified"))
|
||||
.tooltip_text("Try to fill full width/height (e.g. buttons)")
|
||||
.on_hover_text("Try to fill full width/height (e.g. buttons)")
|
||||
.clicked
|
||||
{
|
||||
self.align = None;
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn demo(ui: &mut Ui, on: &mut bool) {
|
|||
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Like this toggle switch:");
|
||||
toggle(ui, on).tooltip_text("Click to toggle");
|
||||
toggle(ui, on).on_hover_text("Click to toggle");
|
||||
ui.add(Hyperlink::new(url).text("(source code)"));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,13 +53,22 @@ impl Widgets {
|
|||
ui.style_mut().spacing.item_spacing.x = 0.0;
|
||||
ui.add(label!("Text can have ").text_color(srgba(110, 255, 110, 255)));
|
||||
ui.add(label!("color ").text_color(srgba(128, 140, 255, 255)));
|
||||
ui.add(label!("and tooltips")).tooltip_text(
|
||||
ui.add(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.add(label!("Tooltips can be more than just simple text."))
|
||||
.on_hover_ui(|ui| {
|
||||
ui.heading("The name of the tooltip");
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("This tooltip was created with");
|
||||
ui.monospace(".on_hover_ui(...)");
|
||||
});
|
||||
let _ = ui.button("A button you can never press");
|
||||
});
|
||||
|
||||
ui.add(label!("Some non-latin characters: Ευρηκα τ = 2×π"))
|
||||
.tooltip_text("The current font supports only a few non-latin characters and Egui does not currently support right-to-left text.");
|
||||
ui.add(label!("Ευρηκα! τ = 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.horizontal(|ui| {
|
||||
ui.radio_value("First", &mut self.radio, Enum::First);
|
||||
|
@ -78,7 +87,7 @@ impl Widgets {
|
|||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add(Button::new("Click me").enabled(self.button_enabled))
|
||||
.tooltip_text("This will just increase a counter.")
|
||||
.on_hover_text("This will just increase a counter.")
|
||||
.clicked
|
||||
{
|
||||
self.count += 1;
|
||||
|
@ -127,7 +136,7 @@ impl Widgets {
|
|||
.multiline(false)
|
||||
.id_source("single line"),
|
||||
);
|
||||
}); // TODO: .tooltip_text("Enter text to edit me")
|
||||
}); // TODO: .on_hover_text("Enter text to edit me")
|
||||
|
||||
ui.add(label!("Multiline text input:"));
|
||||
ui.add(TextEdit::new(&mut self.multiline_text_input).id_source("multiline"));
|
||||
|
|
|
@ -349,12 +349,12 @@ impl RawInput {
|
|||
ui.label(format!("scroll_delta: {:?} points", scroll_delta));
|
||||
ui.label(format!("screen_size: {:?} points", screen_size));
|
||||
ui.label(format!("pixels_per_point: {:?}", pixels_per_point))
|
||||
.tooltip_text(
|
||||
.on_hover_text(
|
||||
"Also called HDPI factor.\nNumber of physical pixels per each logical pixel.",
|
||||
);
|
||||
ui.label(format!("time: {:.3} s", time));
|
||||
ui.label(format!("events: {:?}", events))
|
||||
.tooltip_text("key presses etc");
|
||||
.on_hover_text("key presses etc");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ impl InputState {
|
|||
));
|
||||
ui.label(format!("expected dt: {:.1} ms", 1e3 * predicted_dt));
|
||||
ui.label(format!("events: {:?}", events))
|
||||
.tooltip_text("key presses etc");
|
||||
.on_hover_text("key presses etc");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ impl Spacing {
|
|||
ui_slider_vec2(ui, window_padding, 0.0..=10.0, "window_padding");
|
||||
ui_slider_vec2(ui, button_padding, 0.0..=10.0, "button_padding");
|
||||
ui_slider_vec2(ui, interact_size, 0.0..=60.0, "interact_size")
|
||||
.tooltip_text("Minimum size of an interactive widget");
|
||||
.on_hover_text("Minimum size of an interactive widget");
|
||||
ui.add(Slider::f32(indent, 0.0..=100.0).text("indent"));
|
||||
ui.add(Slider::f32(slider_width, 0.0..=1000.0).text("slider_width"));
|
||||
ui.add(Slider::f32(icon_width, 0.0..=60.0).text("icon_width"));
|
||||
|
@ -441,7 +441,7 @@ impl Stroke {
|
|||
let Self { width, color } = self;
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(DragValue::f32(width).speed(0.1).range(0.0..=5.0))
|
||||
.tooltip_text("Width");
|
||||
.on_hover_text("Width");
|
||||
ui.color_edit_button_srgba(color);
|
||||
ui.label(text);
|
||||
|
||||
|
|
|
@ -95,19 +95,25 @@ impl std::fmt::Debug for Response {
|
|||
}
|
||||
|
||||
impl Response {
|
||||
pub fn tooltip(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||
/// Show this UI if the item was hovered (i.e. a tooltip)
|
||||
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||
if self.hovered {
|
||||
crate::containers::show_tooltip(&self.ctx, add_contents);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Show this text if the item was hovered
|
||||
pub fn tooltip_text(self, text: impl Into<String>) -> Self {
|
||||
self.tooltip(|ui| {
|
||||
/// Show this text if the item was hovered (i.e. a tooltip)
|
||||
pub fn on_hover_text(self, text: impl Into<String>) -> Self {
|
||||
self.on_hover_ui(|ui| {
|
||||
ui.add(crate::widgets::Label::new(text));
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated = "Deprecated 2020-10-01: use `on_hover_text` instead."]
|
||||
pub fn tooltip_text(self, text: impl Into<String>) -> Self {
|
||||
self.on_hover_text(text)
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
|
|
|
@ -489,6 +489,7 @@ impl Ui {
|
|||
}
|
||||
|
||||
/// Shortcut for `add(Button::new(text))`
|
||||
#[must_use = "You should check if the user clicked this with `if ui.button(...).clicked { ... } "]
|
||||
pub fn button(&mut self, text: impl Into<String>) -> Response {
|
||||
self.add(Button::new(text))
|
||||
}
|
||||
|
|
|
@ -194,21 +194,21 @@ fn color_picker_hsvag_2d(ui: &mut Ui, hsva: &mut HsvaGamma) {
|
|||
ui.style().spacing.interact_size.y * 2.0,
|
||||
);
|
||||
|
||||
show_color(ui, *hsva, current_color_size).tooltip_text("Current color");
|
||||
show_color(ui, *hsva, current_color_size).on_hover_text("Current color");
|
||||
|
||||
show_color(ui, HsvaGamma { a: 1.0, ..*hsva }, current_color_size)
|
||||
.tooltip_text("Current color (opaque)");
|
||||
.on_hover_text("Current color (opaque)");
|
||||
|
||||
let opaque = HsvaGamma { a: 1.0, ..*hsva };
|
||||
let HsvaGamma { h, s, v, a } = hsva;
|
||||
color_slider_2d(ui, h, s, |h, s| HsvaGamma::new(h, s, 1.0, 1.0).into())
|
||||
.tooltip_text("Hue - Saturation");
|
||||
.on_hover_text("Hue - Saturation");
|
||||
color_slider_2d(ui, v, s, |v, s| HsvaGamma { v, s, ..opaque }.into())
|
||||
.tooltip_text("Value - Saturation");
|
||||
color_slider_1d(ui, h, |h| HsvaGamma { h, ..opaque }.into()).tooltip_text("Hue");
|
||||
color_slider_1d(ui, s, |s| HsvaGamma { s, ..opaque }.into()).tooltip_text("Saturation");
|
||||
color_slider_1d(ui, v, |v| HsvaGamma { v, ..opaque }.into()).tooltip_text("Value");
|
||||
color_slider_1d(ui, a, |a| HsvaGamma { a, ..opaque }.into()).tooltip_text("Alpha");
|
||||
.on_hover_text("Value - Saturation");
|
||||
color_slider_1d(ui, h, |h| HsvaGamma { h, ..opaque }.into()).on_hover_text("Hue");
|
||||
color_slider_1d(ui, s, |s| HsvaGamma { s, ..opaque }.into()).on_hover_text("Saturation");
|
||||
color_slider_1d(ui, v, |v| HsvaGamma { v, ..opaque }.into()).on_hover_text("Value");
|
||||
color_slider_1d(ui, a, |a| HsvaGamma { a, ..opaque }.into()).on_hover_text("Alpha");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ fn color_picker_hsva_2d(ui: &mut Ui, hsva: &mut Hsva) {
|
|||
|
||||
pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva) -> Response {
|
||||
let pupup_id = ui.make_position_id().with("popup");
|
||||
let button_response = color_button(ui, (*hsva).into()).tooltip_text("Click to edit color");
|
||||
let button_response = color_button(ui, (*hsva).into()).on_hover_text("Click to edit color");
|
||||
|
||||
if button_response.clicked {
|
||||
ui.memory().toggle_popup(pupup_id);
|
||||
|
|
|
@ -138,7 +138,7 @@ impl<'a> Widget for DragValue<'a> {
|
|||
.sense(Sense::click_and_drag())
|
||||
.text_style(TextStyle::Monospace);
|
||||
let response = ui.add(button);
|
||||
// response.tooltip_text("Drag to edit, click to enter a value"); // TODO: may clash with users own tooltips
|
||||
// response.on_hover_text("Drag to edit, click to enter a value"); // TODO: may clash with users own tooltips
|
||||
if response.clicked {
|
||||
ui.memory().request_kb_focus(kb_edit_id);
|
||||
ui.memory().temp_edit_string = None; // Filled in next frame
|
||||
|
|
|
@ -217,7 +217,7 @@ impl Widget for Hyperlink {
|
|||
ui.painter()
|
||||
.galley(response.rect.min, galley, text_style, color);
|
||||
|
||||
response.tooltip_text(url)
|
||||
response.on_hover_text(url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ impl<'a> Slider<'a> {
|
|||
.text_style(TextStyle::Monospace)
|
||||
.text_color_opt(self.text_color),
|
||||
);
|
||||
let response = response.tooltip_text("Click to enter a value");
|
||||
let response = response.on_hover_text("Click to enter a value");
|
||||
// let response = ui.interact(response.rect, kb_edit_id, Sense::click());
|
||||
if response.clicked {
|
||||
ui.memory().request_kb_focus(kb_edit_id);
|
||||
|
|
Loading…
Reference in a new issue