mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 04:38:49 +00:00
Merge branch 'fw/mac1-bars' into fw/mac1
# Conflicts: # crates/ui-contract/src/contract/body/hooks.rs # crates/ui-shell/src/shell/app_shell.rs # crates/ui-shell/tests/it/shell/app_shell.rs
This commit is contained in:
@@ -224,7 +224,7 @@ impl Opened {
|
||||
}
|
||||
}
|
||||
|
||||
/// Photoshop's Brush Preset picker: a closed field showing the current preset's tip with the brush size under it, which opens
|
||||
/// Photoshop's Brush Preset picker: a compact chip (`PickerField::Chip`) showing the current preset's tip with the brush size under it, which opens
|
||||
/// a popover over [`PresetPicker`].
|
||||
///
|
||||
/// - **Head.** While [`BrushPickerValues::tip`] is set, [`TipEllipse`] (angle and roundness) at the start; beside it
|
||||
@@ -459,7 +459,7 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> {
|
||||
});
|
||||
};
|
||||
let mut picker = PresetPicker::new(words.picker.clone(), current.reborrowed(), rows, Bind::bound(&mut browser))
|
||||
.field(PickerField::Thumbnail)
|
||||
.field(PickerField::Chip)
|
||||
.caption(env.units().number(values.diameter.round(), 0..=0))
|
||||
.cell_shape(CellShape::Square)
|
||||
.view(if parts.tip_only() { PresetView::Grid } else { PresetView::List })
|
||||
|
||||
@@ -10,13 +10,13 @@ use craft_behavior::{EditEvent, EditEvents, IconId, NumberCodec};
|
||||
use craft_ui::buttons::{Button, IconButton, ToggleButton};
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{
|
||||
Bind, BodyCx, Entry, Gap, LabelKind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked,
|
||||
Bind, BodyCx, Entry, Gap, LabelKind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, clicked,
|
||||
};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Label, UnitKind, Units};
|
||||
use craft_ui::runtime::env::{Env, Label, Units};
|
||||
use craft_ui::runtime::requests::ColorRequest;
|
||||
use craft_ui::text::NumberField;
|
||||
use egui::{Response, Ui};
|
||||
@@ -46,8 +46,6 @@ pub struct CropBarOutput {
|
||||
pub ratio: Option<CropRatioChange>,
|
||||
/// The Straighten button was pressed: the app calls `CropTool::toggle_straighten`.
|
||||
pub straighten: bool,
|
||||
/// The Angle field was edited: the app turns the frame to this angle, in degrees.
|
||||
pub angle: Option<f64>,
|
||||
/// New Crop Preset…: the app opens its dialog with [`CropSettings::preset_name`].
|
||||
pub new_preset: bool,
|
||||
/// Delete Crop Preset…: the app opens its dialog.
|
||||
@@ -83,8 +81,8 @@ impl Outcome for CropBarOutput {
|
||||
/// - Order (Photoshop's): the preset list ([`CropPresetList`]: Selection when offered, Ratio, W x H x Resolution, the
|
||||
/// ratio presets, the size presets, the user's presets, Front Image, a rule, New Crop Preset…, Delete Crop
|
||||
/// Preset…); the W and H ratio fields (0 to 99,999 with 3 decimals) with the swap button between them, or in
|
||||
/// W × H × Resolution mode the W, H and Resolution fields with the px/in or px/cm select; Clear; the Angle field;
|
||||
/// the Straighten toggle (pressed while armed); the overlay menu ([`CropOverlayMenu`]); the gear popover
|
||||
/// W × H × Resolution mode the W, H and Resolution fields with the px/in or px/cm select; Clear; the labelled
|
||||
/// Straighten toggle (pressed while armed); the frame's angle is edited on the canvas; the overlay menu ([`CropOverlayMenu`]); the gear popover
|
||||
/// ([`CropOptionsMenu`]); the Delete Cropped Pixels check box; Fill and its select; the help button when a help
|
||||
/// label is given; Reset.
|
||||
/// - W and H keep their lengths with the unit they were entered in ([`CropLength`](super::CropLength)); a cleared
|
||||
@@ -94,7 +92,7 @@ impl Outcome for CropBarOutput {
|
||||
/// is `None`; Original Ratio and Front Image without a document.
|
||||
/// - Fill's first entry reads Transparent while Delete Cropped Pixels is off and Background while it is on.
|
||||
/// - **Keyboard and AccessKit:** the list is a select named "Crop ratio" with the chosen entry as its value; the
|
||||
/// fields are named Width, Height, Resolution and Angle; the Straighten toggle has its pressed state; the menus
|
||||
/// fields are named Width, Height and Resolution; the Straighten toggle has its pressed state; the menus
|
||||
/// open with Enter or Space.
|
||||
#[must_use = "show the bar's children with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)]
|
||||
@@ -107,9 +105,6 @@ pub struct CropBar<'a> {
|
||||
/// The Straighten toggle's pressed state (`CropTool::straighten_armed`).
|
||||
#[prop]
|
||||
straighten: bool,
|
||||
/// The frame's angle in degrees, for the Angle field; without a frame the field is disabled.
|
||||
#[prop(quantity = "angle in degrees")]
|
||||
angle: Option<f64>,
|
||||
/// The help button after Fill; `Some` shows it, named by the label.
|
||||
#[prop(into)]
|
||||
help: Option<Label>,
|
||||
@@ -132,7 +127,6 @@ impl<'a> CropBar<'a> {
|
||||
document,
|
||||
user_presets: &[],
|
||||
straighten: false,
|
||||
angle: None,
|
||||
help: None,
|
||||
can_reset: false,
|
||||
selection_entry: false,
|
||||
@@ -142,7 +136,7 @@ impl<'a> CropBar<'a> {
|
||||
|
||||
/// Shows the bar's children.
|
||||
pub fn show(self, ui: &mut Ui) -> CropBarOutput {
|
||||
let Self { settings, document, user_presets, straighten, angle, help, can_reset, selection_entry, selection_chosen } = self;
|
||||
let Self { settings, document, user_presets, straighten, help, can_reset, selection_entry, selection_chosen } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<CropBarWords>();
|
||||
let units = env.units();
|
||||
@@ -179,20 +173,17 @@ impl<'a> CropBar<'a> {
|
||||
settings.clear();
|
||||
report.ratio = Some(CropRatioChange { editing: false });
|
||||
}
|
||||
Field::new(words.angle.clone()).id_salt("angle").sizing(Sizing::Content).enabled(angle.is_some()).show(ui, |ui, _| {
|
||||
let field = NumberField::new(words.angle.clone(), Bind::given(angle)).unit_kind(UnitKind::Degrees).range(-180.0..=180.0).show(ui);
|
||||
if let Some(turned) = field.value().copied().flatten() {
|
||||
report.angle = Some(turned);
|
||||
}
|
||||
});
|
||||
let toggle = ToggleButton::new(words.straighten.clone(), Bind::given(straighten)).icon(IconId::new("ruler")).icon_only().show(ui);
|
||||
let toggle = ToggleButton::new(words.straighten_name.clone(), Bind::given(straighten))
|
||||
.icon(IconId::new("ruler"))
|
||||
.tooltip(words.straighten.clone())
|
||||
.show(ui);
|
||||
report.straighten |= toggle.value().is_some();
|
||||
CropOverlayMenu::new(settings).show(ui);
|
||||
report.pick_color = CropOptionsMenu::new(settings).show(ui).pick_color;
|
||||
Checkbox::new(Bind::bound(&mut settings.delete_pixels)).label(words.delete_pixels.clone()).show(ui);
|
||||
let background = if settings.delete_pixels { words.fill_background.clone() } else { words.fill_transparent.clone() };
|
||||
let fills = [Entry::new(CropFill::Background, background), Entry::new(CropFill::ContentAware, words.fill_content_aware.clone())];
|
||||
Field::new(words.fill_name.clone()).id_salt("fill").sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(words.fill_name.clone()).id_salt("fill").show(ui, |ui, _| {
|
||||
let pick = Select::new(words.fill_name.clone(), Bind::given(settings.fill), &fills).show(ui);
|
||||
if let Some(fill) = pick.value().copied() {
|
||||
settings.fill = fill;
|
||||
@@ -208,7 +199,6 @@ impl<'a> CropBar<'a> {
|
||||
response: shown.output,
|
||||
ratio: report.ratio,
|
||||
straighten: report.straighten,
|
||||
angle: report.angle,
|
||||
new_preset: report.new_preset,
|
||||
delete_preset: report.delete_preset,
|
||||
pick_color: report.pick_color,
|
||||
@@ -226,7 +216,6 @@ impl<'a> CropBar<'a> {
|
||||
struct Report {
|
||||
ratio: Option<CropRatioChange>,
|
||||
straighten: bool,
|
||||
angle: Option<f64>,
|
||||
new_preset: bool,
|
||||
delete_preset: bool,
|
||||
pick_color: Option<ColorRequest>,
|
||||
@@ -285,7 +274,7 @@ fn ratio_field(
|
||||
let current = shown.get(side).copied().unwrap_or(0.0);
|
||||
let salt = if side == 0 { "ratio-width" } else { "ratio-height" };
|
||||
let mut events = EditEvents::new();
|
||||
Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt(salt).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt(salt).show(ui, |ui, _| {
|
||||
let codec = NumberCodec::new(units.reader(None), RATIO_DECIMALS);
|
||||
let field = NumberField::new(caption.clone(), Bind::given((current > 0.0).then_some(current)))
|
||||
.codec(codec)
|
||||
|
||||
@@ -21,7 +21,7 @@ fn crop_bar_ratio(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let document = document();
|
||||
let settings = data.value("settings", CropSettings::default());
|
||||
let mut output = None;
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(CropBar::new(settings, &document).angle(0.0).show(ui)));
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(CropBar::new(settings, &document).show(ui)));
|
||||
output.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ fn crop_bar_selection_and_reset(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu
|
||||
let mut output = None;
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
|
||||
let bar = CropBar::new(settings, &document)
|
||||
.angle(0.0)
|
||||
.selection_entry(true)
|
||||
.selection_chosen(true)
|
||||
.can_reset(true)
|
||||
|
||||
@@ -26,9 +26,9 @@ craft_ui::words! {
|
||||
height: "cropBar.height" = "Height";
|
||||
resolution: "cropBar.resolution" = "Resolution";
|
||||
resolution_unit: "cropBar.resolutionUnit" = "Resolution unit";
|
||||
angle: "cropBar.angle" = "Angle";
|
||||
swap: "cropBar.swap" = "Swaps height and width";
|
||||
clear: "cropBar.clear" = "Clear";
|
||||
straighten_name: "cropBar.straightenName" = "Straighten";
|
||||
straighten: "cropBar.straighten" = "Straighten the image by drawing a line on it";
|
||||
overlay: "cropBar.overlay" = "Set the overlay options for the Crop tool";
|
||||
/// The overlays, in the order of `CropGuide::ALL`.
|
||||
@@ -60,7 +60,7 @@ craft_ui::words! {
|
||||
delete_pixels: "cropBar.deletePixels" = "Delete Cropped Pixels";
|
||||
/// The Fill select's name.
|
||||
fill_name: "cropBar.fillName" = "Fill";
|
||||
fill_background: "cropBar.fillBackground" = "Background (Default)";
|
||||
fill_background: "cropBar.fillBackground" = "Background (default)";
|
||||
fill_content_aware: "cropBar.fillContentAware" = "Content-Aware Fill";
|
||||
/// The preset list's Selection entry.
|
||||
selection: "cropBar.selection" = "Selection";
|
||||
|
||||
@@ -116,7 +116,7 @@ pub struct CropSizeFields {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[non_exhaustive]
|
||||
pub enum CropFill {
|
||||
/// "Background (Default)": the background colour or transparency.
|
||||
/// "Background (default)": the background colour or transparency.
|
||||
#[default]
|
||||
Background,
|
||||
/// "Content-Aware Fill": filled from the surroundings (the engine's). Generative Expand is
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::options::{CropLength, FIELD_MAX, LENGTH_MIN, ResolutionUnit, trim_num
|
||||
use super::{CropBarWords, CropDocument, CropSizeFields};
|
||||
use craft_behavior::{IconId, NumberCodec};
|
||||
use craft_ui::buttons::IconButton;
|
||||
use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Sizing, clicked};
|
||||
use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{LengthUnits, UnitKind, Units};
|
||||
@@ -100,7 +100,7 @@ pub(super) fn show(
|
||||
let resolution = size.resolution.trim().replace(',', ".").parse::<f64>().ok().filter(|v| v.is_finite() && *v > 0.0);
|
||||
let mut typed = None;
|
||||
let mut alert = None;
|
||||
Field::new(words.resolution.clone()).id_salt("size-resolution").sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(words.resolution.clone()).id_salt("size-resolution").show(ui, |ui, _| {
|
||||
let codec = NumberCodec::new(units.reader(None), limits.resolution_decimals);
|
||||
let field = NumberField::new(words.resolution.clone(), Bind::given(resolution)).codec(codec).range(low..=high).automatic(true).show(ui);
|
||||
typed = field.value().copied();
|
||||
@@ -155,7 +155,7 @@ fn length_field(
|
||||
let mut typed = None;
|
||||
let mut typed_unit = None;
|
||||
let mut alert = None;
|
||||
Field::new(caption.clone()).id_salt(salt).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(caption.clone()).id_salt(salt).show(ui, |ui, _| {
|
||||
let lengths = LengthUnits::new(unit, unit, pixels_per_inch);
|
||||
let range = limits.length_range(unit, pixels_per_inch, points_per_inch);
|
||||
let field = NumberField::length(caption.clone(), Bind::given(value.map(|length| length.value)), lengths).range(range).show(ui);
|
||||
|
||||
@@ -40,15 +40,14 @@ impl GradientStyle {
|
||||
}
|
||||
}
|
||||
|
||||
/// The style's icon: `gradient_linear`, `gradient_radial`, `gradient_angle`, `gradient_reflected`
|
||||
/// or `gradient_diamond`.
|
||||
/// The style's icon: `gradient`, `circle`, `rotate_cw`, `swap_horizontal` or `diamond`.
|
||||
pub fn icon(self) -> IconId {
|
||||
IconId::new(match self {
|
||||
GradientStyle::Linear => "gradient_linear",
|
||||
GradientStyle::Radial => "gradient_radial",
|
||||
GradientStyle::Angle => "gradient_angle",
|
||||
GradientStyle::Reflected => "gradient_reflected",
|
||||
GradientStyle::Diamond => "gradient_diamond",
|
||||
GradientStyle::Linear => "gradient",
|
||||
GradientStyle::Radial => "circle",
|
||||
GradientStyle::Angle => "rotate_cw",
|
||||
GradientStyle::Reflected => "swap_horizontal",
|
||||
GradientStyle::Diamond => "diamond",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_behavior::{CursorIcon, CursorPriority, Metrics, Sense};
|
||||
use craft_ui::choice::SwatchMetrics;
|
||||
use craft_ui::contract::{
|
||||
Access, Common, Component, Cx, DisabledLook, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role, Sizing,
|
||||
Access, Common, Component, Cx, DisabledLook, InBar, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role, Sizing,
|
||||
};
|
||||
use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx};
|
||||
use egui::{CornerRadius, Response, Vec2};
|
||||
@@ -27,6 +27,8 @@ pub struct GradientSwatchStyle {
|
||||
radius: CornerRadius,
|
||||
/// The ring on the well's outline, which separates the well from the panel.
|
||||
edge: StyleColor,
|
||||
/// The width of a swatch among a bar's members: `size.length.short`.
|
||||
in_bar: f32,
|
||||
}
|
||||
|
||||
/// What a gradient swatch reports.
|
||||
@@ -52,8 +54,8 @@ impl Outcome for GradientSwatchOutput {
|
||||
///
|
||||
/// The ramp is drawn over the checkerboard where it is translucent, inside the swatch's ring. The
|
||||
/// swatch edits nothing; a click is the host's cue. The well has the gradient chip aspect
|
||||
/// (`GradientRamp::CHIP_ASPECT`); with `Sizing::FillWidth` it takes the wider width the layout
|
||||
/// offers (an options bar cell). AccessKit sees a button named by the label, with `has_popup`
|
||||
/// (`GradientRamp::CHIP_ASPECT`); among a bar's members it is `size.length.short` wide, and with
|
||||
/// `Sizing::FillWidth` it takes the wider width the layout offers. AccessKit sees a button named by the label, with `has_popup`
|
||||
/// when the host opens a dialog on the click.
|
||||
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
|
||||
#[component(content_painter)]
|
||||
@@ -90,7 +92,14 @@ impl Component for GradientSwatch<'_> {
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: GradientSwatchStyleKey) -> GradientSwatchStyle {
|
||||
let (radius, edge) = GradientRamp::chip_look(cx);
|
||||
GradientSwatchStyle { metrics: Metrics::new(), focus: cx.focus_look(), side: SwatchMetrics::of(cx).side, radius, edge }
|
||||
GradientSwatchStyle {
|
||||
metrics: Metrics::new(),
|
||||
focus: cx.focus_look(),
|
||||
side: SwatchMetrics::of(cx).side,
|
||||
radius,
|
||||
edge,
|
||||
in_bar: cx.tokens.size.length.short,
|
||||
}
|
||||
}
|
||||
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
@@ -99,6 +108,8 @@ impl Component for GradientSwatch<'_> {
|
||||
let chip = height * f32::from(wide) / f32::from(high);
|
||||
let width = if cx.resolved.sizing() == Some(Sizing::FillWidth) {
|
||||
cx.room.filter(|room| room.is_finite()).map_or(chip, |room| room.max(chip))
|
||||
} else if cx.env.get::<InBar>().0 {
|
||||
cx.style.in_bar.max(chip)
|
||||
} else {
|
||||
chip
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::words::RulerWords;
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::canvas::CanvasRulers;
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{Bind, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, Sizing, clicked};
|
||||
use craft_ui::contract::{Bind, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft_ui::display::{Divider, Text};
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::Row;
|
||||
@@ -122,7 +122,7 @@ impl<'a> RulerBar<'a> {
|
||||
|
||||
/// One readout: a caption above a tabular value, named `name` for AccessKit.
|
||||
fn readout(ui: &mut Ui, salt: &'static str, name: Label, value: String) {
|
||||
Field::new(name).id_salt(salt).sizing(Sizing::Content).value(value.clone()).show(ui, |ui, _| {
|
||||
Field::new(name).id_salt(salt).value(value.clone()).show(ui, |ui, _| {
|
||||
Text::new(value.clone()).role(TypeRole::Mono).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ use std::sync::Arc;
|
||||
|
||||
use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, Value};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::buttons::IconButton;
|
||||
use craft_theme::ControlSize;
|
||||
use craft_ui::buttons::{IconButton, ToggleButton};
|
||||
use craft_ui::choice::{Checkbox, Swatch};
|
||||
use craft_ui::contract::{
|
||||
Bind, BodyCx, Entry, Gap, LabelKind, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Sizing, Trigger, clicked,
|
||||
Bind, BodyCx, Entry, Gap, LabelKind, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Trigger, clicked,
|
||||
};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
@@ -20,14 +21,15 @@ use craft_ui::runtime::env::{Env, Label, UnitKind};
|
||||
use craft_ui::text::{NumberField, RangeAlert};
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use crate::ui::brush_settings::BrushSizeField;
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
mod words;
|
||||
|
||||
pub use words::PaintBarWords;
|
||||
|
||||
/// The icon of the toggles that let pen pressure control the opacity or the size.
|
||||
const PRESSURE: &str = "target";
|
||||
|
||||
/// The painting tools the bar serves.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
@@ -197,7 +199,10 @@ pub const MIXER_GROUP_STARTS: [usize; 4] = [1, 4, 7, 10];
|
||||
#[derive(Clone, Default)]
|
||||
struct SmoothingOpen(bool);
|
||||
|
||||
/// The bar's members for one painting tool.
|
||||
/// The bar's members for one painting tool, after the preset picker that carries the size and the hardness: a rule,
|
||||
/// Mode, Opacity and the pressure-for-opacity toggle, Flow and the build-up toggle (not the Pencil), Smoothing and its
|
||||
/// options (the Pencil's Auto Erase in their place), Erase to History for the Eraser, a rule and the
|
||||
/// pressure-for-size toggle. The Mixer Brush shows its load, combinations and mix values instead.
|
||||
#[must_use = "show the bar with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
#[pattern(probe(PaintBar<'static, u32>))]
|
||||
@@ -205,7 +210,6 @@ pub struct PaintBar<'a, M: Value> {
|
||||
tool: PaintTool,
|
||||
values: &'a mut PaintValues<M>,
|
||||
eraser_mode: Option<&'a mut EraserMode>,
|
||||
max_size: f64,
|
||||
modes: &'a [Entry<M>],
|
||||
}
|
||||
|
||||
@@ -229,7 +233,7 @@ pub struct PaintBarOutput<M> {
|
||||
impl<'a, M: Value> PaintBar<'a, M> {
|
||||
/// The bar of `tool` over `values`.
|
||||
pub fn new(tool: PaintTool, values: &'a mut PaintValues<M>) -> Self {
|
||||
PaintBar { tool, values, eraser_mode: None, max_size: 5000.0, modes: &[] }
|
||||
PaintBar { tool, values, eraser_mode: None, modes: &[] }
|
||||
}
|
||||
|
||||
/// The Eraser's mode, shown for the Eraser tool.
|
||||
@@ -238,12 +242,6 @@ impl<'a, M: Value> PaintBar<'a, M> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The largest brush size.
|
||||
pub fn max_size(mut self, max: f64) -> Self {
|
||||
self.max_size = max;
|
||||
self
|
||||
}
|
||||
|
||||
/// The blend modes the Mode list offers.
|
||||
pub fn modes(mut self, modes: &'a [Entry<M>]) -> Self {
|
||||
self.modes = modes;
|
||||
@@ -252,7 +250,7 @@ impl<'a, M: Value> PaintBar<'a, M> {
|
||||
|
||||
/// Shows the members.
|
||||
pub fn show(self, ui: &mut Ui) -> PaintBarOutput<M> {
|
||||
let PaintBar { tool, values, mut eraser_mode, max_size, modes } = self;
|
||||
let PaintBar { tool, values, mut eraser_mode, modes } = self;
|
||||
let words = Env::of(ui).words::<PaintBarWords>();
|
||||
let eraser = if tool == PaintTool::Eraser { eraser_mode.as_deref().copied().unwrap_or_default() } else { EraserMode::Brush };
|
||||
// The Block eraser has no brush engine behind it; the Pencil eraser has no soft edge and no flow.
|
||||
@@ -272,30 +270,31 @@ impl<'a, M: Value> PaintBar<'a, M> {
|
||||
pass.check(ui, &words.sample_all_layers, true, None, pass.values.mixer.sample_all_layers, |v, x| v.mixer.sample_all_layers = x);
|
||||
return;
|
||||
}
|
||||
pass.size(ui, &words.size, max_size, sized);
|
||||
if tool != PaintTool::Pencil {
|
||||
pass.percent(ui, "hardness", &words.hardness, sized && soft, pass.values.hardness, |v, x| v.hardness = x);
|
||||
}
|
||||
// The preset picker before the bar carries the size and the hardness.
|
||||
Divider::vertical().show(ui);
|
||||
if tool == PaintTool::Eraser {
|
||||
pass.eraser(ui, &words, eraser_mode.as_deref_mut());
|
||||
} else {
|
||||
pass.mode(ui, &words.mode, modes);
|
||||
}
|
||||
pass.percent(ui, "opacity", &words.opacity, sized, pass.values.opacity, |v, x| v.opacity = x);
|
||||
pass.check(ui, &words.pressure_opacity, sized, None, pass.values.pressure_opacity, |v, x| v.pressure_opacity = x);
|
||||
pass.toggle(ui, PRESSURE, &words.pressure_opacity, sized, pass.values.pressure_opacity, |v, x| v.pressure_opacity = x);
|
||||
if tool != PaintTool::Pencil {
|
||||
pass.percent(ui, "flow", &words.flow, sized && soft, pass.values.flow, |v, x| v.flow = x);
|
||||
pass.check(ui, &words.build_up, sized && soft, None, pass.values.build_up, |v, x| v.build_up = x);
|
||||
pass.toggle(ui, "sparkles", &words.build_up, sized && soft, pass.values.build_up, |v, x| v.build_up = x);
|
||||
}
|
||||
pass.percent(ui, "smoothing", &words.smoothing, true, pass.values.smoothing.amount, |v, x| v.smoothing.amount = x);
|
||||
pass.smoothing_options(ui, cx, &words);
|
||||
if tool == PaintTool::Pencil {
|
||||
Divider::vertical().show(ui);
|
||||
pass.check(ui, &words.auto_erase, true, Some(&words.auto_erase_tip), pass.values.auto_erase, |v, x| v.auto_erase = x);
|
||||
} else {
|
||||
pass.smoothing_options(ui, cx, &words);
|
||||
}
|
||||
if tool == PaintTool::Eraser {
|
||||
pass.check(ui, &words.erase_to_history, true, None, pass.values.erase_to_history, |v, x| v.erase_to_history = x);
|
||||
}
|
||||
if tool == PaintTool::Pencil {
|
||||
pass.check(ui, &words.auto_erase, true, Some(&words.auto_erase_tip), pass.values.auto_erase, |v, x| v.auto_erase = x);
|
||||
}
|
||||
pass.check(ui, &words.pressure_size, sized, None, pass.values.pressure_size, |v, x| v.pressure_size = x);
|
||||
Divider::vertical().show(ui);
|
||||
pass.toggle(ui, PRESSURE, &words.pressure_size, sized, pass.values.pressure_size, |v, x| v.pressure_size = x);
|
||||
});
|
||||
PaintBarOutput {
|
||||
response: shown.output,
|
||||
@@ -348,23 +347,12 @@ impl<M: Value> Pass<'_, M> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Size row.
|
||||
fn size(&mut self, ui: &mut Ui, caption: &Label, max: f64, enabled: bool) {
|
||||
let current = self.values.size;
|
||||
// The size field draws its own caption, so the wrapper only carries the enabled state. The body may run more than
|
||||
// once in a pass and only the run that reads the input reports its events, so every run's events are collected.
|
||||
let collected: RefCell<EditEvents<f64>> = RefCell::new(EditEvents::new());
|
||||
let _ =
|
||||
Field::new(caption.clone()).side(SideLabel::new().kind(LabelKind::Hidden)).id_salt("size").sizing(Sizing::Content).enabled(enabled).show(
|
||||
ui,
|
||||
|ui, _| {
|
||||
for event in BrushSizeField::new(caption.clone(), Bind::given(current), max).show(ui).edit.events.clone() {
|
||||
collected.borrow_mut().push(event);
|
||||
}
|
||||
},
|
||||
);
|
||||
let events = collected.into_inner();
|
||||
self.emit(events, |v, size| v.size = size);
|
||||
/// A pen toggle over a flag: an icon button that stays pressed while on, named `caption`; a click is one `Set`.
|
||||
fn toggle(&mut self, ui: &mut Ui, icon: &'static str, caption: &Label, enabled: bool, current: bool, set: fn(&mut PaintValues<M>, bool)) {
|
||||
let shown = ToggleButton::new(caption.clone(), Bind::given(current)).icon(IconId::new(icon)).icon_only().size(ControlSize::Md).enabled(enabled).show(ui);
|
||||
if let Some(next) = shown.value().copied() {
|
||||
self.set_with(caption, |v| set(v, next));
|
||||
}
|
||||
}
|
||||
|
||||
/// A percent field over a fraction 0..1.
|
||||
@@ -372,7 +360,7 @@ impl<M: Value> Pass<'_, M> {
|
||||
// The body may run more than once in a pass and only the run that reads the input reports its events, so every
|
||||
// run's events and alert are collected.
|
||||
let collected: RefCell<(EditEvents<Option<f64>>, Option<RangeAlert>)> = RefCell::new((EditEvents::new(), None));
|
||||
let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).sizing(Sizing::Content).enabled(enabled).show(
|
||||
let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).enabled(enabled).show(
|
||||
ui,
|
||||
|ui, _| {
|
||||
let field = NumberField::new(caption.clone(), Bind::given(Some(current * 100.0)))
|
||||
@@ -417,7 +405,6 @@ impl<M: Value> Pass<'_, M> {
|
||||
let current = self.values.mode.clone();
|
||||
let pick = Field::new(caption.clone())
|
||||
.id_salt("mode")
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| Select::new(caption.clone(), Bind::given(current.clone()), entries).show(ui).value().cloned())
|
||||
.inner
|
||||
.flatten();
|
||||
@@ -437,7 +424,6 @@ impl<M: Value> Pass<'_, M> {
|
||||
let current = *mode;
|
||||
let pick = Field::new(words.mode.clone())
|
||||
.id_salt("mode")
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| Select::new(words.mode.clone(), Bind::given(current), &entries).show(ui).value().copied())
|
||||
.inner
|
||||
.flatten();
|
||||
@@ -499,7 +485,6 @@ impl<M: Value> Pass<'_, M> {
|
||||
let pick = Field::new(words.combination.clone())
|
||||
.side(SideLabel::new().kind(LabelKind::Hidden))
|
||||
.id_salt("mixer-combination")
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| Select::new(words.combination.clone(), Bind::given(shown), &entries).show(ui).value().copied())
|
||||
.inner
|
||||
.flatten();
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
craft_ui::words! {
|
||||
/// The words of [`PaintBar`](super::PaintBar), English by default (Photoshop's).
|
||||
pub struct PaintBarWords {
|
||||
/// The Size field's caption.
|
||||
size: "paintBar.size" = "Size";
|
||||
/// The Hardness field's caption.
|
||||
hardness: "paintBar.hardness" = "Hardness";
|
||||
/// The Opacity field's caption.
|
||||
opacity: "paintBar.opacity" = "Opacity";
|
||||
/// The Flow field's caption.
|
||||
|
||||
@@ -7,7 +7,7 @@ use craft_behavior::EditEvent;
|
||||
use craft_color::ui::{PaintChip, PaintChipOutput, ScreenPickGesture};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{Bind, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing};
|
||||
use craft_ui::contract::{Bind, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::Row;
|
||||
@@ -125,13 +125,12 @@ impl<'a> ShapeBar<'a> {
|
||||
let fill = Field::new(words.fill_color.clone())
|
||||
.id_salt("fill")
|
||||
.side(hidden)
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| pass.chip(ui, ShapePaint::Fill));
|
||||
if let Some(out) = fill.inner {
|
||||
pass.take_chip(ShapePaint::Fill, out);
|
||||
}
|
||||
let stroke =
|
||||
Field::new(words.stroke.clone()).id_salt("stroke").sizing(Sizing::Content).show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke));
|
||||
Field::new(words.stroke.clone()).id_salt("stroke").show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke));
|
||||
if let Some(out) = stroke.inner {
|
||||
pass.take_chip(ShapePaint::Stroke, out);
|
||||
}
|
||||
@@ -164,7 +163,6 @@ impl<'a> ShapeBar<'a> {
|
||||
let (events, alert) = Field::new(cell.caption.clone())
|
||||
.id_salt(cell.key)
|
||||
.side(side)
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| cell.show(ui))
|
||||
.inner
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -61,11 +61,11 @@ fn disabled(fixture: &Fixture, label: &str) -> bool {
|
||||
#[trial]
|
||||
fn paint_bar_rules() {
|
||||
let cases: [(PaintTool, EraserMode, &[&str], &[&str]); 5] = [
|
||||
(PaintTool::Brush, EraserMode::Brush, &[], &["Size", "Hardness", "Opacity", "Flow", "Mode"]),
|
||||
(PaintTool::Pencil, EraserMode::Brush, &[], &["Size", "Opacity", "Mode"]),
|
||||
(PaintTool::Eraser, EraserMode::Brush, &[], &["Size", "Hardness", "Opacity", "Flow", "Mode"]),
|
||||
(PaintTool::Eraser, EraserMode::Pencil, &["Hardness", "Flow"], &["Size", "Opacity", "Mode"]),
|
||||
(PaintTool::Eraser, EraserMode::Block, &["Size", "Hardness", "Opacity", "Flow"], &["Mode"]),
|
||||
(PaintTool::Brush, EraserMode::Brush, &[], &["Opacity", "Flow", "Mode", "Build-up"]),
|
||||
(PaintTool::Pencil, EraserMode::Brush, &[], &["Opacity", "Mode", "Pressure controls size"]),
|
||||
(PaintTool::Eraser, EraserMode::Brush, &[], &["Opacity", "Flow", "Mode"]),
|
||||
(PaintTool::Eraser, EraserMode::Pencil, &["Flow", "Build-up"], &["Opacity", "Mode"]),
|
||||
(PaintTool::Eraser, EraserMode::Block, &["Opacity", "Flow", "Pressure controls opacity"], &["Mode"]),
|
||||
];
|
||||
for (tool, eraser, off, on) in cases {
|
||||
let (fixture, _) = harness(tool, eraser, |_| {});
|
||||
|
||||
@@ -7,7 +7,7 @@ use egui::{Response, Ui};
|
||||
use craft_behavior::EditEvents;
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing};
|
||||
use craft_ui::contract::{Bind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::runtime::env::{Env, Label, UnitKind};
|
||||
@@ -130,7 +130,7 @@ impl<'a> VanishingPointBar<'a> {
|
||||
/// One captioned number cell: the edit of `value`, if the user made one this pass.
|
||||
fn number(ui: &mut Ui, key: &'static str, caption: &Label, value: f64, range: RangeInclusive<f64>, kind: UnitKind) -> EditEvents<f64> {
|
||||
let mut edited = EditEvents::new();
|
||||
Field::new(caption.clone()).id_salt(key).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(caption.clone()).id_salt(key).side(SideLabel::new().scrub(true)).show(ui, |ui, _| {
|
||||
let out = NumberField::new(caption.clone(), Bind::given(Some(value))).range(range.clone()).unit_kind(kind).scrub_by_label().show(ui);
|
||||
edited = out.edit.events.map(|v| v.unwrap_or(value));
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_theme::Srgba;
|
||||
use craft_ui::buttons::{IconButton, ToggleButton};
|
||||
use craft_ui::choice::Swatch;
|
||||
use craft_ui::contract::{
|
||||
Bind, Entry, FieldLayout, Gap, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked,
|
||||
Bind, Entry, FieldLayout, Gap, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, clicked,
|
||||
};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::form::Field;
|
||||
@@ -18,7 +18,7 @@ use egui::{Response, Ui};
|
||||
|
||||
use crate::ui::character::paragraph::{align_toggles, direction_toggles};
|
||||
use crate::ui::character::rows::{
|
||||
LengthRow, Lengths, family_field, hidden_side, mixed, number_change, select_row, size_menu, string_entries, toggle_row,
|
||||
LengthRow, Lengths, family_field, hidden_side, mark, mixed, number_change, select_row, size_menu, string_entries, toggle_row,
|
||||
};
|
||||
use crate::ui::character::{
|
||||
COLOR_KEY, CharacterChange, CharacterValues, CharacterWords, ParagraphChange, ParagraphValues, ParagraphWords, SIZE_RANGE,
|
||||
@@ -187,12 +187,13 @@ impl<'a> TypeBar<'a> {
|
||||
let style = select_row(ui, &bar_words.style, hidden_side(), mixed(character.style.clone()), &style_entries, CharacterChange::Style);
|
||||
edits.extend(style.into_iter().map(|event| event.map(TypeBarChange::Character)));
|
||||
|
||||
let size =
|
||||
LengthRow { label: bar_words.size.clone(), side: hidden_side(), value: character.size, range: SIZE_RANGE, presets: &size_presets };
|
||||
// The size glyph the Character panel's size row shows.
|
||||
let side = mark(GlyphLabel::text("tT"), None, FieldLayout::Inside);
|
||||
let size = LengthRow { label: bar_words.size.clone(), side, value: character.size, range: SIZE_RANGE, presets: &size_presets };
|
||||
let (event, _) = lengths.row(ui, size);
|
||||
edits.extend(number_change(event, CharacterChange::Size).into_iter().map(|event| event.map(TypeBarChange::Character)));
|
||||
|
||||
let method = Field::new(option_words.anti_alias.clone()).side(hidden_side()).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
let method = Field::new(option_words.anti_alias.clone()).side(hidden_side()).show(ui, |ui, _| {
|
||||
Select::new(option_words.anti_alias.clone(), Bind::given(mixed(anti_alias)), &method_entries).placeholder("—").show(ui).events
|
||||
});
|
||||
edits.extend(method.inner.unwrap_or_default().map(TypeBarChange::AntiAlias));
|
||||
@@ -207,7 +208,6 @@ impl<'a> TypeBar<'a> {
|
||||
let side = SideLabel::new().kind(LabelKind::Hidden).layout(FieldLayout::Beside);
|
||||
let well = Field::new(character_words.text_color.clone())
|
||||
.side(side)
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| Swatch::new(character_words.text_color.clone(), color).picker(COLOR_KEY).show(ui).pick_color);
|
||||
if let Some(request) = well.inner.flatten() {
|
||||
requests.request_color(request);
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::open::open_now;
|
||||
use super::placement::{Placement, measure_layer, overlay_of, shown_placement};
|
||||
use super::regions::{
|
||||
LabelColumns, LabelsFound, RegionFrame, RegionSizes, RuleBands, end_full_height, footer_in_end, footer_rule_under, gap_of, header_gap_of,
|
||||
label_extra_of, least_of, pad_of, pad_vec, paint_edge_rule, paint_rules, rect_of, shared_labels, shared_line,
|
||||
label_extra_of, least_of, pad_of, paint_edge_rule, paint_rules, rect_of, shared_labels, shared_line,
|
||||
};
|
||||
use super::reorder::REORDER_BAND;
|
||||
use super::scroll::{
|
||||
@@ -283,12 +283,12 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
self.given.1 |= self.over_room(props, &env, at, ui.ctx(), id);
|
||||
let measured = self.measured_body.unwrap_or(Vec2::ZERO);
|
||||
let body = if self.presence.visible { Vec2::new(measured.x, measured.y * self.presence.t) } else { Vec2::ZERO };
|
||||
let room = self.room.x - 2.0 * pad_vec(scx.tokens, props).x;
|
||||
let room = self.room.x - 2.0 * self.pads(props, scx.tokens).x;
|
||||
let width = if self.measured_body.is_some() { self.shared_width(room, props) } else { 0.0 };
|
||||
self.overflow = self.wanted_width(props).map_or(0.0, |wanted| (wanted - room.max(0.0)).max(0.0));
|
||||
let (header, end) = (self.measured_header.unwrap_or(Vec2::ZERO), self.measured_end.unwrap_or(Vec2::ZERO));
|
||||
let height = self.regions_size(props, body, header, self.measured_footer, end).y;
|
||||
Vec2::new(width, height) + 2.0 * pad_vec(scx.tokens, props)
|
||||
Vec2::new(width, height) + 2.0 * self.pads(props, scx.tokens)
|
||||
}
|
||||
|
||||
/// The regions run once in an invisible sizing pass over the room, as `content` runs them, and the container takes
|
||||
@@ -371,7 +371,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
if at.ui.is_sizing_pass() && self.given == (true, true) && self.room.is_finite() && !scrolled_share {
|
||||
return self.room;
|
||||
}
|
||||
let pad = 2.0 * pad_vec(at.scx.tokens, &props);
|
||||
let pad = 2.0 * self.pads(&props, at.scx.tokens);
|
||||
let vertical = scroll_of(&props).is_some_and(|scroll| scroll.vertical_on());
|
||||
let tolerance = measure_tolerance(crate::runtime::egui::scale::pixels_per_point(&ctx));
|
||||
// A record a run of this pass left serves as before; a kept one serves only while the inputs it was measured
|
||||
@@ -500,7 +500,13 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
// where it is shown: its measure never sets the column's width.
|
||||
let held = !self.given.0 && self.held(props, &Env::of(ui));
|
||||
let room = if held { room.min(crate::layout::flow_room(ui).x) } else { room };
|
||||
Vec2::new(crate::layout::fill_size(ui, id, craft_behavior::Axis::X, size.x, room, self.given.0 || held), size.y)
|
||||
// Given the height of the row line it sits on, it fills that line (`given_axes`).
|
||||
let height = if self.given.1 {
|
||||
crate::layout::fill_size(ui, id, craft_behavior::Axis::Y, size.y, crate::layout::flow_room(ui).y, true)
|
||||
} else {
|
||||
size.y
|
||||
};
|
||||
Vec2::new(crate::layout::fill_size(ui, id, craft_behavior::Axis::X, size.x, room, self.given.0 || held), height)
|
||||
}
|
||||
Sizing::Content => size,
|
||||
}
|
||||
@@ -520,6 +526,12 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
layout_memory::measured(ctx, sub(id, "first")).map(|found| found.took.y)
|
||||
}
|
||||
|
||||
/// A container with no header whose body is an unwrapped row reports that row's line as its first line.
|
||||
fn first_is_row_line(&self, comp: &C) -> bool {
|
||||
let props = comp.props(Internal::new());
|
||||
props.header.is_none() && super::size::unwrapped_row(props)
|
||||
}
|
||||
|
||||
fn member(&self, comp: &C) -> bool {
|
||||
comp.props(Internal::new()).label.is_some()
|
||||
}
|
||||
@@ -539,7 +551,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
return None;
|
||||
}
|
||||
let tokens = cx.tokens;
|
||||
let pad = pad_vec(tokens, &props);
|
||||
let pad = self.pads(&props, tokens);
|
||||
let inner = content.shrink2(pad);
|
||||
let regions = self.regions(&props, inner, pad, self.room_size(rect, inner), rtl, self.measured_sizes());
|
||||
let (_, slots) = self.header_line(regions.header, pad_of(tokens, header.inset), parts, rtl);
|
||||
@@ -551,7 +563,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
let ctx = pcx.ui.ctx().clone();
|
||||
let rtl = pcx.flow.is_rtl();
|
||||
let tokens = pcx.tokens;
|
||||
let pad = pad_vec(tokens, &props);
|
||||
let pad = self.pads(&props, tokens);
|
||||
let inner = pcx.content_rect.shrink2(pad);
|
||||
let room = self.room_size(rect, inner);
|
||||
let regions = self.regions(&props, inner, pad, room, rtl, self.measured_sizes());
|
||||
@@ -679,7 +691,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
let rtl = env.direction.is_rtl();
|
||||
let node = matches!(C::ROLE, Role::Node(_));
|
||||
let scroll = scroll_of(&props);
|
||||
let pad = pad_vec(&env.tokens, &props);
|
||||
let pad = self.pads(&props, &env.tokens);
|
||||
let inner = cx.core.content_rect.shrink2(pad);
|
||||
let room = self.room_size(rect, inner);
|
||||
let mut regions = self.regions(&props, inner, pad, room, rtl, self.measured_sizes());
|
||||
@@ -791,6 +803,8 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
(regions.body, regions.beside) = (placed.body, placed.beside);
|
||||
}
|
||||
let line = shared_line(&props, beside);
|
||||
// A row given its height sets its line at the middle of its band: the line is as high as the band.
|
||||
let line = if self.centres_line(&props) { Some(line.unwrap_or(0.0).max(regions.body.height())) } else { line };
|
||||
// B2 label: the control gets the rect the label leaves; the label column adds to the container's extent.
|
||||
let mut body_rect = regions.body;
|
||||
let mut label_rect = Rect::NOTHING;
|
||||
@@ -1256,7 +1270,7 @@ impl BodyHooks<'_> {
|
||||
) -> Vec2 {
|
||||
let props = Arc::clone(&self.props);
|
||||
let (id, ctx) = (cx.core.id, at.ui.ctx().clone());
|
||||
let pad = 2.0 * pad_vec(at.scx.tokens, &props);
|
||||
let pad = 2.0 * self.pads(&props, at.scx.tokens);
|
||||
#[cfg(feature = "testing")]
|
||||
crate::runtime::measure::count_body(&ctx, id);
|
||||
layout_memory::begin_measure(&ctx, id);
|
||||
|
||||
@@ -49,12 +49,13 @@ pub fn pad_of(tokens: &UiTokens, pad: Pad) -> f32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// A container's padding on each side along each axis: its tier on the edges its props name, none on the others.
|
||||
pub(super) fn pad_vec(tokens: &UiTokens, props: &ContainerProps) -> Vec2 {
|
||||
let pad = pad_of(tokens, props.pad);
|
||||
match props.pad_edges {
|
||||
/// A container's padding on each side along each axis: its tier on `edges`, none on the others.
|
||||
pub(super) fn pad_vec(tokens: &UiTokens, pad: Pad, edges: PadEdges) -> Vec2 {
|
||||
let pad = pad_of(tokens, pad);
|
||||
match edges {
|
||||
PadEdges::All => Vec2::splat(pad),
|
||||
PadEdges::Block => Vec2::new(0.0, pad),
|
||||
PadEdges::Inline => Vec2::new(pad, 0.0),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::placement::overlay_of;
|
||||
use super::regions::{RegionSizes, end_full_height, footer_in_end};
|
||||
use super::scroll::scroll_of;
|
||||
use crate::contract::run::ShowAt;
|
||||
use crate::contract::{ContainerProps, Mount, ShellPane, Sizing};
|
||||
use crate::contract::{ContainerProps, Mount, PadEdges, ShellPane, Sizing};
|
||||
use crate::runtime::egui::areas;
|
||||
use crate::runtime::env::Env;
|
||||
use crate::runtime::layout_memory;
|
||||
@@ -117,9 +117,15 @@ impl<'b> BodyHooks<'b> {
|
||||
|
||||
/// The axes the container is given where `env` is its parent's: a rect it is shown at gives both; an inline
|
||||
/// container that fills an axis takes the room only where its parent was given that axis.
|
||||
///
|
||||
/// A container that fits its content in a bar (`ContainerProps::content_in_bar`) is not given the width there.
|
||||
/// A fill-width container whose body is a row, shown on the line of a row given its height, is given that height
|
||||
/// too: the line is a fixed cross extent, and the container fills it (a bar in a shell slot).
|
||||
pub(super) fn given_axes(&self, props: &ContainerProps, env: &Env, at: ShowAt) -> (bool, bool) {
|
||||
let sizing = self.sizing(props);
|
||||
let (x, y) = (sizing != Sizing::Content, sizing == Sizing::Fill);
|
||||
let fills_line = sizing == Sizing::FillWidth && unwrapped_row(props) && env.row_line.is_some();
|
||||
let fits_bar = props.content_in_bar && env.values.get::<crate::contract::InBar>().0;
|
||||
let (x, y) = (sizing != Sizing::Content && !fits_bar, sizing == Sizing::Fill || fills_line);
|
||||
match (at, &props.mount) {
|
||||
(ShowAt::Rect(_), _) => (true, true),
|
||||
(ShowAt::Flow, Mount::Inline) => (x && env.gives_width(), y && !env.content.1),
|
||||
@@ -134,6 +140,24 @@ impl<'b> BodyHooks<'b> {
|
||||
matches!((at, &props.mount), (ShowAt::Flow, Mount::Inline)) && self.sizing(props) == Sizing::Content && env.given_column
|
||||
}
|
||||
|
||||
/// Whether the container centres its body's line in the height it is given: its body is a row that does not scroll
|
||||
/// along the height, and the container is given its height (a rect it is shown at, a fill, a fixed row line it
|
||||
/// fills). Its padding then keeps the members off the start and end edges only (`pad_edges`).
|
||||
pub(super) fn centres_line(&self, props: &ContainerProps) -> bool {
|
||||
self.given.1 && unwrapped_row(props) && !scroll_of(props).is_some_and(|scroll| scroll.vertical_on())
|
||||
}
|
||||
|
||||
/// The edges the container's padding tier applies to: `ContainerProps::pad_edges`, or the start and end edges where
|
||||
/// the container centres its line in its height.
|
||||
pub(super) fn pad_edges(&self, props: &ContainerProps) -> PadEdges {
|
||||
if self.centres_line(props) { PadEdges::Inline } else { props.pad_edges }
|
||||
}
|
||||
|
||||
/// The container's padding on each side along each axis.
|
||||
pub(super) fn pads(&self, props: &ContainerProps, tokens: &crate::style::UiTokens) -> Vec2 {
|
||||
super::regions::pad_vec(tokens, props.pad, self.pad_edges(props))
|
||||
}
|
||||
|
||||
/// Whether the container's body is laid out across the width it is offered: the container is given the width,
|
||||
/// passes it on, or is held across the width its column settled on.
|
||||
pub(super) fn wide(&self) -> bool {
|
||||
@@ -293,3 +317,8 @@ impl<'b> BodyHooks<'b> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the container's body is a `Row` that does not wrap: its children sit on one line.
|
||||
pub(super) fn unwrapped_row(props: &ContainerProps) -> bool {
|
||||
matches!(props.layout, crate::layout::BodyLayout::Row { wrap: false, .. })
|
||||
}
|
||||
|
||||
@@ -147,6 +147,9 @@ pub enum PadEdges {
|
||||
/// The top and bottom edges only: a column given its width whose children centre across it, as a tool rail does
|
||||
/// in its pane.
|
||||
Block,
|
||||
/// The start and end edges only: a row given its height that centres its line in it, as a bar does in its pane.
|
||||
/// The body picks it for such a row whatever the props name.
|
||||
Inline,
|
||||
}
|
||||
|
||||
/// The padding of every popup surface around its content.
|
||||
@@ -691,6 +694,9 @@ pub struct ContainerProps {
|
||||
pub pad_edges: PadEdges,
|
||||
/// How the size follows the content.
|
||||
pub sizing: Sizing,
|
||||
/// Among the members of a bar (`InBar`) the container takes its content width, whatever `sizing` says: a field
|
||||
/// fills the width of a form and fits its content in a bar. Setting `sizing` clears it.
|
||||
pub content_in_bar: bool,
|
||||
/// The height the body offers its children in flow, in place of the flow's (unbounded in a scrolling body): the
|
||||
/// most a child takes. Every child takes its content height, a child that fills or scrolls at most this height,
|
||||
/// as a scrolling list is as tall as its rows until they outgrow the room. A host that shows content of either
|
||||
@@ -777,6 +783,7 @@ impl ContainerProps {
|
||||
&& self.pad == other.pad
|
||||
&& self.pad_edges == other.pad_edges
|
||||
&& self.sizing == other.sizing
|
||||
&& self.content_in_bar == other.content_in_bar
|
||||
&& self.room_height == other.room_height
|
||||
&& self.layout == other.layout
|
||||
&& self.header == other.header
|
||||
@@ -806,6 +813,7 @@ impl ContainerProps {
|
||||
pad: Pad::None,
|
||||
pad_edges: PadEdges::All,
|
||||
sizing: Sizing::Content,
|
||||
content_in_bar: false,
|
||||
room_height: None,
|
||||
layout: BodyLayout::Stack,
|
||||
header: None,
|
||||
@@ -866,6 +874,13 @@ impl ContainerProps {
|
||||
/// How the size follows the content.
|
||||
pub const fn sizing(mut self, sizing: Sizing) -> Self {
|
||||
self.sizing = sizing;
|
||||
self.content_in_bar = false;
|
||||
self
|
||||
}
|
||||
|
||||
/// Takes the content width among the members of a bar ([`content_in_bar`](Self::content_in_bar)).
|
||||
pub const fn content_in_bar(mut self) -> Self {
|
||||
self.content_in_bar = true;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +144,13 @@ pub(crate) trait ShapeHooks<C: Component> {
|
||||
Some(height / 2.0)
|
||||
}
|
||||
|
||||
/// Whether the root's first line is the line of its own unwrapped `Row` body: it sits on a `Row`'s line by that
|
||||
/// line even where a child of more than one line makes it taller, so the members of a row nested in a row share
|
||||
/// the outer row's line.
|
||||
fn first_is_row_line(&self, _comp: &C) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Whether the root is one member of a bar's line, shown whole or not at all: a leaf is; a body is when it has a
|
||||
/// side label (a captioned field), and otherwise only lays out the members it holds.
|
||||
fn member(&self, _comp: &C) -> bool {
|
||||
@@ -557,6 +564,7 @@ pub(crate) trait ErasedPass<'a> {
|
||||
fn sized(&self, ui: &Ui, id: Id, size: Vec2) -> Vec2;
|
||||
fn fills_width(&self) -> bool;
|
||||
fn first_line(&self, ctx: &Context, id: Id, height: f32) -> Option<f32>;
|
||||
fn first_is_row_line(&self) -> bool;
|
||||
fn member(&self) -> bool;
|
||||
fn fills_width_only(&self) -> bool;
|
||||
fn arena(&self) -> bool;
|
||||
@@ -804,7 +812,8 @@ fn place_root(p: &Pass<'_, '_, '_>, ui: &mut Ui, at: ShowAt, env: &Env, size: Ve
|
||||
.then(|| crate::layout::flow_room(ui).x)
|
||||
.filter(|width| width.is_finite())
|
||||
.unwrap_or(0.0);
|
||||
let flowed = steps::place(ui, at, Vec2::new(p.measured.x.min(size.x), size.y), InFlow { fill: false, first: first(size.y) });
|
||||
let line = p.p.first_is_row_line();
|
||||
let flowed = steps::place(ui, at, Vec2::new(p.measured.x.min(size.x), size.y), InFlow { fill: false, first: first(size.y), line });
|
||||
// The column's first sweep learns which of its held children measured narrower than it settles on.
|
||||
if let Some(ColumnSweep::Count(column)) = env.column {
|
||||
crate::layout::report_held(&ctx, column, flowed.width());
|
||||
@@ -814,7 +823,7 @@ fn place_root(p: &Pass<'_, '_, '_>, ui: &mut Ui, at: ShowAt, env: &Env, size: Ve
|
||||
} else {
|
||||
let fill = p.p.fills_width() && !p.p.fills_width_only();
|
||||
let size = if inert { Vec2::ZERO } else { size };
|
||||
steps::place(ui, at, size, InFlow { fill, first: first(size.y) })
|
||||
steps::place(ui, at, size, InFlow { fill, first: first(size.y), line: p.p.first_is_row_line() })
|
||||
};
|
||||
(rect, held)
|
||||
}
|
||||
|
||||
@@ -405,6 +405,10 @@ impl<'a, C: Component> ErasedPass<'a> for TypedPass<'_, 'a, C> {
|
||||
self.hooks.first_line(self.comp, ctx, id, height)
|
||||
}
|
||||
|
||||
fn first_is_row_line(&self) -> bool {
|
||||
self.hooks.first_is_row_line(self.comp)
|
||||
}
|
||||
|
||||
fn member(&self) -> bool {
|
||||
self.hooks.member(self.comp)
|
||||
}
|
||||
|
||||
@@ -898,6 +898,9 @@ pub(crate) struct InFlow {
|
||||
/// rows run along Y, or a container whose first child is one. The child is one line when that centre lies at
|
||||
/// half its height (`one_line`).
|
||||
pub first: Option<f32>,
|
||||
/// `first` is the line of the child's own unwrapped `Row` body: the child sits on a row's line by it even when it
|
||||
/// is more than one line (a nested row with a child of two lines).
|
||||
pub line: bool,
|
||||
}
|
||||
|
||||
/// How far a one-line child's first-line centre may lie from half its height: half a pixel at the scales the box runs.
|
||||
@@ -919,7 +922,7 @@ fn one_line(first: Option<f32>, height: f32) -> Option<f32> {
|
||||
/// sits at the vertical centre of its cell.
|
||||
#[doc(hidden)]
|
||||
pub fn place_in_flow(ui: &mut Ui, size: Vec2) -> Rect {
|
||||
place_in_cell(ui, size, InFlow { fill: false, first: Some(size.y / 2.0) })
|
||||
place_in_cell(ui, size, InFlow { fill: false, first: Some(size.y / 2.0), line: false })
|
||||
}
|
||||
|
||||
/// `place_in_flow` for a child that is `child`. In a measuring run the child reports its line to the row around it
|
||||
@@ -927,7 +930,7 @@ pub fn place_in_flow(ui: &mut Ui, size: Vec2) -> Rect {
|
||||
pub(crate) fn place_in_cell(ui: &mut Ui, size: Vec2, child: InFlow) -> Rect {
|
||||
let env = Env::of(ui);
|
||||
let (line, target) = (env.row_line, env.first_line);
|
||||
let child = InFlow { first: one_line(child.first, size.y), ..child };
|
||||
let child = InFlow { first: if child.line { child.first } else { one_line(child.first, size.y) }, ..child };
|
||||
let above = line.and_then(|line| line.centre).zip(child.first).map_or(0.0, |(centre, first)| (centre - first).max(0.0));
|
||||
let slot = Vec2::new(size.x, line.and_then(|line| line.height).map_or(above + size.y, |height| height.max(above + size.y)));
|
||||
let (rect, in_cell) = take_in(ui, env.grid, slot);
|
||||
|
||||
@@ -9,6 +9,7 @@ use craft_ui::contract::{BodyCx, SizeLimits};
|
||||
use craft_ui::docking::{DockHeights, DockPanels, PanelSpec};
|
||||
use craft_ui::menu::PanelRow;
|
||||
use craft_ui::notices::Notice;
|
||||
use craft_window::policy::WindowKind;
|
||||
use egui::Ui;
|
||||
|
||||
/// The viewer's panels as the dock's contents.
|
||||
@@ -29,6 +30,8 @@ impl DockPanels<PanelId> for GalleryDock<'_> {
|
||||
PanelId::Stories => spec.heights(DockHeights::new(80.0).compact(60.0)),
|
||||
PanelId::Properties | PanelId::Inspect | PanelId::Tokens => spec.heights(DockHeights::new(240.0).compact(120.0).fill(300.0)),
|
||||
PanelId::Problems | PanelId::Detail | PanelId::AppSizes => spec.heights(DockHeights::new(210.0)),
|
||||
// The centre's pages are documents: the dock shows them edge to edge.
|
||||
PanelId::Overview | PanelId::Component(_) | PanelId::Preview => spec.window_kind(WindowKind::Document),
|
||||
_ => spec,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ fn title_bar(ui: &mut Ui, state: &MockState) {
|
||||
let document = &state.document;
|
||||
let title = if document.dirty { Title::unsaved(document.title.clone()) } else { Title::new(document.title.clone()) };
|
||||
let frame = Frame::Integrated(Captions { family: CaptionFamily::Generic, layout: Layout::default() });
|
||||
TitleBar::new().frame(frame).separator().show_titled(
|
||||
TitleBar::new().frame(frame).show_titled(
|
||||
ui,
|
||||
title,
|
||||
|ui, _| {
|
||||
|
||||
@@ -500,6 +500,7 @@ pub(crate) fn derive(input: TokenStream) -> syn::Result<TokenStream> {
|
||||
quote! {
|
||||
fn set_sizing(&mut self, sizing: #k::contract::Sizing, _: #k::contract::Internal) {
|
||||
self.#field.sizing = sizing;
|
||||
self.#field.content_in_bar = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -256,7 +256,10 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
|
||||
/// The group named by `anchor` (one of its panels) with its `panels`, `active` showing. The group is named by the
|
||||
/// active panel's title.
|
||||
pub fn new(anchor: P, panels: &'a [PanelTitle], active: PanelKey) -> Self {
|
||||
let props = ContainerProps::new().sizing(Sizing::Fill).header(HeaderRegion::new()).command_scope(DockCommands::SCOPE);
|
||||
let props = ContainerProps::new()
|
||||
.sizing(Sizing::Fill)
|
||||
.header(HeaderRegion::new().fill(SurfaceKind::Background))
|
||||
.command_scope(DockCommands::SCOPE);
|
||||
let title = panels.iter().find(|panel| panel.key == active).map(|panel| panel.title.clone()).unwrap_or_default();
|
||||
DockGroup {
|
||||
common: Common::new(),
|
||||
@@ -336,10 +339,9 @@ impl<P: Clone + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
|
||||
}
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let strip = Rect::from_min_size(cx.rect.min, Vec2::new(cx.rect.width(), cx.style.header));
|
||||
// Painted here, not as the container's surface, which lies over what `paint` draws.
|
||||
// Painted here, not as the container's surface, which lies over what `paint` draws. The header's band paints
|
||||
// the strip over it.
|
||||
ui.draw().surface(cx.rect, SurfaceKind::Panel, Corners::All);
|
||||
ui.draw().surface(strip, SurfaceKind::Background, Corners::None);
|
||||
if cx.part_if_declared(MENU).is_some() {
|
||||
ui.face(MENU, Self::menu_face(cx.words::<DockWords>().panel_menu.clone()));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
use super::hide::{self, Shown};
|
||||
use crate::contract::overlay::PlacementChange;
|
||||
use crate::contract::{Bind, BindMut, BodyCx, Cx, Entry, NoValue, Outcome, Pad, Pointer as _, Props as _, ShowContainer as _, Sizing, WordSetCx as _};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::docking::SplitFramesCx as _;
|
||||
use crate::docking::stack::{StackSection, StackSections, section_heights};
|
||||
use crate::docking::tree::FrameRules;
|
||||
@@ -638,18 +637,9 @@ fn float_space<P: Clone + PartialEq>(bounds: Rect, sizes: &DockSizes, config: &D
|
||||
space
|
||||
}
|
||||
|
||||
/// Shows a docked panel's body as its group holds it: filling the group's body, inset from its edges by the panel
|
||||
/// padding. The group is the body's panel and its tab the body's title, so a docked body pads and frames nothing itself.
|
||||
/// A document's body (`WindowKind::Document`) is no panel content and is shown edge to edge.
|
||||
fn inset(ui: &mut Ui, cx: &mut BodyCx<'_>, document: bool, mut body: impl FnMut(&mut Ui, &mut BodyCx<'_>)) {
|
||||
if document {
|
||||
body(ui, cx);
|
||||
} else {
|
||||
let _ = Stack::new().fill().pad(Pad::Regular).show(ui, |ui, cx| body(ui, cx));
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `spec` is a document's: its body is shown without the panel inset.
|
||||
/// Whether `spec` is a document's: its group shows its body edge to edge. Every other docked body fills its group's
|
||||
/// body, inset from its edges by the panel padding: the group is the body's panel and its tab the body's title, so a
|
||||
/// docked body pads and frames nothing itself.
|
||||
fn document(spec: &PanelSpec) -> bool {
|
||||
matches!(spec.window_kind, WindowKind::Document)
|
||||
}
|
||||
@@ -813,6 +803,8 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
.command_states(states.clone());
|
||||
if minimized {
|
||||
group = group.minimized();
|
||||
} else if !document(scene.spec(&members[at])) {
|
||||
group = group.pad(Pad::Regular);
|
||||
}
|
||||
if scene.config.tab_close_buttons {
|
||||
group = group.closable();
|
||||
@@ -825,19 +817,19 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let rect = match at {
|
||||
GroupAt::Measure(width) => {
|
||||
let measured =
|
||||
make(active, look.minimized).measure_in(ui, Proposal::Width(width), |ui, cx| inset(ui, cx, document(&scene.spec(shown)), |ui, body| panels.borrow_mut().body(shown, ui, body)));
|
||||
make(active, look.minimized).measure_in(ui, Proposal::Width(width), |ui, body| panels.borrow_mut().body(shown, ui, body));
|
||||
return Some(measured.y);
|
||||
}
|
||||
GroupAt::Show(rect) => rect,
|
||||
};
|
||||
let output = make(active, look.minimized).show_at(ui, rect, |ui, cx| inset(ui, cx, document(&scene.spec(shown)), |ui, body| panels.borrow_mut().body(shown, ui, body))).output;
|
||||
let output = make(active, look.minimized).show_at(ui, rect, |ui, body| panels.borrow_mut().body(shown, ui, body)).output;
|
||||
// The size `panel` floats at out of this group: the group's width, and the height the group measures at with
|
||||
// `panel` shown in a floating window's room, so content that fills the body takes that room.
|
||||
let fitted = |ui: &Ui, panel: &P| {
|
||||
let at = members.iter().position(|member| member == panel).unwrap_or(active);
|
||||
let room = Vec2::new(rect.width(), scene.space.content_room());
|
||||
let measured = make(at, false).id(output.response.id).measure_in(ui, Proposal::Size(room), |ui, cx| {
|
||||
inset(ui, cx, document(&scene.spec(&members[at])), |ui, body| panels.borrow_mut().body(&members[at], ui, body));
|
||||
let measured = make(at, false).id(output.response.id).measure_in(ui, Proposal::Size(room), |ui, body| {
|
||||
panels.borrow_mut().body(&members[at], ui, body);
|
||||
});
|
||||
Vec2::new(rect.width(), measured.y)
|
||||
};
|
||||
|
||||
@@ -22,13 +22,13 @@ use crate::contract::{
|
||||
};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::list::RowTest;
|
||||
use crate::pickers::SelectFace;
|
||||
use crate::pickers::{FaceKind, SelectFace};
|
||||
use crate::popover::Popover;
|
||||
use crate::primitives::ContentPainterCx;
|
||||
use crate::runtime::env::{EnvView, Label};
|
||||
use crate::runtime::memory::StageAccess;
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::style::{ComponentStyle, FocusLook, StyleCx, SurfaceLook};
|
||||
use crate::style::{ComponentStyle, FocusLook, StyleCx, SurfaceLook, UiTokens};
|
||||
use crate::tile_grid::TileZoom;
|
||||
use craft_behavior::{EditEvent, EditEvents, HitLevel, HitPriority, Intent, Metrics, Mixed, PartKey, PressPhase, Sense, Value};
|
||||
use egui::{Pos2, Rect, Response, Ui, Vec2};
|
||||
@@ -63,6 +63,10 @@ pub enum PickerField {
|
||||
Name,
|
||||
/// The thumbnail, then the name.
|
||||
ThumbnailAndName,
|
||||
/// A compact chip that sits on a bar's line: a small thumbnail over the caption, the dropdown arrow beside them,
|
||||
/// on no field well (the hover fill shows under the pointer and while the presets are open). A brush preset's tip
|
||||
/// over its size in an options bar.
|
||||
Chip,
|
||||
}
|
||||
|
||||
/// The style of a preset picker's field: the field well and the focus edge; the face carries the padding.
|
||||
@@ -516,6 +520,7 @@ struct PickerFace<'a, K: Value + Eq + Hash + 'static> {
|
||||
common: Common,
|
||||
value: Bind<'a, Option<K>>,
|
||||
rows: &'a [PresetRow<K>],
|
||||
#[style_key]
|
||||
field: PickerField,
|
||||
cell_shape: CellShape,
|
||||
placeholder: Option<Label>,
|
||||
@@ -545,6 +550,11 @@ impl<K: Value> Outcome for FaceOutput<K> {
|
||||
}
|
||||
|
||||
impl<K: Value + Eq + Hash + 'static> PickerFace<'_, K> {
|
||||
/// Whether the field shows the thumbnail without the name.
|
||||
fn thumb_only(&self) -> bool {
|
||||
matches!(self.field, PickerField::Thumbnail | PickerField::Chip)
|
||||
}
|
||||
|
||||
fn preset(&self, key: &K) -> Option<&PresetRow<K>> {
|
||||
self.rows.iter().find(|row| !row.is_group() && row.key == *key)
|
||||
}
|
||||
@@ -559,8 +569,9 @@ impl<K: Value + Eq + Hash + 'static> PickerFace<'_, K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `face` with the caption under its thumbnail, when the picker has one.
|
||||
/// `face` with the caption under its thumbnail, when the picker has one, at the chip's size for a chip.
|
||||
fn captioned<'f>(&self, face: SelectFace<'f>) -> SelectFace<'f> {
|
||||
let face = if self.field == PickerField::Chip { face.kind(FaceKind::Chip) } else { face };
|
||||
match &self.caption {
|
||||
Some(caption) => face.thumb_caption(caption.clone()),
|
||||
None => face,
|
||||
@@ -569,7 +580,7 @@ impl<K: Value + Eq + Hash + 'static> PickerFace<'_, K> {
|
||||
|
||||
/// `face` with an empty thumbnail of the cell shape, and the name unless the field shows the thumbnail alone.
|
||||
fn empty_thumb<'f>(&self, face: SelectFace<'f>) -> SelectFace<'f> {
|
||||
self.captioned(face.thumb(self.cell_shape.aspect(), |_, _| {}).name(self.field != PickerField::Thumbnail))
|
||||
self.captioned(face.thumb(self.cell_shape.aspect(), |_, _| {}).name(!self.thumb_only()))
|
||||
}
|
||||
|
||||
/// The face of a field showing `text`: with a `row`, its thumbnail and name as `field` says; without, the muted
|
||||
@@ -578,7 +589,7 @@ impl<K: Value + Eq + Hash + 'static> PickerFace<'_, K> {
|
||||
fn face_of(&self, text: Label, row: Option<&PresetRow<K>>, paint: bool) -> SelectFace<'static> {
|
||||
let face = SelectFace::new(text);
|
||||
match (row, self.field) {
|
||||
(None, PickerField::Thumbnail) => self.empty_thumb(face.placeholder()),
|
||||
(None, PickerField::Thumbnail | PickerField::Chip) => self.empty_thumb(face.placeholder()),
|
||||
(None, _) => face.placeholder(),
|
||||
(Some(row), field) => match (&row.preview, field) {
|
||||
(_, PickerField::Name) | (None, _) => face,
|
||||
@@ -603,8 +614,19 @@ impl<K: Value + Eq + Hash + 'static> Component for PickerFace<'_, K> {
|
||||
type Style = PresetPickerStyle;
|
||||
type Output = FaceOutput<K>;
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: PickerFaceStyleKey<K>) -> PresetPickerStyle {
|
||||
PresetPickerStyle { surface: cx.dropdown(), metrics: Metrics::new(), focus: cx.focus_look() }
|
||||
fn style(cx: &StyleCx<'_>, key: PickerFaceStyleKey<K>) -> PresetPickerStyle {
|
||||
let surface = if key.field == PickerField::Chip {
|
||||
// A chip has no well: the state layer, held at the hover fill while the presets are open, as the
|
||||
// dropdown's well is.
|
||||
let mut look = SurfaceLook::new(cx.state_layer()).radius(UiTokens::corner(cx.tokens.shape.radius.control));
|
||||
let hover = cx.color(cx.tokens.color.state.hover);
|
||||
look.fill.off.hover = hover;
|
||||
look.fill.off.pressed = hover;
|
||||
look
|
||||
} else {
|
||||
cx.dropdown()
|
||||
};
|
||||
PresetPickerStyle { surface, metrics: Metrics::new(), focus: cx.focus_look() }
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//! Stories of `PresetPicker`.
|
||||
|
||||
use super::{PickerField, PresetPicker};
|
||||
use crate::bars::{Bar, BarKind};
|
||||
use crate::choice::SwatchFace;
|
||||
use crate::contract::{Bind, Role, Validity};
|
||||
use crate::contract::{Bind, Role, ShowContainer as _, Validity};
|
||||
use crate::list::ThumbAspect;
|
||||
use crate::patterns::presets::{PresetRow, PresetState};
|
||||
use crate::runtime::env::Message;
|
||||
@@ -37,6 +38,18 @@ fn preset_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
PresetPicker::new("Swatch", Bind::bound(swatch), &rows, Bind::bound(state)).field(PickerField::ThumbnailAndName).show(ui).into()
|
||||
}
|
||||
|
||||
/// The compact chip in an options bar: the swatch over its caption, on the bar's line.
|
||||
#[story(PresetPicker<'static, u32>, covers = [], drive = Drive::Never)]
|
||||
fn preset_picker_chip(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rows = rows();
|
||||
let (swatch, state) = data.value("chip", (Some(TEAL), PresetState::<u32>::new()));
|
||||
let mut output = None;
|
||||
Bar::new("Brush options", BarKind::Options).show(ui, |ui, _| {
|
||||
output = Some(PresetPicker::new("Swatch", Bind::bound(&mut *swatch), &rows, Bind::bound(&mut *state)).field(PickerField::Chip).caption("20").show(ui));
|
||||
});
|
||||
output.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
#[story(PresetPicker<'static, u32>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn preset_picker_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rows = rows();
|
||||
|
||||
@@ -14,7 +14,7 @@ use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow};
|
||||
use super::words::ShellWords;
|
||||
use crate::contract::overlay::Resize;
|
||||
use crate::contract::{
|
||||
Bind, BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, ShellPane,
|
||||
Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, ShellPane,
|
||||
ShowContainer as _, Sizing,
|
||||
};
|
||||
use crate::notices::ToastStack;
|
||||
@@ -121,9 +121,12 @@ impl ShellRegion {
|
||||
ShellRegion { common: Common::new(), props, shell: Some(shell), senses_surface: false }
|
||||
}
|
||||
|
||||
/// A pane of the window; it fills the room its edge gives it.
|
||||
/// A pane of the window; it fills the room its edge gives it. A top or bottom pane lays its content along its edge
|
||||
/// on one line at the middle of its height, so a bar in it fills that height and centres its members there; a
|
||||
/// start, end or centre pane stacks its content.
|
||||
pub fn pane(pane: ShellPane) -> Self {
|
||||
let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE);
|
||||
let layout = if matches!(pane.edge, PaneEdge::Top | PaneEdge::Bottom) { BodyLayout::row() } else { BodyLayout::stack() };
|
||||
let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE).layout(layout);
|
||||
ShellRegion { common: Common::new(), props, shell: None, senses_surface: false }
|
||||
}
|
||||
|
||||
@@ -531,25 +534,15 @@ impl<'a, S> AppShell<'a, S> {
|
||||
continue;
|
||||
}
|
||||
let extent = placed.extent(&tokens);
|
||||
let Placed { slot, edge, named, add, title, .. } = placed;
|
||||
let Placed { slot, edge, named, add, .. } = placed;
|
||||
let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(rect_of(slot.key()));
|
||||
// Every slot but the title is a chrome pane: it paints the surface under its bar or rail and
|
||||
// the rule toward the body. The title bar paints its own.
|
||||
let region = if *title { ShellRegion::pane(pane) } else { ShellRegion::chrome(pane) };
|
||||
let mut region = region.id_salt(("slot", slot.key()));
|
||||
// A bar is as high as its content and the slot as high as its token, so the bar sits at the
|
||||
// slot's centre line.
|
||||
let centred = !*title && matches!(edge, PaneEdge::Top | PaneEdge::Bottom);
|
||||
// Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward
|
||||
// the body.
|
||||
let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key()));
|
||||
if let Some(label) = slot.name().cloned().or_else(|| named.map(|name| name(&words))) {
|
||||
region = region.label(label);
|
||||
}
|
||||
region.show(ui, |ui, bcx| {
|
||||
if centred {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| add(ui, bcx, app));
|
||||
} else {
|
||||
add(ui, bcx, app);
|
||||
}
|
||||
});
|
||||
region.show(ui, |ui, bcx| add(ui, bcx, app));
|
||||
}
|
||||
};
|
||||
show_slots(ui, false, app);
|
||||
|
||||
@@ -8,10 +8,9 @@ use super::style::TitleBarStyle;
|
||||
use super::title::{Title, centre_line};
|
||||
use crate::contract::{
|
||||
Access, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, DragBand, EndRegion, Gap, HeaderRegion, NoValue, Outcome, Pad,
|
||||
PaintUi, PartsCx, Role, ShowContainer as _, Sizing, WordSetCx as _,
|
||||
PartsCx, Role, ShowContainer as _, Sizing, WordSetCx as _,
|
||||
};
|
||||
use crate::layout::{Placed, arrange};
|
||||
use crate::primitives::{RectSide, RuleKind};
|
||||
use crate::runtime::access::Name;
|
||||
use crate::runtime::egui::pass;
|
||||
use crate::runtime::env::Env;
|
||||
@@ -57,6 +56,8 @@ impl Outcome for TitleBarOutput {
|
||||
/// - **Integrated.** The caption buttons of the window's layout sit at the two ends, flush with the window's edges.
|
||||
/// A double click maximizes or restores.
|
||||
///
|
||||
/// An end with no caption buttons or lights keeps the content `space.pad.regular` off the window's edge.
|
||||
///
|
||||
/// In full screen the bar shows no captions and reserves no room. The free area is the container's move band:
|
||||
/// pressing and dragging it moves the window, and a double click acts as above.
|
||||
///
|
||||
@@ -80,9 +81,6 @@ pub struct TitleBar<'a> {
|
||||
/// Whether a bar in a native frame shows the title.
|
||||
#[prop(flag)]
|
||||
title_when_native: bool,
|
||||
/// A divider rule along the bar's bottom edge, for a bar whose window draws no edge under it.
|
||||
#[prop(flag)]
|
||||
separator: bool,
|
||||
/// The content at the end of the bar, before the caption buttons.
|
||||
#[prop(func = "FnMut(&mut Ui, &mut crate::contract::BodyCx<'_>)")]
|
||||
trailing: Option<RegionBody<'a>>,
|
||||
@@ -118,7 +116,6 @@ impl<'a> TitleBar<'a> {
|
||||
frame: None,
|
||||
maximized: None,
|
||||
title_when_native: false,
|
||||
separator: false,
|
||||
trailing: None,
|
||||
title: None,
|
||||
clicked: None,
|
||||
@@ -164,7 +161,9 @@ impl<'a> TitleBar<'a> {
|
||||
/// Shows one end's room and buttons, and acts on a click: Minimize and Maximize go to the window the bar acts on,
|
||||
/// Close is reported.
|
||||
fn show_end(&mut self, ui: &mut Ui, cx: &BodyCx<'_>, end: &End, window: &Window) {
|
||||
let height = SlotSize::TitleBar.resolve(&Env::of(ui).tokens);
|
||||
let tokens = Env::of(ui).tokens.clone();
|
||||
let height = SlotSize::TitleBar.resolve(&tokens);
|
||||
let pad = tokens.tokens().space.pad.regular;
|
||||
// The running window's captions take the glyphs of the desktop's icon theme; a frame given in place of the
|
||||
// window's (a story, a preview) draws the family's own.
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
@@ -184,7 +183,7 @@ impl<'a> TitleBar<'a> {
|
||||
Placed::new(("caption", index), button)
|
||||
})
|
||||
.collect();
|
||||
arrange(ui, &Strip::new(end, height), &mut buttons);
|
||||
arrange(ui, &Strip::padded(end, height, pad), &mut buttons);
|
||||
let (host, viewport) = (WindowHost::of(&ctx), pass::current_viewport(&ctx));
|
||||
for (slot, placed) in end.captions.iter().zip(&buttons) {
|
||||
if !placed.response().is_some_and(Response::clicked) {
|
||||
@@ -246,14 +245,6 @@ impl Component for TitleBar<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The [`separator`](TitleBar::separator) along the bottom edge, over the content.
|
||||
fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
if !self.separator {
|
||||
return;
|
||||
}
|
||||
ui.draw().edge_rule(RuleKind::Divider, cx.rect, RectSide::Bottom);
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> TitleBarOutput {
|
||||
TitleBarOutput { response: cx.response.clone(), caption_clicked: self.clicked, close_requested: self.close }
|
||||
}
|
||||
|
||||
@@ -24,27 +24,27 @@ fn tools(ui: &mut Ui, _: &mut crate::contract::BodyCx<'_>) {
|
||||
#[story(TitleBar<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn title_bar_windows(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let frame = captions(CaptionFamily::Windows, &[], &[Caption::Minimize, Caption::Maximize, Caption::Close]);
|
||||
TitleBar::new().separator().frame(frame).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
TitleBar::new().frame(frame).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_windows_maximized(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let frame = captions(CaptionFamily::Windows, &[], &[Caption::Minimize, Caption::Maximize, Caption::Close]);
|
||||
TitleBar::new().separator().frame(frame).maximized(true).show_titled(ui, Title::unsaved("Landscape.psd"), menu, tools).into()
|
||||
TitleBar::new().frame(frame).maximized(true).show_titled(ui, Title::unsaved("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_adwaita(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let frame = captions(CaptionFamily::Adwaita, &[], &[Caption::Minimize, Caption::Maximize, Caption::Close]);
|
||||
TitleBar::new().separator().frame(frame).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
TitleBar::new().frame(frame).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_inset(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
TitleBar::new().separator().frame(Frame::Inset(MacInset::default())).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
TitleBar::new().frame(Frame::Inset(MacInset::default())).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_native(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
TitleBar::new().separator().frame(Frame::Native).title_when_native().show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
TitleBar::new().frame(Frame::Native).title_when_native().show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
@@ -73,6 +73,16 @@ impl Strip {
|
||||
pub(super) fn new(end: &End, height: f32) -> Strip {
|
||||
Strip { inset: end.inset, widths: end.captions.iter().map(|slot| slot.rect.width()).collect(), height }
|
||||
}
|
||||
|
||||
/// The strip of `end` that keeps the bar's content `pad` off the window's edge when the end holds no captions and
|
||||
/// no traffic lights.
|
||||
pub(super) fn padded(end: &End, height: f32, pad: f32) -> Strip {
|
||||
let mut strip = Strip::new(end, height);
|
||||
if strip.widths.is_empty() && strip.inset <= 0.0 {
|
||||
strip.inset = pad;
|
||||
}
|
||||
strip
|
||||
}
|
||||
}
|
||||
|
||||
impl Arrangement for Strip {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
//! The app shell's named slots: a slot keeps its region name on either edge.
|
||||
//! The app shell's named slots: a slot keeps its region name on either edge, and a bar in a top or bottom slot fills
|
||||
//! it with its members on the slot's middle.
|
||||
|
||||
use craft_ui::contract::{PaneEdge, Role, Show as _};
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{PaneEdge, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::runtime::env::WindowKey;
|
||||
use craft_ui::shell::AppShell;
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use craft_ui::testing::{Fixture, Frames, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A tool rail placed at the end edge sits at the window's end and screen readers still find it as the Tools region.
|
||||
#[trial]
|
||||
@@ -53,3 +60,53 @@ fn a_two_column_tool_rail_is_twice_as_wide_as_one_column() {
|
||||
assert!(one > 0.0, "the rail shows");
|
||||
assert!((two - 2.0 * one).abs() < 0.5, "two columns take two rail widths: {one} and {two}");
|
||||
}
|
||||
|
||||
/// What the options-bar trial saw: the slot, the bar, a member of the bar and a member of a row nested in it.
|
||||
#[derive(Clone, Copy)]
|
||||
struct InSlot {
|
||||
slot: Rect,
|
||||
bar: Rect,
|
||||
member: Rect,
|
||||
nested: Rect,
|
||||
}
|
||||
|
||||
/// A bar in the options slot is as high as the slot, whatever its own padding and members take, and its members sit
|
||||
/// on the slot's middle: a member of the bar's own row and a member of a row nested in it beside a child of two lines.
|
||||
#[trial]
|
||||
fn a_bar_in_a_top_slot_fills_it_and_centres_its_members_on_one_line() {
|
||||
let seen = Rc::new(Cell::new(None::<InSlot>));
|
||||
let out = Rc::clone(&seen);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let (mut bar, mut member, mut nested) = (Rect::NOTHING, Rect::NOTHING, Rect::NOTHING);
|
||||
let shown = AppShell::new(WindowKey::main())
|
||||
.options_bar(true, |ui, _, _: &mut ()| {
|
||||
bar = Bar::new("Options", BarKind::Options)
|
||||
.show(ui, |ui, _| {
|
||||
member = Button::new("Alpha").show(ui).rect;
|
||||
Row::new().show(ui, |ui, _| {
|
||||
nested = Button::new("Beta").show(ui).rect;
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Text::new("Above").show(ui);
|
||||
Text::new("Below").show(ui);
|
||||
});
|
||||
});
|
||||
})
|
||||
.output
|
||||
.response
|
||||
.rect;
|
||||
})
|
||||
.body(|_, _, _| {})
|
||||
.show(ui, &mut ());
|
||||
let slot = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect);
|
||||
if let Some(slot) = slot {
|
||||
out.set(Some(InSlot { slot, bar, member, nested }));
|
||||
}
|
||||
});
|
||||
fixture.room(Vec2::new(600.0, 300.0)).settle();
|
||||
let InSlot { slot, bar, member, nested } = seen.get().expect("the options slot shows");
|
||||
const SLACK: f32 = 1.0;
|
||||
assert!((bar.min.y - slot.min.y).abs() <= SLACK && (bar.max.y - slot.max.y).abs() <= SLACK, "the bar {bar:?} fills the slot {slot:?}");
|
||||
for (name, rect) in [("the bar's member", member), ("the nested row's member", nested)] {
|
||||
assert!((rect.center().y - slot.center().y).abs() <= SLACK, "{name} {rect:?} sits on the middle of the slot {slot:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ impl Outcome for BarOutput {
|
||||
/// A bar over a chrome surface whose body holds the members in reading order: a tool bar's at the standard control
|
||||
/// size, an options or status bar's at the small one. They are one roving group unless the bar is made of
|
||||
/// [`tab_stops`](Bar::tab_stops). The bar is as tall as its tallest member plus the control padding, and takes the
|
||||
/// width it is offered. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the
|
||||
/// width it is offered. On the line of a row given its height (a top or bottom slot of the shell) it fills that height
|
||||
/// and its members sit on the line's middle, with its padding at the start and end only. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the
|
||||
/// caller makes with `Row`. A member that fills (a leaf with `Sizing::FillWidth`, a fill-width `Row`) takes the room the view
|
||||
/// leaves. A row too long for the bar first narrows its selects and elidable text, the last first, down to their
|
||||
/// readable least (`TextRun::READABLE_CHARACTERS`), then scrolls, so a member past the edge is reached by Tab and
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use super::words::BarWords;
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::{Bind, Entry, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked};
|
||||
use crate::contract::{Bind, Entry, Gap, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
|
||||
use crate::form::Field;
|
||||
use crate::layout_components::Row;
|
||||
use crate::menu::Menu;
|
||||
@@ -150,7 +150,7 @@ impl<'a> ConstraintFields<'a> {
|
||||
Entry::new(StyleChoice::FixedRatio, words.constraint_fixed_ratio.clone()),
|
||||
Entry::new(StyleChoice::FixedSize, words.constraint_fixed_size.clone()),
|
||||
];
|
||||
Field::new(words.constraint_style.clone()).id_salt("style").sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
Field::new(words.constraint_style.clone()).id_salt("style").show(ui, |ui, _| {
|
||||
let pick = Select::new(words.constraint_style.clone(), Bind::given(StyleChoice::of(before)), &styles).show(ui);
|
||||
if let Some(picked) = pick.value().copied()
|
||||
&& picked != StyleChoice::of(before)
|
||||
@@ -259,7 +259,7 @@ impl Cells<'_> {
|
||||
low.min(high)..=low.max(high)
|
||||
});
|
||||
let mut edited = None;
|
||||
Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show(
|
||||
Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).show(
|
||||
ui,
|
||||
|ui, _| {
|
||||
let mut field = NumberField::new(cell.caption.clone(), Bind::given(Some(shown))).range(range.clone()).scrub_by_label();
|
||||
|
||||
@@ -7,9 +7,11 @@ use crate::display::{Divider, Icon};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::IconId;
|
||||
use craft_theme::ControlSize;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
/// The Home button at the start of an options bar: a toggle with the home icon, then a rule. The host decides what
|
||||
/// The Home button at the start of an options bar: a toggle with the home icon at the standard control size, as tall
|
||||
/// as a bar's tool icons, then a rule. The host decides what
|
||||
/// it shows and when it can toggle.
|
||||
#[must_use = "show the button with `show`"]
|
||||
#[derive(crate::contract::Pattern)]
|
||||
@@ -33,7 +35,12 @@ impl<'a> BarHome<'a> {
|
||||
|
||||
/// Shows the button and the rule after it.
|
||||
pub fn show(self, ui: &mut Ui) -> EditResponse<bool> {
|
||||
let shown = ToggleButton::new(self.label, self.on).icon(IconSpec::svg(IconId::new("home"))).icon_only().enabled(self.enabled).show(ui);
|
||||
let shown = ToggleButton::new(self.label, self.on)
|
||||
.icon(IconSpec::svg(IconId::new("home")))
|
||||
.icon_only()
|
||||
.size(ControlSize::Md)
|
||||
.enabled(self.enabled)
|
||||
.show(ui);
|
||||
Divider::vertical().show(ui);
|
||||
shown
|
||||
}
|
||||
@@ -80,7 +87,7 @@ impl BarTool {
|
||||
|
||||
/// Shows the icon, its arrow and the rule after them.
|
||||
pub fn show(self, ui: &mut Ui) -> BarToolOutput {
|
||||
let shown: ButtonOutput = IconButton::new(self.icon).label(self.label).enabled(self.enabled).show(ui);
|
||||
let shown: ButtonOutput = IconButton::new(self.icon).label(self.label).size(ControlSize::Md).enabled(self.enabled).show(ui);
|
||||
Icon::new(DisclosureGlyph::dropdown()).enabled(self.enabled).show(ui);
|
||||
Divider::vertical().show(ui);
|
||||
BarToolOutput { response: shown.response }
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use super::words::BarWords;
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::{Bind, Entry, GlyphLabel, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing};
|
||||
use crate::contract::{Bind, Entry, LabelKind, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use crate::display::{Elide, Text};
|
||||
use crate::form::Field;
|
||||
use crate::layout_components::Row;
|
||||
@@ -56,6 +56,8 @@ pub struct StatusValues {
|
||||
pub document_profile: Option<String>,
|
||||
/// The document's size in pixels, shown in the user's unit.
|
||||
pub document_dimensions: Option<PixelSize>,
|
||||
/// The document's resolution in pixels per inch, shown after its dimensions.
|
||||
pub document_resolution: Option<f64>,
|
||||
/// The measurement scale text, shown as given.
|
||||
pub measurement_scale: Option<String>,
|
||||
/// Used and available bytes.
|
||||
@@ -112,9 +114,15 @@ impl StatusItem {
|
||||
StatusItem::DocumentDimensions => values.document_dimensions.map_or_else(
|
||||
|| MISSING.to_owned(),
|
||||
|size| {
|
||||
words
|
||||
.readout_dimensions_text
|
||||
.fill(&[("width", &units.pixels(f64::from(size.width))), ("height", &units.pixels(f64::from(size.height)))])
|
||||
let (width, height) = (units.pixels(f64::from(size.width)), units.pixels(f64::from(size.height)));
|
||||
match values.document_resolution {
|
||||
Some(ppi) => words.readout_dimensions_resolution_text.fill(&[
|
||||
("width", &width),
|
||||
("height", &height),
|
||||
("resolution", &units.number(ppi, 0..=2)),
|
||||
]),
|
||||
None => words.readout_dimensions_text.fill(&[("width", &width), ("height", &height)]),
|
||||
}
|
||||
},
|
||||
),
|
||||
StatusItem::MeasurementScale => given(&values.measurement_scale),
|
||||
@@ -196,8 +204,7 @@ impl<'a> StatusReadout<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the readout in a row: the zoom field, whose glyph label scrubs the zoom, the info text and the menu
|
||||
/// button.
|
||||
/// Shows the readout in a row: the zoom field, which scrubs the zoom, the info text and the menu button.
|
||||
pub fn show(mut self, ui: &mut Ui) -> StatusReadoutOutput {
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<BarWords>();
|
||||
@@ -210,10 +217,8 @@ impl<'a> StatusReadout<'a> {
|
||||
Some(Mixed::Same(current)) => Some(current),
|
||||
_ => None,
|
||||
};
|
||||
let glyph = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::icon(IconId::new("zoom_in")))).scrub(true);
|
||||
let field = Field::new(words.readout_zoom.clone())
|
||||
.side(glyph)
|
||||
.sizing(Sizing::Content)
|
||||
.side(SideLabel::new().kind(LabelKind::Hidden))
|
||||
.show(ui, |ui, _| ZoomField::new(words.readout_zoom.clone(), current, document).scrub(true).show(ui));
|
||||
let field = field.inner.map(|zoom| {
|
||||
invalid_zoom = zoom.invalid_zoom;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use super::{Bar, BarHome, BarItem, BarItems, BarKind, BarTool, ItemDisplay, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues};
|
||||
use crate::buttons::Link;
|
||||
use crate::choice::{Checkbox, Segmented};
|
||||
use crate::contract::{Bind, Entry, Props as _, Sizing};
|
||||
use crate::contract::{Bind, Entry, Props as _};
|
||||
use crate::contract::{Show as _, ShowContainer as _};
|
||||
use crate::display::{Divider, Shade, Text};
|
||||
use crate::form::Field;
|
||||
@@ -55,11 +55,10 @@ fn bar_options(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shown = Bar::new("Brush options", BarKind::Options).commit_cancel("Commit transform", "Cancel transform").show(ui, |ui, _| {
|
||||
BarHome::new("Home", Bind::bound(&mut home)).show(ui);
|
||||
BarTool::new(IconId::new("brush"), "Brush").show(ui);
|
||||
Field::new("Size").sizing(Sizing::Content).show(ui, |ui, _| NumberField::new("Size", Bind::bound(&mut size)).range(1.0..=5000.0).show(ui));
|
||||
Field::new("Size").show(ui, |ui, _| NumberField::new("Size", Bind::bound(&mut size)).range(1.0..=5000.0).show(ui));
|
||||
Field::new("Opacity")
|
||||
.sizing(Sizing::Content)
|
||||
.show(ui, |ui, _| NumberField::new("Opacity", Bind::bound(&mut opacity)).range(1.0..=100.0).show(ui));
|
||||
Field::new("Mode").sizing(Sizing::Content).show(ui, |ui, _| Select::new("Mode", Bind::bound(&mut mode), &modes).show(ui));
|
||||
Field::new("Mode").show(ui, |ui, _| Select::new("Mode", Bind::bound(&mut mode), &modes).show(ui));
|
||||
Divider::vertical().show(ui);
|
||||
Checkbox::new(Bind::bound(&mut sample_all)).label("Sample All Layers").show(ui);
|
||||
Text::new("Samples the visible image").shade(Shade::Faint).show(ui);
|
||||
@@ -78,11 +77,11 @@ fn bar_captioned(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let modes = [Entry::new(0u8, "Light"), Entry::new(1, "Dark"), Entry::new(2, "System")];
|
||||
Bar::new("Appearance", BarKind::Options)
|
||||
.trailing(|ui, _| {
|
||||
Field::new("Workspace").sizing(Sizing::Content).show(ui, |ui, _| Segmented::new("Workspace", Bind::given(0u8), &modes).show(ui));
|
||||
Field::new("Workspace").show(ui, |ui, _| Segmented::new("Workspace", Bind::given(0u8), &modes).show(ui));
|
||||
})
|
||||
.show(ui, |ui, _| {
|
||||
Field::new("Theme").sizing(Sizing::Content).show(ui, |ui, _| Select::new("Theme", Bind::given(0u8), &themes).show(ui));
|
||||
Field::new("Mode").sizing(Sizing::Content).show(ui, |ui, _| Segmented::new("Mode", Bind::given(1u8), &modes).show(ui));
|
||||
Field::new("Theme").show(ui, |ui, _| Select::new("Theme", Bind::given(0u8), &themes).show(ui));
|
||||
Field::new("Mode").show(ui, |ui, _| Segmented::new("Mode", Bind::given(1u8), &modes).show(ui));
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ craft_ui::words! {
|
||||
readout_scratch: template "bars.statusReadoutScratch" = "Scratch: {used}/{available}";
|
||||
readout_efficiency_text: template "bars.statusReadoutEfficiencyText" = "Efficiency: {value}";
|
||||
readout_dimensions_text: template "bars.statusReadoutDimensionsText" = "{width} x {height}";
|
||||
readout_dimensions_resolution_text: template "bars.statusReadoutDimensionsResolutionText" = "{width} x {height} ({resolution} ppi)";
|
||||
readout_timing_text: template "bars.statusReadoutTimingText" = "Timing: {value}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +52,14 @@ pub struct Field {
|
||||
}
|
||||
|
||||
impl Field {
|
||||
/// A field labelled `label`, beside its control, filling the width offered.
|
||||
/// A field labelled `label`, beside its control, filling the width offered; among the members of a bar it takes
|
||||
/// its content width. `sizing` overrides both.
|
||||
pub fn new(label: impl Into<Label>) -> Self {
|
||||
let props = ContainerProps::new().sizing(Sizing::FillWidth).footer(FooterRegion::new().gap(Gap::Tight).status()).label(SideLabel::new());
|
||||
let props = ContainerProps::new()
|
||||
.sizing(Sizing::FillWidth)
|
||||
.content_in_bar()
|
||||
.footer(FooterRegion::new().gap(Gap::Tight).status())
|
||||
.label(SideLabel::new());
|
||||
Field { common: Common::new(), props, help: None, layout: None, value: None }.label(label)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,18 @@ pub struct SelectFaceStyle {
|
||||
field: FieldStyle,
|
||||
}
|
||||
|
||||
/// How a select face is sized.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum FaceKind {
|
||||
/// A field: the field's height and padding, a thumbnail at `size.thumb.sm`.
|
||||
#[default]
|
||||
Field,
|
||||
/// A chip on a bar's line: a thumbnail at `size.icon.sm` over its caption and the chevron beside them, with the
|
||||
/// field's padding at the start and end only.
|
||||
Chip,
|
||||
}
|
||||
|
||||
/// The closed box of a picker: `text` elided to the room left of a trailing chevron. The box is as wide as the text
|
||||
/// and the chevron need, at least a field wide; a [fitted](SelectFace::fit) box is at most a field wide and has no
|
||||
/// floor; a thumbnail alone takes only its own width. A host shows it as the look of one of its parts with
|
||||
@@ -68,12 +80,26 @@ pub struct SelectFace<'a> {
|
||||
#[style_key]
|
||||
#[prop]
|
||||
fit: bool,
|
||||
/// How the face is sized: a field, or a chip on a bar's line.
|
||||
#[style_key]
|
||||
#[prop]
|
||||
kind: FaceKind,
|
||||
}
|
||||
|
||||
impl<'a> SelectFace<'a> {
|
||||
/// A face showing `text`, which is also its name.
|
||||
pub fn new(text: impl Into<Label>) -> Self {
|
||||
SelectFace { common: Common::new(), placeholder: false, thumb: None, leading: None, thumb_caption: None, name: true, fit: false }.label(text)
|
||||
SelectFace {
|
||||
common: Common::new(),
|
||||
placeholder: false,
|
||||
thumb: None,
|
||||
leading: None,
|
||||
thumb_caption: None,
|
||||
name: true,
|
||||
fit: false,
|
||||
kind: FaceKind::Field,
|
||||
}
|
||||
.label(text)
|
||||
}
|
||||
|
||||
/// A picture `aspect` times as wide as high before the text; `paint` draws into the picture's rect through the
|
||||
@@ -122,7 +148,20 @@ impl Component for SelectFace<'_> {
|
||||
// A thumbnail alone, and a fitted box, keep the field's padding and height, not the widths a field keeps for
|
||||
// its text; `measure` caps a fitted box at the field length.
|
||||
let metrics = field.metrics();
|
||||
let metrics = if key.name && !key.fit { metrics } else { metrics.ideal_width(0.0).min_size(Vec2::new(0.0, metrics.min_size.y)) };
|
||||
let chip = key.kind == FaceKind::Chip;
|
||||
let metrics = if key.name && !key.fit && !chip {
|
||||
metrics
|
||||
} else {
|
||||
metrics.ideal_width(0.0).min_size(Vec2::new(0.0, if chip { 0.0 } else { metrics.min_size.y }))
|
||||
};
|
||||
// A chip's thumbnail and caption take the bar's line: no padding above or below them.
|
||||
let metrics = if chip {
|
||||
let mut padding = metrics.padding;
|
||||
(padding.top, padding.bottom) = (0.0, 0.0);
|
||||
metrics.padding(padding)
|
||||
} else {
|
||||
metrics
|
||||
};
|
||||
let off = cx.color(cx.tokens.color.text.disabled);
|
||||
let (ink, muted) = (cx.ink(Ink::OnPanel), cx.color(cx.tokens.color.text.faint));
|
||||
let caption = cx.color(cx.tokens.color.text.muted);
|
||||
@@ -132,7 +171,7 @@ impl Component for SelectFace<'_> {
|
||||
text: TextLook::new(TypeRole::Body, cx.host_ink(ink.clone())),
|
||||
placeholder: TextLook::new(TypeRole::Body, cx.host_muted_ink(Stateful::new(muted).off(States::new(muted, muted, muted, off)))),
|
||||
chevron: IconLook::new(field.glyph().side, cx.host_ink(ink)),
|
||||
thumb: cx.tokens.size.thumb.sm,
|
||||
thumb: if chip { cx.tokens.size.icon.sm } else { cx.tokens.size.thumb.sm },
|
||||
caption: TextLook::new(TypeRole::Caption, cx.host_muted_ink(Stateful::new(caption).off(States::new(caption, caption, caption, off)))),
|
||||
caption_gap: cx.tokens.space.gap.tight,
|
||||
field,
|
||||
|
||||
@@ -19,7 +19,7 @@ pub use date::{
|
||||
Calendar, CalendarOutput, CalendarStyle, CalendarView, DateCodec, DatePicker, DatePrecision, PickedDate, local_month_grid, month_grid,
|
||||
};
|
||||
pub use dress::RowDress;
|
||||
pub use face::{SelectFace, SelectFaceStyle, toggle_on_key};
|
||||
pub use face::{FaceKind, SelectFace, SelectFaceStyle, toggle_on_key};
|
||||
pub use icon_picker::{IconPicker, IconPickerGroup, IconPickerItem, IconPickerOutput};
|
||||
pub use select::{Select, SelectStyle};
|
||||
pub use tree_picker::{TreeEntry, TreePicker, TreePickerStyle};
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ The host implements `DockPanels<P>`:
|
||||
| --- | --- |
|
||||
| `spec` | The panel's `PanelSpec`, read every pass: label, icon, `SizeLimits`, `DockHeights`, float size, `allow_native`, `window_kind`, `canvas`. |
|
||||
| `permissions` | The panel's `Permissions` (default `ALL`). |
|
||||
| `body` | Shows the panel's body, filling the group's body inset by the panel padding (`Pad::Regular`). The group is the body's panel, so the body adds no `Panel` or padding of its own. A document panel's body (`WindowKind::Document`) is shown edge to edge. |
|
||||
| `body` | Shows the panel's body in the group's body, which the group insets by the panel padding (`Pad::Regular`). The group is the body's panel, so the body adds no `Panel` or padding of its own. A document panel's body (`WindowKind::Document`) is shown edge to edge. |
|
||||
| `group_view` | Takes a whole group in place of its tab strip and body, in a `Ui` held to the group's rect; a canvas group draws its document here. Default `None`. |
|
||||
| `group_header` | The host's controls in a group header, before the tab strip. |
|
||||
| `panel_rows` | The host's rows of a panel's menu, before the dock's own. |
|
||||
@@ -116,7 +116,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
|
||||
|
||||
A floating window is a `Floating` in the layout: its `rect` in logical points in the app's viewport, and `native` and `monitor` while it is an OS window. `FloatingGroup` shows it. With `DockConfig::native_windows` (on by default), every floating window opens in its own OS window (`docking::native`) where the window host opens OS windows and reports where they are (`WindowHost::positions_reported`; not on Wayland); a window never shown native yet opens over its place in the main window. Elsewhere, and for a panel with `allow_native` off, the window stays inside the main window. The OS close of a native window is its Close action: the window closes when every panel in it may close. Dragging a native window by its title row moves the whole window and docks it where it is released over a group of the main window, as a floating window inside the main window does: the window host runs that move (`runtime::windows::keeps_app_drag`). On macOS the row's press hands the move to the OS, the app follows the system pointer and button (`Caps::OS_MOVES_TRACKED`), and a press that ends within the click distance is a click, which docks nothing; elsewhere the app moves the window, and Escape puts it back. The app sends an OS window its place only when the app changes it (an undo, a reloaded layout); the OS's own moves and resizes are recorded and never sent back. `window_kind` says whether an OS window is a document or a tool window. A tool window's title row is its only title bar, whatever frame the main window has (`craft_window::policy::tool_frame`).
|
||||
|
||||
A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: a panel's body fills the group, so it opens at that height; a document's body opens at that height when its content fills it, else at its own. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.
|
||||
A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: content that fills its body opens at that height, other content at its own. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.
|
||||
|
||||
## SplitArea on its own
|
||||
|
||||
|
||||
Reference in New Issue
Block a user