mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
Docking: a new float opens at a height fitted to its content
A panel or group floated out of the dock opens at its docked width and at the height its group measures at in a floating window's room, at most size.float.height. Content that fills its body opens at that height. - Proposal::Size measures a component as it is shown at a rect of that size, with no share of the parent body's room. - drag::amend lets a host change a drag's payload in the frame the drag started. The dock area measures the dragged panel there and puts the size on PanelDrag::source / GroupDrag::source. The Float command and a tab torn out of the window measure where they run. - DockGroupOutput::drag_started also reports tab drags. - FloatSpace::size_of caps a panel's, group's or column's height at the default float height. FloatSpace::record and its contents are gone.
This commit is contained in:
@@ -14,6 +14,10 @@ pub enum Proposal {
|
||||
Min,
|
||||
/// The height at this width.
|
||||
Width(f32),
|
||||
/// The size in a room this wide and tall, as the component takes it shown at a rect of that size: it takes no share
|
||||
/// of the room of the body it is measured in. A container's content that fills the room takes it; other content
|
||||
/// its own size.
|
||||
Size(Vec2),
|
||||
}
|
||||
|
||||
/// What the pipeline adds around a component's measured content.
|
||||
|
||||
@@ -1215,16 +1215,17 @@ fn measure_shape<C: Component>(
|
||||
let scx = steps::style_cx(ui.ctx(), &env, &step1);
|
||||
let style = steps::style::<C>(ui.ctx(), &scx, comp.style_key());
|
||||
let resolved = steps::resolved(id, &step1, &common);
|
||||
let width = match proposal {
|
||||
Proposal::Width(width) => Some(width),
|
||||
_ => None,
|
||||
let (at, width) = match proposal {
|
||||
Proposal::Width(width) => (ShowAt::Flow, Some(width)),
|
||||
Proposal::Size(size) => (ShowAt::Rect(Rect::from_min_size(ui.available_rect_before_wrap().min, size)), None),
|
||||
_ => (ShowAt::Flow, None),
|
||||
};
|
||||
// A leaf adds nothing to its own measure, so it opens no stage.
|
||||
let (extent, shown) = if hooks.shape() == ShapeKind::Leaf {
|
||||
(Vec2::ZERO, shown)
|
||||
} else {
|
||||
let mut stage = MemoryStage::open_peek(ui.ctx(), id);
|
||||
let measuring = Measuring { ui, at: ShowAt::Flow, width, env: &env, scx: &scx, resolved: &resolved, command: step1.command.clone(), mixed };
|
||||
let measuring = Measuring { ui, at, width, env: &env, scx: &scx, resolved: &resolved, command: step1.command.clone(), mixed };
|
||||
measured_extent(comp, hooks, &measuring, &mut stage, &style, shown)
|
||||
};
|
||||
let ask = |comp: &mut C, proposal: Proposal| {
|
||||
|
||||
@@ -163,6 +163,8 @@ struct Session {
|
||||
os: bool,
|
||||
/// The root frame in which the OS dropped the files.
|
||||
dropped: Option<u64>,
|
||||
/// The root frame the session started in, the only one in which [`amend`] changes its payload.
|
||||
began: u64,
|
||||
}
|
||||
|
||||
/// A drop a target took: the source's `drag_ended` reads it in the next frame.
|
||||
@@ -210,6 +212,7 @@ fn board<R>(ctx: &Context, f: impl FnOnce(&mut Board) -> R) -> R {
|
||||
#[doc(hidden)]
|
||||
pub fn start(ctx: &Context, source: Id, payload: Arc<dyn Any + Send + Sync>, also: Option<Arc<dyn Any + Send + Sync>>, preview: DragPreview) {
|
||||
let viewport = WindowHost::of(ctx).viewport_of(source).unwrap_or_else(|| pass::current_viewport(ctx));
|
||||
let began = pass::root_frame_nr(ctx);
|
||||
board(ctx, |board| {
|
||||
if board.session.is_none() {
|
||||
let buttons = pointer::buttons_of(ctx, viewport);
|
||||
@@ -230,6 +233,7 @@ pub fn start(ctx: &Context, source: Id, payload: Arc<dyn Any + Send + Sync>, als
|
||||
taken: false,
|
||||
os: false,
|
||||
dropped: None,
|
||||
began,
|
||||
});
|
||||
board.ended = None;
|
||||
board.started += 1;
|
||||
@@ -242,6 +246,23 @@ fn operation(ctx: &Context, mods: Mods) -> DropOperation {
|
||||
drop_operation(windows::os_of(ctx), mods)
|
||||
}
|
||||
|
||||
/// Changes the running session's payload of type `P` (or its second payload of that type) with `change`, in the frame
|
||||
/// the session started only: a host completes what a drag its component started carries with what only the host knows
|
||||
/// (a dock measures the panel a tab drag floats). Returns whether a payload changed; from the next frame on, the
|
||||
/// payload is fixed and nothing changes.
|
||||
pub fn amend<P: Clone + Send + Sync + 'static>(ctx: &Context, change: impl FnOnce(&mut P)) -> bool {
|
||||
let frame = pass::root_frame_nr(ctx);
|
||||
board(ctx, |board| {
|
||||
let Some(session) = board.session.as_mut().filter(|session| session.began == frame) else { return false };
|
||||
let slot = if session.payload.is::<P>() { Some(&mut session.payload) } else { session.also.as_mut().filter(|also| also.is::<P>()) };
|
||||
let Some(slot) = slot else { return false };
|
||||
let Some(mut payload) = slot.downcast_ref::<P>().cloned() else { return false };
|
||||
change(&mut payload);
|
||||
*slot = Arc::new(payload);
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
/// The active drag payload of type `P`, from any viewport. For code without a `Cx`.
|
||||
pub fn active<P: Send + Sync + 'static>(ctx: &Context) -> Option<Arc<P>> {
|
||||
let (payload, also) = board(ctx, |board| board.session.as_ref().map(|session| (session.payload.clone(), session.also.clone())))?;
|
||||
@@ -308,6 +329,7 @@ fn os_files(ctx: &Context) {
|
||||
taken: false,
|
||||
os: true,
|
||||
dropped: None,
|
||||
began: frame,
|
||||
});
|
||||
board.ended = None;
|
||||
board.started += 1;
|
||||
|
||||
@@ -58,9 +58,6 @@ impl<P> Clone for HidePanels<'_, P> {
|
||||
|
||||
impl<P> Copy for HidePanels<'_, P> {}
|
||||
|
||||
/// How much shorter than its body content must be to count as not filling it.
|
||||
const FILL_TOLERANCE: f32 = 1.0;
|
||||
|
||||
/// Where a docking command floats a panel, group or column when it gives no rect. A dock records one each pass;
|
||||
/// the host reads it to turn a command into placements.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -72,13 +69,11 @@ pub struct FloatSpace<P> {
|
||||
pub inset: f32,
|
||||
/// The height of a floating window's title row (`DockSizes::bar`), which a drop keeps under the pointer.
|
||||
pub title_row: f32,
|
||||
/// The size a unit floats at when neither its panel nor where it came from gives one.
|
||||
/// The size a unit floats at when neither its panel nor where it came from gives one. Its height is also the
|
||||
/// most a panel, group or column floats at.
|
||||
pub default_size: Vec2,
|
||||
/// The float size of each panel that has one of its own (`PanelSpec::float_size`).
|
||||
panels: Vec<(P, Vec2)>,
|
||||
/// The height each panel's content used when it was last drawn, which fits a floated group to its content;
|
||||
/// `None` for content that filled its body.
|
||||
contents: Vec<(P, Option<f32>)>,
|
||||
/// The area draws with `DockConfig::side_edge_zones`: an outer edge drop wraps the part between the docks.
|
||||
side_edge_zones: bool,
|
||||
}
|
||||
@@ -93,7 +88,6 @@ impl<P: PartialEq> FloatSpace<P> {
|
||||
title_row: sizes.bar,
|
||||
default_size: sizes.float_size,
|
||||
panels: Vec::new(),
|
||||
contents: Vec::new(),
|
||||
side_edge_zones: false,
|
||||
}
|
||||
}
|
||||
@@ -122,17 +116,28 @@ impl<P: PartialEq> FloatSpace<P> {
|
||||
Self::find(&self.panels, panel)
|
||||
}
|
||||
|
||||
/// The size `unit` floats at: a panel's own float size, else the size it had where it came from (`source`, a
|
||||
/// window's own or a group's or column's with the window's title row above it), else the default.
|
||||
/// The size `unit` floats at: a panel's own float size, else the size it had where it came from (`source`), else
|
||||
/// the default. A window keeps its own size. A panel, group or column takes the source's width and its height
|
||||
/// with the window's title row above it, at most the default height: the dock passes the height its content
|
||||
/// measures at in that room, so content that fills floats at the default height.
|
||||
pub fn size_of(&self, unit: &DragUnit<P>, source: Option<Vec2>) -> Vec2 {
|
||||
let own = match unit {
|
||||
DragUnit::Panel(panel) => self.panel(panel),
|
||||
_ => None,
|
||||
};
|
||||
let framed = |size: Vec2| if matches!(unit, DragUnit::Window(_)) { size } else { size + Vec2::new(0.0, self.title_row) };
|
||||
let framed = |size: Vec2| match unit {
|
||||
DragUnit::Window(_) => size,
|
||||
_ => Vec2::new(size.x, (size.y + self.title_row).min(self.default_size.y)),
|
||||
};
|
||||
own.or(source.map(framed)).unwrap_or(self.default_size)
|
||||
}
|
||||
|
||||
/// The height a panel, group or column's content is measured in for a float of it: the default height less the
|
||||
/// window's title row.
|
||||
pub fn content_room(&self) -> f32 {
|
||||
(self.default_size.y - self.title_row).max(0.0)
|
||||
}
|
||||
|
||||
fn find(sizes: &[(P, Vec2)], panel: &P) -> Option<Vec2> {
|
||||
sizes.iter().find(|(held, _)| held == panel).map(|(_, size)| *size)
|
||||
}
|
||||
@@ -143,18 +148,4 @@ impl<P: PartialEq> FloatSpace<P> {
|
||||
let min = (self.area.min + Vec2::splat(self.inset)).min(self.area.max - size).max(self.area.min);
|
||||
Rect::from_min_size(min, size)
|
||||
}
|
||||
|
||||
/// Records the height `panel`'s content used in a body `available` tall. Content that reaches the body's bottom
|
||||
/// filled it and has no height of its own, unless the body was sized to the height recorded before (a fitted
|
||||
/// window).
|
||||
pub fn record(&mut self, panel: P, used: f32, available: f32) {
|
||||
let used = if used.is_finite() { used.max(0.0) } else { 0.0 };
|
||||
let at = self.contents.iter().position(|(held, _)| *held == panel);
|
||||
let fitted = at.and_then(|at| self.contents[at].1).is_some_and(|height| height >= available - FILL_TOLERANCE);
|
||||
let height = (used < available - FILL_TOLERANCE || fitted).then_some(used);
|
||||
match at {
|
||||
Some(at) => self.contents[at].1 = height,
|
||||
None => self.contents.push((panel, height)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,8 @@ pub struct DockGroupOutput {
|
||||
pub toggle_minimized: bool,
|
||||
/// A tab was dragged out of the dock's windows.
|
||||
pub torn_off: Option<TornOff<PanelKey>>,
|
||||
/// A drag of the whole group started on the grip.
|
||||
/// A drag started on the group this pass: of the whole group on the grip, or of a tab. The host may add the size
|
||||
/// the dragged unit floats at with `drag::amend` in this pass.
|
||||
pub drag_started: bool,
|
||||
}
|
||||
|
||||
@@ -329,6 +330,7 @@ impl<P: Clone + Hash + Send + Sync + 'static> Container for DockGroup<'_, P> {
|
||||
let surface_pressed = cx.surface_pressed();
|
||||
let (size, movable, move_group) = (self.size, self.movable, words.move_group.fill(&[]));
|
||||
let reported = &mut self.reported;
|
||||
let drags = crate::runtime::drag::started(ui.ctx());
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if let Some(hook) = extra.as_mut() {
|
||||
hook.run(ui, cx);
|
||||
@@ -362,6 +364,8 @@ impl<P: Clone + Hash + Send + Sync + 'static> Container for DockGroup<'_, P> {
|
||||
if let Some(dock) = dock {
|
||||
register_insertions(ui.ctx(), dock, &anchor, panels, &strip.tab_rects, rtl);
|
||||
}
|
||||
reported.drag_started |= crate::runtime::drag::started(ui.ctx()) != drags
|
||||
&& crate::runtime::drag::active::<PanelDrag>(ui.ctx()).is_some_and(|drag| drag.from == from);
|
||||
reported.picked = strip.picked.or(reported.picked);
|
||||
reported.closed.extend(strip.closed);
|
||||
reported.menu = strip.menu.or(reported.menu.take());
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::docking::{
|
||||
};
|
||||
use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow};
|
||||
use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within};
|
||||
use crate::runtime::drag;
|
||||
use crate::runtime::env::{Env, Label, RevealEdge, ShellCx, ShellEntry};
|
||||
use crate::runtime::memory::Remember as _;
|
||||
use crate::runtime::windows::WindowHost;
|
||||
@@ -680,27 +681,61 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let permissions = |panel: &P| scene.permissions(panel);
|
||||
let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions), shown);
|
||||
let panels = RefCell::new(&mut *self.panels);
|
||||
let mut group = DockGroup::new(anchor.clone(), &titles, PanelKey::of(shown))
|
||||
.extra(|ui, body| panels.borrow_mut().group_header(members, active, ui, body))
|
||||
.dock(self.dock)
|
||||
.zones(scene.config.zone_rule())
|
||||
.movable(scene.permissions(shown).movable)
|
||||
.menu(menu)
|
||||
.panel_menu_shown(hosted)
|
||||
.command_states(states);
|
||||
if look.minimized {
|
||||
group = group.minimized();
|
||||
}
|
||||
if scene.config.tab_close_buttons {
|
||||
group = group.closable();
|
||||
}
|
||||
// The group with `members[at]` shown: as it shows, or as it is measured.
|
||||
let make = |at: usize, minimized: bool| {
|
||||
let panels = &panels;
|
||||
let mut group = DockGroup::new(anchor.clone(), &titles, PanelKey::of(&members[at]))
|
||||
.extra(move |ui, body| panels.borrow_mut().group_header(members, at, ui, body))
|
||||
.dock(self.dock)
|
||||
.zones(scene.config.zone_rule())
|
||||
.movable(scene.permissions(shown).movable)
|
||||
.menu(menu.clone())
|
||||
.panel_menu_shown(hosted)
|
||||
.command_states(states.clone());
|
||||
if minimized {
|
||||
group = group.minimized();
|
||||
}
|
||||
if scene.config.tab_close_buttons {
|
||||
group = group.closable();
|
||||
}
|
||||
group
|
||||
};
|
||||
let rect = match at {
|
||||
GroupAt::Measure(width) => {
|
||||
return Some(group.measure_in(ui, Proposal::Width(width), |ui, body| panels.borrow_mut().body(shown, ui, body)).y);
|
||||
let measured =
|
||||
make(active, look.minimized).measure_in(ui, Proposal::Width(width), |ui, body| panels.borrow_mut().body(shown, ui, body));
|
||||
return Some(measured.y);
|
||||
}
|
||||
GroupAt::Show(rect) => rect,
|
||||
};
|
||||
let output = group.show_at(ui, rect, |ui, body| panels.borrow_mut().body(shown, ui, body)).output;
|
||||
let output = make(active, look.minimized).show_at(ui, rect, |ui, body| panels.borrow_mut().body(shown, ui, body)).output;
|
||||
// The size `panel` floats at out of this group: the group's width, and the height the group measures at with
|
||||
// `panel` shown in a floating window's room, so content that fills the body takes that room.
|
||||
let fitted = |ui: &Ui, panel: &P| {
|
||||
let at = members.iter().position(|member| member == panel).unwrap_or(active);
|
||||
let room = Vec2::new(rect.width(), scene.space.content_room());
|
||||
let measured = make(at, false).id(output.response.id).measure_in(ui, Proposal::Size(room), |ui, body| {
|
||||
panels.borrow_mut().body(&members[at], ui, body);
|
||||
});
|
||||
Vec2::new(rect.width(), measured.y)
|
||||
};
|
||||
let floats = output.commands.iter().any(|command| matches!(command, DockCommands::FloatPanel | DockCommands::FloatGroup));
|
||||
let source = if floats { fitted(ui, shown) } else { rect.size() };
|
||||
if output.drag_started {
|
||||
let ctx = ui.ctx().clone();
|
||||
let tab = drag::active::<PanelDrag>(&ctx).and_then(|drag| scene.panel(drag.panel).cloned());
|
||||
let size = fitted(ui, tab.as_ref().unwrap_or(shown));
|
||||
drag::amend::<PanelDrag>(&ctx, |drag| drag.source = Some(size));
|
||||
drag::amend::<GroupDrag<P>>(&ctx, |drag| drag.source = Some(size));
|
||||
}
|
||||
// A tear-off inside the window is a release no spot took: it floats only with `float_on_empty_drop`.
|
||||
let torn =
|
||||
output.torn_off.as_ref().and_then(|torn| scene.panel(torn.grabbed).map(|panel| (panel, torn.pointer))).filter(|(panel, pointer)| {
|
||||
scene.permissions(panel).movable
|
||||
&& scene.permissions(panel).floatable
|
||||
&& (scene.config.float_on_empty_drop || !ui.ctx().content_rect().contains(*pointer))
|
||||
});
|
||||
let torn = torn.map(|(panel, pointer)| float_drop(&DragUnit::Panel(panel.clone()), scene.space, pointer, Some(fitted(ui, panel))).action);
|
||||
if let Some(panel) = output.picked.and_then(|key| scene.panel(key)) {
|
||||
self.report.actions.push(Action::activate(panel.clone()));
|
||||
self.report.picked = Some(panel.clone());
|
||||
@@ -715,7 +750,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
self.pick(shown, item);
|
||||
}
|
||||
for command in output.commands {
|
||||
self.run(shown, command, Some(rect.size()));
|
||||
self.run(shown, command, Some(source));
|
||||
}
|
||||
if output.toggle_minimized {
|
||||
self.report.actions.push(match look.section {
|
||||
@@ -723,15 +758,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
None => Action::set_minimized(shown.clone(), !look.minimized),
|
||||
});
|
||||
}
|
||||
// A tear-off inside the window is a release no spot took: it floats only with `float_on_empty_drop`.
|
||||
if let Some(torn) = output.torn_off
|
||||
&& let Some(panel) = scene.panel(torn.grabbed)
|
||||
&& scene.permissions(panel).movable
|
||||
&& scene.permissions(panel).floatable
|
||||
&& (scene.config.float_on_empty_drop || !ui.ctx().content_rect().contains(torn.pointer))
|
||||
{
|
||||
self.report.actions.push(float_drop(&DragUnit::Panel(panel.clone()), scene.space, torn.pointer, Some(rect.size())).action);
|
||||
}
|
||||
self.report.actions.extend(torn);
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
//! Floating windows of a `DockArea`: a drop over a window lands on it.
|
||||
|
||||
use craft_behavior::dock::{Action, Floating, Layout, Node, Permissions, Workspace};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role};
|
||||
use craft_behavior::Axis;
|
||||
use craft_behavior::dock::{Action, Floating, Layout, Node, Permissions, SplitSize, Workspace};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::docking::{DockConfig, DockPanels, GroupDrag, PanelSpec};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::drag::{self, DropMark};
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Pos2, Rect, Ui, Vec2};
|
||||
use egui::{Modifiers, Pos2, Rect, Ui, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
const DOCKED: usize = 1;
|
||||
const WINDOW: usize = 2;
|
||||
const SECOND: usize = 3;
|
||||
/// A panel whose content is two lines of text.
|
||||
const SHORT: usize = 4;
|
||||
/// A panel whose content fills its body.
|
||||
const FILL: usize = 5;
|
||||
/// Inside the fixture's room, so the area's bounds clamp neither the window nor the moves and resizes made of it.
|
||||
const WINDOW_AT: Rect = Rect { min: Pos2::new(130.0, 90.0), max: Pos2::new(330.0, 210.0) };
|
||||
const SLACK: f32 = 1.5;
|
||||
@@ -35,7 +42,20 @@ impl DockPanels<usize> for Panels {
|
||||
(self.rights)(panel)
|
||||
}
|
||||
|
||||
fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {}
|
||||
fn body(&mut self, panel: &usize, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
match *panel {
|
||||
SHORT => {
|
||||
Text::new("One").show(ui);
|
||||
Text::new("Two").show(ui);
|
||||
}
|
||||
FILL => {
|
||||
Stack::new().fill().show(ui, |ui, _| {
|
||||
Text::new("Fills").show(ui);
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A dock area over a bound workspace; the area applies its actions. A second area over its own workspace shows
|
||||
@@ -45,13 +65,16 @@ struct Bed {
|
||||
workspace: Rc<RefCell<Workspace<usize>>>,
|
||||
actions: Rc<RefCell<Vec<Action<usize>>>>,
|
||||
second: Rc<Cell<bool>>,
|
||||
/// The tallest a floated panel opens (`FloatSpace::default_size`), as the area reported it.
|
||||
float_height: Rc<Cell<f32>>,
|
||||
}
|
||||
|
||||
fn bed(layout: Layout<usize>, rights: fn(&usize) -> Permissions) -> Bed {
|
||||
let workspace = Rc::new(RefCell::new(Workspace::new(layout)));
|
||||
let actions: Rc<RefCell<Vec<Action<usize>>>> = Rc::default();
|
||||
let second = Rc::new(Cell::new(false));
|
||||
let (held, seen_actions, shows_second) = (Rc::clone(&workspace), Rc::clone(&actions), Rc::clone(&second));
|
||||
let float_height = Rc::new(Cell::new(0.0));
|
||||
let (held, seen_actions, shows_second, seen_height) = (Rc::clone(&workspace), Rc::clone(&actions), Rc::clone(&second), Rc::clone(&float_height));
|
||||
let mut other = Workspace::new(Layout::new(Some(Node::tabs(vec![SECOND], 0)), Vec::new()));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut workspace = held.borrow().clone();
|
||||
@@ -59,12 +82,15 @@ fn bed(layout: Layout<usize>, rights: fn(&usize) -> Permissions) -> Bed {
|
||||
let out = DockArea::new("Floating dock", Bind::bound(&mut workspace), &mut panels, DockConfig::default()).show(ui);
|
||||
*held.borrow_mut() = workspace;
|
||||
seen_actions.borrow_mut().extend(out.actions);
|
||||
if let Some(space) = out.float_space {
|
||||
seen_height.set(space.default_size.y);
|
||||
}
|
||||
if shows_second.get() {
|
||||
DockArea::new("Second dock", Bind::bound(&mut other), &mut panels, DockConfig::default()).show(ui);
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
Bed { fixture, workspace, actions, second }
|
||||
Bed { fixture, workspace, actions, second, float_height }
|
||||
}
|
||||
|
||||
/// A point on the floating window's title row.
|
||||
@@ -167,16 +193,47 @@ fn a_floating_windows_drag_bar_shows_no_title() {
|
||||
|
||||
/// A tab dragged out of the window floats at the width its group had where it was docked, not a default size.
|
||||
#[trial]
|
||||
fn a_tab_torn_out_of_its_group_floats_at_the_groups_width() {
|
||||
let mut bed = bed(Layout::new(Some(Node::tabs(vec![DOCKED, SECOND], 0)), Vec::new()), |_| Permissions::ALL);
|
||||
let group = bed.fixture.by_role(Role::TAB_PANEL).first().expect("the docked group shows").rect;
|
||||
let tab = bed.fixture.by_role(Role::TAB).into_iter().max_by(|a, b| a.rect.min.x.total_cmp(&b.rect.min.x)).expect("the second tab shows");
|
||||
fn a_floated_panel_fits_its_content_up_to_the_float_height() {
|
||||
let floated = |bed: &Bed, panel: usize| {
|
||||
let layout = bed.workspace.borrow().layout.clone();
|
||||
let window = layout.floating.iter().find(|window| window.contains(&panel)).map(|window| window.rect);
|
||||
window.unwrap_or_else(|| panic!("panel {panel} floats: {:?}", bed.actions.borrow()))
|
||||
};
|
||||
|
||||
// Torn out of the window: the filling panel floats at the group's width and the cap, which a measure of its
|
||||
// content alone would not reach.
|
||||
let mut torn = bed(Layout::new(Some(Node::tabs(vec![FILL, SHORT], 0)), Vec::new()), |_| Permissions::ALL);
|
||||
let group = torn.fixture.by_role(Role::TAB_PANEL).first().expect("the docked group shows").rect;
|
||||
let tab = torn.fixture.by_role(Role::TAB).into_iter().min_by(|a, b| a.rect.min.x.total_cmp(&b.rect.min.x)).expect("FILL's tab shows").rect;
|
||||
let outside = Pos2::new(group.center().x, -40.0);
|
||||
press_and_move(&mut bed.fixture, tab.center(), outside - tab.center());
|
||||
bed.fixture.frame(vec![release(outside)]);
|
||||
bed.fixture.settle();
|
||||
let layout = bed.workspace.borrow().layout.clone();
|
||||
let window =
|
||||
layout.floating.iter().find(|window| window.contains(&SECOND)).unwrap_or_else(|| panic!("the tab floats: {:?}", bed.actions.borrow()));
|
||||
assert!((window.rect.width() - group.width()).abs() <= SLACK, "floated {:?}, docked group {group:?}", window.rect);
|
||||
press_and_move(&mut torn.fixture, tab.center(), outside - tab.center());
|
||||
torn.fixture.frame(vec![release(outside)]);
|
||||
torn.fixture.settle();
|
||||
let fill = floated(&torn, FILL);
|
||||
let cap = torn.float_height.get();
|
||||
assert!(cap < group.height() - SLACK, "the cap {cap} is below the docked group {group:?}");
|
||||
assert!((fill.width() - group.width()).abs() <= SLACK, "floated {fill:?}, docked group {group:?}");
|
||||
assert!((fill.height() - cap).abs() <= SLACK, "filling content floats at the cap: {fill:?}, cap {cap}");
|
||||
|
||||
// The group dragged by its strip's empty room into its own body and released with the key that floats: the
|
||||
// drag carries the measure the area added in the pass it started, and the short panel floats at its content's
|
||||
// height.
|
||||
let root = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![SHORT], 0), Node::tabs(vec![DOCKED], 0));
|
||||
let mut dragged = bed(Layout::new(Some(root), Vec::new()), |_| Permissions::ALL);
|
||||
let tab = dragged.fixture.by_role(Role::TAB).into_iter().min_by(|a, b| a.rect.min.x.total_cmp(&b.rect.min.x)).expect("the tab shows").rect;
|
||||
let group = dragged.fixture.by_role(Role::TAB_PANEL).into_iter().find(|group| group.rect.contains(tab.center())).expect("its group shows").rect;
|
||||
assert!(cap < group.height() - SLACK, "the cap {cap} is below the docked group {group:?}");
|
||||
let grip = Pos2::new(group.center().x + group.width() / 4.0, tab.center().y);
|
||||
let inside = group.center();
|
||||
press_and_move(&mut dragged.fixture, grip, inside - grip);
|
||||
assert!(dragging(&dragged), "the strip's empty room drags the group");
|
||||
// The key goes down while the pointer still moves, so the drop target marks the float before the release.
|
||||
dragged.fixture.hold(Modifiers::COMMAND);
|
||||
dragged.fixture.frame(vec![moved(inside)]);
|
||||
dragged.fixture.frame(vec![release(inside)]);
|
||||
dragged.fixture.hold(Modifiers::NONE);
|
||||
dragged.fixture.settle();
|
||||
let short = floated(&dragged, SHORT);
|
||||
assert!((short.width() - group.width()).abs() <= SLACK, "floated {short:?}, docked group {group:?}");
|
||||
assert!(short.height() < cap - SLACK, "short content floats at its height: {short:?}, cap {cap}");
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
|
||||
|
||||
A floating window is a `Floating` in the layout: its `rect` in logical points in the app's viewport, and `native` and `monitor` while it is an OS window. `FloatingGroup` shows it. With `DockConfig::native_windows` (on by default), every floating window opens in its own OS window (`docking::native`) where the window host opens OS windows and reports where they are (`WindowHost::positions_reported`; not on Wayland); a window never shown native yet opens over its place in the main window. Elsewhere, and for a panel with `allow_native` off, the window stays inside the main window. The OS close of a native window is its Close action: the window closes when every panel in it may close. Dragging a native window by its title row moves the whole window and docks it where it is released over a group of the main window, as a floating window inside the main window does: the window host runs that move (`runtime::windows::keeps_app_drag`). On macOS the row's press hands the move to the OS, the app follows the system pointer and button (`Caps::OS_MOVES_TRACKED`), and a press that ends within the click distance is a click, which docks nothing; elsewhere the app moves the window, and Escape puts it back. The app sends an OS window its place only when the app changes it (an undo, a reloaded layout); the OS's own moves and resizes are recorded and never sent back. `window_kind` says whether an OS window is a document or a tool window. A tool window's title row is its only title bar, whatever frame the main window has (`craft_window::policy::tool_frame`).
|
||||
|
||||
A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: content that fills its body opens at that height, other content at its own. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.
|
||||
|
||||
## SplitArea on its own
|
||||
|
||||
`SplitArea::new(label, layout, rules)` shows the docked tree of a `Layout` with handles between groups; `FrameRules` give each panel's limits. `SplitArea::pair(label, axis, bodies, share, rules)` is a two-body split with one divider. The host keeps the share and reads its edits from `SplitAreaOutput::share`; the timeline's track split works this way.
|
||||
|
||||
Reference in New Issue
Block a user