layers, menu, print, font-manager, color-ui: finish calls against the contract (Button popup props, imports, style derive, palette drag map)

This commit is contained in:
bflatastic committed 2026-11-21 21:51:15 +07:00
1 parent 37a598bd50
commit 02aeea721f
10 files changed
+31 -16

No files matched your search

-2
View File
@@ -30,10 +30,8 @@ pub struct ColorAreaStyle {
#[style(metrics)]
metrics: Metrics,
/// The fill of a cell the gamut moves (`surface.scrim`).
#[style(skip)]
scrim: StyleColor,
/// The marker look: its halo is the dark edge line and its ring the light one.
#[style(skip)]
marker: MarkerLook,
}
+1 -1
View File
@@ -17,7 +17,7 @@ use craft_theme::Srgba;
use craft_ui::buttons::Button;
use craft_ui::choice::{ChoiceWords, RING_SHARE, Segmented, Swatch, SwatchFace, SwatchStyle, paint_ring};
use craft_ui::contract::{
Access, Activation, Bind, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Entry, Outcome, Overlay, OverlayUi, Overlays as _, Pages,
Access, Activation, Bind, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Entry, Meta as _, Outcome, Overlay, OverlayUi, Overlays as _, Pages,
PaintUi, PartsCx, Pointer as _, PopupKind, Props as _, Remember as _, Role, Show as _, ShowContainer as _, WordSetCx as _,
};
use craft_ui::display::{Shade, Text};
+6 -3
View File
@@ -14,7 +14,7 @@ use std::sync::Arc;
mod stories;
/// The table's drag mapper, type-erased so the palette needs no payload parameter.
type TableMap<'a> = Arc<dyn Fn(SwatchTable<'a>) -> SwatchTable<'a> + 'a>;
type TableMap = Arc<dyn for<'t> Fn(SwatchTable<'t>) -> SwatchTable<'t>>;
/// What a [`SwatchPalette`] reports.
#[derive(Debug)]
@@ -53,7 +53,7 @@ pub struct SwatchPalette<'a> {
color: Bind<'a, Srgba>,
swatches: &'a [(Label, Srgba)],
spacing: SwatchSpacing,
drag: Option<TableMap<'a>>,
drag: Option<TableMap>,
}
impl<'a> SwatchPalette<'a> {
@@ -90,7 +90,10 @@ impl<'a> SwatchPalette<'a> {
let selected = swatches.iter().position(|(_, c)| c.to_rgba() == before.to_rgba());
let mut current = selected.map_or_else(Selection::default, Selection::single);
let table = SwatchTable::new(label.clone(), swatches).tips(true).wells(true).spacing(spacing).selection(Bind::bound(&mut current));
let table = drag.as_ref().map_or(table, |map| map(table));
let table = match &drag {
Some(map) => map(table),
None => table,
};
let table = table.show_all(ui);
let picked = table.selected.or(table.open)?;
let after = swatches.get(picked)?.1;
+1 -1
View File
@@ -53,7 +53,7 @@ fn color_wheel_square_gamut(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(ColorWheel<'static>, covers = [Mixed], drive = Drive::Never, title = "Square, mixed")]
fn color_wheel_square_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let values = data.value("mixed", craft_ui::contract::Mixed::<craft_theme::ModelValues>::Mixed);
let values = data.value("mixed", craft_behavior::Mixed::<craft_theme::ModelValues>::Mixed);
ColorWheel::new("Color wheel", Bind::bound_mixed(values)).inner(WheelInner::Square).show(ui).into()
}
+1 -1
View File
@@ -21,7 +21,7 @@ use craft_ui::pickers::Select;
use craft_ui::popover::Popover;
use craft_ui::primitives::ContentPainterCx;
use craft_ui::primitives::textures::{Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails};
use craft_ui::runtime::commands::{CommandSet as _, CommandState, Commands as _};
use craft_ui::runtime::commands::{CommandState, Commands as _};
use craft_ui::runtime::env::{Env, Label};
use craft_ui::style::{DataColor, SurfaceKind};
use craft_ui::tile_grid::{CaptionPlace, ThumbnailSlider, Tile, TileGrid, TilePartEvent, TileZoom};
+3 -3
View File
@@ -178,18 +178,18 @@ fn paint_picture<Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static>(
fn paint_kind_tile(painter: &ContentPainterCx<'_>, rect: Rect, kind: LayerKind, glyph: Option<IconId>) {
let rect = rect.round_to_pixels(painter.pixels_per_point());
let side = rect.width().min(rect.height()) * KIND_GLYPH_SHARE;
let glyph = Rect::from_center_size(rect.center(), vec2(side, side));
let at = Rect::from_center_size(rect.center(), vec2(side, side));
let icon = glyph.map(IconSpec::svg);
if kind == LayerKind::Text {
painter.painter.rect_filled(rect, 0.0, TYPE_PAPER);
if let Some(icon) = icon {
painter.icon(glyph, &icon.data_color(DataColor::new(TYPE_INK)));
painter.icon(at, &icon.data_color(DataColor::new(TYPE_INK)));
}
return;
}
painter.surface(rect, SurfaceKind::Sunken, Corners::None);
if let Some(icon) = icon {
painter.icon(glyph, &icon.ink(SurfaceKind::Sunken.ink()));
painter.icon(at, &icon.ink(SurfaceKind::Sunken.ink()));
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ use craft_keymap::{Binding, CommandDef, CommandRef, ImportPlan, ImportReport};
use craft_theme::variant::Tone;
use craft_ui::buttons::Button;
use craft_ui::choice::{Checkbox, Radio, RadioGroup};
use craft_ui::contract::{Bind, BodyCx, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
use craft_ui::contract::{Animate as _, Bind, BodyCx, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
use craft_ui::display::{Shade, Text};
use craft_ui::layout_components::{Row, Stack};
use craft_ui::notices::Notice;
+2 -2
View File
@@ -5,12 +5,12 @@ use std::sync::Arc;
use std::sync::mpsc::Receiver;
use craft_behavior::{
CursorIcon, EditEvent, EditEvents, IconId, Metrics, Mixed, PartKey, PointerButton, PressPhase, Sense, keyed,
CursorIcon, EditEvent, EditEvents, IconId, Metrics, Mixed, PartKey, PointerButton, PressPhase, Sense, Value, keyed,
};
use craft_ui::buttons::IconButton;
use craft_ui::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Pointer as _,
Props as _, Remember as _, Role, Show as _, ShowContainer as _, Validity, Value, WordSetCx as _, clicked,
Props as _, Remember as _, Role, Show as _, ShowContainer as _, Validity, WordSetCx as _, clicked,
};
use craft_ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldAnswer, HeldOk, HoldsOk, StackDialog, dialog_id};
use craft_ui::display::{Shade, Text};
@@ -58,7 +58,7 @@ mod new_document;
pub use new_document::{
BACKGROUND_COLOR_KEY, BackgroundContents, BitDepth, CardCx, CardSource, ColorMode, ColorProfiles, DetailsCx, DocumentCard, DocumentOptions,
DocumentPreset, DocumentSettings, HostedNewDocument, NewDocumentDialog, NewDocumentOutput, NewDocumentPresetWords, NewDocumentResult,
NewDocumentWords, Orientation, PIXEL_ASPECTS, PresetCategory, RasterSetup, SQUARE_PIXELS,
NewDocumentWords, Orientation, PIXEL_ASPECTS, PresetCategory, RasterMemory, RasterSetup, SQUARE_PIXELS,
};
mod about;
+15 -1
View File
@@ -2,7 +2,7 @@
use super::face::{self, FaceLook, FaceSpec};
use crate::contract::{
Access, Common, Component, Cx, LeastWidth, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props, Role, Styled as _, WordSetCx as _,
Access, Common, Component, Cx, LeastWidth, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, PopupKind, Props, Role, Styled as _, WordSetCx as _,
};
use crate::display::{ChordWrite, DisplayWords, Kbd, Spinner};
use crate::primitives::{HAlign, IconSpec, PaintShape};
@@ -180,6 +180,12 @@ pub struct Button<'a> {
/// Whether a command button shows its command's chord after the label.
#[prop]
chord: ButtonChord,
/// The kind of popup the button opens: AccessKit reports it.
#[prop(into)]
popup: Option<PopupKind>,
/// Whether the popup the button opens is open, as the host knows it.
#[prop(into)]
expanded: Option<bool>,
}
impl<'a> Button<'a> {
@@ -196,6 +202,8 @@ impl<'a> Button<'a> {
align: HAlign::Center,
detail: None,
chord: ButtonChord::Hidden,
popup: None,
expanded: None,
}
.label(label)
}
@@ -286,6 +294,12 @@ impl Component for Button<'_> {
{
access.description(detail);
}
if let Some(kind) = self.popup {
access.has_popup(kind);
}
if let Some(open) = self.expanded {
access.expanded(open);
}
}
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {