From 7cb4ffd5141c1b48542e0e084e75f04092b8ce40 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 09:07:12 +0700 Subject: [PATCH] ui-contract, ui-panels panel: QuietHeader, a root style value; under QuietHeader::Heads a titled panel's quiet title (an inspector's kind line) heads its body as a rule would (HeaderRegion::heads, set by Panel::titled), so the first section under it draws no rule above it and sections after it keep theirs. QuietHeader::Ruled, the default, keeps today's rule above the first section, so no other app changes. Inspector story under Heads; trial --- .../ui-contract/src/contract/body/inherit.rs | 10 +++--- crates/ui-contract/src/contract/container.rs | 36 ++++++++++++++++++- crates/ui-contract/src/contract/mod.rs | 4 +-- crates/ui-panels/src/sections/panel.rs | 6 ++-- .../tests/it/sections/panel_header.rs | 32 +++++++++++++++++ .../src/patterns/panels/inspector/stories.rs | 27 +++++++++++++- 6 files changed, 105 insertions(+), 10 deletions(-) diff --git a/crates/ui-contract/src/contract/body/inherit.rs b/crates/ui-contract/src/contract/body/inherit.rs index c8494bf35..c16d15959 100644 --- a/crates/ui-contract/src/contract/body/inherit.rs +++ b/crates/ui-contract/src/contract/body/inherit.rs @@ -2,7 +2,7 @@ use super::BodyHooks; use super::reorder::REORDER_SCOPE; -use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, Scroll}; +use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, QuietHeader, Scroll}; use crate::runtime::commands::{self, CommandSet as _, WindowCommand}; use crate::runtime::env::{AppValues, ArenaId, Scoped, ScrollOwner}; use crate::style::{ComponentStyle as _, SurfaceKind}; @@ -113,9 +113,11 @@ impl BodyHooks<'_> { if props.arena { scoped.arena = Some(ArenaId::new(id)); } - // The body's flow starts after a rule when the container draws one under its header, or when the container - // draws nothing of its own (no header, surface or mount) and itself started after a rule. - scoped.after_rule = props.header.is_some_and(|header| header.rule && !header.inline) + // The body's flow starts after a rule when the container draws one under its header or its title heads the + // body as one would (`QuietHeader::Heads`), or when the container draws nothing of its own (no header, surface + // or mount) and itself started after a rule. + let heads = scoped.values.get::() == QuietHeader::Heads; + scoped.after_rule = props.header.is_some_and(|header| (header.rule || (header.heads && heads)) && !header.inline) || (props.header.is_none() && props.surface.is_none() && props.mount == Mount::Inline && self.after_rule); scoped.flow_body = None; scoped.column_row = diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 39148cc4f..cb3bef55f 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -321,6 +321,20 @@ pub enum SectionRhythm { Spaced, } +/// Whether a titled header that draws no rule under it (a quiet title, [`HeaderRegion::heads`]) still heads its body as +/// a rule would. An app sets it once at its root (`RootEnv::values`); the default is `Ruled`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum QuietHeader { + /// The body's first section draws its own rule above, as under no header. + #[default] + Ruled, + /// The header heads the body: its flow starts as after a rule, so the first section under the title draws no rule + /// above it and sections after it keep theirs. Production VectorCraft's kind line over its inspector's sections. + Heads, +} + /// A header region, filled by `Container::header`. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] @@ -332,6 +346,9 @@ pub struct HeaderRegion { /// Whether a rule separates the header from the body, in a band of its own between them. An inline header has no /// rule. pub rule: bool, + /// Whether the header is a title that heads the body as a rule would where the app asks for it + /// ([`QuietHeader::Heads`]), though it draws none. + pub heads: bool, /// Whether a rule runs across the container's width above the header, in a band of its own at the top edge. pub rule_above: bool, /// Whether the header shares a line with the body: the header at its measured width, the body in the rest. @@ -351,7 +368,17 @@ pub struct HeaderRegion { impl HeaderRegion { /// A header with no drag band, no rule, on its own line, with no trailing region, no fill and no inset. pub const fn new() -> Self { - HeaderRegion { band: DragBand::None, rule: false, rule_above: false, inline: false, trailing: false, fill: None, inset: Pad::None, gap: None } + HeaderRegion { + band: DragBand::None, + rule: false, + heads: false, + rule_above: false, + inline: false, + trailing: false, + fill: None, + inset: Pad::None, + gap: None, + } } /// The surface of a band behind the header. @@ -391,6 +418,13 @@ impl HeaderRegion { self } + /// Whether the header is a title that heads the body as a rule would where the app asks for it + /// ([`QuietHeader::Heads`]), though it draws none. + pub const fn heads(mut self, on: bool) -> Self { + self.heads = on; + self + } + /// Whether a rule runs above the header. pub const fn rule_above(mut self, on: bool) -> Self { self.rule_above = on; diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index ba740f9ee..0e2d9db94 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -69,8 +69,8 @@ pub use container::InBar; pub use container::InMenu; pub use container::{ BandFill, Bracket, Collapse, ContainerProps, DragBand, EndRegion, FooterPlace, FooterRegion, Gap, HeaderEdge, HeaderParts, HeaderRegion, - LeastWidth, Mount, Notch, POPUP_PAD, Pad, PadEdges, PaneEdge, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, SectionRhythm, ShellPane, - Sizing, ThemeScope, WrapWidth, + LeastWidth, Mount, Notch, POPUP_PAD, Pad, PadEdges, PaneEdge, QuietHeader, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, SectionRhythm, + ShellPane, Sizing, ThemeScope, WrapWidth, }; pub use craft_tracked::{PlainData, Revision, Tracked}; pub use craft_ui_macros::{CommandSet, Component, Pattern, PlainData, Props, register_contract}; diff --git a/crates/ui-panels/src/sections/panel.rs b/crates/ui-panels/src/sections/panel.rs index 2d27b2c03..16f330cc1 100644 --- a/crates/ui-panels/src/sections/panel.rs +++ b/crates/ui-panels/src/sections/panel.rs @@ -133,10 +133,12 @@ impl<'a> Panel<'a> { } /// A header showing the title in a title row, with a rule under it unless the title's weight is a quiet one - /// ([`strength`](Panel::strength)): for a panel that no dock tab or window names. + /// ([`strength`](Panel::strength)): for a panel that no dock tab or window names. Where the app's quiet titles head + /// their body ([`QuietHeader::Heads`](crate::contract::QuietHeader)), the first section under a quiet title draws + /// no rule above it. #[must_use] pub fn titled(mut self) -> Self { - self.props.header = Some(HeaderRegion::new().rule(self.strength.ruled())); + self.props.header = Some(HeaderRegion::new().rule(self.strength.ruled()).heads(true)); self } diff --git a/crates/ui-panels/tests/it/sections/panel_header.rs b/crates/ui-panels/tests/it/sections/panel_header.rs index 090b7c9da..90efd080f 100644 --- a/crates/ui-panels/tests/it/sections/panel_header.rs +++ b/crates/ui-panels/tests/it/sections/panel_header.rs @@ -70,3 +70,35 @@ fn panel_routes_unused_arrow_from_button_to_its_collection() { fixture.key(Key::ArrowDown, Modifiers::NONE).settle(); assert!(events.borrow().iter().any(|event| matches!(event, CollectionEvent::LeadMoved { .. })), "the list receives the move"); } + +/// An app whose quiet title heads its body (`QuietHeader::Heads`, VectorCraft's kind line) draws no rule between the +/// title and the first section, where the default keeps the section's rule; a second section still stands under its +/// rule. +#[trial] +fn the_first_section_under_a_heading_quiet_title_draws_no_rule() { + use craft_ui::contract::QuietHeader; + use craft_ui::sections::{HeaderStrength, Section}; + use egui::Shape; + let rules = |sections: &'static [&'static str], quiet: QuietHeader| { + let mut fixture = Fixture::new(move |ui| { + Panel::new("Properties").titled().strength(HeaderStrength::Quiet).show(ui, |ui, _| { + for title in sections { + Section::fixed(*title).show(ui, |ui, _| { + ui.label("body"); + }); + } + }); + }); + fixture.root_value(quiet).room(egui::Vec2::new(400.0, 300.0)).settle(); + fixture + .frame_shapes() + .iter() + .filter(|shape| !matches!(shape, Shape::Text(_))) + .map(Shape::visual_bounding_rect) + .filter(|rect| rect.is_finite() && rect.height() <= 2.0 && rect.width() >= 200.0) + .count() + }; + let one = rules(&["Transform"], QuietHeader::Heads); + assert!(one < rules(&["Transform"], QuietHeader::Ruled), "no rule between the heading title and the first section"); + assert!(rules(&["Transform", "Appearance"], QuietHeader::Heads) > one, "a section after another still stands under its rule"); +} diff --git a/crates/ui-patterns/src/patterns/panels/inspector/stories.rs b/crates/ui-patterns/src/patterns/panels/inspector/stories.rs index fb22c14c9..1b1a34a41 100644 --- a/crates/ui-patterns/src/patterns/panels/inspector/stories.rs +++ b/crates/ui-patterns/src/patterns/panels/inspector/stories.rs @@ -1,8 +1,9 @@ //! Stories of `Inspector`. use super::Inspector; -use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use crate::contract::{Bind, Props as _, QuietHeader, Show as _, ShowContainer as _}; use crate::primitives::IconSpec; +use crate::runtime::env::with_env; use crate::sections::{HeaderStrength, Section, SectionStack}; use crate::testing::{Drive, StoryData, StoryOutput, story}; use crate::value_drag::Slider; @@ -63,6 +64,30 @@ fn inspector_quiet_title(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .into() } +/// A quiet title in an app whose quiet titles head their body (`QuietHeader::Heads`): the first section under the kind +/// line draws no rule above it; the second keeps its rule. +#[story(Inspector<'static>, covers = [], drive = Drive::Never)] +fn inspector_quiet_title_heads(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + with_env( + ui, + |overrides| { + overrides.values.set(QuietHeader::Heads); + }, + |ui| { + let inspector = Inspector::new("Properties").target("ellipse").header("Ellipse").title_strength(HeaderStrength::Quiet); + inspector + .show(ui, |ui, _| { + for title in &TITLES[..2] { + Section::fixed(*title).show(ui, |ui, _| { + Slider::new(Bind::given(30.0), 0.0..=100.0).label("Opacity").show(ui); + }); + } + }) + .into() + }, + ) +} + #[story(Inspector<'static>, covers = [], drive = Drive::Never)] fn inspector_empty(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Inspector::new("Properties").show(ui, |_, _| {}).into()