buttons, dock: ActiveLook::Control shows an icon button or segment that is on in surface.control with no edge and the normal text; beside PanelTabLook::Block tabs a collapsed column's open panel icon takes it, as the shown tab does, and its flyouts' groups keep the active look around the column

This commit is contained in:
bflatastic
2026-11-25 11:34:03 +07:00
parent 9f1b8d6d20
commit cadd08b988
6 changed files with 104 additions and 14 deletions
+38 -8
View File
@@ -7,7 +7,7 @@ use super::dock_column::{
};
use super::group::{GripMarks, strip_surface};
use super::{CardInset, DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag};
use crate::buttons::IconButton;
use crate::buttons::{ActiveLook, IconButton};
use crate::contract::overlay::Anchor;
use crate::contract::{
Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, HeaderEdge, HeaderParts, HeaderRegion,
@@ -16,7 +16,7 @@ use crate::contract::{
};
use crate::menu::GroupItem;
use crate::primitives::{IconSpec, TextRun};
use crate::runtime::env::{EnvValue, Label};
use crate::runtime::env::{Env, EnvValue, Label, with_env};
use crate::runtime::focus::KeyUse;
use crate::style::{ComponentStyle, Corners, GlyphRole, RuleKind, StyleColor, StyleCx, SurfaceKind, SurfaceStyle};
use crate::tabs::PanelTabLook;
@@ -340,25 +340,55 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> {
/// Shows the column; `view` measures the group of an open flyout at the width it gets and returns its height
/// (`None` takes the flyout's least height), then shows it in the rect it gets.
pub fn show_flyouts(
mut self,
self,
ui: &mut Ui,
view: impl FnMut(&Group<P>, GroupAt, &mut Ui, &mut BodyCx<'_>) -> Option<f32> + 'a,
) -> IconicColumnOutput<P> {
self.view = Some(Box::new(view));
self.show(ui, |_, _| ()).output
self.in_look(ui, view, |column, ui| column.show(ui, |_, _| ()).output)
}
/// Shows the column at `rect` with no allocation, so its paint is clipped by the dock and not by a region of its
/// own: the accent line of its edge reaches into the gutter beside it.
#[doc(hidden)]
pub fn show_flyouts_at(
mut self,
self,
ui: &mut Ui,
rect: Rect,
view: impl FnMut(&Group<P>, GroupAt, &mut Ui, &mut BodyCx<'_>) -> Option<f32> + 'a,
) -> IconicColumnOutput<P> {
self.view = Some(Box::new(view));
self.show_at(ui, rect, |_, _| ()).output
self.in_look(ui, view, |column, ui| column.show_at(ui, rect, |_, _| ()).output)
}
/// Shows the column through `show` with its flyouts' `view`. Beside [`PanelTabLook::Block`] tabs the open panel's
/// icon shows on `surface.control`, as the shown tab does ([`ActiveLook::Control`]); the flyouts' groups keep the
/// active look around the column.
fn in_look(
mut self,
ui: &mut Ui,
mut view: impl FnMut(&Group<P>, GroupAt, &mut Ui, &mut BodyCx<'_>) -> Option<f32> + 'a,
show: impl FnOnce(Self, &mut Ui) -> IconicColumnOutput<P>,
) -> IconicColumnOutput<P> {
if self.tab_look != PanelTabLook::Block {
self.view = Some(Box::new(view));
return show(self, ui);
}
let outer = Env::of(ui).get::<ActiveLook>();
self.view = Some(Box::new(move |group, at, ui, body| {
with_env(
ui,
|overrides| {
overrides.values.set(outer);
},
|ui| view(group, at, ui, body),
)
}));
with_env(
ui,
|overrides| {
overrides.values.set(ActiveLook::Control);
},
|ui| show(self, ui),
)
}
/// Whether the column is a rail beside its expanded column: its chevron collapses the column.
@@ -8,6 +8,7 @@ use crate::docking::{ColumnBar, ColumnCards, DockSizes, GroupAt, IconGroupSepara
use crate::runtime::commands::{CommandState, CommandStates};
use crate::runtime::env::{Env, Message, with_env};
use crate::sections::Panel;
use crate::tabs::PanelTabLook;
use crate::testing::memory::global;
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, stage, story};
use craft_behavior::Mixed;
@@ -233,3 +234,22 @@ fn a_flyout_of_a_panel_not_in_the_column(ui: &mut Ui, data: &mut StoryData) -> S
};
flyout_of(ui, open_at.bind(open).check(in_column))
}
/// A column of VectorCraft 0.24's dock (`DockConfig::flush_docks`, `PanelTabLook::Block`): framed in `line.border`, its
/// bar on `surface.canvas`, the open panel's icon on `surface.control`, and its flyout square on the panel surface with
/// the same frame and no shadow. The flyout opens from its icon.
#[story(IconicColumn<'static, u8>, covers = [], drive = Drive::Custom(open_first_flyout), title = "A flush dock's column and its flyout")]
fn a_flush_docks_column_and_its_flyout(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let (open, open_at) = data.value_at("open", None::<u8>);
let column = Column::new(vec![Group::new(vec![0, 1], 0), Group::new(vec![2], 0)]);
let column = IconicColumn::new("Panels", global("iconic column", "flush story"), &column, open_at.bind(open), &spec)
.framed(true)
.tab_look(PanelTabLook::Block);
at_stage(ui, column, |group, at, ui, _| {
let GroupAt::Show(rect) = at else { return None };
let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned());
Panel::new(title).titled().show_at(ui, rect, |_, _| ());
None
})
.into()
}
@@ -18,6 +18,7 @@ use crate::runtime::focus::{FocusTarget, request};
use crate::runtime::frame::take_output;
use crate::sections::Panel;
use crate::style::StyleCx;
use crate::tabs::PanelTabLook;
use crate::testing::memory::global;
use crate::testing::relations::{equals_token, grows_with};
use crate::testing::{Fixture, trial};
@@ -771,3 +772,38 @@ fn a_flush_docks_flyout_stands_square_with_no_shadow() {
assert!(rect.blur_width <= 0.0, "the docked flyout casts no shadow: {rect:?}");
}
}
/// The fills painted on the open panel's icon of a column beside tabs in `look`, with the colour of `surface.control`.
fn open_icon_fills(look: PanelTabLook) -> (Vec<egui::Color32>, egui::Color32) {
let mut fixture = Fixture::hosted(move |ui| {
let column = Column::new(vec![Group::new(vec![0, 1], 0)]);
let mut open = Some(0_u8);
let output = IconicColumn::new("Panels", global("iconic column", "open icon"), &column, Bind::bound(&mut open), &spec)
.tab_look(look)
.show_flyouts_at(ui, Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, 300.0)), |_, _, _, _| None);
Some(output.into())
});
fixture.room(SCREEN).settle();
let id = fixture.root_id().expect("the column shows");
let cell = fixture.part_rect(id, CELL.at(0)).expect("the open panel's icon");
let control = StyleCx::with_root(fixture.ctx(), |cx| cx.tokens.color.surface.control).0;
let fills = fixture
.frame_shapes()
.into_iter()
.filter_map(|shape| match shape {
egui::Shape::Rect(rect) if cell.expand(EPS).contains_rect(rect.rect) && rect.fill != egui::Color32::TRANSPARENT => Some(rect.fill),
_ => None,
})
.collect();
(fills, egui::Color32::from_rgba_unmultiplied(control[0], control[1], control[2], control[3]))
}
/// Beside block tabs (`PanelTabLook::Block`, VectorCraft's) the open panel's icon shows on `surface.control`, as the
/// shown tab does; beside the other looks it keeps the accent's on look.
#[trial]
fn beside_block_tabs_the_open_icon_shows_on_the_control_surface() {
let (block, control) = open_icon_fills(PanelTabLook::Block);
assert!(block.contains(&control), "the open icon shows surface.control {control:?}: {block:?}");
let (plain, _) = open_icon_fills(PanelTabLook::Plain);
assert!(!plain.is_empty() && !plain.contains(&control), "beside plain tabs the open icon keeps its own fill: {plain:?}");
}
+5 -5
View File
@@ -398,7 +398,8 @@ pub(crate) struct IconFace {
pub(crate) fn icon_face(cx: &StyleCx<'_>) -> IconFace {
let on = match cx.env::<ActiveLook>() {
ActiveLook::Accent => on_parts(cx),
ActiveLook::Pressed => pressed_parts(cx),
ActiveLook::Pressed => filled_parts(cx, cx.tokens.color.state.pressed),
ActiveLook::Control => filled_parts(cx, cx.tokens.color.surface.control),
};
let off = cx.variant_look();
let (icon, text) = (&cx.tokens.size.icon, &cx.tokens.color.text);
@@ -430,11 +431,10 @@ pub(super) fn on_parts(cx: &StyleCx<'_>) -> VariantParts {
VariantParts { fill: Stateful::new(fill), text: Stateful::new(ink).off(States::new(ink, ink, ink, soft.text.off.disabled)), ..soft }
}
/// The on look under `ActiveLook::Pressed`: the pressed state's fill with no edge, the normal text colour.
fn pressed_parts(cx: &StyleCx<'_>) -> VariantParts {
/// The on look under `ActiveLook::Pressed` and `ActiveLook::Control`: `fill` with no edge, the normal text colour.
fn filled_parts(cx: &StyleCx<'_>, fill: craft_theme::Rgba) -> VariantParts {
let soft = on_parts(cx);
let colors = &cx.tokens.color;
let (fill, ink) = (cx.color(colors.state.pressed), cx.color(colors.text.normal));
let (fill, ink) = (cx.color(fill), cx.color(cx.tokens.color.text.normal));
VariantParts { fill: Stateful::new(fill), text: Stateful::new(ink).off(States::new(ink, ink, ink, soft.text.off.disabled)), edge: None, ..soft }
}
+3
View File
@@ -80,6 +80,9 @@ pub enum ActiveLook {
Accent,
/// The pressed state's fill with no edge, and the glyph in the normal text colour.
Pressed,
/// The `surface.control` fill with no edge, and the glyph in the normal text colour: the open panel's icon of a
/// dock in VectorCraft 0.24's block look (`PanelTabLook::Block`).
Control,
}
/// The look of a push or split button that asks for no variant. An app sets it once at its root (`RootEnv::values`);
+2 -1
View File
@@ -215,10 +215,11 @@ impl Component for Segment {
fn style(cx: &StyleCx<'_>, _: SegmentStyleKey) -> SegmentStyle {
let colors = &cx.tokens.color;
let c = |rgba| cx.color(rgba);
// The picked segment wears the look of an icon button that is on (`face::pressed_parts` under `Pressed`).
// The picked segment wears the look of an icon button that is on (`face::filled_parts` under `Pressed` and `Control`).
let (selected, selected_hover, on_ink) = match cx.env::<ActiveLook>() {
ActiveLook::Accent => (c(colors.state.selected), c(colors.state.selected_hover), c(colors.text.on_selected)),
ActiveLook::Pressed => (c(colors.state.pressed), c(colors.state.pressed), c(colors.text.normal)),
ActiveLook::Control => (c(colors.surface.control), c(colors.surface.control), c(colors.text.normal)),
};
let (clear, disabled) = (c(Rgba::TRANSPARENT), c(colors.state.disabled_fill));
let fill = cx.state_layer().on(States::new(selected, selected_hover, selected_hover, disabled));