|
@ -25,10 +25,10 @@ use crate::*; |
|
|
/// ```
|
|
|
/// ```
|
|
|
pub fn show_tooltip<R>( |
|
|
pub fn show_tooltip<R>( |
|
|
ctx: &Context, |
|
|
ctx: &Context, |
|
|
id: Id, |
|
|
widget_id: Id, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
) -> Option<R> { |
|
|
) -> Option<R> { |
|
|
show_tooltip_at_pointer(ctx, id, add_contents) |
|
|
show_tooltip_at_pointer(ctx, widget_id, add_contents) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Show a tooltip at the current pointer position (if any).
|
|
|
/// Show a tooltip at the current pointer position (if any).
|
|
@ -50,11 +50,12 @@ pub fn show_tooltip<R>( |
|
|
/// ```
|
|
|
/// ```
|
|
|
pub fn show_tooltip_at_pointer<R>( |
|
|
pub fn show_tooltip_at_pointer<R>( |
|
|
ctx: &Context, |
|
|
ctx: &Context, |
|
|
id: Id, |
|
|
widget_id: Id, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
) -> Option<R> { |
|
|
) -> Option<R> { |
|
|
ctx.input(|i| i.pointer.hover_pos()) |
|
|
ctx.input(|i| i.pointer.hover_pos()).map(|pointer_pos| { |
|
|
.map(|pointer_pos| show_tooltip_at(ctx, id, pointer_pos + vec2(16.0, 16.0), add_contents)) |
|
|
show_tooltip_at(ctx, widget_id, pointer_pos + vec2(16.0, 16.0), add_contents) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Show a tooltip under the given area.
|
|
|
/// Show a tooltip under the given area.
|
|
@ -62,7 +63,7 @@ pub fn show_tooltip_at_pointer<R>( |
|
|
/// If the tooltip does not fit under the area, it tries to place it above it instead.
|
|
|
/// If the tooltip does not fit under the area, it tries to place it above it instead.
|
|
|
pub fn show_tooltip_for<R>( |
|
|
pub fn show_tooltip_for<R>( |
|
|
ctx: &Context, |
|
|
ctx: &Context, |
|
|
id: Id, |
|
|
widget_id: Id, |
|
|
widget_rect: &Rect, |
|
|
widget_rect: &Rect, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
) -> R { |
|
|
) -> R { |
|
@ -70,7 +71,7 @@ pub fn show_tooltip_for<R>( |
|
|
let allow_placing_below = !is_touch_screen; // There is a finger below.
|
|
|
let allow_placing_below = !is_touch_screen; // There is a finger below.
|
|
|
show_tooltip_at_avoid_dyn( |
|
|
show_tooltip_at_avoid_dyn( |
|
|
ctx, |
|
|
ctx, |
|
|
id, |
|
|
widget_id, |
|
|
allow_placing_below, |
|
|
allow_placing_below, |
|
|
widget_rect, |
|
|
widget_rect, |
|
|
Box::new(add_contents), |
|
|
Box::new(add_contents), |
|
@ -82,13 +83,19 @@ pub fn show_tooltip_for<R>( |
|
|
/// Returns `None` if the tooltip could not be placed.
|
|
|
/// Returns `None` if the tooltip could not be placed.
|
|
|
pub fn show_tooltip_at<R>( |
|
|
pub fn show_tooltip_at<R>( |
|
|
ctx: &Context, |
|
|
ctx: &Context, |
|
|
id: Id, |
|
|
widget_id: Id, |
|
|
suggested_position: Pos2, |
|
|
suggested_position: Pos2, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
add_contents: impl FnOnce(&mut Ui) -> R, |
|
|
) -> R { |
|
|
) -> R { |
|
|
let allow_placing_below = true; |
|
|
let allow_placing_below = true; |
|
|
let rect = Rect::from_center_size(suggested_position, Vec2::ZERO); |
|
|
let rect = Rect::from_center_size(suggested_position, Vec2::ZERO); |
|
|
show_tooltip_at_avoid_dyn(ctx, id, allow_placing_below, &rect, Box::new(add_contents)) |
|
|
show_tooltip_at_avoid_dyn( |
|
|
|
|
|
ctx, |
|
|
|
|
|
widget_id, |
|
|
|
|
|
allow_placing_below, |
|
|
|
|
|
&rect, |
|
|
|
|
|
Box::new(add_contents), |
|
|
|
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fn show_tooltip_at_avoid_dyn<'c, R>( |
|
|
fn show_tooltip_at_avoid_dyn<'c, R>( |
|
@ -212,8 +219,8 @@ fn find_tooltip_position( |
|
|
/// }
|
|
|
/// }
|
|
|
/// # });
|
|
|
/// # });
|
|
|
/// ```
|
|
|
/// ```
|
|
|
pub fn show_tooltip_text(ctx: &Context, id: Id, text: impl Into<WidgetText>) -> Option<()> { |
|
|
pub fn show_tooltip_text(ctx: &Context, widget_id: Id, text: impl Into<WidgetText>) -> Option<()> { |
|
|
show_tooltip(ctx, id, |ui| { |
|
|
show_tooltip(ctx, widget_id, |ui| { |
|
|
crate::widgets::Label::new(text).ui(ui); |
|
|
crate::widgets::Label::new(text).ui(ui); |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|