Fix / remove small todos

This commit is contained in:
Mikayla 2024-01-09 14:16:46 -08:00
parent 145f3f55e9
commit 80790d921d
No known key found for this signature in database
11 changed files with 52 additions and 34 deletions

View file

@ -481,7 +481,7 @@ impl<V> View<V> {
use postage::prelude::{Sink as _, Stream as _};
let (tx, mut rx) = postage::mpsc::channel(1024);
let timeout_duration = Duration::from_millis(100); //todo!() cx.condition_duration();
let timeout_duration = Duration::from_millis(100);
let mut cx = cx.app.borrow_mut();
let subscriptions = (

View file

@ -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,