Skip to content

Commit

Permalink
position bug fix for floating elements
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Jul 24, 2023
1 parent 414a213 commit b0ee43f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/native/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ where
if state.children.len() == 2 {
let bounds = layout.bounds();

let position = match self.anchor {
let offset = match self.anchor {
Anchor::NorthWest => Point::new(0.0, 0.0),
Anchor::NorthEast => Point::new(bounds.width, 0.0),
Anchor::SouthWest => Point::new(0.0, bounds.height),
Anchor::SouthEast => Point::new(bounds.width, bounds.height),
Anchor::North => Point::new(bounds.center_x(), 0.0),
Anchor::East => Point::new(bounds.width, bounds.center_y()),
Anchor::South => Point::new(bounds.center_x(), bounds.height),
Anchor::West => Point::new(0.0, bounds.center_y()),
Anchor::North => Point::new(bounds.width / 2.0, 0.0),
Anchor::East => Point::new(bounds.width, bounds.height / 2.0),
Anchor::South => Point::new(bounds.width / 2.0, bounds.height),
Anchor::West => Point::new(0.0, bounds.height / 2.0),
};

let position = Point::new(bounds.x + position.x, bounds.y + position.y);
let position = Point::new(bounds.x + offset.x, bounds.y + offset.y);

Some(overlay::Element::new(
position,
Expand Down
14 changes: 4 additions & 10 deletions src/native/overlay/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iced_widget::core::{
mouse::{self, Cursor},
overlay, renderer,
widget::Tree,
Clipboard, Element, Event, Layout, Point, Rectangle, Shell, Size,
Clipboard, Element, Event, Layout, Point, Rectangle, Shell, Size,
};

use crate::native::floating_element::{Anchor, Offset};
Expand Down Expand Up @@ -61,21 +61,15 @@ where
position.x + self.offset.x + element.bounds().width,
position.y + self.offset.y + element.bounds().height,
),
Anchor::NorthEast =>
Size::new(
Anchor::NorthEast => Size::new(
position.x - self.offset.x,
position.y + self.offset.y + element.bounds().height,
),
Anchor::SouthWest | Anchor::South =>
Size::new(
Anchor::SouthWest | Anchor::South => Size::new(
position.x + self.offset.x + element.bounds().width,
position.y - self.offset.y,
),
Anchor::SouthEast =>
Size::new(
position.x - self.offset.x,
position.y - self.offset.y,
),
Anchor::SouthEast => Size::new(position.x - self.offset.x, position.y - self.offset.y),
Anchor::East => Size::new(
position.x - self.offset.x,
position.y + element.bounds().height / 2.0,
Expand Down

0 comments on commit b0ee43f

Please sign in to comment.