Remove position from overlay::Element
This commit is contained in:
parent
7bbe450217
commit
738aa47547
27 changed files with 230 additions and 283 deletions
|
|
@ -231,6 +231,7 @@ where
|
|||
tree: &'b mut widget::Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
translation: Vector,
|
||||
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
|
||||
let state = tree.state.downcast_ref::<State>();
|
||||
|
||||
|
|
@ -240,23 +241,22 @@ where
|
|||
children.next().unwrap(),
|
||||
layout,
|
||||
renderer,
|
||||
translation,
|
||||
);
|
||||
|
||||
let tooltip = if let State::Hovered { cursor_position } = *state {
|
||||
Some(overlay::Element::new(
|
||||
layout.position(),
|
||||
Box::new(Overlay {
|
||||
tooltip: &self.tooltip,
|
||||
state: children.next().unwrap(),
|
||||
cursor_position,
|
||||
content_bounds: layout.bounds(),
|
||||
snap_within_viewport: self.snap_within_viewport,
|
||||
position: self.position,
|
||||
gap: self.gap,
|
||||
padding: self.padding,
|
||||
style: &self.style,
|
||||
}),
|
||||
))
|
||||
Some(overlay::Element::new(Box::new(Overlay {
|
||||
position: layout.position() + translation,
|
||||
tooltip: &self.tooltip,
|
||||
state: children.next().unwrap(),
|
||||
cursor_position,
|
||||
content_bounds: layout.bounds(),
|
||||
snap_within_viewport: self.snap_within_viewport,
|
||||
positioning: self.position,
|
||||
gap: self.gap,
|
||||
padding: self.padding,
|
||||
style: &self.style,
|
||||
})))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
@ -317,12 +317,13 @@ where
|
|||
Theme: container::StyleSheet + widget::text::StyleSheet,
|
||||
Renderer: text::Renderer,
|
||||
{
|
||||
position: Point,
|
||||
tooltip: &'b Text<'a, Theme, Renderer>,
|
||||
state: &'b mut widget::Tree,
|
||||
cursor_position: Point,
|
||||
content_bounds: Rectangle,
|
||||
snap_within_viewport: bool,
|
||||
position: Position,
|
||||
positioning: Position,
|
||||
gap: f32,
|
||||
padding: f32,
|
||||
style: &'b <Theme as container::StyleSheet>::Style,
|
||||
|
|
@ -335,13 +336,7 @@ where
|
|||
Theme: container::StyleSheet + widget::text::StyleSheet,
|
||||
Renderer: text::Renderer,
|
||||
{
|
||||
fn layout(
|
||||
&mut self,
|
||||
renderer: &Renderer,
|
||||
bounds: Size,
|
||||
position: Point,
|
||||
_translation: Vector,
|
||||
) -> layout::Node {
|
||||
fn layout(&mut self, renderer: &Renderer, bounds: Size) -> layout::Node {
|
||||
let viewport = Rectangle::with_size(bounds);
|
||||
|
||||
let text_layout = Widget::<(), Theme, Renderer>::layout(
|
||||
|
|
@ -358,37 +353,44 @@ where
|
|||
);
|
||||
|
||||
let text_bounds = text_layout.bounds();
|
||||
let x_center =
|
||||
position.x + (self.content_bounds.width - text_bounds.width) / 2.0;
|
||||
let y_center = position.y
|
||||
let x_center = self.position.x
|
||||
+ (self.content_bounds.width - text_bounds.width) / 2.0;
|
||||
let y_center = self.position.y
|
||||
+ (self.content_bounds.height - text_bounds.height) / 2.0;
|
||||
|
||||
let mut tooltip_bounds = {
|
||||
let offset = match self.position {
|
||||
let offset = match self.positioning {
|
||||
Position::Top => Vector::new(
|
||||
x_center,
|
||||
position.y - text_bounds.height - self.gap - self.padding,
|
||||
self.position.y
|
||||
- text_bounds.height
|
||||
- self.gap
|
||||
- self.padding,
|
||||
),
|
||||
Position::Bottom => Vector::new(
|
||||
x_center,
|
||||
position.y
|
||||
self.position.y
|
||||
+ self.content_bounds.height
|
||||
+ self.gap
|
||||
+ self.padding,
|
||||
),
|
||||
Position::Left => Vector::new(
|
||||
position.x - text_bounds.width - self.gap - self.padding,
|
||||
self.position.x
|
||||
- text_bounds.width
|
||||
- self.gap
|
||||
- self.padding,
|
||||
y_center,
|
||||
),
|
||||
Position::Right => Vector::new(
|
||||
position.x
|
||||
self.position.x
|
||||
+ self.content_bounds.width
|
||||
+ self.gap
|
||||
+ self.padding,
|
||||
y_center,
|
||||
),
|
||||
Position::FollowCursor => {
|
||||
let translation = position - self.content_bounds.position();
|
||||
let translation =
|
||||
self.position - self.content_bounds.position();
|
||||
|
||||
Vector::new(
|
||||
self.cursor_position.x,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue