mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
panels-w11: written by an agent
This commit is contained in:
@@ -10,12 +10,12 @@ Fonts tab; the standalone app
|
||||
| `filter` | always | Search over the index: family names ignoring case and accents, category, language (English name, autonym or id) and script |
|
||||
| `index` | always | The pinned built-in indexes (Google Fonts and Noto) compiled into [`craft-font-store`](../font-store/README.md) (`bundled`), each family's source (`source_label`: its name and whether it is curated), and the categories |
|
||||
| `installed` | always | The installed fonts [`craft-font-catalog`](../font-catalog/README.md) sees, grouped by family and source |
|
||||
| `store` | always | `Installer`, what the interface needs from the font store: the download consent, install, remove, downloads for a preview, the indexes (`indexes`, `fetch_indexes`) and the sources the user added (`user_sources`, `add_user_source`, `remove_user_source`). `SuiteStore` is craft-font-store's store, `FakeStore` a stand-in for tests, `NoStore` one for when the store folder is unknown |
|
||||
| `store` | always | `Installer`, what the interface needs from the font store: the download consent, install, remove, downloads for a preview, the indexes (`indexes`, `fetch_indexes`) and the sources the user added (`user_sources`, `add_user_source`, `remove_user_source`). `SuiteStore` is craft-font-store's store (native only), `FakeStore` a stand-in for tests, `NoStore` one for when the store folder is unknown |
|
||||
| `FontsPanel` | `ui` | The whole interface as one egui panel |
|
||||
| `glyphs` | `ui` | `GlyphsPanel`: the character grid of a face with categories, zoom and Recently Used; the app supplies the glyphs through `GlyphSource`. Sizes are the `glyphs.*` tokens |
|
||||
| `glyphs` | `ui` | `GlyphsPanel`: the character grid of a face with categories, zoom and Recently Used; the app supplies the glyphs through `GlyphSource`, which also reports when it is ready and when its faces change. Sizes are the `glyphs.*` tokens |
|
||||
| `missing` | `ui` | `document_fonts`, `missing_font_warnings` and `MissingFontsDialog`: which fonts a document names are not installed, and a replacement for each |
|
||||
| `axes` | `ui` | `read_axes`, `read_named_instances` and `AxisSliders`: a variable face's axes as sliders with a Style list of its named instances |
|
||||
| `picker` | `ui` | `FontPicker`: the family field with its list (stars, recents, class and feature filters, similar fonts, previews) |
|
||||
| `picker` | `ui` | `FontPicker`: the family field with its list (stars, recents, class and feature filters, similar fonts, previews, style rows, the served families and the banner) |
|
||||
|
||||
The stories (`patterns/font-picker/*`, `patterns/glyphs-panel/panel`, `patterns/missing-fonts-dialog/dialog`, `composites/axis-sliders/sliders`) use the two faces egui ships.
|
||||
|
||||
@@ -54,6 +54,8 @@ its strings and numbers are in `host.lang()` each frame (English without a Host,
|
||||
has no catalog for the language), its settings section is `fonts_panel`, and installs, removals and
|
||||
previews run through `host.jobs()`, one at a time in request order (without a Host, on craft-host's default job service: a thread per runner, inline on wasm32).
|
||||
|
||||
Native code (`SuiteStore` is not built for wasm32):
|
||||
|
||||
```rust
|
||||
let catalog = Arc::clone(Catalog::global());
|
||||
catalog.scan_in_background();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! [`GlyphsPanel`]: Photoshop's Glyphs panel. A family and style picker, a category list (Entire Font, Punctuation,
|
||||
//! Currency, ...), a grid of glyph cells drawn by the app's text engine, a zoom slider, and the recently used
|
||||
//! glyphs in a row at the top. Double-click or Enter inserts the glyph into the text being edited.
|
||||
//! glyphs in a row at the top. Double-click or Enter inserts the glyph where the app can insert.
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
@@ -13,7 +13,7 @@ use craft_ui::contract::{
|
||||
ActivateOn, Bind, CollectionEvent, Entry, NoValue, Outcome, Pad, Pattern, Props, Remember as _, SelectMode, Show as _, ShowCollection as _,
|
||||
ShowContainer as _,
|
||||
};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::display::{Shade, Spinner, Text};
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::list::ThumbAspect;
|
||||
use craft_ui::list::ThumbSize;
|
||||
@@ -26,6 +26,7 @@ use craft_ui::tile_grid::{CaptionPlace, ThumbnailSlider, Tile, TileGrid, TileZoo
|
||||
use egui::{ColorImage, Rect, Response, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::panel::browse::SCAN_POLL_SECONDS;
|
||||
use crate::picker::{read_bind, write_bind};
|
||||
|
||||
craft_ui::words! {
|
||||
@@ -152,7 +153,7 @@ impl Section for GlyphsPanelSettings {
|
||||
pub struct GlyphsPanelOutput {
|
||||
/// The panel's response.
|
||||
pub response: Response,
|
||||
/// A glyph to insert at the caret (double-click, Enter on the focused cell); only while text is edited.
|
||||
/// A glyph to insert at the caret (double-click, Enter on the focused cell); only where the app can insert.
|
||||
pub insert: Option<String>,
|
||||
/// The family or style changed in the panel's own pickers.
|
||||
pub font_changed: bool,
|
||||
@@ -262,7 +263,8 @@ impl craft_behavior::ItemSource<usize> for Chars<'_> {}
|
||||
/// Enter inserts. Hovering a cell shows its character and code point as a tooltip.
|
||||
/// - A cell is drawn from [`GlyphSource::glyph`] at the zoom size, cached per face and character. The grid shows
|
||||
/// only the current category; a cell the source returns no image for stays empty.
|
||||
/// - Without text being edited the cells still show, Enter and double-click do nothing and the footer says so.
|
||||
/// - Where the app cannot insert, the cells still show, Enter and double-click do nothing and the footer says so.
|
||||
/// - While the source is not [ready](GlyphSource::ready) the panel shows a spinner and "Loading fonts…" only.
|
||||
/// - The font and style lists come from the app ([`families`](GlyphsPanel::families),
|
||||
/// [`styles`](GlyphsPanel::styles)); without a list the name is shown as text.
|
||||
#[must_use = "show the panel with `show`"]
|
||||
@@ -301,6 +303,16 @@ impl<'a> GlyphsPanel<'a> {
|
||||
let GlyphsPanel { label, source, mut family, mut style, mut settings, families, styles, can_insert } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<GlyphsWords>();
|
||||
if !source.ready() {
|
||||
let shown = Stack::new().label(label).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Spinner::new().label(words.loading.clone()).show(ui);
|
||||
Text::new(words.loading.clone()).shade(Shade::Muted).show(ui);
|
||||
});
|
||||
});
|
||||
craft_ui::runtime::frame::request_repaint_after(ui.ctx(), SCAN_POLL_SECONDS);
|
||||
return GlyphsPanelOutput { response: shown.output, insert: None, font_changed: false };
|
||||
}
|
||||
let thumbs = Thumbnails::<GlyphKey>::in_context(ui.ctx(), "craft-font-manager-glyphs", ThumbnailOptions::new());
|
||||
let pictures = GlyphPictures(source);
|
||||
let mut insert: Option<String> = None;
|
||||
|
||||
@@ -51,6 +51,35 @@ fn glyphs_panel_not_editing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
show_panel(ui, data, false)
|
||||
}
|
||||
|
||||
/// The panel while the app is still reading its fonts: a spinner and the loading line, no grid.
|
||||
#[story(GlyphsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn glyphs_panel_loading(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let Demo { family, style, settings } =
|
||||
data.value("loading", Demo { family: String::new(), style: String::new(), settings: GlyphsPanelSettings::default() });
|
||||
GlyphsPanel::new("Glyphs", &NotReady, Bind::bound(family), Bind::bound(style), Bind::bound(settings)).can_insert(true).show(ui).into()
|
||||
}
|
||||
|
||||
/// A source whose fonts are not read yet.
|
||||
struct NotReady;
|
||||
|
||||
impl GlyphSource for NotReady {
|
||||
fn charmap(&self, _: &str, _: &str) -> Vec<char> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn glyph(&self, _: &str, _: &str, _: char, _: u32) -> Option<ColorImage> {
|
||||
None
|
||||
}
|
||||
|
||||
fn in_category(&self, _: char, _: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn ready(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Glyphs of the shipped faces, drawn by skrifa's outlines.
|
||||
struct FaceGlyphs;
|
||||
|
||||
|
||||
@@ -43,6 +43,20 @@ pub use pin::{IndexPin, PINNED_INDEX};
|
||||
pub use sources::{SourceEntry, SourcesFile};
|
||||
pub use verify::{VerifyError, is_font, sha256_hex, verify_font};
|
||||
|
||||
/// A source the user added: an index file at an https URL, never curated. Plain data, so it builds on every target
|
||||
/// for the interfaces that list the sources.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct UserSource {
|
||||
/// The index file (format 1.x, JSON or gzipped JSON).
|
||||
pub url: String,
|
||||
/// When it was added, in seconds since 1970.
|
||||
pub added_at: u64,
|
||||
/// The sha256 of the file first fetched from it. A different file later shows as
|
||||
/// [`FontSource::changed`].
|
||||
#[serde(default)]
|
||||
pub last_sha256: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use http::{Cancel, Client, FetchError, Timeouts, USER_AGENT};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -51,7 +65,7 @@ pub use language_packs::{
|
||||
MAX_PACK_INDEX_BYTES, MAX_PACK_UNPACKED_BYTES, PackEntry, PackIndex, PackIndexPin, language_pack_index_overridden,
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress, UserSource};
|
||||
pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -23,6 +23,7 @@ use std::time::{Duration, SystemTime};
|
||||
use craft_font_catalog::{Catalog, FontEnv, font_store_dir};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::UserSource;
|
||||
use crate::http::{Cancel, Client, FetchError};
|
||||
use crate::index::{Face, Family, FontFile, GOOGLE_FONTS, Index, IndexError, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, SourceProblem, Unavailable};
|
||||
use crate::pin::IndexPin;
|
||||
@@ -183,19 +184,6 @@ fn google_fonts() -> String {
|
||||
GOOGLE_FONTS.into()
|
||||
}
|
||||
|
||||
/// A source the user added: an index file at an https URL, never curated.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct UserSource {
|
||||
/// The index file (format 1.x, JSON or gzipped JSON).
|
||||
pub url: String,
|
||||
/// When it was added, in seconds since 1970.
|
||||
pub added_at: u64,
|
||||
/// The sha256 of the file first fetched from it. A different file later shows as
|
||||
/// [`crate::FontSource::changed`].
|
||||
#[serde(default)]
|
||||
pub last_sha256: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
struct Settings {
|
||||
#[serde(default)]
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
//! [`AdjustmentKind`] and the Adjustments panel: a grid of icon buttons, one per adjustment.
|
||||
//! [`AdjustmentKind`]: the adjustments the Adjustments panel offers, with their command key, icon and title.
|
||||
|
||||
use craft_behavior::IconId;
|
||||
use craft_ui::contract::{NoValue, Outcome, Pattern};
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use super::AdjustWords;
|
||||
|
||||
@@ -66,69 +64,69 @@ impl AdjustmentKind {
|
||||
AdjustmentKind::ColorLookup,
|
||||
];
|
||||
|
||||
/// The kind's key (`"brightnessContrast"`).
|
||||
/// The kind's key (`"brightnessContrast"`): the suffix of the app's `layer.newAdjustmentLayer.{key}` command.
|
||||
pub fn key(self) -> &'static str {
|
||||
let _ = self;
|
||||
todo!("pn.C44")
|
||||
match self {
|
||||
AdjustmentKind::BrightnessContrast => "brightnessContrast",
|
||||
AdjustmentKind::Levels => "levels",
|
||||
AdjustmentKind::Curves => "curves",
|
||||
AdjustmentKind::Exposure => "exposure",
|
||||
AdjustmentKind::Vibrance => "vibrance",
|
||||
AdjustmentKind::HueSaturation => "hueSaturation",
|
||||
AdjustmentKind::ColorBalance => "colorBalance",
|
||||
AdjustmentKind::BlackWhite => "blackWhite",
|
||||
AdjustmentKind::PhotoFilter => "photoFilter",
|
||||
AdjustmentKind::ChannelMixer => "channelMixer",
|
||||
AdjustmentKind::Invert => "invert",
|
||||
AdjustmentKind::Posterize => "posterize",
|
||||
AdjustmentKind::Threshold => "threshold",
|
||||
AdjustmentKind::GradientMap => "gradientMap",
|
||||
AdjustmentKind::SelectiveColor => "selectiveColor",
|
||||
AdjustmentKind::ColorLookup => "colorLookup",
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind's icon from the catalog.
|
||||
pub fn icon(self) -> IconId {
|
||||
let _ = self;
|
||||
todo!("pn.C44")
|
||||
IconId::new(match self {
|
||||
AdjustmentKind::BrightnessContrast => "sun",
|
||||
AdjustmentKind::Levels => "gauge",
|
||||
AdjustmentKind::Curves => "pen_tool",
|
||||
AdjustmentKind::Exposure => "scan",
|
||||
AdjustmentKind::Vibrance => "sparkles",
|
||||
AdjustmentKind::HueSaturation => "droplet",
|
||||
AdjustmentKind::ColorBalance => "blend",
|
||||
AdjustmentKind::BlackWhite => "contrast",
|
||||
AdjustmentKind::PhotoFilter => "target",
|
||||
AdjustmentKind::ChannelMixer => "adjustments",
|
||||
AdjustmentKind::Invert => "squares_subtract",
|
||||
AdjustmentKind::Posterize => "layers",
|
||||
AdjustmentKind::Threshold => "square",
|
||||
AdjustmentKind::GradientMap => "palette",
|
||||
AdjustmentKind::SelectiveColor => "swatch_book",
|
||||
AdjustmentKind::ColorLookup => "grid",
|
||||
})
|
||||
}
|
||||
|
||||
/// The kind's title.
|
||||
/// The kind's title, from `words`.
|
||||
pub fn label(self, words: &AdjustWords) -> Label {
|
||||
let _ = (self, words);
|
||||
todo!("pn.C44")
|
||||
}
|
||||
}
|
||||
|
||||
/// What the Adjustments panel reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct AdjustmentsPanelOutput {
|
||||
/// The panel's response.
|
||||
pub response: Response,
|
||||
/// The kind the user picked this pass.
|
||||
pub picked: Option<AdjustmentKind>,
|
||||
}
|
||||
|
||||
impl Outcome for AdjustmentsPanelOutput {
|
||||
type Value = NoValue;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
&self.response
|
||||
}
|
||||
}
|
||||
|
||||
/// A grid of icon buttons in one roving group; the app picks which kinds it offers (default all).
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(Pattern)]
|
||||
#[allow(dead_code)] // P3(panels-w11): pn.C44
|
||||
pub struct AdjustmentsPanel<'a> {
|
||||
label: Label,
|
||||
kinds: &'a [AdjustmentKind],
|
||||
}
|
||||
|
||||
impl<'a> AdjustmentsPanel<'a> {
|
||||
/// A panel named `label` offering every kind.
|
||||
pub fn new(label: impl Into<Label>) -> Self {
|
||||
let _ = label.into();
|
||||
todo!("pn.C44")
|
||||
}
|
||||
|
||||
/// Offers only `kinds`.
|
||||
#[must_use]
|
||||
pub fn kinds(mut self, kinds: &'a [AdjustmentKind]) -> Self {
|
||||
let _ = (&mut self, kinds);
|
||||
todo!("pn.C44")
|
||||
}
|
||||
|
||||
/// Draws the grid and reports the picked kind.
|
||||
pub fn show(self, ui: &mut Ui) -> AdjustmentsPanelOutput {
|
||||
let _ = (self, ui);
|
||||
todo!("pn.C44")
|
||||
match self {
|
||||
AdjustmentKind::BrightnessContrast => words.brightness_contrast.clone(),
|
||||
AdjustmentKind::Levels => words.levels.clone(),
|
||||
AdjustmentKind::Curves => words.curves.clone(),
|
||||
AdjustmentKind::Exposure => words.exposure.clone(),
|
||||
AdjustmentKind::Vibrance => words.vibrance.clone(),
|
||||
AdjustmentKind::HueSaturation => words.hue_saturation.clone(),
|
||||
AdjustmentKind::ColorBalance => words.color_balance.clone(),
|
||||
AdjustmentKind::BlackWhite => words.black_white.clone(),
|
||||
AdjustmentKind::PhotoFilter => words.photo_filter.clone(),
|
||||
AdjustmentKind::ChannelMixer => words.channel_mixer.clone(),
|
||||
AdjustmentKind::Invert => words.invert.clone(),
|
||||
AdjustmentKind::Posterize => words.posterize.clone(),
|
||||
AdjustmentKind::Threshold => words.threshold.clone(),
|
||||
AdjustmentKind::GradientMap => words.gradient_map.clone(),
|
||||
AdjustmentKind::SelectiveColor => words.selective_color.clone(),
|
||||
AdjustmentKind::ColorLookup => words.color_lookup.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Photoshop's adjustments as editors: each takes a plain value in a binding and reports an
|
||||
//! [`EditResponse`](craft_ui::contract::EditResponse) of it, and the same editor serves the Image › Adjustments dialog
|
||||
//! and the Properties panel ([`AdjustContext`]). The app converts values to its engine's parameters; the library has no
|
||||
//! JSON.
|
||||
//! and the Properties panel ([`AdjustContext`]). The app converts values to its engine's parameters; the values
|
||||
//! serialize with their own field names (serde).
|
||||
//!
|
||||
//! - Tone: [`LevelsEditor`] (one channel's levels over its histogram), [`LevelsPanel`] and [`CurvesPanel`] around it
|
||||
//! and the curve editor, with the channels ([`ToneChannels`]) and the point pickers ([`TonePickerRow`],
|
||||
@@ -11,6 +11,7 @@
|
||||
//! [`BlackWhiteEditor`], [`ChannelMixerEditor`], [`SelectiveColorEditor`].
|
||||
//! - The Image › Adjustments dialog around any of them on the dialog host ([`HostedAdjustDialog`]).
|
||||
//! - The Properties panel's session ([`AdjustSession`]).
|
||||
//! - The Adjustments panel: a grid of buttons that add an adjustment layer ([`AdjustmentsPanel`], [`AdjustmentKind`]).
|
||||
//!
|
||||
//! Gradient Map is `craft_draw::ui::gradient::map`, beside the gradient editor it builds on.
|
||||
|
||||
@@ -24,6 +25,7 @@ mod labels;
|
||||
mod levels_editor;
|
||||
mod levels_panel;
|
||||
mod mixers;
|
||||
mod panel;
|
||||
mod session;
|
||||
mod sliders;
|
||||
mod style;
|
||||
@@ -37,7 +39,7 @@ pub use context::{AdjustContext, ToneChannel, ToneChannelCommands, ToneChannels,
|
||||
pub use curves_panel::{CurvesMode, CurvesPanel, CurvesPanelOutput, ToneCurves};
|
||||
pub use hosted::{AdjustDialogCx, EditPhase, HostedAdjustDialog};
|
||||
pub use hue_saturation::{HueRangeValue, HueSaturation, HueSaturationEditor, HueSaturationOutput};
|
||||
pub use kinds::{AdjustmentKind, AdjustmentsPanel, AdjustmentsPanelOutput};
|
||||
pub use kinds::AdjustmentKind;
|
||||
pub use labels::AdjustWords;
|
||||
pub use levels_editor::{Levels, LevelsClip, LevelsEditor, LevelsEditorOutput, LevelsWords};
|
||||
pub use levels_panel::{LevelsPanel, LevelsPanelOutput};
|
||||
@@ -45,6 +47,7 @@ pub use mixers::{
|
||||
BlackWhite, BlackWhiteEditor, BlackWhiteOutput, ChannelMixer, ChannelMixerEditor, SelectiveColor, SelectiveColorEditor, SelectiveColorOutput,
|
||||
SelectiveMethod,
|
||||
};
|
||||
pub use panel::{AdjustmentsPanel, AdjustmentsPanelOutput};
|
||||
pub use session::AdjustSession;
|
||||
pub use sliders::{AdjustField, AdjustSliders, AdjustTrack};
|
||||
pub use tone::{TonePick, TonePickTool, TonePicker, TonePickerRow, TonePickerRowOutput};
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
//! [`AdjustmentsPanel`]: the grid of adjustment buttons a document panel offers for adding an adjustment layer.
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
|
||||
use craft_behavior::{Metrics, NavShape, Roving, Sense};
|
||||
use craft_ui::buttons::IconButton;
|
||||
use craft_ui::contract::{
|
||||
BodyLayout, Common, Component, Container, ContainerProps, Cx, Gap, NoValue, Outcome, Pad, Pattern, Props as _, Role, Show as _,
|
||||
ShowContainer as _, Sizing, clicked,
|
||||
};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::style::{ComponentStyle, StyleCx};
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use super::{AdjustWords, AdjustmentKind};
|
||||
|
||||
/// What the Adjustments panel reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct AdjustmentsPanelOutput {
|
||||
/// The panel's response.
|
||||
pub response: Response,
|
||||
/// The kind whose button was activated this pass.
|
||||
pub picked: Option<AdjustmentKind>,
|
||||
}
|
||||
|
||||
impl Outcome for AdjustmentsPanelOutput {
|
||||
type Value = NoValue;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
&self.response
|
||||
}
|
||||
}
|
||||
|
||||
/// A grid of icon buttons in one roving group; the app picks which kinds it offers (default all).
|
||||
///
|
||||
/// - Each button shows the kind's icon and is named, and has its tooltip, by the kind's title. The buttons keep the
|
||||
/// order of [`AdjustmentKind::ALL`], or of the subset given to [`kinds`](Self::kinds), and wrap to the width the
|
||||
/// panel is given.
|
||||
/// - The arrow keys move between the buttons by the grid they form; Tab leaves the group.
|
||||
/// - The app names what the buttons are for (its "Add an adjustment" caption) and runs the command of the picked kind.
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(Pattern)]
|
||||
pub struct AdjustmentsPanel<'a> {
|
||||
label: Label,
|
||||
kinds: &'a [AdjustmentKind],
|
||||
}
|
||||
|
||||
impl<'a> AdjustmentsPanel<'a> {
|
||||
/// A panel named `label` offering every kind.
|
||||
pub fn new(label: impl Into<Label>) -> Self {
|
||||
AdjustmentsPanel { label: label.into(), kinds: &AdjustmentKind::ALL }
|
||||
}
|
||||
|
||||
/// Offers only `kinds`, in that order.
|
||||
#[must_use]
|
||||
pub fn kinds(mut self, kinds: &'a [AdjustmentKind]) -> Self {
|
||||
self.kinds = kinds;
|
||||
self
|
||||
}
|
||||
|
||||
/// Draws the grid and reports the picked kind.
|
||||
pub fn show(self, ui: &mut Ui) -> AdjustmentsPanelOutput {
|
||||
let AdjustmentsPanel { label, kinds } = self;
|
||||
let words = Env::of(ui).words::<AdjustWords>();
|
||||
let mut picked = None;
|
||||
let shown = ButtonGrid::new(label).show(ui, |ui, _| {
|
||||
for &kind in kinds {
|
||||
let name = kind.label(&words);
|
||||
let button = IconButton::new(kind.icon()).id_salt(kind.key()).label(name.clone()).tooltip(name).show(ui);
|
||||
if clicked(&button) {
|
||||
picked = Some(kind);
|
||||
}
|
||||
}
|
||||
});
|
||||
AdjustmentsPanelOutput { response: shown.output, picked }
|
||||
}
|
||||
}
|
||||
|
||||
/// The style of the button grid: it paints nothing of its own.
|
||||
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
struct ButtonGridStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
}
|
||||
|
||||
/// The wrapping row of buttons, one roving group. The column count follows the width the host gives, so the group
|
||||
/// steps by the buttons' positions (`RaggedGrid`) and not by a fixed column count.
|
||||
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
|
||||
#[component(container)]
|
||||
struct ButtonGrid {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container()]
|
||||
props: ContainerProps,
|
||||
}
|
||||
|
||||
impl ButtonGrid {
|
||||
fn new(label: Label) -> Self {
|
||||
let props = ContainerProps::new()
|
||||
.pad(Pad::None)
|
||||
.sizing(Sizing::FillWidth)
|
||||
.layout(BodyLayout::row().wrap(true))
|
||||
.body_gap(Gap::Tight)
|
||||
.roving(Roving::new(NavShape::RaggedGrid));
|
||||
ButtonGrid { common: Common::new(), props }.label(label)
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for ButtonGrid {
|
||||
const ROLE: Role = Role::GROUP;
|
||||
const PARTS: bool = false;
|
||||
const STOPS: bool = false;
|
||||
type Style = ButtonGridStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: ButtonGridStyleKey) -> ButtonGridStyle {
|
||||
ButtonGridStyle::default()
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
Sense::empty()
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Container for ButtonGrid {}
|
||||
@@ -0,0 +1,24 @@
|
||||
//! Stories of the Adjustments panel: every kind, and an app's subset in its own order.
|
||||
|
||||
use super::{AdjustmentKind, AdjustmentsPanel};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(AdjustmentsPanel<'static>, covers = [Default], drive = Drive::Never, title = "Every adjustment")]
|
||||
fn adjustments_panel(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
AdjustmentsPanel::new("Add an adjustment").show(ui).into()
|
||||
}
|
||||
|
||||
/// An app that offers six adjustments, in its own order.
|
||||
#[story(AdjustmentsPanel<'static>, covers = [], drive = Drive::Never, title = "A subset in the app's order")]
|
||||
fn adjustments_panel_subset(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
const SUBSET: [AdjustmentKind; 6] = [
|
||||
AdjustmentKind::Curves,
|
||||
AdjustmentKind::Levels,
|
||||
AdjustmentKind::Invert,
|
||||
AdjustmentKind::HueSaturation,
|
||||
AdjustmentKind::Threshold,
|
||||
AdjustmentKind::BrightnessContrast,
|
||||
];
|
||||
AdjustmentsPanel::new("Add an adjustment").kinds(&SUBSET).show(ui).into()
|
||||
}
|
||||
Reference in New Issue
Block a user