add Label::show_tooltip_when_elided (#5710)
fixes #5708 Allows the user to disable the automatic tooltip when a Label is elided * Closes <https://github.com/emilk/egui/issues/5708> * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
770c976ed7
commit
071e090e2b
|
|
@ -30,6 +30,7 @@ pub struct Label {
|
|||
sense: Option<Sense>,
|
||||
selectable: Option<bool>,
|
||||
halign: Option<Align>,
|
||||
show_tooltip_when_elided: bool,
|
||||
}
|
||||
|
||||
impl Label {
|
||||
|
|
@ -40,6 +41,7 @@ impl Label {
|
|||
sense: None,
|
||||
selectable: None,
|
||||
halign: None,
|
||||
show_tooltip_when_elided: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +118,23 @@ impl Label {
|
|||
self.sense = Some(sense);
|
||||
self
|
||||
}
|
||||
|
||||
/// Show the full text when hovered, if the text was elided.
|
||||
///
|
||||
/// By default, this is true.
|
||||
///
|
||||
/// ```
|
||||
/// # use egui::{Label, Sense};
|
||||
/// # egui::__run_test_ui(|ui| {
|
||||
/// ui.add(Label::new("some text").show_tooltip_when_elided(false))
|
||||
/// .on_hover_text("completely different text");
|
||||
/// # });
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn show_tooltip_when_elided(mut self, show: bool) -> Self {
|
||||
self.show_tooltip_when_elided = show;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Label {
|
||||
|
|
@ -247,13 +266,14 @@ impl Widget for Label {
|
|||
let interactive = self.sense.is_some_and(|sense| sense != Sense::hover());
|
||||
|
||||
let selectable = self.selectable;
|
||||
let show_tooltip_when_elided = self.show_tooltip_when_elided;
|
||||
|
||||
let (galley_pos, galley, mut response) = self.layout_in_ui(ui);
|
||||
response
|
||||
.widget_info(|| WidgetInfo::labeled(WidgetType::Label, ui.is_enabled(), galley.text()));
|
||||
|
||||
if ui.is_rect_visible(response.rect) {
|
||||
if galley.elided {
|
||||
if show_tooltip_when_elided && galley.elided {
|
||||
// Show the full (non-elided) text on hover:
|
||||
response = response.on_hover_text(galley.text());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue