mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
ui-patterns: clippy 1.100 clean: no must_use on builders of must_use types; collapsed ifs; Copy fields not cloned; the drop builder type named; the PDF export automation trial is two trials
This commit is contained in:
1 parent
03ef469d99
commit
e85a6d3fee
10 files changed
+35
-30
No files matched your search
@@ -53,7 +53,6 @@ impl<'a, P> WorkspaceSwitcher<'a, P> {
|
||||
}
|
||||
|
||||
/// The header menu's command rows, in place of the default `WorkspaceCommands` rows.
|
||||
#[must_use]
|
||||
pub fn commands(mut self, rows: Vec<CommandRef>) -> Self {
|
||||
self.commands = Some(rows);
|
||||
self
|
||||
|
||||
@@ -558,11 +558,12 @@ impl<'a> ParamDialog<'a> {
|
||||
}
|
||||
apply_answers(¶ms, values, cx.take_answers());
|
||||
// A footer row pressed in the previous pass flips once; a measuring run leaves it for the real one.
|
||||
if !footer_rows.is_empty() && !crate::runtime::measure::active(ui.ctx()) {
|
||||
if let Some(flip) = with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.flip.take()) {
|
||||
let on = values.bool(&flip).unwrap_or(false);
|
||||
values.set(flip, FieldValue::Bool(!on));
|
||||
}
|
||||
if !footer_rows.is_empty()
|
||||
&& !crate::runtime::measure::active(ui.ctx())
|
||||
&& let Some(flip) = with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.flip.take())
|
||||
{
|
||||
let on = values.bool(&flip).unwrap_or(false);
|
||||
values.set(flip, FieldValue::Bool(!on));
|
||||
}
|
||||
if let Some(presets) = &presets {
|
||||
show_presets(ui, &presets_label, presets, values, &mut preset_events);
|
||||
|
||||
@@ -549,28 +549,24 @@ impl<'a> NewDocumentDialog<'a, DocumentOptions> {
|
||||
|
||||
/// The cards Recent shows after the recent documents, in place of `PresetCategory::default_recent()`. A card with
|
||||
/// the id `"default"` is named "Default {app} Size".
|
||||
#[must_use]
|
||||
pub fn recent_defaults(mut self, presets: Vec<DocumentPreset>) -> Self {
|
||||
self.setup.recent_defaults = presets;
|
||||
self
|
||||
}
|
||||
|
||||
/// The clipboard holds an image of this size: Recent shows a Clipboard card first and the dialog opens on it.
|
||||
#[must_use]
|
||||
pub fn clipboard(mut self, size: PixelSize) -> Self {
|
||||
self.setup.clipboard = Some(size);
|
||||
self
|
||||
}
|
||||
|
||||
/// The app's background colour, offered as the Background Color choice.
|
||||
#[must_use]
|
||||
pub fn background_color(mut self, color: Srgba) -> Self {
|
||||
self.setup.background = color.to_rgb_array();
|
||||
self
|
||||
}
|
||||
|
||||
/// The colour profiles each mode offers.
|
||||
#[must_use]
|
||||
pub fn profiles(mut self, profiles: Vec<ColorProfiles>) -> Self {
|
||||
self.setup.profiles = profiles;
|
||||
self
|
||||
@@ -578,14 +574,12 @@ impl<'a> NewDocumentDialog<'a, DocumentOptions> {
|
||||
|
||||
/// The app's own pixel aspect ratios as `(id, name)`, listed after the built-in ones ([`PIXEL_ASPECTS`]); the
|
||||
/// names are the user's and are not translated.
|
||||
#[must_use]
|
||||
pub fn custom_pixel_aspects(mut self, aspects: Vec<(String, String)>) -> Self {
|
||||
self.setup.custom_pixel_aspects = aspects;
|
||||
self
|
||||
}
|
||||
|
||||
/// The application's name, for the "Default {app} Size" card.
|
||||
#[must_use]
|
||||
pub fn app_name(mut self, name: impl Into<Label>) -> Self {
|
||||
self.setup.app_name = Some(name.into());
|
||||
self
|
||||
|
||||
@@ -426,7 +426,7 @@ fn color_table_section(ui: &mut Ui, kit: &Kit<'_>, live: &mut Live, asked: &mut
|
||||
];
|
||||
Row::new().id_salt("table-tools").show(ui, |ui, _| {
|
||||
for (icon, label, edit) in &tools {
|
||||
let button = IconButton::new(IconId::new(*icon)).label((*label).clone()).enabled(!selected.is_empty()).id_salt(*icon).show(ui);
|
||||
let button = IconButton::new(IconId::new(icon)).label((*label).clone()).enabled(!selected.is_empty()).id_salt(*icon).show(ui);
|
||||
if clicked(&button) {
|
||||
asked.table.push(ColorTableEvent { edit: edit.clone(), colors: selected.clone() });
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> SectionList<'a, K> {
|
||||
}
|
||||
|
||||
/// Content under the list, in the list's column.
|
||||
#[must_use]
|
||||
pub fn foot(mut self, foot: impl FnMut(&mut Ui) + 'a) -> Self {
|
||||
self.foot = Some(Box::new(foot));
|
||||
self
|
||||
|
||||
@@ -415,10 +415,8 @@ impl<'a> HistoryPanel<'a> {
|
||||
CollectionEvent::Delete(keys) => {
|
||||
picked.extend(keys.into_iter().filter(|key| deletable.contains(key)).map(|key| HistoryEvent::Delete(Some(key))));
|
||||
}
|
||||
CollectionEvent::ContextMenu(request) => {
|
||||
if renamable(&request.key) || removable(&request.key) {
|
||||
target = Some(request.key);
|
||||
}
|
||||
CollectionEvent::ContextMenu(request) if renamable(&request.key) || removable(&request.key) => {
|
||||
target = Some(request.key);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ impl<'a> CommandPalette<'a> {
|
||||
let format = stack.env.format();
|
||||
let text = match &*status.borrow() {
|
||||
Status::Quiet => return,
|
||||
Status::Empty => Label::from(words.palette_empty.clone()),
|
||||
Status::Empty => words.palette_empty.clone(),
|
||||
Status::Line(line) => Label::from(line.clone()),
|
||||
Status::Count { shown, total } if shown < total => Label::from(
|
||||
words.palette_count.fill(&[("shown", &format.integer(*shown as u64)), ("n", &format.integer(*total as u64))]),
|
||||
|
||||
@@ -202,12 +202,15 @@ impl<K: Clone + Eq> RowMap<'_, K> {
|
||||
/// borrows its rows for less than the host's closure lives takes the drop as it is.
|
||||
type DropAccepts<'a, K> = Rc<dyn Fn(&dyn Any, &DropAt<K>) -> bool + 'a>;
|
||||
|
||||
/// Builds the drop kind of one payload type over the rows of one browser pass.
|
||||
type BuildDrop<K> = for<'m> fn(DropPlace, DropAccepts<'m, K>, Rc<RowMap<'m, K>>) -> DropKind<'m, BrowserKey<K>>;
|
||||
|
||||
/// A drop target on the presets: a host payload of type `P` dropped onto a preset or between presets.
|
||||
pub struct PresetDrop<'a, K> {
|
||||
place: DropPlace,
|
||||
accepts: DropAccepts<'a, K>,
|
||||
/// The drop kind of the payload type the drop was made for, over the rows of one browser pass.
|
||||
build: for<'m> fn(DropPlace, DropAccepts<'m, K>, Rc<RowMap<'m, K>>) -> DropKind<'m, BrowserKey<K>>,
|
||||
build: BuildDrop<K>,
|
||||
}
|
||||
|
||||
impl<'a, K: Clone + Eq + 'a> PresetDrop<'a, K> {
|
||||
@@ -411,7 +414,6 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + MemoProps + 'static> PresetBrowser
|
||||
}
|
||||
|
||||
/// Takes host payloads dropped onto a preset or between presets; each drop comes back as `PresetEvent::Dropped`.
|
||||
#[must_use]
|
||||
pub fn takes_drop(mut self, drop: PresetDrop<'a, K>) -> Self {
|
||||
self.drops.push(drop);
|
||||
self
|
||||
|
||||
@@ -256,16 +256,16 @@ impl<'a, K: Value + Eq + Hash + MemoProps + 'static> PresetPicker<'a, K> {
|
||||
value: self.value.reborrowed(),
|
||||
source: self.source,
|
||||
state: self.state.reborrowed(),
|
||||
field: self.field.clone(),
|
||||
cell_shape: self.cell_shape.clone(),
|
||||
view: self.view.clone(),
|
||||
default_open: self.default_open.clone(),
|
||||
field: self.field,
|
||||
cell_shape: self.cell_shape,
|
||||
view: self.view,
|
||||
default_open: self.default_open,
|
||||
browser: self.browser,
|
||||
toolbar: self.toolbar,
|
||||
search: self.search,
|
||||
tools: self.tools.as_mut().map(|tools| BrowserTools::new(move |ui| tools.show(ui))),
|
||||
browser_id: self.browser_id,
|
||||
row_menu: self.row_menu.clone(),
|
||||
row_menu: self.row_menu,
|
||||
tip: self.tip.as_deref().map(|tip| Box::new(move |ui: &mut Ui, key: &K| tip(ui, key)) as TipFn<'_, K>),
|
||||
placeholder: self.placeholder.clone(),
|
||||
display_name: self.display_name.clone(),
|
||||
@@ -275,7 +275,7 @@ impl<'a, K: Value + Eq + Hash + MemoProps + 'static> PresetPicker<'a, K> {
|
||||
head: self.head.as_mut().map(|head| PickerHead::new(move |ui, body| (head.0)(ui, body))),
|
||||
keep_open: self.keep_open,
|
||||
footer: self.footer.clone(),
|
||||
thumb_range: self.thumb_range.clone(),
|
||||
thumb_range: self.thumb_range,
|
||||
edit_face: self.edit_face,
|
||||
create_row: self.create_row.clone(),
|
||||
detach_row: self.detach_row.clone(),
|
||||
|
||||
@@ -12,8 +12,7 @@ use std::rc::Rc;
|
||||
|
||||
/// A saved preset that differs from the defaults in its version and its trim marks.
|
||||
fn mine() -> PdfPreset {
|
||||
let mut settings = PdfSettings::default();
|
||||
settings.compatibility = Compatibility::Pdf15;
|
||||
let mut settings = PdfSettings { compatibility: Compatibility::Pdf15, ..PdfSettings::default() };
|
||||
settings.marks.trim = true;
|
||||
PdfPreset { name: "Mine".to_owned(), description: String::new(), settings }
|
||||
}
|
||||
@@ -29,6 +28,11 @@ fn listed(host: &DialogHost, id: DialogId, field: &str) -> Value {
|
||||
fields.pointer(&format!("/{}", field.replace('.', "/"))).cloned().unwrap_or(Value::Null)
|
||||
}
|
||||
|
||||
/// Writes `value` to `field` of the open dialog `id`.
|
||||
fn write_field(host: &mut DialogHost, ctx: &Context, id: DialogId, field: &str, value: Value) -> Result<(), String> {
|
||||
host.set_json_field(ctx, id, field, value)
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_hosted_dialog_takes_the_automation_fields() {
|
||||
let ctx = Context::default();
|
||||
@@ -37,7 +41,7 @@ fn the_hosted_dialog_takes_the_automation_fields() {
|
||||
for name in ["section", "preset", "artboards", "range", "bleedLinked", "marks", "compression"] {
|
||||
assert_ne!(listed(&host, id, name), Value::Null, "{name} is listed");
|
||||
}
|
||||
let set = |host: &mut DialogHost, field: &str, value: Value| host.set_json_field(&ctx, id, field, value);
|
||||
let set = |host: &mut DialogHost, field: &str, value: Value| write_field(host, &ctx, id, field, value);
|
||||
|
||||
// The preset applies a listed name and refuses an unknown one.
|
||||
assert!(set(&mut host, "preset", json!("No such preset")).is_err());
|
||||
@@ -60,6 +64,14 @@ fn the_hosted_dialog_takes_the_automation_fields() {
|
||||
assert_eq!(set(&mut host, "bleedLinked", json!(true)), Ok(()));
|
||||
assert_eq!(listed(&host, id, "bleed.right"), json!(3.0));
|
||||
assert_eq!(listed(&host, id, "bleedLinked"), json!(true));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_hosted_dialog_takes_the_artboards_and_refuses_what_a_standard_disables() {
|
||||
let ctx = Context::default();
|
||||
let mut host = DialogHost::new();
|
||||
let id = host.open(dialog());
|
||||
let set = |host: &mut DialogHost, field: &str, value: Value| write_field(host, &ctx, id, field, value);
|
||||
|
||||
// The artboards and the range.
|
||||
assert!(set(&mut host, "artboards", json!("everything")).is_err());
|
||||
|
||||
Reference in new issue
Block a user