mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Add Popup and Tooltip, unifying the previous behaviours (#5713)
This introduces new `Tooltip` and `Popup` structs that unify and extend the old popups and tooltips. `Popup` handles the positioning and optionally stores state on whether the popup is open (for click based popups like `ComboBox`, menus, context menus). `Tooltip` is based on `Popup` and handles state of whether the tooltip should be shown (which turns out to be quite complex to handles all the edge cases). Both `Popup` and `Tooltip` can easily be constructed from a `Response` and then customized via builder methods. This also introduces `PositionAlign`, for aligning something outside of a `Rect` (in contrast to `Align2` for aligning inside a `Rect`). But I don't like the name, any suggestions? Inspired by [mui's tooltip positioning](https://mui.com/material-ui/react-tooltip/#positioned-tooltips). * Part of #4607 * [x] I have followed the instructions in the PR template TODOs: - [x] Automatic tooltip positioning based on available space - [x] Review / fix / remove all code TODOs - [x] ~Update the helper fns on `Response` to be consistent in naming and parameters (Some use tooltip, some hover_ui, some take &self, some take self)~ actually, I think the naming and parameter make sense on second thought - [x] Make sure all old code is marked deprecated For discussion during review: - the following check in `show_tooltip_for` still necessary?: ```rust let is_touch_screen = ctx.input(|i| i.any_touches()); let allow_placing_below = !is_touch_screen; // There is a finger below. TODO: Needed? ```
This commit is contained in:
@@ -50,6 +50,16 @@ impl Align {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the inverse alignment.
|
||||
/// `Min` becomes `Max`, `Center` stays the same, `Max` becomes `Min`.
|
||||
pub fn flip(self) -> Self {
|
||||
match self {
|
||||
Self::Min => Self::Max,
|
||||
Self::Center => Self::Center,
|
||||
Self::Max => Self::Min,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a range of given size within a specified range.
|
||||
///
|
||||
/// If the requested `size` is bigger than the size of `range`, then the returned
|
||||
@@ -170,6 +180,24 @@ impl Align2 {
|
||||
vec2(self.x().to_sign(), self.y().to_sign())
|
||||
}
|
||||
|
||||
/// Flip on the x-axis
|
||||
/// e.g. `TOP_LEFT` -> `TOP_RIGHT`
|
||||
pub fn flip_x(self) -> Self {
|
||||
Self([self.x().flip(), self.y()])
|
||||
}
|
||||
|
||||
/// Flip on the y-axis
|
||||
/// e.g. `TOP_LEFT` -> `BOTTOM_LEFT`
|
||||
pub fn flip_y(self) -> Self {
|
||||
Self([self.x(), self.y().flip()])
|
||||
}
|
||||
|
||||
/// Flip on both axes
|
||||
/// e.g. `TOP_LEFT` -> `BOTTOM_RIGHT`
|
||||
pub fn flip(self) -> Self {
|
||||
Self([self.x().flip(), self.y().flip()])
|
||||
}
|
||||
|
||||
/// Used e.g. to anchor a piece of text to a part of the rectangle.
|
||||
/// Give a position within the rect, specified by the aligns
|
||||
pub fn anchor_rect(self, rect: Rect) -> Rect {
|
||||
|
||||
Reference in New Issue
Block a user