diff --git a/crates/ui-contract/src/contract/mount.rs b/crates/ui-contract/src/contract/mount.rs index 0abbea9a6..0642f34bb 100644 --- a/crates/ui-contract/src/contract/mount.rs +++ b/crates/ui-contract/src/contract/mount.rs @@ -356,11 +356,12 @@ impl Host for ViewportHost { let open = ViewportOpen { id, title: title.as_str(), - // A placed rect is the caller's size for the window, then a resizable fallback's default size, as the layer - // takes it; the measured size is for a window sized by content: what its body took in the window, recorded - // once the window reported its place (`steps::record_body_size`). + // A placed rect is the caller's size for the window, within the window's limits, which the OS would clamp it + // to; then a resizable fallback's default size, as the layer takes it; the measured size is for a window + // sized by content: what its body took in the window, recorded once the window reported its place + // (`steps::record_body_size`). size: placed - .map(|rect| rect.size()) + .map(|rect| self.overlay.size_limits.clamp(rect.size())) .or(self.overlay.size.filter(|_| self.overlay.fit == overlay::OverlayFit::Resizable)) .or_else(measured), // A resizable window takes its default or content size to open; from then on its size is the user's. diff --git a/crates/ui-contract/src/contract/overlay/place.rs b/crates/ui-contract/src/contract/overlay/place.rs index 700b14911..ed97d3dea 100644 --- a/crates/ui-contract/src/contract/overlay/place.rs +++ b/crates/ui-contract/src/contract/overlay/place.rs @@ -192,6 +192,11 @@ impl SizeLimits { SizeLimits { min: self.min + extra, max: self.max.map(|max| max + extra) } } + /// `size` within these limits; the minimum wins over a smaller maximum. + pub fn clamp(self, size: Vec2) -> Vec2 { + size.min(self.max.unwrap_or(Vec2::INFINITY)).max(self.min) + } + /// Whether every value is finite and non-negative, the maximum is no less than the minimum and no value is /// above [`Self::BOUND`]. pub fn valid(self) -> bool { diff --git a/crates/ui-contract/src/runtime/egui/viewports.rs b/crates/ui-contract/src/runtime/egui/viewports.rs index bd009c5d0..65f0231d6 100644 --- a/crates/ui-contract/src/runtime/egui/viewports.rs +++ b/crates/ui-contract/src/runtime/egui/viewports.rs @@ -27,7 +27,7 @@ pub(crate) struct Spec<'a> { pub os_buttons: bool, /// The smallest inner size. pub min_size: Option, - /// The largest inner size. + /// The largest inner size; `Vec2::INFINITY` lifts an earlier one. pub max_size: Option, /// The window level. pub level: WindowLevel, diff --git a/crates/ui-contract/src/runtime/windows.rs b/crates/ui-contract/src/runtime/windows.rs index f3ec67e21..42df34bdb 100644 --- a/crates/ui-contract/src/runtime/windows.rs +++ b/crates/ui-contract/src/runtime/windows.rs @@ -309,11 +309,17 @@ pub(crate) fn blocking_modal(ctx: &Context) -> Option { /// It reads only this pass's facts, so the mount, the body (which runs inside the child's pass) and the window steps /// agree within a pass. pub(crate) fn mount_window(ctx: &Context, id: Id) -> bool { + let current = pass::current_viewport(ctx); + let opener = if current == viewports::viewport_id(id) { viewports::parent(ctx) } else { current }; + opens_over(ctx, opener) +} + +/// Whether a viewport mount opened from `opener`'s window shows in an OS window of its own: the rule of +/// [`mount_window`]. +fn opens_over(ctx: &Context, opener: ViewportId) -> bool { if !WindowHost::of(ctx).viewports_available() { return false; } - let current = pass::current_viewport(ctx); - let opener = if current == viewports::viewport_id(id) { viewports::parent(ctx) } else { current }; let shell = shell_of(ctx, opener); let covers = match shell.window.state { WindowState::Fullscreen => true, diff --git a/crates/ui-contract/src/runtime/windows/host.rs b/crates/ui-contract/src/runtime/windows/host.rs index b6be02411..5ce81ebda 100644 --- a/crates/ui-contract/src/runtime/windows/host.rs +++ b/crates/ui-contract/src/runtime/windows/host.rs @@ -77,6 +77,13 @@ impl WindowHost { base_shell(&self.ctx).caps.contains(Caps::VIEWPORTS) && viewports::available(&self.ctx) } + /// Whether a viewport mount opened in the running viewport's pass shows in an OS window of its own, and not in + /// its fallback layer: OS viewports are available and the running window is neither full screen nor, on Wayland, + /// maximized. + pub fn opens_windows(&self) -> bool { + super::opens_over(&self.ctx, pass::current_viewport(&self.ctx)) + } + /// Whether the platform reports where windows are on the desktop and moves them there; false on Wayland. pub fn positions_reported(&self) -> bool { base_shell(&self.ctx).window_positions() diff --git a/crates/ui-contract/src/runtime/windows/viewport.rs b/crates/ui-contract/src/runtime/windows/viewport.rs index 55af6c762..62cc36634 100644 --- a/crates/ui-contract/src/runtime/windows/viewport.rs +++ b/crates/ui-contract/src/runtime/windows/viewport.rs @@ -83,7 +83,9 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im // A tool window has no OS caption buttons; its panel's title row carries a close action. os_buttons: !(spec.kind == WindowKind::Tool && captions.is_none() && chrome != WindowChrome::Native), min_size: open.limits.0, - max_size: open.limits.1, + // egui sends a limit only when it has one: an open window always carries its maximum, unbounded when the + // caller has none, so a lifted maximum reaches the OS. + max_size: open.limits.1.or(opened.then_some(Vec2::INFINITY)), level, resizable: open.resizable, taskbar: spec.taskbar, diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index fee1675aa..7379ef514 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -2,8 +2,9 @@ //! //! The group is a movable, resizable container on a layer (or in an OS window) whose rect the caller owns: the //! caller places it with the rect the dock model keeps and takes the rect the output reports after each step of -//! a gesture. The title row carries the active panel's title and the Menu, Float and Close actions; the Menu action -//! opens the `menu` rows. The body step supplies the move band, the edge grips and the keyboard Move and Size modes. +//! a gesture. The title row carries the Close action; a context request on its band opens the `menu` rows, as the +//! Menu action does where `actions` asks for one. The body step supplies the move band, the edge grips and the +//! keyboard Move and Size modes. //! A dock window's title row is also the bar of the column the window holds, with the column's double arrow. use super::dock_column::{CHEVRON, ColumnArrow, describe_chevron, paint_chevron}; @@ -38,8 +39,9 @@ pub(crate) fn title_row(tokens: &UiTokens) -> f32 { tokens.size.panel_header } -/// The actions a floating group's title row shows unless `actions` says otherwise. -const ACTIONS: [HeaderAction; 3] = [HeaderAction::Menu, HeaderAction::Float, HeaderAction::Close]; +/// The actions a floating group's title row shows unless `actions` says otherwise: Close alone, as a floating panel's +/// title bar has beside its double arrow; the menu opens from the band. +const ACTIONS: [HeaderAction; 1] = [HeaderAction::Close]; /// The style of a floating group: the surface and padding come from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] @@ -90,6 +92,21 @@ impl WindowColumn { self } + /// Where a window that keeps `rect` shows while its column is collapsed: the collapsed column under a title row + /// `header` tall, at the top of `rect` and against the edge the window keeps to. `None` while the column is + /// expanded. + pub fn shown(self, rect: Rect, header: f32, rtl: bool) -> Option { + let size = self.collapsed? + Vec2::new(0.0, header); + let left = if at_left(self.edge, rtl) { rect.left() } else { rect.right() - size.x }; + Some(Rect::from_min_size(Pos2::new(left, rect.top()), size)) + } + + /// The rect a window that keeps `rect` keeps when it shows at `shown`: while collapsed, `rect` moved with the + /// collapsed column ([`Self::shown`]), so it keeps its expanded size; while expanded, `shown`. + pub fn kept(self, shown: Rect, rect: Rect, header: f32, rtl: bool) -> Rect { + self.shown(rect, header, rtl).map_or(shown, |at| rect.translate(shown.min - at.min)) + } + /// The edge of `bounds`, in reading order, nearer the window at `rect`: the start edge when the window's centre is /// in the half of the bounds there or `bounds` is empty. pub fn nearer_edge(rect: Rect, bounds: Rect, rtl: bool) -> DockEdge { @@ -204,7 +221,7 @@ pub struct FloatingGroup<'a> { /// Opens the group in an OS window of this kind. #[prop] native: Option, - /// The rows of the menu the Menu action opens. + /// The rows of the menu a context request on the title row, or the Menu action, opens. #[prop(func = "FnMut(&mut Ui, &mut BodyCx<'_>)")] menu: Option>, actions: Vec, @@ -235,7 +252,7 @@ type StartDrag<'a> = Box FnOnce(&'b mut Cx<'c, FloatingGroup<'a> type TakeDrop<'a> = Box FnMut(&'b mut Cx<'c, FloatingGroup<'a>>) + 'a>; impl<'a> FloatingGroup<'a> { - /// A floating group titled `title` at `rect`, with the Menu, Float and Close actions. + /// A floating group titled `title` at `rect`, with the Close action. pub fn new(title: impl Into