mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 20:23:38 +00:00
Layers: small touching lock buttons, small filter toggles, typed thumbnail badges
The Lock row's five buttons are small (ControlSize::Sm) and touch, as Photoshop's, so Fill and its field stay on the row at a panel's width instead of wrapping below it. The Kind filter toggles are small too. LayerInfo::thumb_badge is a ThumbBadge (SmartObject, Shape) that craft-layers paints: a window glyph, or a path with an anchor on each corner. Kind and mask badges share one badge box, a field well at the small icon size in the thumbnail's corner.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
mod stories;
|
||||
|
||||
use craft_behavior::{EditEvent, IconId, Mixed, SelectionChange};
|
||||
use craft_theme::LabelColor;
|
||||
use craft_theme::{ControlSize, LabelColor};
|
||||
use craft_ui::buttons::ToggleButton;
|
||||
use craft_ui::contract::{Bind, Entry, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, Sizing};
|
||||
use craft_ui::layout_components::Row;
|
||||
@@ -793,13 +793,17 @@ const fn smart_salt(kind: SmartKind) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// One icon toggle button per `(value, icon, name)`, pressed while `on` holds the value; a toggle
|
||||
/// One small icon toggle button per `(value, icon, name)`, pressed while `on` holds the value; a toggle
|
||||
/// adds the value to `on` or takes it out.
|
||||
fn toggles<K: Copy + PartialEq>(ui: &mut Ui, buttons: &[(K, &'static str, &Label)], salt: fn(K) -> &'static str, on: &mut Vec<K>) {
|
||||
let shown = on.clone();
|
||||
for &(value, icon, name) in buttons {
|
||||
let toggled =
|
||||
ToggleButton::new(name.clone(), Bind::given(shown.contains(&value))).icon(IconId::new(icon)).icon_only().id_salt(salt(value)).show(ui);
|
||||
let toggled = ToggleButton::new(name.clone(), Bind::given(shown.contains(&value)))
|
||||
.icon(IconId::new(icon))
|
||||
.icon_only()
|
||||
.size(ControlSize::Sm)
|
||||
.id_salt(salt(value))
|
||||
.show(ui);
|
||||
match toggled.value() {
|
||||
Some(true) => on.push(value),
|
||||
Some(false) => on.retain(|held| *held != value),
|
||||
|
||||
@@ -9,9 +9,8 @@ use super::filter::{EffectKind, FilterBy, LayerAttribute, LayerFilter, SmartKind
|
||||
use super::tree::LayerRowKey;
|
||||
use super::tree::{
|
||||
LayerInfo, LayerKind, LayerLocks, LayerPart, LayerProperties, LayerSelection, LayerTree, LayersFooterState, MaskInfo, SubRow, SubRowGroup,
|
||||
SubRows,
|
||||
SubRows, ThumbBadge,
|
||||
};
|
||||
use craft_behavior::IconId;
|
||||
|
||||
/// One layer of a [`FakeLayers`] tree.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -179,7 +178,7 @@ impl FakeLayers {
|
||||
}),
|
||||
false,
|
||||
);
|
||||
tree.add(None, named("Rectangle 1", LayerKind::Shape, |_| {}), false);
|
||||
tree.add(None, named("Rectangle 1", LayerKind::Shape, |i| i.thumb_badge = Some(ThumbBadge::Shape)), false);
|
||||
tree.add(None, named("Ellipse 1", LayerKind::Shape, |i| i.locks.position = true), false);
|
||||
tree.add(
|
||||
None,
|
||||
@@ -275,7 +274,7 @@ impl FakeLayers {
|
||||
Some(board),
|
||||
named("Photo", LayerKind::SmartObject, |i| {
|
||||
i.has_smart_filters = true;
|
||||
i.thumb_badge = Some(IconId::new("app_window"));
|
||||
i.thumb_badge = Some(ThumbBadge::SmartObject);
|
||||
}),
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -11,14 +11,14 @@ use craft_ui::primitives::{ContentPainterCx, IconSpec};
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::style::{Corners, DataColor, SurfaceKind};
|
||||
use egui::emath::GuiRounding as _;
|
||||
use egui::{Color32, Rect, Stroke, pos2, vec2};
|
||||
use egui::{Color32, Rect, Stroke, StrokeKind, pos2, vec2};
|
||||
|
||||
use super::LayersPanelWords;
|
||||
use super::body::thumb_click_replaces_select;
|
||||
use super::context::{PanelContext, ThumbHost};
|
||||
use super::drag::LayersDrag;
|
||||
use crate::ui::thumbs::LayerThumb;
|
||||
use crate::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerTree, MaskInfo, SubRowGroup};
|
||||
use crate::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerTree, MaskInfo, SubRowGroup, ThumbBadge};
|
||||
|
||||
/// The eye column.
|
||||
pub(super) const EYE: ColumnKey = ColumnKey::new("eye");
|
||||
@@ -41,6 +41,8 @@ const DISABLED_MASK: LabelColor = LabelColor::Red;
|
||||
const CROSS_INSET_SHARE: f32 = 0.12;
|
||||
const MARK_WIDTH_SHARE: f32 = 0.06;
|
||||
const BADGE_GLYPH_SHARE: f32 = 0.28;
|
||||
/// The side of a shape badge's anchor point, as a share of the badge.
|
||||
const ANCHOR_SHARE: f32 = 0.25;
|
||||
/// The kind glyph's share of the tile's shorter side.
|
||||
const KIND_GLYPH_SHARE: f32 = 0.64;
|
||||
/// A type layer's tile is ink on paper, the same in every theme, as the checkerboard is.
|
||||
@@ -186,20 +188,36 @@ fn paint_kind_tile(painter: &ContentPainterCx<'_>, rect: Rect, kind: LayerKind)
|
||||
}
|
||||
}
|
||||
|
||||
/// The square in the bottom corner of the thumbnail `rect` that a badge fills: the small icon size, the least that
|
||||
/// still reads, within the thumbnail.
|
||||
fn badge_area(painter: &ContentPainterCx<'_>, rect: Rect) -> Rect {
|
||||
/// The badge box in the bottom corner of the thumbnail `rect`, painted as a field well at the small icon size (the
|
||||
/// least that still reads, within the thumbnail); returns the box and the ink its mark draws in. The kind badges and
|
||||
/// the mask badges share it.
|
||||
fn badge_box(painter: &ContentPainterCx<'_>, rect: Rect) -> (Rect, Color32) {
|
||||
let badge = painter.style_cx().tokens.size.icon.sm.min(rect.width().min(rect.height()));
|
||||
Rect::from_min_size(pos2(rect.right() - badge, rect.bottom() - badge), vec2(badge, badge))
|
||||
let area = Rect::from_min_size(pos2(rect.right() - badge, rect.bottom() - badge), vec2(badge, badge));
|
||||
painter.surface(area, SurfaceKind::Well, Corners::All);
|
||||
(area, painter.ink_on(SurfaceKind::Well))
|
||||
}
|
||||
|
||||
/// The app's badge on a layer thumbnail: its icon at the small glyph size on the scrim.
|
||||
fn paint_thumb_badge(painter: &ContentPainterCx<'_>, rect: Rect, icon: IconId) {
|
||||
let area = badge_area(painter, rect);
|
||||
painter.surface(area, SurfaceKind::Scrim, Corners::None);
|
||||
let side = painter.style_cx().tokens.size.icon.glyph_sm.min(area.width());
|
||||
let glyph = Rect::from_center_size(area.center(), vec2(side, side));
|
||||
painter.icon(glyph, &IconSpec::svg(icon).ink(SurfaceKind::Scrim.ink()));
|
||||
/// The app's badge on a layer thumbnail: a window glyph for a smart object, or for a shape layer a path with an
|
||||
/// anchor point on each corner, painted so the anchors stay solid squares at this size.
|
||||
fn paint_thumb_badge(painter: &ContentPainterCx<'_>, rect: Rect, mark: ThumbBadge) {
|
||||
let (area, ink) = badge_box(painter, rect);
|
||||
let badge = area.width();
|
||||
match mark {
|
||||
ThumbBadge::SmartObject => {
|
||||
let side = painter.style_cx().tokens.size.icon.glyph_sm.min(badge);
|
||||
let glyph = Rect::from_center_size(area.center(), vec2(side, side));
|
||||
painter.icon(glyph, &IconSpec::svg(IconId::new("app_window")).ink(SurfaceKind::Well.ink()));
|
||||
}
|
||||
ThumbBadge::Shape => {
|
||||
let path = area.shrink(badge * CROSS_INSET_SHARE * 2.0);
|
||||
painter.painter.rect_stroke(path, 0.0, Stroke::new(badge * MARK_WIDTH_SHARE * 2.0, ink), StrokeKind::Middle);
|
||||
let anchor = vec2(badge * ANCHOR_SHARE, badge * ANCHOR_SHARE);
|
||||
for corner in [path.left_top(), path.right_top(), path.right_bottom(), path.left_bottom()] {
|
||||
painter.painter.rect_filled(Rect::from_center_size(corner, anchor), 0.0, ink);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The cross of a disabled mask and the badge that names a layer or vector mask.
|
||||
@@ -212,10 +230,8 @@ fn paint_mask_marks(painter: &ContentPainterCx<'_>, rect: Rect, mask: &MaskInfo,
|
||||
painter.painter.line_segment([inner.right_top(), inner.left_bottom()], stroke);
|
||||
}
|
||||
if badges {
|
||||
let area = badge_area(painter, rect);
|
||||
let (area, ink) = badge_box(painter, rect);
|
||||
let badge = area.width();
|
||||
painter.surface(area, SurfaceKind::Scrim, Corners::None);
|
||||
let ink = painter.ink_on(SurfaceKind::Scrim);
|
||||
let glyph = Stroke::new(badge * MARK_WIDTH_SHARE * 2.0, ink);
|
||||
if mask.part == LayerPart::VectorMask {
|
||||
let inset = area.shrink(badge * CROSS_INSET_SHARE * 2.0);
|
||||
@@ -254,13 +270,13 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
|
||||
if size != ThumbSize::None && !compact {
|
||||
let host = cx.thumbs;
|
||||
let (layer, kind, badge) = (id.clone(), info.kind, info.thumb_badge.clone());
|
||||
let (layer, kind, badge) = (id.clone(), info.kind, info.thumb_badge);
|
||||
row = row.thumb(size, move |painter, rect| {
|
||||
if !paint_picture(host, &LayerThumb::pixels(layer, contents), painter, rect, &PicturePaint::default()) {
|
||||
paint_kind_tile(painter, rect, kind);
|
||||
}
|
||||
if let Some(icon) = badge {
|
||||
paint_thumb_badge(painter, rect, icon);
|
||||
if let Some(mark) = badge {
|
||||
paint_thumb_badge(painter, rect, mark);
|
||||
}
|
||||
});
|
||||
let frame = info.kind == LayerKind::Frame;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
mod stories;
|
||||
|
||||
use craft_behavior::{EditEvent, EditEvents, IconId};
|
||||
use craft_theme::ControlSize;
|
||||
use craft_ui::buttons::ToggleButton;
|
||||
use craft_ui::contract::{Bind, Entry, Gap, NoValue, Outcome, Props as _, RowAlign, Show as _, ShowContainer as _, SideLabel, Sizing, TooltipSpec};
|
||||
use craft_ui::form::Field;
|
||||
@@ -74,7 +75,7 @@ craft_ui::words! {
|
||||
/// - **Row 1**: the blend [`Select`] with `blend_modes` and their separators, then Opacity as a
|
||||
/// percent field with its pop-up slider. A wheel notch over the closed select steps one mode;
|
||||
/// hovering a mode in the open list proposes it (`LayerPropertyEdit::Blend` with an `Update`).
|
||||
/// - **Row 2** (with [`locks`](Self::locks)): five toggle buttons in [`LockKind::ALL`] order beside
|
||||
/// - **Row 2** (with [`locks`](Self::locks)): five small toggle buttons that touch, in [`LockKind::ALL`] order beside
|
||||
/// their "Lock" caption, then Fill as Opacity's field. Lock image pixels disables Lock transparent pixels. Lock
|
||||
/// all shows the other four on and disabled.
|
||||
/// - **Caption**: a drag on the "Opacity" or "Fill" caption scrubs its field.
|
||||
@@ -154,7 +155,8 @@ impl<'a> BlendRows<'a> {
|
||||
Row::new().fill_width().align(RowAlign::SpaceBetween).gap(Gap::Section).show(ui, |ui, _| {
|
||||
// The lock buttons' side label: it names the group, and each button keeps its own name.
|
||||
Field::new(words.lock.clone()).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
// Small buttons that touch, as Photoshop's: the five fit beside Fill in a panel's width.
|
||||
Row::new().gap(Gap::None).show(ui, |ui, _| {
|
||||
let names = [&words.lock_transparency, &words.lock_pixels, &words.lock_position, &words.lock_artboard, &words.lock_all];
|
||||
let icons = ["grid", "brush", "move", "scan", "lock"];
|
||||
for ((kind, name), icon) in LockKind::ALL.into_iter().zip(names).zip(icons) {
|
||||
@@ -171,6 +173,7 @@ impl<'a> BlendRows<'a> {
|
||||
let button = ToggleButton::new(name.clone(), Bind::given(held.get(kind) || included))
|
||||
.icon(IconId::new(icon))
|
||||
.icon_only()
|
||||
.size(ControlSize::Sm)
|
||||
.enabled(live && reason.is_none())
|
||||
.tooltip(TooltipSpec::new(name).disabled_text(reason.map_or_else(|| no_layer.clone(), |reason| reason.clone())))
|
||||
.show(ui);
|
||||
|
||||
@@ -170,9 +170,9 @@ pub struct LayerInfo {
|
||||
/// Whether Cmd/Ctrl-click on the layer thumbnail loads it as a selection; false for the
|
||||
/// Background, where Cmd-click is a plain click.
|
||||
pub thumb_loads_selection: bool,
|
||||
/// A badge in the layer thumbnail's corner on the scrim, as the mask badges: PhotoCraft's smart
|
||||
/// object and shape marks. The app names it in [`description`](Self::description).
|
||||
pub thumb_badge: Option<IconId>,
|
||||
/// The mark in the layer thumbnail's corner that tells a smart object or a shape layer from a
|
||||
/// pixel layer, whose pictures look alike; the app picks which layers carry one.
|
||||
pub thumb_badge: Option<ThumbBadge>,
|
||||
/// The app's own words, added to the row's description for a screen reader.
|
||||
pub description: Option<String>,
|
||||
}
|
||||
@@ -238,6 +238,17 @@ impl LayerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// The mark in a layer thumbnail's corner ([`LayerInfo::thumb_badge`]), in the badge box the mask
|
||||
/// badges use.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum ThumbBadge {
|
||||
/// A smart object: a window glyph.
|
||||
SmartObject,
|
||||
/// A shape layer: a path with an anchor point on each corner, as Photoshop's.
|
||||
Shape,
|
||||
}
|
||||
|
||||
/// What a layer is.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
|
||||
Reference in New Issue
Block a user