mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 18:23:52 -06:00
Format panes: one slider column, wrapping button rows, production precision
The picture sliders sit in one field group, so their tracks share one column. The Columns row and Format Background's Apply/Reset row wrap in a narrow pane instead of cutting a button. Transparency reads to a tenth of a percent and effect amounts in whole units, as production shows them (the Half reflection's blur reads 0 pt). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6f590e2e77
commit
9877e57f7e
@@ -110,7 +110,7 @@ pub(super) fn background(app: &mut SlideApp, ui: &mut Ui) {
|
||||
_ => None,
|
||||
};
|
||||
let picture = matches!(fill, Some(Fill::Picture(_)));
|
||||
let mut buttons = Row::new().show(ui, |ui, _| {
|
||||
let mut buttons = Row::new().wrap(true).show(ui, |ui, _| {
|
||||
let apply = Button::new(Word::plain("Apply to All")).enabled(current.is_some() || picture).show(ui).clicked();
|
||||
let reset = Button::new(Word::plain("Reset Background")).show(ui).clicked();
|
||||
(apply, reset)
|
||||
@@ -130,7 +130,10 @@ pub(super) fn background(app: &mut SlideApp, ui: &mut Ui) {
|
||||
}
|
||||
|
||||
fn transparency(ui: &mut Ui, alpha: f64) -> Option<Value> {
|
||||
let result = SliderField::new(Word::plain("Transparency"), Bind::given((1.0 - alpha) * 100.0), 0.0..=100.0).unit_kind(UnitKind::Percent).show(ui);
|
||||
let result = SliderField::new(Word::plain("Transparency"), Bind::given((1.0 - alpha) * 100.0), 0.0..=100.0)
|
||||
.unit_kind(UnitKind::Percent)
|
||||
.field_decimals(super::format_shape::TRANSPARENCY_DECIMALS)
|
||||
.show(ui);
|
||||
result.events.committed().map(|value| json!({"transparency": value / 100.0}))
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use craft::ui::buttons::{Button, IconButton};
|
||||
use craft::ui::choice::{Checkbox, Radio, RadioGroup, Segmented};
|
||||
use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::display::{Divider, Shade, Text};
|
||||
use craft::ui::form::{Field, SliderField, SliderFieldLayout};
|
||||
use craft::ui::form::{Field, FieldDecimals, FieldGroup, SliderField, SliderFieldLayout};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::IconSpec;
|
||||
@@ -24,6 +24,9 @@ use super::color_row::color_row;
|
||||
use super::{SlideApp, cref_param, run};
|
||||
use crate::icons::Icon;
|
||||
|
||||
/// A transparency reads to a tenth of a percent ("0.0%").
|
||||
pub(crate) const TRANSPARENCY_DECIMALS: FieldDecimals = FieldDecimals::Fixed(1);
|
||||
|
||||
/// The formatting pane scale bases and reference options.
|
||||
#[derive(Default)]
|
||||
pub struct FormatPaneState {
|
||||
@@ -98,9 +101,20 @@ fn selection_takes_background_fill(app: &SlideApp) -> bool {
|
||||
ok
|
||||
}
|
||||
|
||||
fn slider(ui: &mut Ui, label: &'static str, value: f64, range: std::ops::RangeInclusive<f64>, unit: UnitKind) -> Option<f64> {
|
||||
fn slider(
|
||||
ui: &mut Ui,
|
||||
label: &'static str,
|
||||
value: f64,
|
||||
range: std::ops::RangeInclusive<f64>,
|
||||
unit: UnitKind,
|
||||
decimals: FieldDecimals,
|
||||
) -> Option<f64> {
|
||||
let mut field = Field::new(Word::plain(label)).layout(FieldLayout::Beside).id_salt(label).show(ui, |ui, _| {
|
||||
SliderField::new(Word::plain(label), Bind::given(value), range.clone()).layout(SliderFieldLayout::Inline).unit_kind(unit).show(ui)
|
||||
SliderField::new(Word::plain(label), Bind::given(value), range.clone())
|
||||
.layout(SliderFieldLayout::Inline)
|
||||
.unit_kind(unit)
|
||||
.field_decimals(decimals)
|
||||
.show(ui)
|
||||
});
|
||||
field.settle(|_, output| output.events.committed().copied()).flatten().filter(|shown| *shown != value)
|
||||
}
|
||||
@@ -288,7 +302,7 @@ fn fill_options(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) {
|
||||
Some(Fill::Picture(pf)) => ((1.0 - pf.alpha.unwrap_or(1.0)) * 100.0) as f32,
|
||||
fill => solid_fill_transparency_percent(fill.as_ref()),
|
||||
};
|
||||
if let Some(shown) = slider(ui, "Transparency", f64::from(seed), 0.0..=100.0, UnitKind::Percent)
|
||||
if let Some(shown) = slider(ui, "Transparency", f64::from(seed), 0.0..=100.0, UnitKind::Percent, TRANSPARENCY_DECIMALS)
|
||||
&& let Some(value) = fill_transparency_to_apply(shown as f32, seed)
|
||||
{
|
||||
run(app, "shape.fill", json!({"transparency": value}));
|
||||
@@ -511,7 +525,7 @@ fn text_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) {
|
||||
}
|
||||
});
|
||||
let mut columns = Field::new(Word::plain("Columns")).layout(FieldLayout::Beside).show(ui, |ui, _| {
|
||||
let mut row = Row::new().show(ui, |ui, _| {
|
||||
let mut row = Row::new().wrap(true).show(ui, |ui, _| {
|
||||
let mut picked = None;
|
||||
for count in 1..=3 {
|
||||
if Button::new(count.to_string()).show(ui).clicked() {
|
||||
@@ -535,15 +549,22 @@ fn text_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) {
|
||||
|
||||
fn picture_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) {
|
||||
let ShapeKind::Picture { fill } = &sh.kind else { return };
|
||||
for (label, key, value, range) in [
|
||||
("Brightness", "brightness", fill.adjust.brightness * 100.0, -100.0..=100.0),
|
||||
("Contrast", "contrast", fill.adjust.contrast * 100.0, -100.0..=100.0),
|
||||
("Saturation", "saturation", fill.adjust.saturation.unwrap_or(1.0) * 100.0, 0.0..=400.0),
|
||||
("Transparency", "transparency", (1.0 - fill.alpha.unwrap_or(1.0)) * 100.0, 0.0..=100.0),
|
||||
] {
|
||||
if let Some(value) = slider(ui, label, value, range, UnitKind::Percent) {
|
||||
run(app, "picture.adjust", json!({key: value / 100.0}));
|
||||
// One label column for the four sliders, so their tracks line up.
|
||||
let mut adjusts = Vec::new();
|
||||
FieldGroup::new(Word::plain("Picture Corrections")).show(ui, |ui, _| {
|
||||
for (label, key, value, range) in [
|
||||
("Brightness", "brightness", fill.adjust.brightness * 100.0, -100.0..=100.0),
|
||||
("Contrast", "contrast", fill.adjust.contrast * 100.0, -100.0..=100.0),
|
||||
("Saturation", "saturation", fill.adjust.saturation.unwrap_or(1.0) * 100.0, 0.0..=400.0),
|
||||
("Transparency", "transparency", (1.0 - fill.alpha.unwrap_or(1.0)) * 100.0, 0.0..=100.0),
|
||||
] {
|
||||
if let Some(value) = slider(ui, label, value, range, UnitKind::Percent, FieldDecimals::Look) {
|
||||
adjusts.push(json!({key: value / 100.0}));
|
||||
}
|
||||
}
|
||||
});
|
||||
for params in adjusts {
|
||||
run(app, "picture.adjust", params);
|
||||
}
|
||||
if Button::new(Word::plain("Reset Picture")).show(ui).clicked() {
|
||||
run(app, "picture.reset", json!({}));
|
||||
@@ -562,7 +583,7 @@ pub(crate) fn text_transparency_of(sh: &deckcraft_model::Shape) -> f64 {
|
||||
|
||||
/// Edits the selected text's transparency without a draft shared across shapes.
|
||||
pub(crate) fn text_transparency_slider(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) {
|
||||
if let Some(value) = slider(ui, "Transparency", text_transparency_of(sh) * 100.0, 0.0..=100.0, UnitKind::Percent) {
|
||||
if let Some(value) = slider(ui, "Transparency", text_transparency_of(sh) * 100.0, 0.0..=100.0, UnitKind::Percent, TRANSPARENCY_DECIMALS) {
|
||||
run(app, "format.textTransparency", json!({"value": value / 100.0}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use craft::i18n::Word;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::choice::Segmented;
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::form::{Field, SliderField};
|
||||
use craft::ui::form::{Field, FieldDecimals, SliderField};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use craft::ui::sections::Section;
|
||||
@@ -103,8 +103,15 @@ pub(super) fn tab(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape)
|
||||
}
|
||||
}
|
||||
|
||||
/// An effect amount reads in whole units, so a preset's half-point blur reads "0 pt".
|
||||
fn slider(ui: &mut Ui, label: &'static str, value: f64, range: std::ops::RangeInclusive<f64>, unit: UnitKind) -> Option<f64> {
|
||||
SliderField::new(Word::plain(label), Bind::given(value), range).unit_kind(unit).show(ui).events.committed().copied()
|
||||
SliderField::new(Word::plain(label), Bind::given(value), range)
|
||||
.unit_kind(unit)
|
||||
.field_decimals(FieldDecimals::Fixed(0))
|
||||
.show(ui)
|
||||
.events
|
||||
.committed()
|
||||
.copied()
|
||||
}
|
||||
|
||||
/// Camel-case preset ids are file-format names; the field presents readable words.
|
||||
|
||||
@@ -279,3 +279,20 @@ fn dash_samples_and_direction_buttons_set_what_they_show() -> TestResult {
|
||||
assert!((angle - 180.0).abs() < 0.5, "the 180° button turns the gradient to 180°: {angle}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picture_sliders_share_one_column() -> TestResult {
|
||||
let mut session = Session::with_new();
|
||||
session.execute("slide.new", &json!({"layout": "blank"}))?;
|
||||
let result = session.execute("insert.picture", &json!({"data": picture_data(), "name": "generated.png"}))?;
|
||||
session.execute("edit.select", &json!({"ids": [result["id"]]}))?;
|
||||
let mut h = pane(session);
|
||||
h.state_mut().ui.format_tab = "picture".into();
|
||||
h.run_steps(3);
|
||||
let starts: Vec<f32> = ["Brightness", "Contrast", "Saturation", "Transparency"]
|
||||
.iter()
|
||||
.map(|label| h.get_by_role_and_label(Role::Slider, label).rect().left())
|
||||
.collect();
|
||||
assert!(starts.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 0.5), "the sliders start in one column: {starts:?}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user