Fix / remove small todos
This commit is contained in:
parent
145f3f55e9
commit
80790d921d
11 changed files with 52 additions and 34 deletions
|
@ -15,8 +15,7 @@ pub struct Overlay {
|
|||
anchor_corner: AnchorCorner,
|
||||
fit_mode: OverlayFitMode,
|
||||
anchor_position: Option<Point<Pixels>>,
|
||||
// todo!();
|
||||
// position_mode: OverlayPositionMode,
|
||||
position_mode: OverlayPositionMode,
|
||||
}
|
||||
|
||||
/// overlay gives you a floating element that will avoid overflowing the window bounds.
|
||||
|
@ -27,6 +26,7 @@ pub fn overlay() -> Overlay {
|
|||
anchor_corner: AnchorCorner::TopLeft,
|
||||
fit_mode: OverlayFitMode::SwitchAnchor,
|
||||
anchor_position: None,
|
||||
position_mode: OverlayPositionMode::Window,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,14 @@ impl Overlay {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the position mode for this overlay. Local will have this
|
||||
/// interpret it's [Overlay::position] as relative to the parent element.
|
||||
/// While Window will have it interpret the position as relative to the window.
|
||||
pub fn position_mode(mut self, mode: OverlayPositionMode) -> Self {
|
||||
self.position_mode = mode;
|
||||
self
|
||||
}
|
||||
|
||||
/// Snap to window edge instead of switching anchor corner when an overflow would occur.
|
||||
pub fn snap_to_window(mut self) -> Self {
|
||||
self.fit_mode = OverlayFitMode::SnapToWindow;
|
||||
|
@ -100,9 +108,14 @@ impl Element for Overlay {
|
|||
child_max = child_max.max(&child_bounds.lower_right());
|
||||
}
|
||||
let size: Size<Pixels> = (child_max - child_min).into();
|
||||
let origin = self.anchor_position.unwrap_or(bounds.origin);
|
||||
|
||||
let mut desired = self.anchor_corner.get_bounds(origin, size);
|
||||
let (origin, mut desired) = self.position_mode.get_position_and_bounds(
|
||||
self.anchor_position,
|
||||
self.anchor_corner,
|
||||
size,
|
||||
bounds,
|
||||
);
|
||||
|
||||
let limits = Bounds {
|
||||
origin: Point::default(),
|
||||
size: cx.viewport_size(),
|
||||
|
@ -184,6 +197,35 @@ pub enum OverlayFitMode {
|
|||
SwitchAnchor,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum OverlayPositionMode {
|
||||
Window,
|
||||
Local,
|
||||
}
|
||||
|
||||
impl OverlayPositionMode {
|
||||
fn get_position_and_bounds(
|
||||
&self,
|
||||
anchor_position: Option<Point<Pixels>>,
|
||||
anchor_corner: AnchorCorner,
|
||||
size: Size<Pixels>,
|
||||
bounds: Bounds<Pixels>,
|
||||
) -> (Point<Pixels>, Bounds<Pixels>) {
|
||||
match self {
|
||||
OverlayPositionMode::Window => {
|
||||
let anchor_position = anchor_position.unwrap_or_else(|| bounds.origin);
|
||||
let bounds = anchor_corner.get_bounds(anchor_position, size);
|
||||
(anchor_position, bounds)
|
||||
}
|
||||
OverlayPositionMode::Local => {
|
||||
let anchor_position = anchor_position.unwrap_or_default();
|
||||
let bounds = anchor_corner.get_bounds(bounds.origin + anchor_position, size);
|
||||
(anchor_position, bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AnchorCorner {
|
||||
TopLeft,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue