mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
Panes: a container can rule the inner edge of the edge pane it sits in; the panel rail does
The env carries the window edge of the innermost edge pane, so the panel rail draws the old hairline on its canvas side whichever edge the shell docks it at, mirrored under right-to-left.
This commit is contained in:
@@ -4,8 +4,8 @@ use super::inherit::{BodyScope, register_instances};
|
||||
use super::open::open_now;
|
||||
use super::placement::{Placement, measure_layer, overlay_of, shown_placement};
|
||||
use super::regions::{
|
||||
RegionFrame, RegionSizes, footer_in_end, gap_of, header_gap_of, label_extra_of, least_of, pad_of, paint_rules, rect_of, shared_labels,
|
||||
shared_line,
|
||||
RegionFrame, RegionSizes, footer_in_end, gap_of, header_gap_of, label_extra_of, least_of, pad_of, paint_edge_rule, paint_rules, rect_of,
|
||||
shared_labels, shared_line,
|
||||
};
|
||||
use super::reorder::REORDER_BAND;
|
||||
use super::scroll::{Glide, Jumps, ScrollState, aim_glide, follow_anchor, jump_frame, overflow_inset, scroll_of};
|
||||
@@ -988,6 +988,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
ui.painter().set(band_slot, Shape::rect_filled(regions.header, radius, surface_style(&env.tokens, kind).fill));
|
||||
}
|
||||
paint_rules(ui, &props, env, inner, ®ions);
|
||||
paint_edge_rule(ui, &props, env, rect);
|
||||
}
|
||||
|
||||
fn settle(&mut self, comp: &mut C, cx: &mut Cx<'_, C>) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::BodyHooks;
|
||||
use super::reorder::REORDER_SCOPE;
|
||||
use crate::contract::{Container, ContainerProps, Cx, DragBand, Scroll, Sizing};
|
||||
use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, PaneEdge, Scroll, Sizing};
|
||||
use crate::runtime::commands::{self, CommandSet as _, WindowCommand};
|
||||
use crate::runtime::env::{AppValues, ArenaId, Scoped};
|
||||
use crate::style::{ComponentStyle as _, SurfaceKind};
|
||||
@@ -86,6 +86,11 @@ impl BodyHooks<'_> {
|
||||
scoped.arena = Some(ArenaId::new(id));
|
||||
}
|
||||
scoped.transform = props.transform;
|
||||
match &props.mount {
|
||||
Mount::Pane(pane) if pane.edge != PaneEdge::Center => scoped.pane_edge = Some(pane.edge),
|
||||
Mount::Inline => {}
|
||||
_ => scoped.pane_edge = None,
|
||||
}
|
||||
scoped.content_column = content_column;
|
||||
scoped.row_room = None;
|
||||
scoped.row_line = None;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::BodyHooks;
|
||||
use crate::contract::cx::BodyCx;
|
||||
use crate::contract::{Container, ContainerProps, FooterPlace, Gap, LeastWidth, Pad, Sizing};
|
||||
use crate::contract::{Container, ContainerProps, FooterPlace, Gap, LeastWidth, Pad, PaneEdge, Sizing};
|
||||
use crate::layout::ColumnGroup;
|
||||
use crate::primitives::Rule;
|
||||
use crate::runtime::access::{self};
|
||||
@@ -114,6 +114,25 @@ impl RegionFrame<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The divider along the inner edge of the edge pane that encloses a container with `edge_rule`, inside `rect`: the
|
||||
/// edge toward the window's centre, mirrored for a start or end pane under right-to-left.
|
||||
pub(super) fn paint_edge_rule(ui: &mut Ui, props: &ContainerProps, env: &Env, rect: Rect) {
|
||||
let Some(edge) = env.pane_edge.filter(|_| props.edge_rule) else { return };
|
||||
let rule = rule_look(&env.tokens, RuleKind::Divider);
|
||||
let half = rule.width / 2.0;
|
||||
let rtl = env.direction.is_rtl();
|
||||
let (from, to) = match edge {
|
||||
PaneEdge::Start if rtl => (Pos2::new(rect.min.x + half, rect.min.y), Pos2::new(rect.min.x + half, rect.max.y)),
|
||||
PaneEdge::Start => (Pos2::new(rect.max.x - half, rect.min.y), Pos2::new(rect.max.x - half, rect.max.y)),
|
||||
PaneEdge::End if rtl => (Pos2::new(rect.max.x - half, rect.min.y), Pos2::new(rect.max.x - half, rect.max.y)),
|
||||
PaneEdge::End => (Pos2::new(rect.min.x + half, rect.min.y), Pos2::new(rect.min.x + half, rect.max.y)),
|
||||
PaneEdge::Top => (Pos2::new(rect.min.x, rect.max.y - half), Pos2::new(rect.max.x, rect.max.y - half)),
|
||||
PaneEdge::Bottom => (Pos2::new(rect.min.x, rect.min.y + half), Pos2::new(rect.max.x, rect.min.y + half)),
|
||||
PaneEdge::Center => return,
|
||||
};
|
||||
ui.painter().extend(Rule::shapes(&rule, from, to, ui.ctx().pixels_per_point()));
|
||||
}
|
||||
|
||||
/// The divider rules above and under the header and above the footer.
|
||||
pub(super) fn paint_rules(ui: &mut Ui, props: &ContainerProps, env: &Env, inner: Rect, regions: &Regions) {
|
||||
let rule = rule_look(&env.tokens, RuleKind::Divider);
|
||||
|
||||
@@ -573,6 +573,9 @@ pub struct ContainerProps {
|
||||
pub body_gap: Gap,
|
||||
/// The least width of the content, from a size role; the content may be wider.
|
||||
pub least_width: Option<LeastWidth>,
|
||||
/// A divider along the inner edge of the edge pane the container sits in: the edge that faces the window's centre.
|
||||
/// Outside an edge pane it draws nothing.
|
||||
pub edge_rule: bool,
|
||||
/// A scope size for the body.
|
||||
pub child_size: Option<ControlSize>,
|
||||
/// The container is an arena root.
|
||||
@@ -654,6 +657,7 @@ impl ContainerProps {
|
||||
collapse: None,
|
||||
body_gap: Gap::Row,
|
||||
least_width: None,
|
||||
edge_rule: false,
|
||||
child_size: None,
|
||||
arena: false,
|
||||
gates: false,
|
||||
@@ -775,6 +779,12 @@ impl ContainerProps {
|
||||
self
|
||||
}
|
||||
|
||||
/// Draws a divider along the inner edge of the edge pane the container sits in.
|
||||
pub const fn edge_rule(mut self, on: bool) -> Self {
|
||||
self.edge_rule = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// A scope size for the body.
|
||||
pub const fn child_size(mut self, size: ControlSize) -> Self {
|
||||
self.child_size = Some(size);
|
||||
|
||||
@@ -136,6 +136,8 @@ pub struct Scoped {
|
||||
pub(crate) unbounded: (bool, bool),
|
||||
/// The view of the innermost scroll area, for the children that run only in view (`contract::Lazy`).
|
||||
pub(crate) lazy: Option<crate::runtime::lazy::View>,
|
||||
/// The window edge of the innermost edge pane that encloses the scope (`Mount::Pane`).
|
||||
pub(crate) pane_edge: Option<crate::contract::PaneEdge>,
|
||||
/// The id of the collection item the scope shows: its root is not a Tab stop (17.3).
|
||||
pub(crate) item: Option<Id>,
|
||||
/// The roving group of the collection row the scope shows: the stops of its components and parts join it, so
|
||||
@@ -363,6 +365,7 @@ impl Env {
|
||||
scroll_owner: None,
|
||||
unbounded: (false, false),
|
||||
lazy: None,
|
||||
pane_edge: None,
|
||||
item: None,
|
||||
row: None,
|
||||
item_facts: None,
|
||||
@@ -413,6 +416,7 @@ impl Env {
|
||||
s.wheel = WheelScope::Plain;
|
||||
s.unbounded = (false, false);
|
||||
s.lazy = None;
|
||||
s.pane_edge = None;
|
||||
s.item = None;
|
||||
s.row = None;
|
||||
s.item_facts = None;
|
||||
|
||||
@@ -58,7 +58,8 @@ impl<P: Value> Outcome for PanelRailOutput<P> {
|
||||
|
||||
type FooterFn<'a> = Box<dyn FnMut(&mut Ui) + 'a>;
|
||||
|
||||
/// The rail of icons that open panels, as a side panel at one edge of the window. A panel is a toggle command: its
|
||||
/// The rail of icons that open panels, as a side panel at one edge of the window, with a rule along the edge that faces
|
||||
/// the canvas (the inner edge of its pane). A panel is a toggle command: its
|
||||
/// label, icon, chord and enabled state come from the command, the icon shows the on look while the command is
|
||||
/// checked (the panel is open), and the command's `marked` state and `hint` tell that the closed panel has content
|
||||
/// to show. A click runs the command and reports the request that matches the panel's state. The icons are one
|
||||
@@ -87,7 +88,8 @@ impl<'a, P: Value + 'static> PanelRail<'a, P> {
|
||||
.child_size(ControlSize::Md)
|
||||
.roving(Roving::new(NavShape::Flat))
|
||||
.scroll(Scroll::vertical())
|
||||
.footer(FooterRegion::new());
|
||||
.footer(FooterRegion::new())
|
||||
.edge_rule(true);
|
||||
PanelRail { common: Common::new(), props, panels, footer: None }.label(label)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user