diff --git a/crates/font-manager/src/axes.rs b/crates/font-manager/src/axes.rs index 6401367c6..a5949fe72 100644 --- a/crates/font-manager/src/axes.rs +++ b/crates/font-manager/src/axes.rs @@ -2,9 +2,13 @@ //! that edits them (Photoshop's Properties › Character axis sliders; FigCraft's axis panel). The data types //! and reading them from a font are always available; the sliders are on `ui`. +#[cfg(feature = "ui")] +mod button; #[cfg(feature = "ui")] mod sliders; #[cfg(feature = "ui")] +pub use button::AxesButton; +#[cfg(feature = "ui")] pub use sliders::*; use skrifa::string::StringId; diff --git a/crates/font-manager/src/axes/button.rs b/crates/font-manager/src/axes/button.rs new file mode 100644 index 000000000..3c9e67281 --- /dev/null +++ b/crates/font-manager/src/axes/button.rs @@ -0,0 +1,40 @@ +//! The axes behind one button: a `Button` that opens the axis sliders in a popover. + +use craft_ui::contract::{Bind, Pattern, Props}; +use craft_ui::runtime::env::Label; +use egui::Ui; + +use super::{AxisSlidersOutput, AxisValues, FontAxis, NamedInstance}; + +/// A `Button` with the label that opens an anchored `Popover` holding `AxisSliders` over the same props. The open +/// state is the button's own memory. The output is the sliders' (`edit`, `instance`), with the button's response. +#[must_use = "show the button with `show`"] +#[derive(Pattern, Props)] +#[allow(dead_code)] // P3(type-w3): ty.X21 +pub struct AxesButton<'a> { + label: Label, + axes: &'a [FontAxis], + values: Bind<'a, AxisValues>, + /// The named instances of the face, listed above the sliders. + #[prop] + instances: &'a [NamedInstance], + /// The style's weight, which an unset `wght` axis shows (an unset axis shows its default without it). + #[prop(quantity = "font weight, the `wght` coordinate")] + weight: Option, + /// Whether the style is italic: an unset `ital` axis then shows its maximum, once a weight is given. + #[prop] + italic: bool, +} + +impl<'a> AxesButton<'a> { + /// A button named `label` over the `axes` of a face, editing the coordinates `values`. + pub fn new(label: impl Into