mirror of
https://github.com/storytold/craft-libs.git
synced 2026-10-31 07:39:23 +00:00
docking: rustfmt, and doc comments for floating trees
This commit is contained in:
1 parent
deec5af9cf
commit
9ff107c2c1
9 files changed
+28
-28
No files matched your search
@@ -40,7 +40,7 @@ use crate::layout::SplitSize;
|
||||
/// | `ui.dock` | `{action}`, or `{operation, …}`, see [`DockOperation`] |
|
||||
///
|
||||
/// `zone` is `tab` (the default for `move` and `dock`), `center`, `left`, `right`, `top`,
|
||||
/// `bottom`, `above` or `below` (a new group in a dock column or floating stack). The side
|
||||
/// `bottom`, `above` or `below` (a new group in a dock column, or a split in a floating window). The side
|
||||
/// zones map onto the anchor's container with [`Placement::for_zone`]. `before`
|
||||
/// names the tab to insert before; `null` appends. `group` moves the panel's whole group,
|
||||
/// `column` its dock column. `side` is `Start` or `End`.
|
||||
@@ -369,7 +369,8 @@ impl<P: Clone + Eq + Hash> DockCommand<P> {
|
||||
let any = given.iter().any(Option::is_some);
|
||||
let unit = Unit::of(*group, *column);
|
||||
let lone = layout.floating.iter().any(|w| w.contains(panel) && w.panels().count() == 1);
|
||||
let whole = layout.floating.iter().any(|w| w.contains(panel) && matches!(w.root, super::Node::Tabs { .. } | super::Node::Stack { .. }));
|
||||
let whole =
|
||||
layout.floating.iter().any(|w| w.contains(panel) && matches!(w.root, super::Node::Tabs { .. } | super::Node::Stack { .. }));
|
||||
// The rect a drag would float the unit at, inside the area.
|
||||
let placed = || {
|
||||
let docked = layout.location(panel).ok().and_then(|l| l.group).and_then(|g| g.column).map(|c| c.width);
|
||||
|
||||
@@ -264,6 +264,7 @@ pub(super) fn tree_panels<P>(root: &Node<P>) -> Vec<&P> {
|
||||
}
|
||||
|
||||
/// The shown panel of a tree's first group.
|
||||
#[cfg(feature = "native-windows")]
|
||||
pub(super) fn first_active<P>(root: &Node<P>) -> Option<&P> {
|
||||
match leaves(root).into_iter().next()?.0 {
|
||||
Node::Tabs { panels, active } => panels.get(*active),
|
||||
|
||||
@@ -676,7 +676,10 @@ fn top_edges_resize_from_the_band_above_the_title_bar() {
|
||||
#[test]
|
||||
fn undock_panel_group_floats_one_group_of_a_floating_window() {
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
let stacked = || Layout { root: Some(tabs(&[1], 0)), floating: vec![Floating::stack(vec![Group::new(vec![5], 0), Group::new(vec![6, 7], 0)], [300.0, 80.0, 300.0, 400.0])] };
|
||||
let stacked = || Layout {
|
||||
root: Some(tabs(&[1], 0)),
|
||||
floating: vec![Floating::stack(vec![Group::new(vec![5], 0), Group::new(vec![6, 7], 0)], [300.0, 80.0, 300.0, 400.0])],
|
||||
};
|
||||
type State = (Content, Layout<u32>, Vec<Action<u32>>);
|
||||
let mut h = Harness::builder().with_size(vec2(800.0, 600.0)).build_ui_state(
|
||||
|ui, (content, layout, actions): &mut State| {
|
||||
|
||||
@@ -66,7 +66,7 @@ pub enum Divider<P> {
|
||||
Stack(P),
|
||||
/// [D] The inner edge of the column holding this panel first.
|
||||
Column(P),
|
||||
/// Below the dock or floating group holding this panel first.
|
||||
/// Below the dock group holding this panel first.
|
||||
Group(P),
|
||||
/// Where the divider of a split inside another split ends on the outer split's divider,
|
||||
/// by the outer and the inner split's paths. Dragging it moves both dividers.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{collections::HashSet, fmt, hash::Hash};
|
||||
|
||||
use super::dock_model::{
|
||||
Column, ColumnLocation, Group, GroupLocation, Moving, PanelState, Place, Side, Target, Unit, node_at, split_frame, stack_tree, tree_panels, valid_column,
|
||||
Column, ColumnLocation, Group, GroupLocation, Moving, PanelState, Place, Side, Target, Unit, node_at, split_frame, tree_panels, valid_column,
|
||||
};
|
||||
use crate::layout::{SplitAxis, SplitSize};
|
||||
|
||||
@@ -90,7 +90,7 @@ impl<P> Floating<P> {
|
||||
/// Groups stacked top to bottom, as a v1 layout stored them.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn stack(groups: Vec<Group<P>>, rect: [f32; 4]) -> Self {
|
||||
Self::new(stack_tree(groups).expect("a group"), rect)
|
||||
Self::new(super::dock_model::stack_tree(groups).expect("a group"), rect)
|
||||
}
|
||||
|
||||
/// The window's groups, first to last.
|
||||
@@ -116,7 +116,8 @@ impl<P> Floating<P> {
|
||||
mod floating_serde {
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use super::{Floating, Group, Node, stack_tree};
|
||||
use super::{Floating, Group, Node};
|
||||
use crate::docking::dock_model::stack_tree;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct V1<'a, P> {
|
||||
@@ -204,7 +205,8 @@ pub enum Placement<P> {
|
||||
/// along the same axis keeps it: on its outer side the new split wraps the parent, on its
|
||||
/// inner side it halves the parent's other child.
|
||||
Split(Zone),
|
||||
/// A new group above or below the anchor's group, in a dock column or a floating stack.
|
||||
/// A new group above or below the anchor's group in a dock column. On an anchor in a
|
||||
/// floating window, a split of the anchor's group above or below.
|
||||
/// `height` is the inserted group's preferred height ([`super::Group::height`]); `None`
|
||||
/// keeps a moved group's own height, or shares the free height for a new group.
|
||||
Group {
|
||||
@@ -236,7 +238,7 @@ pub struct Location<P> {
|
||||
/// rather than accidentally inserting beside only its first leaf when restoring.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub sibling: Vec<P>,
|
||||
/// Group and column state when the panel was in a dock or a floating stack. Applies when
|
||||
/// Group and column state when the panel was in a dock. Applies when
|
||||
/// restoring creates a new group, column or dock for the panel.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub group: Option<GroupLocation>,
|
||||
@@ -273,7 +275,7 @@ pub enum Action<P> {
|
||||
anchor: P,
|
||||
placement: Placement<P>,
|
||||
},
|
||||
/// Reposition/resize a floating group, identified by one of its panels.
|
||||
/// Reposition/resize a floating window, identified by one of its panels.
|
||||
MoveFloating {
|
||||
panel: P,
|
||||
rect: [f32; 4],
|
||||
@@ -327,7 +329,8 @@ pub enum Action<P> {
|
||||
CloseOthers {
|
||||
panel: P,
|
||||
},
|
||||
/// Minimize a dock or floating group to its tab strip. On an accordion entry, closes it.
|
||||
/// Minimize a dock group to its tab strip, or the floating window holding the panel to its
|
||||
/// title bar (and the strip of its only group). On an accordion entry, closes it.
|
||||
SetMinimized {
|
||||
panel: P,
|
||||
minimized: bool,
|
||||
@@ -340,7 +343,7 @@ pub enum Action<P> {
|
||||
panel: P,
|
||||
width: f32,
|
||||
},
|
||||
/// Preferred height of a dock or floating group, or of an accordion entry.
|
||||
/// Preferred height of a dock group or of an accordion entry.
|
||||
ResizeGroup {
|
||||
panel: P,
|
||||
height: Option<f32>,
|
||||
|
||||
@@ -472,11 +472,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Renderer<'_, P> {
|
||||
fn dock_covered(&self, pointer: Pos2, moving: Option<&P>) -> bool {
|
||||
self.blockers.iter().any(|r| r.contains(pointer))
|
||||
|| self.iconic.covers(pointer)
|
||||
|| self
|
||||
.frame
|
||||
.windows
|
||||
.iter()
|
||||
.any(|window| window.window.contains(pointer) && !moving.is_some_and(|p| window.members.contains(p)))
|
||||
|| self.frame.windows.iter().any(|window| window.window.contains(pointer) && !moving.is_some_and(|p| window.members.contains(p)))
|
||||
}
|
||||
|
||||
/// Dock targets, with the new-dock bands along the docked area's left and right edges that
|
||||
|
||||
@@ -6,9 +6,7 @@ use super::{DROP_MARGIN, Drawn, Renderer, clamp_float, dock::group_action};
|
||||
use crate::docking::chrome::drop_preview;
|
||||
use crate::docking::{
|
||||
Action, Drag, DropProposal, DropRequest, DropTarget, GroupDrag, GroupGesture, Layout, Node, Placement, Target, Zone, cancel_drag,
|
||||
dock_model::Place,
|
||||
resolve_drop,
|
||||
surface::TAB_PADDING,
|
||||
dock_model::Place, resolve_drop, surface::TAB_PADDING,
|
||||
};
|
||||
|
||||
/// Ctrl (Windows, Linux) or Cmd (macOS) held: the drop floats and no target is offered.
|
||||
@@ -259,8 +257,8 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Renderer<'_, P> {
|
||||
}
|
||||
let float_only = float_only(ctx) || drag.undock;
|
||||
let outside = gone || !ctx.content_rect().contains(pointer);
|
||||
let empty_drop = self.style.float_on_empty_drop
|
||||
&& (!drag.source.contains(pointer) || self.layout.floating.iter().any(|g| g.contains(&drag.panel)));
|
||||
let empty_drop =
|
||||
self.style.float_on_empty_drop && (!drag.source.contains(pointer) || self.layout.floating.iter().any(|g| g.contains(&drag.panel)));
|
||||
let floatable = self.permissions(&drag.panel).floatable && (float_only || outside || empty_drop);
|
||||
let floating_rect = floatable.then(|| self.tab_float_rect(&drag, pointer));
|
||||
if self.host_drop(ctx, &drag.panel, pointer, false, released, floating_rect) {
|
||||
|
||||
@@ -651,10 +651,9 @@ fn the_preview_fills_the_zone_under_the_pointer_and_outlines_the_result() {
|
||||
let timeline = group(&d, TIMELINE);
|
||||
let strip = Rect::from_min_size(timeline.min, vec2(timeline.width(), 26.0));
|
||||
// A side band: its trapezoid, and the half the panel takes.
|
||||
for (zone, at) in [
|
||||
(Zone::Left, pos2(timeline.left() + 8.0, timeline.center().y + 13.0)),
|
||||
(Zone::Bottom, pos2(timeline.center().x, timeline.bottom() - 20.0)),
|
||||
] {
|
||||
for (zone, at) in
|
||||
[(Zone::Left, pos2(timeline.left() + 8.0, timeline.center().y + 13.0)), (Zone::Bottom, pos2(timeline.center().x, timeline.bottom() - 20.0))]
|
||||
{
|
||||
let mut d = film();
|
||||
d.hold(tab(&d, INFO), at);
|
||||
assert!(d.filled_polygon(&zone_shape(timeline, zone).unwrap()), "{zone:?}");
|
||||
|
||||
@@ -56,8 +56,7 @@ pub struct DockStyle {
|
||||
pub new_dock_zones: bool,
|
||||
/// [D] Height of the bar above each dock column. It drags the column and holds its »/« button.
|
||||
pub column_bar_height: f32,
|
||||
/// [D] Height of the band around the seam between two stacked groups, in docks and
|
||||
/// floating windows.
|
||||
/// [D] Height of the band around the seam between two stacked groups in a dock column.
|
||||
pub seam_band: f32,
|
||||
/// [D] Width of the band along the docked area's left and right edges that makes a new dock.
|
||||
pub new_dock_band: f32,
|
||||
|
||||
Reference in new issue
Block a user