Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tooltip overlay position inside Scrollable #1978

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Quad rendering including border only inside of the bounds. [#1843](https://github.com/iced-rs/iced/pull/1843)
- Redraw requests not being forwarded for `Component` overlays. [#1949](https://github.com/iced-rs/iced/pull/1949)
- Blinking input cursor when window loses focus. [#1955](https://github.com/iced-rs/iced/pull/1955)
- `Tooltip` overlay position inside `Scrollable`. [#1978](https://github.com/iced-rs/iced/pull/1978)
- `BorderRadius` not exposed in root crate. [#1972](https://github.com/iced-rs/iced/pull/1972)
- Outdated `ROADMAP`. [#1958](https://github.com/iced-rs/iced/pull/1958)

Expand Down
34 changes: 16 additions & 18 deletions widget/src/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
&self,
renderer: &Renderer,
bounds: Size,
_position: Point,
position: Point,
) -> layout::Node {
let viewport = Rectangle::with_size(bounds);

Expand All @@ -331,45 +331,43 @@ where
);

let text_bounds = text_layout.bounds();
let x_center = self.content_bounds.x
+ (self.content_bounds.width - text_bounds.width) / 2.0;
let y_center = self.content_bounds.y
let x_center =
position.x + (self.content_bounds.width - text_bounds.width) / 2.0;
let y_center = position.y
+ (self.content_bounds.height - text_bounds.height) / 2.0;

let mut tooltip_bounds = {
let offset = match self.position {
Position::Top => Vector::new(
x_center,
self.content_bounds.y
- text_bounds.height
- self.gap
- self.padding,
position.y - text_bounds.height - self.gap - self.padding,
),
Position::Bottom => Vector::new(
x_center,
self.content_bounds.y
position.y
+ self.content_bounds.height
+ self.gap
+ self.padding,
),
Position::Left => Vector::new(
self.content_bounds.x
- text_bounds.width
- self.gap
- self.padding,
position.x - text_bounds.width - self.gap - self.padding,
y_center,
),
Position::Right => Vector::new(
self.content_bounds.x
position.x
+ self.content_bounds.width
+ self.gap
+ self.padding,
y_center,
),
Position::FollowCursor => Vector::new(
self.cursor_position.x,
self.cursor_position.y - text_bounds.height,
),
Position::FollowCursor => {
let translation = position - self.content_bounds.position();

Vector::new(
self.cursor_position.x,
self.cursor_position.y - text_bounds.height,
) + translation
}
};

Rectangle {
Expand Down
Loading