Merge remote-tracking branch 'origin/next' into fix/next-reds

This commit is contained in:
Martin Ball
2026-11-25 12:48:25 +00:00
12 changed files with 153 additions and 24 deletions
@@ -810,8 +810,9 @@ impl BodyHooks<'_> {
// areas cover its ends and top edge, and a cursor set over them fights the OS's.
let moved = os.or(moves_window.then(|| pass::current_viewport(&ctx)));
let os_bar = moved.is_some_and(|viewport| windows::shell_of(&ctx, viewport).window.chrome == WindowChrome::Inset);
let hand = pcx.env.get::<crate::contract::MoveBandCursor>() == crate::contract::MoveBandCursor::Hand;
let mut part = pcx.part(MOVE_BAND, band).sense(craft_behavior::Sense::DRAG).pointer_only(reason);
if !os_bar {
if !os_bar && hand {
part = part.cursor(CursorIcon::Grab).drag_cursor(CursorIcon::Grabbing);
}
if let Some(hit) = exclusive(WindowHit::Move).or(moves_window.then_some(WindowHit::Move)) {
@@ -337,6 +337,20 @@ pub enum QuietHeader {
Heads,
}
/// The cursor over a header's move band ([`DragBand::Move`]). An app sets it once at its root (`RootEnv::values`); the
/// default is `Hand`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
#[env(style)]
#[non_exhaustive]
pub enum MoveBandCursor {
/// The open hand, and the closed hand while the band is dragged.
#[default]
Hand,
/// The arrow, as an OS title bar shows, also over the click-only controls on the band (menu titles, buttons):
/// production VectorCraft's title bar and panel headers.
Arrow,
}
/// A header region, filled by `Container::header`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
+2 -2
View File
@@ -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, QuietHeader, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, SectionRhythm,
ShellPane, Sizing, ThemeScope, WrapWidth,
LeastWidth, Mount, MoveBandCursor, 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};
+2 -2
View File
@@ -211,9 +211,9 @@ fn page_templates() -> Vec<Template> {
/// The links of the Column stories: a call to action and two plain links.
fn column_links() -> [StartLink; 3] {
[
StartLink::url("Join the community", Some(IconId::new("message-circle")), "https://example.com/chat").primary(),
StartLink::url("Join the community", Some(IconId::new("note")), "https://example.com/chat").primary(),
StartLink::url("Website", Some(IconId::new("globe")), "https://example.com"),
StartLink::url("Source code", Some(IconId::new("git-branch")), "https://example.com/source"),
StartLink::url("Source code", Some(IconId::new("open")), "https://example.com/source"),
]
}
@@ -388,6 +388,42 @@ fn whole_bar(_: &mut WholeBar, ui: &mut Ui) {
);
}
/// The cursor over the File title and over the band of the whole bar in a window, with the band's cursor `look`.
fn cursors_over_the_bar(look: craft_ui::contract::MoveBandCursor) -> (Option<craft_behavior::Cursor>, Option<craft_behavior::Cursor>) {
let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] };
let frame = Frame::Integrated(Captions { family: CaptionFamily::Windows, layout });
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
let windows = Windows::with(InstallSpec::new(ShellInfo::default(), Arc::new(NoWindows)).frame(Decision { frame, overridden: None, desktop }));
let mut root = craft_ui::runtime::env::RootEnv::default();
root.values.set(look);
windows.root_env(root);
let show = |ui: &mut Ui| whole_bar(&mut WholeBar { version: 0 }, ui);
windows.frame(vec![], vec![], show);
let settled = windows.frame(vec![], vec![], show);
let tree = &settled.trees.iter().rev().find(|(viewport, _)| *viewport == ViewportId::ROOT).expect("the root pass ran").1;
let title = |name: &str| {
tree.with_role(Role::MENU_ITEM).into_iter().find(|key| tree.name_of(*key) == Some(name)).and_then(|key| tree.bounds_of(key)).expect("a title")
};
let (file, help) = (title("File"), title("Help"));
let over = |at: Pos2| {
windows.frame(vec![moved(at)], vec![], show);
windows.frame(vec![], vec![], show);
craft_ui::runtime::cursor::current(&windows.ctx)
};
(over(file.center()), over(Pos2::new(help.right() + 40.0, help.center().y)))
}
/// A title bar's move band shows the open hand by default, also through the menu titles on it, which sense clicks
/// only; under `MoveBandCursor::Arrow` the band and the titles show the arrow, as an OS title bar does.
#[trial]
fn a_move_band_shows_the_arrow_when_the_app_asks() {
use craft_behavior::{Cursor, CursorIcon};
use craft_ui::contract::MoveBandCursor;
let grab = Some(Cursor::System(CursorIcon::Grab));
assert_eq!(cursors_over_the_bar(MoveBandCursor::Hand), (grab.clone(), grab), "the hand over the band and the titles on it");
assert_eq!(cursors_over_the_bar(MoveBandCursor::Arrow), (None, None), "the arrow over the band and the titles on it");
}
/// A whole title bar an app shows through a memoized view in the shell's title slot (1600 × 1000 px at 125 %) fills
/// the slot as the bar shown directly does: the captions end at the slot's end edge and the document title is drawn
/// whole after the last menu.
+35 -11
View File
@@ -37,7 +37,7 @@ use crate::runtime::env::{EnvView, Label};
use crate::runtime::focus::{self, FocusTarget};
use crate::runtime::memory::{Facts, Remember as _};
use crate::runtime::words::common::CommonWords;
use crate::style::{ComponentStyle, FocusLook, IconLook, StyleCx, SurfaceLook, TextLook, TypeRole};
use crate::style::{ComponentStyle, FocusLook, IconLook, StyleCx, SurfaceLook, TextLook, TypeRole, UiTokens};
use crate::text::TextField;
use craft_behavior::fit::{FitItem, FitKeep, fit_items};
use craft_behavior::{Arrows, Flow, Intent, Metrics, NavMove, NavShape, PartKey, PartRef, Proposal, Roving, Sense};
@@ -63,6 +63,19 @@ pub enum MenuTitlePad {
Control,
}
/// How a menu bar's titles stand. An app sets it once at its root (`RootEnv::values`); the default is a menu row's.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
#[env(style)]
#[non_exhaustive]
pub enum MenuTitleLook {
/// A menu row's: square corners, a control high, [`MenuTitlePad`] beside the text.
#[default]
Row,
/// A bare push button's, as egui's menu bar draws its titles: a push button high with the button's corners
/// (`radius.button`) and `space.gap.tight` beside the text, the titles `space.pad.control` apart.
Button,
}
/// The style of a title's face: a menu row's surface and ink (flat, square corners, no border), with the command
/// highlight (`CommandHighlight`) under the pointer and while its menu is open or the keyboard is on it.
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
@@ -114,15 +127,14 @@ impl Component for TitleFace {
let surface = cx.command_row_look();
let ink = cx.command_row_ink(tokens.color.text.normal);
let control = cx.control();
let (surface, pad, height) = match (cx.env::<MenuTitleLook>(), cx.env::<MenuTitlePad>()) {
(MenuTitleLook::Button, _) => (surface.radius(UiTokens::corner(tokens.shape.radius.button)), tokens.space.gap.tight, cx.button_height()),
(MenuTitleLook::Row, MenuTitlePad::Regular) => (surface, tokens.space.pad.regular, control.height),
(MenuTitleLook::Row, MenuTitlePad::Control) => (surface, tokens.space.pad.control, control.height),
};
TitleFaceStyle {
surface,
metrics: Metrics::new()
.padding(craft_behavior::Insets::horizontal(match cx.env::<MenuTitlePad>() {
MenuTitlePad::Regular => tokens.space.pad.regular,
MenuTitlePad::Control => tokens.space.pad.control,
}))
.min_size(Vec2::new(0.0, control.height))
.gap(control.gap),
metrics: Metrics::new().padding(craft_behavior::Insets::horizontal(pad)).min_size(Vec2::new(0.0, height)).gap(control.gap),
focus: cx.focus_look(),
text: TextLook::new(TypeRole::Label, ink.clone()),
icon: IconLook::new(control.icon, ink),
@@ -387,13 +399,23 @@ impl<'a> MenuBar<'a> {
if shown == 0 { words.bar_all.as_str().to_owned() } else { words.bar_more.as_str().to_owned() }
}
/// Each title's width as its face measures, the face height, and the width of the "…" title.
/// Each title's width as its face measures, the face height, and the width of the "…" title, each with the gap
/// after it ([`Self::gap`]).
fn widths(&self, cx: &MeasureCx<'_, Self>) -> (Vec<f32>, f32, f32) {
let texts = self.texts(&cx.env);
let gap = Self::gap(cx);
let sizes: Vec<Vec2> = texts.iter().map(|(text, _)| cx.face(Self::face(text, false, None))).collect();
let more = cx.face(Self::face(&Self::more_text(&cx.env.words::<MenuWords>(), 1), false, None));
let height = sizes.iter().map(|size| size.y).fold(more.y, f32::max);
(sizes.iter().map(|size| size.x).collect(), height, more.x)
(sizes.iter().map(|size| size.x + gap).collect(), height, more.x + gap)
}
/// The room after each title: `space.pad.control` between titles that stand as buttons, none between rows.
fn gap(cx: &MeasureCx<'_, Self>) -> f32 {
match cx.env.get::<MenuTitleLook>() {
MenuTitleLook::Button => cx.tokens.space.pad.control,
MenuTitleLook::Row => 0.0,
}
}
fn slot_part(open: Open) -> PartRef {
@@ -500,14 +522,16 @@ impl Component for MenuBar<'_> {
}
let (widths, _, more) = self.widths(cx);
let fit = fit_titles(&widths, more, rect.width());
let gap = Self::gap(cx);
let mut flow = Flow::new(rect, cx.flow.is_rtl());
for (at, width) in widths.iter().take(fit.shown).enumerate() {
let (cell, rest) = flow.take_start(*width);
flow = rest;
let cell = Flow::new(cell, cx.flow.is_rtl()).take_start(width - gap).0;
cx.part(TITLE.at(at as u64), cell).sense(Sense::CLICK | Sense::FOCUS).focusable().toggles_at("menu", at);
}
if fit.overflow {
let (cell, _) = flow.take_start(more);
let cell = flow.take_start(more - gap).0;
cx.part(MORE, cell).sense(Sense::CLICK | Sense::FOCUS).focusable().toggles_at("menu", fit.shown);
}
cx.roving(Roving::new(NavShape::Flat).arrows(Arrows::Horizontal));
+16 -1
View File
@@ -1,6 +1,6 @@
//! Stories of the menu bar, the edit menu and the panel menu.
use super::{MenuBar, MenuHelp, MenuTitle, MenuTitlePad};
use super::{MenuBar, MenuHelp, MenuTitle, MenuTitleLook, MenuTitlePad};
use crate::buttons::{IconButton, PopupMark};
use crate::contract::{Entry, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
use crate::display::Divider;
@@ -103,6 +103,21 @@ fn menu_bar_close_titles(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
.into()
}
/// Titles that stand as bare push buttons (`MenuTitleLook::Button`), a push button high with its corners and the tight
/// gap beside the text, as egui's menu bar draws them; the open File menu's title shows the hover tint.
#[story(MenuBar<'static>, covers = [], drive = Drive::Custom(open_file))]
fn menu_bar_button_titles(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
with_env(
ui,
|overrides| {
overrides.values.set(MenuTitleLook::Button);
overrides.values.set(CommandHighlight::Hover);
},
|ui| MenuBar::new("Main menu", titles()).show(ui),
)
.into()
}
/// The open File menu under `CommandHighlight::Hover`: the open title and the active row show the hover tint with
/// their own ink, as an app sets it at its root for a quiet command highlight.
#[story(MenuBar<'static>, covers = [], drive = Drive::Custom(open_file))]
+1 -1
View File
@@ -15,7 +15,7 @@ pub(crate) mod stories;
mod words;
pub use alternate::Alternate;
pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle, MenuTitlePad};
pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle, MenuTitleLook, MenuTitlePad};
pub(crate) use edit::text_menu;
pub use edit::{EditMenu, EditMenuOutput};
pub use icon_row::{MenuIcon, MenuIconRow, MenuIconRowOutput};
@@ -96,3 +96,19 @@ fn semibold_document_tabs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|ui| DocumentTabs::new("Documents", &tabs).selected(shown).reorderable(true).show(ui).response.into(),
)
}
/// VectorCraft's close buttons (`TabCloseLook::Glyph`): the × alone, a small muted glyph that turns to the text colour
/// under the pointer, with no fill.
#[story(DocumentTabs<'static, usize>, covers = [], drive = Drive::Never, title = "Close glyph")]
fn close_glyph_document_tabs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let tabs = [DocumentTab::new(0, "Untitled-1 @ 93.5 % (RGB/Preview)").modified(true).name_len(10), DocumentTab::new(1, "Poster.vectorcraft")];
let shown = *data.value("shown", 0_usize);
crate::runtime::env::with_env(
ui,
|overrides| {
overrides.values.set(crate::tabs::DocumentTabLook::Semibold);
overrides.values.set(crate::tabs::TabCloseLook::Glyph);
},
|ui| DocumentTabs::new("Documents", &tabs).selected(shown).show(ui).response.into(),
)
}
+1 -1
View File
@@ -6,7 +6,7 @@ mod words;
mod rules;
pub(crate) mod tab;
pub use rules::{CloseSide, DocumentTabLook, FitMode, OverflowMenu, OverflowPlace, PanelTabLook, TabKind, close_side};
pub use rules::{CloseSide, DocumentTabLook, FitMode, OverflowMenu, OverflowPlace, PanelTabLook, TabCloseLook, TabKind, close_side};
pub use tab::{Tab, TabOutput, TabPartEvent, TabRole, TabStyle};
pub use words::TabWords;
+14
View File
@@ -19,6 +19,20 @@ pub enum DocumentTabLook {
Semibold,
}
/// The look of a tab's close button app-wide. An app sets it once at its root (`RootEnv::values`); the default is
/// `Button`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
#[env(style)]
#[non_exhaustive]
pub enum TabCloseLook {
/// An icon button as tall as the tab's content, which the pointer fills.
#[default]
Button,
/// The × alone, a small icon (`size.icon.sm`) in the muted ink that turns to the text colour under the pointer, with
/// no fill; it takes clicks in a square of the button's width. Production VectorCraft's.
Glyph,
}
/// The look of panel tabs ([`TabKind::Panel`]): a strip's choice ([`TabStrip::panel_look`](super::TabStrip)), which a
/// dock makes for its groups' tabs.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::contract::MemoProps)]
+14 -5
View File
@@ -5,7 +5,7 @@
//! measure is its natural width (`Proposal::Min` the room for the first letters of its title beside its icon and close
//! button), and a narrower rect cuts the label first, then the detail, and shows the whole text as a tooltip.
use super::rules::{CloseSide, PanelTabLook, TabKind, close_side};
use super::rules::{CloseSide, PanelTabLook, TabCloseLook, TabKind, close_side};
use super::words::TabWords;
use std::borrow::Cow;
@@ -14,8 +14,8 @@ const MAX_NAME_DIGITS: usize = 22;
use crate::buttons::IconButton;
use crate::buttons::icon_button::{MarkerStyle, paint_marker};
use crate::contract::{
Access, Common, Component, Cx, ItemOutput, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Props as _, Role, SetPosition, Styled as _,
WordSetCx as _,
Access, Common, Component, Cx, ItemOutput, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Role, SetPosition,
Styled as _, WordSetCx as _,
};
use crate::display::Progress;
use crate::primitives::{IconSpec, PaintShape, RectSide, StrokeWidth, TextRun, Wrap};
@@ -136,6 +136,9 @@ pub struct TabStyle {
/// The pill a panel tab in [`PanelTabLook::Pill`] shows under its label in place of the surface.
pill: Option<Pill>,
close_side: CloseSide,
/// The close glyph's side and its ink at rest and under the pointer under [`TabCloseLook::Glyph`]; none for the icon
/// button.
close_glyph: Option<(f32, StyleColor, StyleColor)>,
sizes: Sizes,
/// Document tabs in [`DocumentTabLook::Shrinking`](super::DocumentTabLook::Shrinking): a name capped at
/// `MAX_NAME_DIGITS` digits' width, a readable prefix at their least, and the marker dot for a modified tab.
@@ -317,7 +320,8 @@ impl<'a> Tab<'a> {
if self.shows_close() {
let at_start = style.close_side == if rtl { CloseSide::Right } else { CloseSide::Left };
let (slot, rest) = if at_start { flow.take_start(sizes.close_box) } else { flow.take_end(sizes.close_box) };
close = Some(slot);
// The glyph takes clicks in a square of the button's width, not the content's whole height.
close = Some(if style.close_glyph.is_some() { Rect::from_center_size(slot.center(), Vec2::splat(sizes.close_box)) } else { slot });
flow = if at_start { rest.take_start(sizes.gap).1 } else { rest.take_end(sizes.gap).1 };
}
flow = flow.take_end(sizes.tail).1;
@@ -476,6 +480,7 @@ impl Component for Tab<'_> {
divider: key.kind.trailing_divider(),
pill,
close_side: close_side(cx.os, cx.direction.is_rtl()),
close_glyph: (cx.env::<TabCloseLook>() == TabCloseLook::Glyph).then(|| (size.icon.sm, c(colors.text.muted), c(colors.text.normal))),
sizes,
shrinking: key.kind.shrinks_in(cx.env::<super::DocumentTabLook>()),
strong: key.kind == TabKind::Document && cx.env::<super::DocumentTabLook>() == super::DocumentTabLook::Semibold,
@@ -635,7 +640,11 @@ impl Component for Tab<'_> {
}
ui.draw().icon(at, icon);
}
if placed.close.is_some() {
if let (Some(at), Some((side, rest, hover))) = (placed.close, style.close_glyph) {
let mut glyph = IconSpec::from(IconId::new("close"));
glyph.color = Some(if cx.hover_pos(CLOSE).is_some() { hover } else { rest });
ui.draw().icon(Rect::from_center_size(at.center(), Vec2::splat(side)), &glyph);
} else if placed.close.is_some() {
let words = cx.words::<TabWords>();
let name = match &self.close_label {
Some(name) => name.as_str().to_owned(),