mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
Show slice warnings below Save for Web previews
This commit is contained in:
@@ -9,9 +9,11 @@ use super::size_model::LinkedSize;
|
||||
use super::sizing::{Resample, SizingWords};
|
||||
use crate::runtime::requests::{HostAnswer, PathFilter, PathRequest};
|
||||
|
||||
use crate::contract::{Bind, Held, NoValue, Outcome, Props as _, ShowContainer as _};
|
||||
use crate::contract::{Bind, Held, NoValue, Outcome, Props as _, Show as _, ShowContainer as _};
|
||||
|
||||
use crate::display::Text;
|
||||
use crate::layout_components::{Row, Stack};
|
||||
use crate::style::TypeRole;
|
||||
|
||||
use crate::runtime::env::{Env, Label};
|
||||
|
||||
@@ -22,7 +24,7 @@ use crate::runtime::overlay::CloseReason;
|
||||
use craft_behavior::{PixelSize, Selection};
|
||||
use craft_keymap::{Chord, Key, Mods};
|
||||
|
||||
use craft_theme::Rgba;
|
||||
use craft_theme::{Rgba, variant::Tone};
|
||||
|
||||
use egui::load::SizedTexture;
|
||||
use egui::{Response, Ui};
|
||||
@@ -348,6 +350,9 @@ pub struct SaveForWebDialog<'a> {
|
||||
/// The document's slices, for the Slices choice.
|
||||
#[prop]
|
||||
slices: &'a [WebSlice],
|
||||
/// A notice from the host about slices omitted from the preview and export.
|
||||
#[prop]
|
||||
slice_warning: Option<Label>,
|
||||
/// Binds the view tab to `view`: the dialog shows the bound view and writes the tab the user picks, so the host
|
||||
/// and the dialog share one value.
|
||||
#[prop]
|
||||
@@ -373,6 +378,7 @@ impl<'a> SaveForWebDialog<'a> {
|
||||
saving: false,
|
||||
answers: Vec::new(),
|
||||
slices: &[],
|
||||
slice_warning: None,
|
||||
view: None,
|
||||
frame: None,
|
||||
}
|
||||
@@ -380,7 +386,22 @@ impl<'a> SaveForWebDialog<'a> {
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(self, ui: &mut Ui) -> SaveForWebOutput {
|
||||
let SaveForWebDialog { name, size, pictures, options, open, presets, animation, remember, saving, answers, slices, view, frame } = self;
|
||||
let SaveForWebDialog {
|
||||
name,
|
||||
size,
|
||||
pictures,
|
||||
options,
|
||||
open,
|
||||
presets,
|
||||
animation,
|
||||
remember,
|
||||
saving,
|
||||
answers,
|
||||
slices,
|
||||
slice_warning,
|
||||
view,
|
||||
frame,
|
||||
} = self;
|
||||
let mut view_held = view.map(Held::new);
|
||||
let mut frame_held = frame.map(Held::new);
|
||||
let env = Env::of(ui);
|
||||
@@ -474,7 +495,10 @@ impl<'a> SaveForWebDialog<'a> {
|
||||
slices,
|
||||
chosen: options.slices.selected(),
|
||||
};
|
||||
panes::show(ui, &reads, &mut live, &mut slice_click)
|
||||
panes::show(ui, &reads, &mut live, &mut slice_click);
|
||||
if let Some(warning) = &slice_warning {
|
||||
Text::new(warning.clone()).role(TypeRole::Caption).tone(Tone::Warn).show(ui);
|
||||
}
|
||||
});
|
||||
Stack::new().id_salt("settings").show(ui, |ui, _| {
|
||||
let kit =
|
||||
|
||||
@@ -7,6 +7,7 @@ use super::{SaveForWebDialog, WebPictures, WebSlice, WebView, result_of, save_re
|
||||
use crate::contract::Bind;
|
||||
use crate::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldOk, StackDialog, dialog_id, serde_fields, set_serde_field};
|
||||
use crate::patterns::form_dialogs::host_requests::HostRequests;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::memory::SaveKey;
|
||||
use crate::runtime::requests::{ColorRequest, PathRequest};
|
||||
use craft_behavior::PixelSize;
|
||||
@@ -42,6 +43,7 @@ pub struct HostedSaveForWeb {
|
||||
open: bool,
|
||||
/// The document's slices.
|
||||
slices: Vec<WebSlice>,
|
||||
slice_warning: Option<Label>,
|
||||
/// The view tab: bound to the dialog's `view` prop, so automation reads and writes it here.
|
||||
view: WebView,
|
||||
/// The path the app answered the save request with.
|
||||
@@ -58,6 +60,13 @@ impl HostedSaveForWeb {
|
||||
self
|
||||
}
|
||||
|
||||
/// A notice placed below the preview captions when the host omits slices.
|
||||
#[must_use]
|
||||
pub fn slice_warning(mut self, warning: Option<Label>) -> Self {
|
||||
self.slice_warning = warning;
|
||||
self
|
||||
}
|
||||
|
||||
/// The options as the user left them.
|
||||
pub fn current(&self) -> &SaveForWebOptions {
|
||||
&self.options
|
||||
@@ -81,6 +90,7 @@ impl HostedSaveForWeb {
|
||||
saving: false,
|
||||
open: true,
|
||||
slices: Vec::new(),
|
||||
slice_warning: None,
|
||||
view: WebView::default(),
|
||||
path: None,
|
||||
pixels: size,
|
||||
@@ -229,6 +239,7 @@ impl StackDialog for HostedSaveForWeb {
|
||||
animation: self.animation,
|
||||
remember: self.remember.clone(),
|
||||
slices: &self.slices,
|
||||
slice_warning: self.slice_warning.clone(),
|
||||
view: Some(Bind::bound(&mut self.view)),
|
||||
frame: Some(Bind::bound(&mut self.frame)),
|
||||
open: Some(Bind::bound(&mut self.open)),
|
||||
|
||||
@@ -77,6 +77,23 @@ fn gif(colors: u16) -> SaveForWebOptions {
|
||||
options
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_slice_warning_appears_once_below_the_preview_captions() {
|
||||
let warning = "5 stored slices past the first 10000 were ignored";
|
||||
let web = || HostedSaveForWeb::new("poster.psd", IMAGE, texture()).slices(slices());
|
||||
let (_, normal) = open(web());
|
||||
assert!(!normal.texts().iter().any(|run| run.text == warning));
|
||||
|
||||
let (_, mut overflow) = open(web().slice_warning(Some(warning.into())));
|
||||
let four_up = overflow.by_label("4-Up").expect("the 4-Up view");
|
||||
overflow.click(&four_up).idle(4);
|
||||
let notices = overflow.texts().iter().filter(|run| run.text == warning).collect::<Vec<_>>();
|
||||
assert_eq!(notices.len(), 1, "the dialog shows one warning before Save is pressed");
|
||||
let captions = overflow.texts().iter().filter(|run| run.text == "Encoding").collect::<Vec<_>>();
|
||||
assert_eq!(captions.len(), 3, "the three encoded preview captions");
|
||||
assert!(captions.iter().all(|caption| notices[0].rect.top() >= caption.rect.bottom()), "the warning follows both rows");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn slices_and_palette_edits_follow_the_settings() {
|
||||
let start = gif(8);
|
||||
|
||||
Reference in New Issue
Block a user