mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 11:48:53 +00:00
dock: Flyout::docked stands a flyout as a docked column does, square on surface.panel with the column's line.border frame and no shadow; the flyouts of a flush dock's columns (DockConfig::flush_docks) take it, the others stay raised popups
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Outside, Place, PlacementChange, ResizeEdges};
|
||||
use crate::contract::{
|
||||
BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PopupHandle, Role, SizeLimits, Sizing,
|
||||
BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PaintUi, PopupHandle, Role,
|
||||
SizeLimits, Sizing,
|
||||
};
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use crate::style::{ComponentStyle, Corners, StyleCx, SurfaceKind};
|
||||
use craft_behavior::overlay::Side;
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use egui::{Pos2, Rect, Response, Ui, Vec2};
|
||||
@@ -72,6 +73,8 @@ pub struct Flyout {
|
||||
/// The least size a resize leaves the flyout.
|
||||
#[prop(quantity = "least room a resize leaves, from the dock's measured sizes, in points")]
|
||||
least: Vec2,
|
||||
/// The flyout stands as a docked column does: [`docked`](Flyout::docked).
|
||||
docked: bool,
|
||||
placed: Option<PlacementChange>,
|
||||
}
|
||||
|
||||
@@ -80,7 +83,19 @@ impl Flyout {
|
||||
/// `Side::End`), closing on a press outside it and when the focus leaves it if `auto_collapse`.
|
||||
pub fn new(opens: Side, size: Vec2, auto_collapse: bool) -> Self {
|
||||
let props = ContainerProps::new().surface(SurfaceKind::Popup).pad(Pad::None).sizing(Sizing::Content);
|
||||
Flyout { common: Common::new(), props, opens, size, auto_collapse, within: Rect::EVERYTHING, least: Vec2::ZERO, placed: None }
|
||||
Flyout { common: Common::new(), props, opens, size, auto_collapse, within: Rect::EVERYTHING, least: Vec2::ZERO, docked: false, placed: None }
|
||||
}
|
||||
|
||||
/// The flyout stands as a docked column does, in place of a popup's raised surface: square on `surface.panel`, with
|
||||
/// the column's `line.border` frame and no shadow (the flyouts of a flush dock's columns,
|
||||
/// [`DockConfig::flush_docks`](super::DockConfig::flush_docks)).
|
||||
#[must_use]
|
||||
pub fn docked(mut self, on: bool) -> Self {
|
||||
if on {
|
||||
self.props = self.props.surface(SurfaceKind::Panel);
|
||||
}
|
||||
self.docked = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The layer the flyout shows in, its top left at `top_left`: placed by the caller, resizable on every edge but
|
||||
@@ -155,6 +170,12 @@ impl Component for Flyout {
|
||||
Sense::empty()
|
||||
}
|
||||
|
||||
fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
if self.docked {
|
||||
ui.draw().surface(cx.rect, SurfaceKind::Frame, Corners::None);
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> FlyoutOutput {
|
||||
FlyoutOutput { response: cx.response.clone(), placed: self.placed }
|
||||
}
|
||||
|
||||
@@ -772,7 +772,7 @@ impl<P: Value + Hash + Debug + 'static> Component for IconicColumn<'_, P> {
|
||||
let mut resized = None;
|
||||
for (at, plan) in plans.into_iter().enumerate() {
|
||||
let Some(FlyoutPlan { group, top_left, size, fixed, icons_top }) = plan else { continue };
|
||||
let shown = Flyout::new(opens, size, auto_collapse).within(bounds).least(least).show_popup(
|
||||
let shown = Flyout::new(opens, size, auto_collapse).within(bounds).least(least).docked(self.framed).show_popup(
|
||||
ui,
|
||||
popup.at(at),
|
||||
Anchor::Point(top_left),
|
||||
|
||||
@@ -727,3 +727,47 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() {
|
||||
fixture.release_at(icon.center() + Vec2::new(RAIL * 2.0, 0.0)).settle();
|
||||
}
|
||||
}
|
||||
|
||||
/// The surface shapes painted around the open flyout of a column that is `framed` (a flush dock's): the rects whose
|
||||
/// rect holds the flyout's body.
|
||||
fn flyout_surfaces(framed: bool) -> Vec<egui::epaint::RectShape> {
|
||||
let shown: Rc<Cell<Option<Rect>>> = Rc::default();
|
||||
let seen = Rc::clone(&shown);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let column = Column::new(vec![Group::new(vec![0, 1], 0)]);
|
||||
let mut open = Some(0_u8);
|
||||
IconicColumn::new("Panels", global("iconic column", "docked flyout"), &column, Bind::bound(&mut open), &spec).framed(framed).show_flyouts(
|
||||
ui,
|
||||
|_, at, ui, _| {
|
||||
let GroupAt::Show(rect) = at else { return None };
|
||||
seen.set(Some(rect));
|
||||
Panel::new("Flyout").show_at(ui, rect, |_, _| ());
|
||||
None
|
||||
},
|
||||
);
|
||||
});
|
||||
fixture.room(Vec2::new(RAIL, 300.0)).settle();
|
||||
let body = shown.get().expect("the flyout shows");
|
||||
fixture
|
||||
.frame_shapes()
|
||||
.into_iter()
|
||||
.filter_map(|shape| match shape {
|
||||
egui::Shape::Rect(rect) if rect.rect.expand(EPS).contains_rect(body) && rect.rect.width() < body.width() + RAIL => Some(rect),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The flyout of a flush dock's column (`DockConfig::flush_docks`, VectorCraft's) stands as a docked column does:
|
||||
/// square, with no shadow; a column of another dock opens a raised popup with rounded corners.
|
||||
#[trial]
|
||||
fn a_flush_docks_flyout_stands_square_with_no_shadow() {
|
||||
let raised = flyout_surfaces(false);
|
||||
assert!(raised.iter().any(|rect| rect.corner_radius != egui::CornerRadius::ZERO), "the popup flyout is rounded: {raised:?}");
|
||||
let docked = flyout_surfaces(true);
|
||||
assert!(!docked.is_empty(), "the docked flyout paints its surface");
|
||||
for rect in &docked {
|
||||
assert_eq!(rect.corner_radius, egui::CornerRadius::ZERO, "the docked flyout's surface is square: {rect:?}");
|
||||
assert!(rect.blur_width <= 0.0, "the docked flyout casts no shadow: {rect:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user