More attachment configuration for context menus
This commit is contained in:
@@ -15,7 +15,7 @@ pub struct Overlay<V> {
|
||||
anchor_corner: AnchorCorner,
|
||||
fit_mode: OverlayFitMode,
|
||||
// todo!();
|
||||
// anchor_position: Option<Vector2F>,
|
||||
anchor_position: Option<Point<Pixels>>,
|
||||
// position_mode: OverlayPositionMode,
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ pub fn overlay<V: 'static>() -> Overlay<V> {
|
||||
children: SmallVec::new(),
|
||||
anchor_corner: AnchorCorner::TopLeft,
|
||||
fit_mode: OverlayFitMode::SwitchAnchor,
|
||||
anchor_position: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +37,13 @@ impl<V> Overlay<V> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the position in window co-ordinates
|
||||
/// (otherwise the location the overlay is rendered is used)
|
||||
pub fn position(mut self, anchor: Point<Pixels>) -> Self {
|
||||
self.anchor_position = Some(anchor);
|
||||
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;
|
||||
@@ -102,7 +110,7 @@ impl<V: 'static> Element<V> for Overlay<V> {
|
||||
child_max = child_max.max(&child_bounds.lower_right());
|
||||
}
|
||||
let size: Size<Pixels> = (child_max - child_min).into();
|
||||
let origin = bounds.origin;
|
||||
let origin = self.anchor_position.unwrap_or(bounds.origin);
|
||||
|
||||
let mut desired = self.anchor_corner.get_bounds(origin, size);
|
||||
let limits = Bounds {
|
||||
@@ -196,6 +204,15 @@ impl AnchorCorner {
|
||||
Bounds { origin, size }
|
||||
}
|
||||
|
||||
pub fn corner(&self, bounds: Bounds<Pixels>) -> Point<Pixels> {
|
||||
match self {
|
||||
Self::TopLeft => bounds.origin,
|
||||
Self::TopRight => bounds.upper_right(),
|
||||
Self::BottomLeft => bounds.lower_left(),
|
||||
Self::BottomRight => bounds.lower_right(),
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_axis(self, axis: Axis) -> Self {
|
||||
match axis {
|
||||
Axis::Vertical => match self {
|
||||
|
||||
@@ -1151,6 +1151,14 @@ impl<'a> WindowContext<'a> {
|
||||
self.window.mouse_position = mouse_move.position;
|
||||
InputEvent::MouseMove(mouse_move)
|
||||
}
|
||||
InputEvent::MouseDown(mouse_down) => {
|
||||
self.window.mouse_position = mouse_down.position;
|
||||
InputEvent::MouseDown(mouse_down)
|
||||
}
|
||||
InputEvent::MouseUp(mouse_up) => {
|
||||
self.window.mouse_position = mouse_up.position;
|
||||
InputEvent::MouseUp(mouse_up)
|
||||
}
|
||||
// Translate dragging and dropping of external files from the operating system
|
||||
// to internal drag and drop events.
|
||||
InputEvent::FileDrop(file_drop) => match file_drop {
|
||||
|
||||
Reference in New Issue
Block a user