mod blob;
mod chrome;
mod dock;
pub mod dragout;
pub mod expand;
mod rects;
mod splitter;
use std::collections::{BTreeMap, BTreeSet};
use smallvec::SmallVec;
use uzor::layout::docking::{DockPanel, FloatingWindowId, LeafId, SnapBackAnimation};
use uzor::layout::{ChromeSlot, EdgePanels, EdgeSide, LayoutSolved, LayoutTree};
use uzor::render::InvalidateBits;
use uzor::widgets::composite::chrome::ChromeState;
use uzor::{Rect, ResizeDirection};
use crate::types::bus::HostCaps;
use crate::types::command::{
ChromeModel, DockTarget, DragOutChrome, LayoutCmd, LayoutHit, LayoutPolicy,
};
use crate::types::ids::{Revision, Seconds, WindowId};
use crate::types::intent::DockIntent;
use crate::types::layout_blob::WindowGeometrySnapshot;
use crate::types::ops::{DockPointer, LayoutEffect, LayoutOp};
use crate::types::snapshot::{ChromeView, DockView, EdgeSlotView};
use crate::types::spec::{PanelHome, Spec};
use crate::types::window::{Point, WindowCommand};
#[allow(unused_imports)]
pub use blob::BLOB_VERSION;
#[allow(unused_imports)]
pub use dragout::{DragOutView, DWELL_S, MOVE_FRESH_S, STALE_S};
#[allow(unused_imports)]
pub use expand::{ExpandState, ExpandTarget};
pub use uzor::layout::DockState;
pub type LayoutEffects = SmallVec<[LayoutEffect; 2]>;
pub type PanelDecoder<P> = fn(PanelHome, &str) -> Option<P>;
pub const DRAG_START_PX: f64 = 4.0;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SessionKind {
Splitter {
sep: usize,
frozen: bool,
},
Corner {
vertical: usize,
horizontal: usize,
frozen: bool,
},
TabPressed {
leaf: LeafId,
tab: usize,
},
TabReorder {
leaf: LeafId,
},
HeaderPressed(LeafId),
PanelDrag {
leaf: LeafId,
},
Refused,
FloatingMove(FloatingWindowId),
FloatingResize(FloatingWindowId),
Click(LayoutHit),
MicroMove,
}
#[derive(Clone, Copy, Debug, PartialEq)]
enum Session {
Splitter(splitter::SplitDrag),
Tab {
leaf: LeafId,
tab: usize,
origin: Point,
stage: dock::TabStage,
},
Header {
leaf: LeafId,
origin: Point,
stage: dock::HeaderStage,
},
FloatingMove {
id: FloatingWindowId,
grab: (f64, f64),
},
FloatingResize {
id: FloatingWindowId,
dir: ResizeDirection,
origin: Point,
start: Rect,
},
Click(LayoutHit),
MicroMove {
grab: Point,
},
}
impl Session {
fn kind(&self) -> SessionKind {
match *self {
Session::Splitter(d) => d.kind(),
Session::Tab {
leaf, tab, stage, ..
} => match stage {
dock::TabStage::Pressed => SessionKind::TabPressed { leaf, tab },
dock::TabStage::Reorder => SessionKind::TabReorder { leaf },
dock::TabStage::Tear => SessionKind::PanelDrag { leaf },
dock::TabStage::Refused => SessionKind::Refused,
},
Session::Header { leaf, stage, .. } => match stage {
dock::HeaderStage::Pressed => SessionKind::HeaderPressed(leaf),
dock::HeaderStage::Dragging => SessionKind::PanelDrag { leaf },
dock::HeaderStage::Refused => SessionKind::Refused,
},
Session::FloatingMove { id, .. } => SessionKind::FloatingMove(id),
Session::FloatingResize { id, .. } => SessionKind::FloatingResize(id),
Session::Click(hit) => SessionKind::Click(hit),
Session::MicroMove { .. } => SessionKind::MicroMove,
}
}
}
struct WindowLayout<P: DockPanel> {
caps: HostCaps,
viewport: Rect,
chrome_slot: ChromeSlot,
chrome: ChromeModel,
chrome_state: ChromeState,
edges: EdgePanels,
tree: LayoutTree,
solved: LayoutSolved,
dock: DockState<P>,
session: Option<Session>,
dock_rev: Revision,
wire: blob::WireDock,
outer: Option<Rect>,
scale: f64,
expand: Option<expand::Expand>,
micro: Option<DragOutChrome>,
}
impl<P: DockPanel> WindowLayout<P> {
fn new(caps: HostCaps, viewport: Rect, policy: &LayoutPolicy) -> Self {
let mut dock = DockState::new();
dock::configure(&mut dock, policy);
let wire = blob::WireDock::capture(&dock);
let mut w = Self {
caps,
viewport,
chrome_slot: ChromeSlot {
height: 32.0,
visible: false,
},
chrome: ChromeModel::default(),
chrome_state: ChromeState::new(),
edges: EdgePanels::new(),
tree: LayoutTree::new(),
solved: LayoutSolved::default(),
dock,
session: None,
dock_rev: Revision::ZERO,
wire,
outer: None,
scale: 1.0,
expand: None,
micro: None,
};
rects::solve(&mut w);
w
}
}
#[derive(PartialEq)]
struct Observed {
caps: HostCaps,
viewport: Rect,
chrome: chrome::ChromeObs,
edges: Vec<EdgeSlotView>,
dock: dock::DockObs,
session: Option<SessionKind>,
outer: Option<Rect>,
scale: f64,
expand: Option<expand::Expand>,
micro: Option<DragOutChrome>,
}
impl Observed {
fn of<P: DockPanel>(w: &WindowLayout<P>) -> Self {
Self {
caps: w.caps,
viewport: w.viewport,
chrome: chrome::ChromeObs::of(w),
edges: rects::edge_views(w),
dock: dock::DockObs::of(&w.dock),
session: w.session.map(|s| s.kind()),
outer: w.outer,
scale: w.scale,
expand: w.expand,
micro: w.micro,
}
}
}
struct Ctx<P> {
policy: LayoutPolicy,
decode: PanelDecoder<P>,
dragout_busy: bool,
}
impl<P> Clone for Ctx<P> {
fn clone(&self) -> Self {
*self
}
}
impl<P> Copy for Ctx<P> {}
pub struct LayoutEngine<P: DockPanel> {
windows: BTreeMap<WindowId, WindowLayout<P>>,
dragout: Option<dragout::DragOutSession<P>>,
policy: LayoutPolicy,
decode: PanelDecoder<P>,
changed: BTreeSet<WindowId>,
clock: Option<Seconds>,
touched: bool,
rev: Revision,
}
impl<P: DockPanel> LayoutEngine<P> {
#[allow(dead_code)]
pub fn new(decode: PanelDecoder<P>) -> Self {
Self::with_policy(decode, LayoutPolicy::default())
}
pub fn with_policy(decode: PanelDecoder<P>, policy: LayoutPolicy) -> Self {
Self {
windows: BTreeMap::new(),
dragout: None,
policy,
decode,
changed: BTreeSet::new(),
clock: None,
touched: false,
rev: Revision::ZERO,
}
}
#[allow(dead_code)]
pub fn for_spec<S: Spec<Panel = P>>() -> Self {
Self::new(S::decode_panel)
}
pub fn apply(&mut self, op: LayoutOp<P>) -> LayoutEffects {
let before = self.dragout_obs();
let mut fx = LayoutEffects::new();
match op {
LayoutOp::Open {
win,
caps,
viewport,
} => {
if !self.windows.contains_key(&win) {
self.windows
.insert(win, WindowLayout::new(caps, viewport, &self.policy));
self.touched = true;
fx.push(invalidate(win, InvalidateBits::ALL));
} else {
self.edit(win, &mut fx, |w, _, _| {
w.caps = caps;
w.viewport = viewport;
});
}
self.dragout_place(win, &mut fx);
}
LayoutOp::Close(win) => {
if self.windows.remove(&win).is_some() {
self.changed.remove(&win);
self.touched = true;
}
self.dragout_window_closed(win);
}
LayoutOp::Solve { win, viewport } => {
self.edit(win, &mut fx, |w, _, _| w.viewport = viewport);
}
LayoutOp::Pointer { win, now, event } => {
self.clock = Some(match self.clock {
Some(c) if c.get() > now.get() => c,
_ => now,
});
self.dragout_pointer(win, event);
let outer_before = self.windows.get(&win).and_then(|w| w.outer);
let mut out = None;
self.edit(win, &mut fx, |w, ctx, fx| {
pointer(win, w, ctx, event, fx, &mut out)
});
let outer_after = self.windows.get(&win).and_then(|w| w.outer);
if outer_after != outer_before {
self.dragout_moved(win, now);
}
if let Some(out) = out {
self.dragout_start(win, now, out, &mut fx);
}
}
LayoutOp::Cmd(cmd) => self.cmd(cmd, &mut fx),
LayoutOp::OuterRect {
win,
now,
rect,
scale,
} => {
let before = self.windows.get(&win).and_then(|w| w.outer);
let scale = if scale.is_finite() && scale > 0.0 {
scale
} else {
1.0
};
self.edit(win, &mut fx, |w, _, _| {
w.outer = Some(rect);
w.scale = scale;
});
let moved = match before {
Some(b) => b.x != rect.x || b.y != rect.y,
None => false,
};
if moved {
self.dragout_moved(win, now);
}
}
LayoutOp::ExpandValue { win, kind, t } => {
self.edit(win, &mut fx, |w, _, fx| expand::value(win, w, kind, t, fx));
}
LayoutOp::AdoptPanel { win } => self.dragout_adopt(win, &mut fx),
}
self.settle_rev(before);
fx
}
fn settle_rev(&mut self, dragout_before: Option<DragOutView>) {
if std::mem::take(&mut self.touched) || self.dragout_obs() != dragout_before {
self.rev.bump();
}
}
pub fn tick(&mut self, now: Seconds) -> LayoutEffects {
let dragout_before = self.dragout_obs();
let dt = match self.clock {
Some(c) => now.since(c).get(),
None => 0.0,
};
match self.clock {
Some(c) if c.get() >= now.get() => {}
_ => self.clock = Some(now),
}
let mut fx = LayoutEffects::new();
let mut moved = false;
for (&win, w) in self.windows.iter_mut() {
if w.dock.snap_animations().is_empty() {
continue;
}
let before = splitter::snap_obs(&w.dock);
w.dock.update_snap_animations(dt as f32);
if splitter::snap_obs(&w.dock) != before {
moved = true;
fx.push(invalidate(win, InvalidateBits::GEOMETRY));
}
}
if moved {
self.touched = true;
}
self.dragout_tick(now, &mut fx);
for win in std::mem::take(&mut self.changed) {
if let Some(w) = self.windows.get(&win) {
fx.push(LayoutEffect::Intent(DockIntent::LayoutChanged {
win,
dock_rev: w.dock_rev,
}));
}
}
self.settle_rev(dragout_before);
fx
}
pub fn hit(&self, win: WindowId, p: Point) -> LayoutHit {
match self.windows.get(&win) {
Some(w) => hit_window(w, &self.policy, p),
None => LayoutHit::None,
}
}
pub fn revision(&self) -> Revision {
self.rev
}
pub fn view(&self) -> LayoutEngineView<'_, P> {
LayoutEngineView { engine: self }
}
fn edit<F>(&mut self, win: WindowId, fx: &mut LayoutEffects, f: F)
where
F: FnOnce(&mut WindowLayout<P>, Ctx<P>, &mut LayoutEffects),
{
if self.edit_quiet(win, fx, f) {
self.touched = true;
}
}
fn edit_quiet<F>(&mut self, win: WindowId, fx: &mut LayoutEffects, f: F) -> bool
where
F: FnOnce(&mut WindowLayout<P>, Ctx<P>, &mut LayoutEffects),
{
let ctx = Ctx {
policy: self.policy,
decode: self.decode,
dragout_busy: self.dragout.as_ref().is_some_and(|s| s.holds_panel()),
};
let Some(w) = self.windows.get_mut(&win) else {
return false;
};
let before = Observed::of(w);
f(w, ctx, fx);
rects::solve(w);
let after = Observed::of(w);
let moved = after != before;
if moved {
let bits = if after.dock.structure_differs(&before.dock) {
InvalidateBits::STRUCTURE.union(InvalidateBits::GEOMETRY)
} else {
InvalidateBits::GEOMETRY
};
fx.push(invalidate(win, bits));
}
let wire = blob::WireDock::capture(&w.dock);
if wire != w.wire {
w.wire = wire;
w.dock_rev.bump();
self.changed.insert(win);
}
moved
}
fn cmd(&mut self, cmd: LayoutCmd<P>, fx: &mut LayoutEffects) {
match cmd {
LayoutCmd::SetPolicy(policy) => {
if policy == self.policy {
return;
}
self.policy = policy;
self.touched = true;
let wins: Vec<WindowId> = self.windows.keys().copied().collect();
for win in wins {
self.edit_quiet(win, fx, |w, ctx, _| {
dock::configure(&mut w.dock, &ctx.policy)
});
}
}
LayoutCmd::OpenPanel {
panel,
at: DockTarget::Window(target),
..
} => {
self.edit(target, fx, |w, _, _| {
dock::open_panel(w, panel, DockTarget::Root)
});
}
LayoutCmd::RequestBlob { win, ticket } => {
if let Some(w) = self.windows.get(&win) {
let wire = blob::WireDock::capture(&w.dock);
fx.push(LayoutEffect::Intent(match blob::encode(&wire, None) {
Ok(blob) => DockIntent::LayoutBlob { win, ticket, blob },
Err(error) => DockIntent::LayoutBlobFailed { win, ticket, error },
}));
}
}
LayoutCmd::Restore { win, blob } => {
if !self.windows.contains_key(&win) {
return;
}
let mut outcome = None;
self.edit(win, fx, |w, ctx, fx| {
let held = w.session.is_some();
let result = blob::restore(w, &blob, &ctx);
if let Ok(geometry) = &result {
if held {
fx.push(LayoutEffect::Capture { win, hold: false });
}
restore_geometry(win, *geometry, fx);
}
outcome = Some(result);
});
fx.push(LayoutEffect::Intent(match outcome {
Some(Err(error)) => DockIntent::LayoutRestoreFailed { win, error },
_ => DockIntent::LayoutRestored { win },
}));
}
other => {
let Some(win) = cmd_window(&other) else {
return;
};
self.edit(win, fx, |w, _, _| window_cmd(w, other));
}
}
}
}
fn restore_geometry(
win: WindowId,
geometry: Option<WindowGeometrySnapshot>,
fx: &mut LayoutEffects,
) {
let Some(g) = geometry else {
return;
};
if g.maximized {
fx.push(LayoutEffect::Window {
win,
cmd: WindowCommand::SetMaximized(true),
});
} else if let Some(position) = g.position {
fx.push(LayoutEffect::Window {
win,
cmd: WindowCommand::SetOuterRect {
position,
size: g.outer_size,
},
});
}
}
fn cmd_window<P>(cmd: &LayoutCmd<P>) -> Option<WindowId> {
match cmd {
LayoutCmd::SetChrome { win, .. }
| LayoutCmd::SetChromeModel { win, .. }
| LayoutCmd::AddEdgeSlot { win, .. }
| LayoutCmd::RemoveEdgeSlot { win, .. }
| LayoutCmd::OpenPanel { win, .. }
| LayoutCmd::ClosePanel { win, .. }
| LayoutCmd::ActivateTab { win, .. }
| LayoutCmd::Split { win, .. }
| LayoutCmd::Float { win, .. }
| LayoutCmd::SetPreset { win, .. }
| LayoutCmd::SetRatios { win, .. }
| LayoutCmd::SetGrid { win, .. }
| LayoutCmd::RequestBlob { win, .. }
| LayoutCmd::Restore { win, .. } => Some(*win),
LayoutCmd::SetPolicy(_) => None,
}
}
fn window_cmd<P: DockPanel>(w: &mut WindowLayout<P>, cmd: LayoutCmd<P>) {
match cmd {
LayoutCmd::SetChrome {
visible, height, ..
} => {
w.chrome_slot.visible = visible;
w.chrome_slot.height = if height.is_finite() {
height.max(0.0)
} else {
0.0
};
}
LayoutCmd::SetChromeModel { model, .. } => w.chrome = model,
LayoutCmd::AddEdgeSlot { slot, .. } => w.edges.add(slot),
LayoutCmd::RemoveEdgeSlot { id, .. } => w.edges.remove(&id),
LayoutCmd::OpenPanel { panel, at, .. } => dock::open_panel(w, panel, at),
LayoutCmd::ClosePanel { leaf, index, .. } => {
w.dock.tree_mut().remove_tab(leaf, index);
}
LayoutCmd::ActivateTab { leaf, index, .. } => {
dock::activate_tab(&mut w.dock, leaf, index);
}
LayoutCmd::Split {
leaf, dir, panel, ..
} => dock::split(&mut w.dock, leaf, dir, panel),
LayoutCmd::Float {
leaf, index, rect, ..
} => dock::float_tab(w, leaf, index, rect),
LayoutCmd::SetPreset { preset, .. } => w.dock.tree_mut().set_layout(preset),
LayoutCmd::SetRatios { branch, ratios, .. } => {
dock::set_ratios(&mut w.dock, branch, ratios)
}
LayoutCmd::SetGrid {
branch, rows, cols, ..
} => {
w.dock.tree_mut().set_branch_grid(branch, rows, cols);
}
LayoutCmd::SetPolicy(_) | LayoutCmd::RequestBlob { .. } | LayoutCmd::Restore { .. } => {}
}
}
fn pointer<P: DockPanel>(
win: WindowId,
w: &mut WindowLayout<P>,
ctx: Ctx<P>,
event: DockPointer,
fx: &mut LayoutEffects,
out: &mut Option<dragout::Outbound<P>>,
) {
match event {
DockPointer::Down { pos, button } => {
if button != uzor::input::MouseButton::Left {
return;
}
if w.session.is_some() {
end_session(win, w, fx, None, ctx, out);
}
let hit = hit_window(w, &ctx.policy, pos);
press(win, w, hit, pos, fx);
}
DockPointer::Move(pos) => {
let Some(session) = w.session else {
return;
};
let next = match session {
Session::Splitter(d) => Session::Splitter(splitter::drag(w, d, pos, &ctx.policy)),
Session::Tab { .. } | Session::Header { .. } => {
let next = dock::drag_move(w, session, pos);
if dock::is_live_drag(&next) {
expand::track(win, w, &ctx.policy, pos, fx);
}
next
}
Session::FloatingMove { .. } | Session::FloatingResize { .. } => {
dock::floating_move(w, session, pos);
session
}
Session::Click(_) => session,
Session::MicroMove { grab } => {
dragout::micro_move(win, w, grab, pos, fx);
session
}
};
w.session = Some(next);
}
DockPointer::Up(pos) => {
if w.session.is_some() {
end_session(win, w, fx, Some(pos), ctx, out);
}
}
DockPointer::Cancel => {
if w.session.is_some() {
end_session(win, w, fx, None, ctx, out);
}
}
}
}
fn press<P: DockPanel>(
win: WindowId,
w: &mut WindowLayout<P>,
hit: LayoutHit,
pos: Point,
fx: &mut LayoutEffects,
) {
let session = match hit {
LayoutHit::Bezel(dir) => {
fx.push(LayoutEffect::Window {
win,
cmd: WindowCommand::DragResizeWindow(dir),
});
None
}
LayoutHit::Chrome(part) => chrome::press(win, part, fx),
LayoutHit::Splitter { sep, .. } => {
splitter::start_line(&w.dock, sep, pos).map(Session::Splitter)
}
LayoutHit::Corner {
vertical,
horizontal,
} => splitter::start_corner(&w.dock, vertical, horizontal, pos).map(Session::Splitter),
LayoutHit::PanelHeader(_) if w.micro == Some(DragOutChrome::None) => {
Some(Session::MicroMove { grab: pos })
}
LayoutHit::Tab { leaf, tab } => {
if dock::activate_tab(&mut w.dock, leaf, tab) {
fx.push(LayoutEffect::Intent(DockIntent::TabActivated {
win,
leaf,
index: tab,
}));
}
let stage = if w.micro.is_some() {
dock::TabStage::Refused
} else {
dock::TabStage::Pressed
};
Some(Session::Tab {
leaf,
tab,
origin: pos,
stage,
})
}
LayoutHit::PanelHeader(leaf) => {
w.dock.set_active_leaf(leaf);
let stage = if w.micro.is_some() {
dock::HeaderStage::Refused
} else {
dock::HeaderStage::Pressed
};
Some(Session::Header {
leaf,
origin: pos,
stage,
})
}
LayoutHit::FloatingHeader(id) => dock::floating_press(&mut w.dock, id, pos),
LayoutHit::FloatingResize { id, dir } => dock::floating_resize_press(&w.dock, id, dir, pos),
LayoutHit::TabClose { .. } | LayoutHit::TabNew { .. } | LayoutHit::FloatingClose(_) => {
Some(Session::Click(hit))
}
LayoutHit::PanelBody(_)
| LayoutHit::FloatingBody(_)
| LayoutHit::EdgeGutter(_)
| LayoutHit::None => None,
};
if let Some(s) = session {
w.session = Some(s);
fx.push(LayoutEffect::Capture { win, hold: true });
}
}
fn end_session<P: DockPanel>(
win: WindowId,
w: &mut WindowLayout<P>,
fx: &mut LayoutEffects,
release: Option<Point>,
ctx: Ctx<P>,
out: &mut Option<dragout::Outbound<P>>,
) {
let Some(session) = w.session.take() else {
return;
};
match (session, release) {
(Session::Splitter(_), _) => {}
(Session::Tab { .. } | Session::Header { .. }, Some(pos)) => {
if dock::is_live_drag(&session) {
expand::track(win, w, &ctx.policy, pos, fx);
}
if !expand::commit_drop(win, w, session, fx) {
dock::drag_release(win, w, session, pos, ctx, fx, out);
}
expand::unhot(win, w, fx);
}
(Session::Tab { .. } | Session::Header { .. }, None) => {
dock::drag_cancel(w, session);
expand::unhot(win, w, fx);
}
(Session::FloatingMove { .. }, _) => {
w.dock.end_floating_drag();
}
(Session::FloatingResize { .. }, _) | (Session::MicroMove { .. }, _) => {}
(Session::Click(hit), Some(pos)) => {
if hit_window(w, &ctx.policy, pos) == hit {
click(win, w, hit, fx);
}
}
(Session::Click(_), None) => {}
}
fx.push(LayoutEffect::Capture { win, hold: false });
}
fn click<P: DockPanel>(
win: WindowId,
w: &mut WindowLayout<P>,
hit: LayoutHit,
fx: &mut LayoutEffects,
) {
match hit {
LayoutHit::TabClose { leaf, tab } => {
if let Some(type_id) = dock::close_tab(&mut w.dock, leaf, tab) {
fx.push(LayoutEffect::Intent(DockIntent::PanelClosed {
win,
leaf,
index: tab,
type_id,
}));
}
}
LayoutHit::TabNew { leaf } => {
fx.push(LayoutEffect::Intent(DockIntent::NewPanelRequested {
win,
leaf,
}));
}
LayoutHit::FloatingClose(id) => w.dock.close_floating(id),
LayoutHit::Chrome(part) => chrome::click(win, part, fx),
_ => {}
}
}
fn hit_window<P: DockPanel>(w: &WindowLayout<P>, policy: &LayoutPolicy, p: Point) -> LayoutHit {
if !rects::contains(w.viewport, p) {
return LayoutHit::None;
}
if let Some(side) = expand::gutter(w, policy, p, expand::drag_live(w)) {
return LayoutHit::EdgeGutter(side);
}
if !w.caps.os_resize_bezel {
if let Some(dir) = chrome::bezel(w.viewport, policy.bezel_px, p) {
return LayoutHit::Bezel(dir);
}
}
if let Some(hit) = chrome::hit(w, p) {
return hit;
}
if rects::in_edge_slot(&w.solved, p) {
return LayoutHit::None;
}
if let Some(hit) = dock::floating_hit(&w.dock, policy, p) {
return hit;
}
dock::dock_hit(&w.dock, policy, p)
}
fn invalidate(win: WindowId, bits: InvalidateBits) -> LayoutEffect {
LayoutEffect::Invalidate { win, bits }
}
pub struct LayoutEngineView<'a, P: DockPanel> {
engine: &'a LayoutEngine<P>,
}
impl<P: DockPanel> Clone for LayoutEngineView<'_, P> {
fn clone(&self) -> Self {
*self
}
}
impl<P: DockPanel> Copy for LayoutEngineView<'_, P> {}
#[allow(dead_code)]
impl<'a, P: DockPanel> LayoutEngineView<'a, P> {
pub fn ids(&self) -> impl Iterator<Item = WindowId> + 'a {
self.engine.windows.keys().copied()
}
pub fn window(&self, win: WindowId) -> Option<WindowLayoutView<'a, P>> {
self.engine
.windows
.get(&win)
.map(|w| WindowLayoutView { w })
}
pub fn policy(&self) -> LayoutPolicy {
self.engine.policy
}
pub fn hit(&self, win: WindowId, p: Point) -> LayoutHit {
self.engine.hit(win, p)
}
pub fn revision(&self) -> Revision {
self.engine.rev
}
pub fn drag_out(&self) -> Option<DragOutView> {
self.engine.dragout_obs()
}
pub fn next_deadline(&self) -> Option<Seconds> {
self.engine.dragout.as_ref().and_then(|s| s.deadline())
}
}
pub struct WindowLayoutView<'a, P: DockPanel> {
w: &'a WindowLayout<P>,
}
impl<P: DockPanel> Clone for WindowLayoutView<'_, P> {
fn clone(&self) -> Self {
*self
}
}
impl<P: DockPanel> Copy for WindowLayoutView<'_, P> {}
#[allow(dead_code)]
impl<'a, P: DockPanel> WindowLayoutView<'a, P> {
pub fn viewport(&self) -> Rect {
self.w.viewport
}
pub fn caps(&self) -> HostCaps {
self.w.caps
}
pub fn solved(&self) -> &'a LayoutSolved {
&self.w.solved
}
pub fn dock_area(&self) -> Rect {
self.w.solved.dock_area
}
pub fn chrome_slot(&self) -> &'a ChromeSlot {
&self.w.chrome_slot
}
pub fn chrome_model(&self) -> &'a ChromeModel {
&self.w.chrome
}
pub fn chrome_state(&self) -> &'a ChromeState {
&self.w.chrome_state
}
pub fn dock(&self) -> &'a DockState<P> {
&self.w.dock
}
pub fn dock_rev(&self) -> Revision {
self.w.dock_rev
}
pub fn session(&self) -> Option<SessionKind> {
self.w.session.map(|s| s.kind())
}
pub fn outer_rect(&self) -> Option<Rect> {
self.w.outer
}
pub fn scale(&self) -> f64 {
self.w.scale
}
pub fn expand(&self) -> Option<ExpandState> {
self.w.expand.map(|x| x.state())
}
pub fn content_rect(&self) -> Rect {
expand::content_rect(self.w)
}
pub fn micro(&self) -> Option<DragOutChrome> {
self.w.micro
}
pub fn snap_backs(&self) -> &'a [SnapBackAnimation] {
self.w.dock.snap_animations()
}
pub fn tab_new_rect(&self, leaf: LeafId, policy: &LayoutPolicy) -> Option<Rect> {
dock::tab_new_rect(&self.w.dock, policy, leaf)
}
pub fn chrome_view(&self) -> ChromeView {
ChromeView {
visible: self.w.solved.chrome.is_some(),
rect: self.w.solved.chrome.unwrap_or_default(),
}
}
pub fn edge_views(&self) -> Vec<EdgeSlotView> {
rects::edge_views(self.w)
}
pub fn dock_view(&self) -> DockView {
dock::dock_view(&self.w.dock, self.w.dock_rev)
}
pub fn edge_rects(&self, side: EdgeSide) -> &'a [Rect] {
let e = &self.w.solved.edges;
match side {
EdgeSide::Top => &e.top,
EdgeSide::Bottom => &e.bottom,
EdgeSide::Left => &e.left,
EdgeSide::Right => &e.right,
}
}
}
#[cfg(test)]
mod tests;