feat(xiaoyi): polish 3-stage creation wizard UX, compact barcode accordion, and single-row footer
This commit is contained in:
parent
fe533072b4
commit
9757545ece
@ -118,18 +118,25 @@ fn structure_preview_card(
|
||||
let t = Tokens::get(ui.ctx()).agent();
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::MD;
|
||||
let thumb_size = vec2(72.0, 98.0);
|
||||
let thumb_size = if cover.is_some() || preview.is_some() { vec2(136.0, 184.0) } else { vec2(96.0, 128.0) };
|
||||
let (area, _) = ui.allocate_exact_size(thumb_size, egui::Sense::hover());
|
||||
ui.painter().rect_filled(area, radius::ROW, t.dock);
|
||||
ui.painter().rect_stroke(area, radius::ROW, egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
|
||||
ui.painter().rect_filled(area, radius::CONTROL, t.dock);
|
||||
ui.painter().rect_stroke(area, radius::CONTROL, egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
|
||||
if let Some(texture) = cover {
|
||||
let size = preview_size(texture.size_vec2(), area.shrink(2.0).size());
|
||||
let size = preview_size(texture.size_vec2(), area.shrink(4.0).size());
|
||||
let rect = egui::Align2::CENTER_CENTER.align_size_within_rect(size, area);
|
||||
ui.painter().image(texture.id(), rect, egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(1.0, 1.0)), AGENT_SEMANTIC.on_image_text);
|
||||
} else if let Some(preview) = preview {
|
||||
paint_template_structure(ui, preview, area.shrink(2.0));
|
||||
paint_template_structure(ui, preview, area.shrink(4.0));
|
||||
} else {
|
||||
crate::icons::paint(ui, area, "layers", icon::LG, t.text_dim);
|
||||
crate::icons::paint(ui, area.translate(vec2(0.0, -10.0)), "layers", icon::LG, t.text_dim);
|
||||
ui.painter().text(
|
||||
egui::pos2(area.center().x, area.center().y + 18.0),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
"暂无预览图",
|
||||
Type::Meta.font_id(),
|
||||
t.text_dim,
|
||||
);
|
||||
}
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = space::XS;
|
||||
@ -154,6 +161,8 @@ fn structure_preview_card(
|
||||
stitch_kit::caption(ui, "模板原稿预览");
|
||||
} else if preview.is_some() {
|
||||
stitch_kit::caption(ui, "首屏结构示意");
|
||||
} else {
|
||||
stitch_kit::caption(ui, "模板已就绪(当前组件未附带预览图)");
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1210,8 +1219,23 @@ fn intake_fields_with_errors(
|
||||
intake_label(field), Type::Meta.font_id(), Tokens::get(ui.ctx()).agent().text_dim, field_width,
|
||||
).size().y).fold(0.0_f32, f32::max);
|
||||
for field in row {
|
||||
let raw_hint = intake_hint(field);
|
||||
let fallback;
|
||||
let effective_hint = if !raw_hint.is_empty() {
|
||||
raw_hint
|
||||
} else {
|
||||
let clean_label = field["label"].as_str().unwrap_or("").trim().trim_end_matches(['*', '*']).trim();
|
||||
fallback = match clean_label {
|
||||
"" => String::new(),
|
||||
"核心卖点" => "输入核心卖点、材质亮点或使用场景优势".to_owned(),
|
||||
"注意事项" => "输入安装、保养或画面避坑注意事项(选填)".to_owned(),
|
||||
other if field["required"] == true => format!("输入{other}"),
|
||||
other => format!("输入{other}(选填)"),
|
||||
};
|
||||
fallback.as_str()
|
||||
};
|
||||
changed |= intake_field(
|
||||
ui, scope, field_width, label_height, field, intake_hint(field),
|
||||
ui, scope, field_width, label_height, field, effective_hint,
|
||||
values, reduced, barcode, inline_errors, scroll_to_field, manual_edited,
|
||||
);
|
||||
}
|
||||
@ -2603,26 +2627,43 @@ impl Workspace {
|
||||
egui::Panel::bottom("creation-sticky-footer")
|
||||
.resizable(false)
|
||||
.show_separator_line(true)
|
||||
.frame(egui::Frame::NONE.fill(background).inner_margin(egui::Margin::symmetric(pad_x, 10)))
|
||||
.frame(egui::Frame::NONE.fill(background).inner_margin(egui::Margin::symmetric(pad_x, 7)))
|
||||
.show(ui, |ui| wizard_column(ui, |ui| {
|
||||
if stage == CreationStage::Details {
|
||||
self.brief_footer_ui(app, ui, barcode_pending);
|
||||
} else {
|
||||
self.reference_drop_warning_ui(ui);
|
||||
if let Some((message, _, action)) = self.brief_setup_warning() {
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Quiet, true).on_hover_text(message);
|
||||
self.control_geometry(if self.key_saved { "select-model" } else { "configure-personal-key" }, configure.rect);
|
||||
if configure.clicked() {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
let setup_warning = self.brief_setup_warning();
|
||||
let key_saved = self.key_saved;
|
||||
let mut open_settings = false;
|
||||
let mut cfg_rect = None;
|
||||
let action = wizard::wizard_footer_ui_with_status(
|
||||
ui,
|
||||
WizardFooterState {
|
||||
stage,
|
||||
can_continue: form_editable(self.busy.as_deref(), self.unknown)
|
||||
&& (stage == CreationStage::Source || has_template),
|
||||
can_enter_canvas: false,
|
||||
can_start: false,
|
||||
},
|
||||
true,
|
||||
|ui| {
|
||||
if let Some((message, _, action)) = setup_warning {
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Quiet, true).on_hover_text(message);
|
||||
cfg_rect = Some(configure.rect);
|
||||
if configure.clicked() {
|
||||
open_settings = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, _| {},
|
||||
);
|
||||
if let Some(rect) = cfg_rect {
|
||||
self.control_geometry(if key_saved { "select-model" } else { "configure-personal-key" }, rect);
|
||||
}
|
||||
if open_settings {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
let action = wizard::wizard_footer_ui(ui, WizardFooterState {
|
||||
stage,
|
||||
can_continue: form_editable(self.busy.as_deref(), self.unknown)
|
||||
&& (stage == CreationStage::Source || has_template),
|
||||
can_enter_canvas: false,
|
||||
can_start: false,
|
||||
}, true, |_, _| {});
|
||||
self.handle_wizard_navigation(app, action);
|
||||
}
|
||||
}));
|
||||
@ -2712,6 +2753,7 @@ impl Workspace {
|
||||
self.product_select_results(app, ui);
|
||||
}
|
||||
_ => {
|
||||
self.poll_imported_reference_previews(app, ui.ctx());
|
||||
wizard::section_heading_with_tip(ui, "本机资料", "支持 PNG、JPG、WebP。每次最多 8 张,单张不超过 20 MB。");
|
||||
ui.add_space(space::XS);
|
||||
let rect = self.reference_picker(app, ui, width, scope.with("source-drop"),
|
||||
@ -2720,12 +2762,65 @@ impl Workspace {
|
||||
if ui.is_enabled() && let Some(target) = self.reference_drop_geometry(app, ui, rect) {
|
||||
self.creation_view_geometry["referenceDrop"] = target;
|
||||
}
|
||||
if stitch_ui::action_button(ui, "选择文件夹", stitch_ui::ButtonRole::Quiet, true).clicked() {
|
||||
self.open_reference_dialog(app, Value::Null, true);
|
||||
}
|
||||
ui.add_space(space::XS);
|
||||
let count = self.creation_brief["images"].as_array().map_or(0, Vec::len);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::MD;
|
||||
if stitch_ui::action_button(ui, "选择文件夹", stitch_ui::ButtonRole::Quiet, true).clicked() {
|
||||
self.open_reference_dialog(app, Value::Null, true);
|
||||
}
|
||||
if count > 0 {
|
||||
stitch_kit::label(ui, format!("已添加 {count} 张图片"), Type::Meta, Tone::Success);
|
||||
}
|
||||
});
|
||||
if count > 0 {
|
||||
stitch_kit::label(ui, format!("已添加 {count} 张图片"), Type::Meta, Tone::Success);
|
||||
ui.add_space(space::XS);
|
||||
let t = Tokens::get(ui.ctx()).agent();
|
||||
let images = self.creation_brief["images"].as_array().cloned().unwrap_or_default();
|
||||
let mut remove_idx = None;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(space::SM, space::SM);
|
||||
for (idx, img) in images.iter().enumerate() {
|
||||
let src = img["source"].as_str().unwrap_or("");
|
||||
let name = img["name"].as_str().unwrap_or("产品图片");
|
||||
let key = super::creation_reads::reference_key(src);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(76.0);
|
||||
ui.spacing_mut().item_spacing.y = 4.0;
|
||||
let (thumb_rect, thumb_resp) = ui.allocate_exact_size(vec2(76.0, 76.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(thumb_rect, radius::ROW, t.field);
|
||||
ui.painter().rect_stroke(thumb_rect, radius::ROW, egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
|
||||
if ui.is_rect_visible(thumb_rect) && !src.is_empty() {
|
||||
self.queue_creation_reference(app, src);
|
||||
}
|
||||
if let Some(tex) = self.creation_thumbs.get(&key).cloned() {
|
||||
let size = preview_size(tex.size_vec2(), thumb_rect.shrink(3.0).size());
|
||||
let fit = egui::Align2::CENTER_CENTER.align_size_within_rect(size, thumb_rect);
|
||||
ui.painter().image(tex.id(), fit, egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(1.0, 1.0)), AGENT_SEMANTIC.on_image_text);
|
||||
self.material_preview(thumb_resp, &key, name, &tex);
|
||||
} else {
|
||||
crate::icons::paint(ui, thumb_rect, "image", icon::MD, t.text_dim);
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
ui.add_sized(
|
||||
vec2(54.0, 18.0),
|
||||
egui::Label::new(egui::RichText::new(name).font(Type::Meta.font_id()).color(t.text_dim)).truncate(),
|
||||
).on_hover_text(name);
|
||||
if stitch_ui::icon_button(ui, "trash", 18.0, false, "移除此图片").clicked() {
|
||||
remove_idx = Some(idx);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
if let Some(idx) = remove_idx
|
||||
&& let Some(list) = self.creation_brief["images"].as_array_mut()
|
||||
&& idx < list.len()
|
||||
{
|
||||
list.remove(idx);
|
||||
self.creation_dirty = true;
|
||||
}
|
||||
}
|
||||
if !self.creation_reads.reference_import_error.is_empty() && self.creation_reads.reference_import_error != REFERENCE_DROP_HINT {
|
||||
stitch_ui::status_label(ui, &self.creation_reads.reference_import_error, stitch_ui::StatusTone::Error);
|
||||
@ -2756,21 +2851,81 @@ impl Workspace {
|
||||
.collect::<Vec<_>>();
|
||||
let images = schema.as_array().into_iter().flatten().filter(|field| field_kind(field) == "image").collect::<Vec<_>>();
|
||||
|
||||
self.poll_imported_reference_previews(app, ui.ctx());
|
||||
let hint = |key| schema.as_array().into_iter().flatten()
|
||||
.find(|field| structured_barcode_field(field) && field_key(field) == key).map(intake_hint).unwrap_or("");
|
||||
let action = wizard::barcode_cards_section_ui(ui, scope, &mut rows, self.reduce_motion, hint, |ui, id, row| {
|
||||
let Some(code) = non_empty_str(&row["barcode"]) else {
|
||||
stitch_ui::action_button(ui, "添加图片", stitch_ui::ButtonRole::Secondary, false)
|
||||
.on_disabled_hover_text("先填写条码编码");
|
||||
return;
|
||||
};
|
||||
if !project_barcodes(&self.creation_brief).any(|existing| existing == code) { return; }
|
||||
self.barcode_intake_ui(app, ui, id, width, code, &fields, &images);
|
||||
if images.is_empty() {
|
||||
self.image_slot_control_ui(app, ui, width, "图片", "拖入或选择条码图片",
|
||||
json!({"scope":"barcode","barcode":code,"purpose":"product","multiple":true}));
|
||||
}
|
||||
});
|
||||
let mut open_image_for_barcode: Option<String> = None;
|
||||
let action = wizard::barcode_cards_section_ui(
|
||||
ui,
|
||||
scope,
|
||||
&mut rows,
|
||||
self.reduce_motion,
|
||||
hint,
|
||||
|ui, id, slot| match slot {
|
||||
wizard::BarcodeSlotRender::Image { row, size, editable: editable_slot } => {
|
||||
let t = Tokens::get(ui.ctx()).agent();
|
||||
let code = non_empty_str(&row["barcode"]);
|
||||
let matched_sources: Vec<(String, String)> = self.creation_brief["images"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|img| code.is_some() && img["barcode"].as_str() == code)
|
||||
.filter_map(|img| Some((img["source"].as_str()?.to_owned(), img["name"].as_str().unwrap_or("条码图片").to_owned())))
|
||||
.collect();
|
||||
let sense = if editable_slot && code.is_some() { egui::Sense::click() } else { egui::Sense::hover() };
|
||||
let (rect, resp) = ui.allocate_exact_size(vec2(size, size), sense);
|
||||
ui.painter().rect_filled(rect, radius::ROW, t.field);
|
||||
let stroke_color = if resp.hovered() && editable_slot && code.is_some() { t.primary_bg } else { t.card_border };
|
||||
ui.painter().rect_stroke(rect, radius::ROW, egui::Stroke::new(1.0, stroke_color), egui::StrokeKind::Inside);
|
||||
if let Some((first_src, first_name)) = matched_sources.first() {
|
||||
if ui.is_rect_visible(rect) {
|
||||
self.queue_creation_reference(app, first_src);
|
||||
}
|
||||
let key = super::creation_reads::reference_key(first_src);
|
||||
if let Some(tex) = self.creation_thumbs.get(&key).cloned() {
|
||||
let fit_sz = preview_size(tex.size_vec2(), rect.shrink(2.0).size());
|
||||
let fit = egui::Align2::CENTER_CENTER.align_size_within_rect(fit_sz, rect);
|
||||
ui.painter().image(tex.id(), fit, egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(1.0, 1.0)), AGENT_SEMANTIC.on_image_text);
|
||||
} else {
|
||||
crate::icons::paint(ui, rect, "image", if size >= 48.0 { icon::MD } else { icon::SM }, t.text_dim);
|
||||
}
|
||||
if matched_sources.len() > 1 {
|
||||
let badge = egui::Rect::from_min_size(egui::pos2(rect.right() - 18.0, rect.bottom() - 15.0), vec2(17.0, 14.0));
|
||||
ui.painter().rect_filled(badge, 3.0, egui::Color32::from_rgba_unmultiplied(15, 16, 18, 210));
|
||||
ui.painter().text(badge.center(), egui::Align2::CENTER_CENTER, format!("{}", matched_sources.len()), Type::Meta.font_id(), t.text);
|
||||
}
|
||||
let tip = if editable_slot { format!("{first_name}(点击继续添加条码图)") } else { first_name.clone() };
|
||||
let resp = resp.on_hover_text(tip);
|
||||
if resp.clicked() && let Some(c) = code {
|
||||
open_image_for_barcode = Some(c.to_owned());
|
||||
}
|
||||
} else {
|
||||
crate::icons::paint(ui, rect, if editable_slot { "plus" } else { "image" }, if size >= 48.0 { icon::MD } else { icon::SM }, t.text_dim);
|
||||
let tip = if !editable_slot {
|
||||
"暂无条码专属图片"
|
||||
} else if code.is_some() {
|
||||
"点击为该条码添加图片"
|
||||
} else {
|
||||
"请先填写条码编码,再添加图片"
|
||||
};
|
||||
let resp = resp.on_hover_text(tip);
|
||||
if resp.clicked() && let Some(c) = code {
|
||||
open_image_for_barcode = Some(c.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
wizard::BarcodeSlotRender::Related { row } => {
|
||||
let Some(code) = non_empty_str(&row["barcode"]) else { return; };
|
||||
if !project_barcodes(&self.creation_brief).any(|existing| existing == code) { return; }
|
||||
if !fields.is_empty() || !images.is_empty() {
|
||||
self.barcode_intake_ui(app, ui, id, width, code, &fields, &images);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
if let Some(code) = open_image_for_barcode {
|
||||
self.open_reference_dialog(app, json!({"scope":"barcode","barcode":code,"purpose":"product","multiple":true}), false);
|
||||
}
|
||||
if let Some(index) = action.remove_index {
|
||||
rows.remove(index);
|
||||
}
|
||||
@ -3965,66 +4120,8 @@ impl Workspace {
|
||||
None
|
||||
};
|
||||
|
||||
// Readiness and settings stay directly actionable.
|
||||
// Compact single-row footer when in 3-stage wizard mode
|
||||
let mut clicked_missing: Option<(String, String)> = None;
|
||||
let hint_row = ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
if !missing_items.is_empty() {
|
||||
stitch_kit::label(ui, "待补齐:", Type::Meta, Tone::Warning);
|
||||
for item in &missing_items {
|
||||
let chip = stitch_ui::action_button(ui, &item.label, stitch_ui::ButtonRole::Quiet, true)
|
||||
.on_hover_text(&item.message);
|
||||
self.control_geometry(&format!("readiness-{}", item.field_key), chip.rect);
|
||||
if chip.clicked() {
|
||||
clicked_missing = Some((item.field_key.clone(), item.message.clone()));
|
||||
}
|
||||
}
|
||||
} else if let Some(msg) = blocked.as_deref() {
|
||||
stitch_ui::status_label(ui, msg, stitch_ui::StatusTone::Warning);
|
||||
} else {
|
||||
// Concise pre-launch summary when all brief inputs are ready.
|
||||
let scopes_label = selected_output_scopes(&self.creation_brief)
|
||||
.iter()
|
||||
.map(|s| match s.as_str() {
|
||||
"detail" => "详情页",
|
||||
"main_images" => "主图",
|
||||
"sku_images" => "SKU 图",
|
||||
_ => s.as_str(),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(" / ");
|
||||
let mut parts = vec![format!("将生成:{scopes_label}")];
|
||||
if let Some(detail) = non_empty_str(&self.creation_brief["detailBarcode"]) {
|
||||
parts.push(format!("主款:{}", sku_short_label(&self.creation_brief, detail)));
|
||||
}
|
||||
if let Some(tpl_name) = non_empty_str(&template["name"]) {
|
||||
parts.push(format!("模板:{tpl_name}"));
|
||||
}
|
||||
let img_count = selected_visual_asset_count(&self.creation_brief);
|
||||
if img_count > 0 {
|
||||
parts.push(format!("{img_count} 张素材"));
|
||||
}
|
||||
stitch_kit::label(ui, parts.join(" · "), Type::Meta, Tone::Success);
|
||||
}
|
||||
if let Some((message, chip, action)) = setup_warning {
|
||||
stitch_ui::status_chip(ui, chip, stitch_ui::StatusTone::Warning).on_hover_text(message);
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Secondary, true);
|
||||
self.control_geometry(if self.key_saved { "select-model" } else { "configure-personal-key" }, configure.rect);
|
||||
if configure.clicked() {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
} else if new_project {
|
||||
stitch_kit::label(ui, "模型已就绪", Type::Meta, Tone::Quiet);
|
||||
}
|
||||
});
|
||||
self.control_geometry("entry-hint", hint_row.response.rect);
|
||||
if let Some((key, msg)) = clicked_missing {
|
||||
self.focus_brief_field(&key, &msg);
|
||||
|
||||
}
|
||||
self.reference_drop_warning_ui(ui);
|
||||
|
||||
ui.add_space(space::XS);
|
||||
let actions_ready = self.busy.is_none() && !self.unknown && !barcode_pending;
|
||||
let canvas_ready = actions_ready && missing_items.is_empty() && missing.is_empty();
|
||||
let production_ready = blocked.is_none() && setup_warning.is_none();
|
||||
@ -4036,20 +4133,79 @@ impl Workspace {
|
||||
None
|
||||
};
|
||||
if self.creation_reads.wizard_stage.is_some() {
|
||||
self.brief_autosave_status_ui(ui);
|
||||
self.reference_drop_warning_ui(ui);
|
||||
let resume = self.has_production_stages() || self.has_paused_production();
|
||||
let action = wizard::wizard_footer_ui(ui, WizardFooterState {
|
||||
stage: CreationStage::Details,
|
||||
can_continue: resume,
|
||||
can_enter_canvas: canvas_ready,
|
||||
can_start: if resume { self.can_resume_product() } else { production_ready },
|
||||
}, new_project || resume, |action, response| {
|
||||
match action {
|
||||
WizardFooterOutcome::EnterCanvas => self.control_geometry("enter-canvas", response.rect),
|
||||
WizardFooterOutcome::Start => self.control_geometry(if resume { "resume-product" } else { "start-product" }, response.rect),
|
||||
let mut open_settings = false;
|
||||
let mut recorded_geometries: Vec<(String, egui::Rect)> = Vec::new();
|
||||
let mut button_geometries: Vec<(WizardFooterOutcome, egui::Rect)> = Vec::new();
|
||||
let autosave_info = if self.creation_reads.staged_new_project {
|
||||
("草稿暂存中", Tone::Quiet)
|
||||
} else if self.busy.as_deref() == Some("creation-save") {
|
||||
("保存中…", Tone::Quiet)
|
||||
} else if self.creation_dirty {
|
||||
("有未保存修改 · 将自动保存", Tone::Warning)
|
||||
} else {
|
||||
("已自动保存", Tone::Success)
|
||||
};
|
||||
let key_saved = self.key_saved;
|
||||
let action = wizard::wizard_footer_ui_with_status(
|
||||
ui,
|
||||
WizardFooterState {
|
||||
stage: CreationStage::Details,
|
||||
can_continue: resume,
|
||||
can_enter_canvas: canvas_ready,
|
||||
can_start: if resume { self.can_resume_product() } else { production_ready },
|
||||
},
|
||||
new_project || resume,
|
||||
|ui| {
|
||||
let hint_row = ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::XS;
|
||||
if !missing_items.is_empty() {
|
||||
stitch_kit::label(ui, "待补齐:", Type::Meta, Tone::Warning);
|
||||
for item in &missing_items {
|
||||
let chip = stitch_ui::action_button(ui, &item.label, stitch_ui::ButtonRole::Quiet, true)
|
||||
.on_hover_text(&item.message);
|
||||
recorded_geometries.push((format!("readiness-{}", item.field_key), chip.rect));
|
||||
if chip.clicked() {
|
||||
clicked_missing = Some((item.field_key.clone(), item.message.clone()));
|
||||
}
|
||||
}
|
||||
} else if let Some(msg) = blocked.as_deref() {
|
||||
stitch_ui::status_label(ui, msg, stitch_ui::StatusTone::Warning);
|
||||
} else {
|
||||
stitch_kit::label(ui, autosave_info.0, Type::Meta, autosave_info.1);
|
||||
}
|
||||
if let Some((message, chip, action)) = setup_warning {
|
||||
stitch_ui::status_chip(ui, chip, stitch_ui::StatusTone::Warning).on_hover_text(message);
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Quiet, true);
|
||||
recorded_geometries.push((if key_saved { "select-model" } else { "configure-personal-key" }.to_owned(), configure.rect));
|
||||
if configure.clicked() {
|
||||
open_settings = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
recorded_geometries.push(("entry-hint".to_owned(), hint_row.response.rect));
|
||||
},
|
||||
|action, response| {
|
||||
button_geometries.push((action, response.rect));
|
||||
},
|
||||
);
|
||||
for (k, rect) in recorded_geometries {
|
||||
self.control_geometry(&k, rect);
|
||||
}
|
||||
for (btn_action, rect) in button_geometries {
|
||||
match btn_action {
|
||||
WizardFooterOutcome::EnterCanvas => self.control_geometry("enter-canvas", rect),
|
||||
WizardFooterOutcome::Start => self.control_geometry(if resume { "resume-product" } else { "start-product" }, rect),
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
if open_settings {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
if let Some((key, msg)) = clicked_missing.take() {
|
||||
self.focus_brief_field(&key, &msg);
|
||||
}
|
||||
match action {
|
||||
WizardFooterOutcome::Start if resume => self.resume_product_production(app),
|
||||
WizardFooterOutcome::Start | WizardFooterOutcome::EnterCanvas => {
|
||||
@ -4060,6 +4216,34 @@ impl Workspace {
|
||||
}
|
||||
#[cfg(test)]
|
||||
if self.creation_reads.wizard_stage.is_none() {
|
||||
let hint_row = ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
if !missing_items.is_empty() {
|
||||
stitch_kit::label(ui, "待补齐:", Type::Meta, Tone::Warning);
|
||||
for item in &missing_items {
|
||||
let chip = stitch_ui::action_button(ui, &item.label, stitch_ui::ButtonRole::Quiet, true)
|
||||
.on_hover_text(&item.message);
|
||||
self.control_geometry(&format!("readiness-{}", item.field_key), chip.rect);
|
||||
if chip.clicked() {
|
||||
clicked_missing = Some((item.field_key.clone(), item.message.clone()));
|
||||
}
|
||||
}
|
||||
} else if let Some(msg) = blocked.as_deref() {
|
||||
stitch_ui::status_label(ui, msg, stitch_ui::StatusTone::Warning);
|
||||
}
|
||||
if let Some((message, chip, action)) = setup_warning {
|
||||
stitch_ui::status_chip(ui, chip, stitch_ui::StatusTone::Warning).on_hover_text(message);
|
||||
let configure = stitch_ui::action_button(ui, action, stitch_ui::ButtonRole::Secondary, true);
|
||||
self.control_geometry(if self.key_saved { "select-model" } else { "configure-personal-key" }, configure.rect);
|
||||
if configure.clicked() {
|
||||
self.open_brief_setup_settings();
|
||||
}
|
||||
}
|
||||
});
|
||||
self.control_geometry("entry-hint", hint_row.response.rect);
|
||||
if let Some((key, msg)) = clicked_missing {
|
||||
self.focus_brief_field(&key, &msg);
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
self.brief_autosave_status_ui(ui);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
@ -5082,10 +5266,25 @@ impl Workspace {
|
||||
}
|
||||
let tpl_name = self.creation_reads.resource_set["name"].as_str().or(choice["name"].as_str()).unwrap_or("项目模板").to_owned();
|
||||
let tpl_width = result["choice"]["width"].as_u64().unwrap_or(self.creation_width as u64) as u32;
|
||||
if let Some((_, image)) = self.creation_reads.resource_image.clone() {
|
||||
ui.add_space(space::XS);
|
||||
let cover_img = self.creation_reads.resource_image.clone().map(|(_, tex)| tex);
|
||||
let fallback_structure = if cover_img.is_none() {
|
||||
choice.get("structurePreview").filter(|v| v.is_object())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if cover_img.is_some() || fallback_structure.is_some() || template_identity(choice) {
|
||||
ui.add_space(space::SM);
|
||||
let card = ui.scope(|ui| {
|
||||
structure_preview_card(ui, None, Some(&image), &tpl_name, "企业知识库", self.creation_template_screen_count(), tpl_width, Some("已就绪"));
|
||||
structure_preview_card(
|
||||
ui,
|
||||
fallback_structure,
|
||||
cover_img.as_ref(),
|
||||
&tpl_name,
|
||||
"企业知识库",
|
||||
self.creation_template_screen_count(),
|
||||
tpl_width,
|
||||
Some("已就绪"),
|
||||
);
|
||||
});
|
||||
self.control_geometry("resource-preview", card.response.rect);
|
||||
}
|
||||
@ -5266,12 +5465,13 @@ impl Workspace {
|
||||
} else {
|
||||
draw_picker(self, app, ui, picker_width, &mut geometry);
|
||||
let chosen = selected_template(&self.creation_brief, &self.template_workflow, &self.creation["brief"]);
|
||||
if let Some(preview) = rows.iter().find_map(|row| verified_structure_preview(row, &chosen, &brand, &category)) {
|
||||
ui.add_space(space::XS);
|
||||
let preview = rows.iter().find_map(|row| verified_structure_preview(row, &chosen, &brand, &category));
|
||||
if preview.is_some() || template_identity(&chosen) {
|
||||
ui.add_space(space::SM);
|
||||
let card = ui.scope(|ui| {
|
||||
structure_preview_card(
|
||||
ui,
|
||||
Some(preview),
|
||||
preview,
|
||||
None,
|
||||
name,
|
||||
version_label,
|
||||
|
||||
@ -4,9 +4,8 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::jiansun::{stitch_kit, stitch_ui};
|
||||
#[cfg(test)]
|
||||
use crate::theme::Tokens;
|
||||
use crate::theme::agent_scale::{Type, control, motion, space};
|
||||
use crate::theme::agent_scale::{Type, control, motion, radius, space};
|
||||
use egui::{Id, Response, Ui};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@ -269,77 +268,243 @@ pub(crate) struct BarcodeCardAction {
|
||||
pub add_barcode: bool,
|
||||
}
|
||||
|
||||
fn barcode_dimensions_summary(dimensions: &Value) -> Option<String> {
|
||||
let l = field_text(&dimensions["length"]);
|
||||
let w = field_text(&dimensions["width"]);
|
||||
let h = field_text(&dimensions["height"]);
|
||||
let parts: Vec<&str> = [l.trim(), w.trim(), h.trim()].into_iter().filter(|s| !s.is_empty()).collect();
|
||||
if parts.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let unit = dimensions["unit"].as_str().filter(|s| !s.is_empty()).unwrap_or("mm");
|
||||
Some(format!("{} {}", parts.join("×"), unit))
|
||||
}
|
||||
|
||||
pub(crate) enum BarcodeSlotRender<'a> {
|
||||
Image { row: &'a Value, size: f32, editable: bool },
|
||||
Related { row: &'a Value },
|
||||
}
|
||||
|
||||
pub(crate) fn barcode_cards_section_ui<'a>(
|
||||
ui: &mut Ui,
|
||||
scope: Id,
|
||||
rows: &mut Vec<Value>,
|
||||
reduce_motion: bool,
|
||||
hint: impl Fn(&'static str) -> &'a str,
|
||||
mut related_fields: impl FnMut(&mut Ui, Id, &Value),
|
||||
mut render_slot: impl FnMut(&mut Ui, Id, BarcodeSlotRender<'_>),
|
||||
) -> BarcodeCardAction {
|
||||
let mut action = BarcodeCardAction::default();
|
||||
let t = Tokens::get(ui.ctx()).agent();
|
||||
let mut used_codes: HashSet<_> = rows.iter().filter_map(|row| row["barcode"].as_str()).filter(|code| !code.is_empty()).map(str::to_owned).collect();
|
||||
let removable = rows.len() > 1 || rows.first().is_some_and(|row| row["barcode"].as_str().is_some_and(|code| !code.is_empty()));
|
||||
section_heading_with_tip(ui, "产品条码", "每个条码可填写自己的花色、规格与图片。");
|
||||
|
||||
let expanded_key = scope.with("expanded-barcode-id");
|
||||
let expand_newest_key = scope.with("expand-newest-barcode");
|
||||
let mut expanded_id: Option<String> = ui.data(|data| data.get_temp::<Option<String>>(expanded_key)).unwrap_or_else(|| {
|
||||
if rows.len() == 1 && rows[0]["barcode"].as_str().unwrap_or("").trim().is_empty() {
|
||||
rows[0]["id"].as_str().map(str::to_owned)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
if ui.data(|data| data.get_temp::<bool>(expand_newest_key)).unwrap_or(false) {
|
||||
if let Some(last_id) = rows.last().and_then(|row| row["id"].as_str()).map(str::to_owned) {
|
||||
expanded_id = Some(last_id);
|
||||
}
|
||||
ui.data_mut(|data| data.remove::<bool>(expand_newest_key));
|
||||
}
|
||||
if let Some(ref cur) = expanded_id
|
||||
&& !rows.iter().any(|row| row["id"].as_str() == Some(cur.as_str()))
|
||||
{
|
||||
expanded_id = None;
|
||||
}
|
||||
|
||||
// Header row: title + count + top-right add button (ergonomic even for 100 barcodes)
|
||||
ui.horizontal(|ui| {
|
||||
section_heading_with_tip(ui, &format!("产品条码({})", rows.len()), "点击条码可展开编辑花色、尺寸、材质与专属图片;完成后自动收起。");
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if stitch_ui::action_button(ui, "添加条码", stitch_ui::ButtonRole::Secondary, rows.len() < 200).clicked() {
|
||||
action.add_barcode = true;
|
||||
ui.data_mut(|data| data.insert_temp(expand_newest_key, true));
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
|
||||
let mut next_expanded = expanded_id.clone();
|
||||
let mut collapse_requested = false;
|
||||
for (index, row) in rows.iter_mut().enumerate() {
|
||||
let row_id_str = row["id"].as_str().unwrap_or("").to_owned();
|
||||
let id = scope.with(row["id"].as_str());
|
||||
let is_expanded = expanded_id.as_deref() == Some(row_id_str.as_str()) && !row_id_str.is_empty();
|
||||
|
||||
ui.push_id(id, |ui| {
|
||||
if index > 0 {
|
||||
ui.add_space(space::SM);
|
||||
if index > 0 && !is_expanded {
|
||||
stitch_ui::divider(ui);
|
||||
}
|
||||
ui.add_space(space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
stitch_kit::label(ui, format!("条码 {}", index + 1), Type::Body, super::super::stitch_state::Tone::Active);
|
||||
if removable {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if stitch_ui::action_button(ui, "移除条码", stitch_ui::ButtonRole::QuietDanger, true).clicked() {
|
||||
action.remove_index = Some(index);
|
||||
if !is_expanded {
|
||||
// Compact single-line display row (~44px tall) — scales effortlessly to 100+ barcodes.
|
||||
let row_frame = egui::Frame::NONE
|
||||
.inner_margin(egui::Margin::symmetric(6, 5))
|
||||
.corner_radius(egui::CornerRadius::same(radius::ROW as u8));
|
||||
let resp = row_frame.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
// 32x32 image slot thumbnail
|
||||
render_slot(ui, id.with("thumb"), BarcodeSlotRender::Image { row, size: 32.0, editable: false });
|
||||
|
||||
let code = field_text(&row["barcode"]);
|
||||
let color = field_text(&row["colorName"]);
|
||||
let dims = barcode_dimensions_summary(&row["dimensions"]);
|
||||
let material = field_text(&row["material"]);
|
||||
let board = field_text(&row["boardType"]);
|
||||
|
||||
let mut meta_parts = Vec::new();
|
||||
if !color.trim().is_empty() {
|
||||
meta_parts.push(color.trim().to_owned());
|
||||
}
|
||||
if let Some(d) = dims {
|
||||
meta_parts.push(d);
|
||||
}
|
||||
if !material.trim().is_empty() {
|
||||
meta_parts.push(material.trim().to_owned());
|
||||
}
|
||||
if !board.trim().is_empty() {
|
||||
meta_parts.push(board.trim().to_owned());
|
||||
}
|
||||
|
||||
// Right-aligned compact actions first so middle text gets exact remaining width
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
if removable && stitch_ui::action_button(ui, "移除条码", stitch_ui::ButtonRole::QuietDanger, true).clicked() {
|
||||
action.remove_index = Some(index);
|
||||
}
|
||||
if stitch_ui::action_button(ui, "编辑", stitch_ui::ButtonRole::Quiet, true).clicked() {
|
||||
next_expanded = Some(row_id_str.clone());
|
||||
}
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
let code_text = if code.trim().is_empty() { format!("条码 {}(未填编码)", index + 1) } else { code.trim().to_owned() };
|
||||
let code_color = if code.trim().is_empty() { t.text_dim } else { t.text };
|
||||
let click_label = ui.add(
|
||||
egui::Label::new(egui::RichText::new(code_text).font(Type::Body.semibold()).color(code_color))
|
||||
.truncate()
|
||||
.sense(egui::Sense::click()),
|
||||
);
|
||||
if click_label.clicked() {
|
||||
next_expanded = Some(row_id_str.clone());
|
||||
}
|
||||
if !meta_parts.is_empty() {
|
||||
let meta = format!("· {}", meta_parts.join(" · "));
|
||||
let click_meta = ui.add(
|
||||
egui::Label::new(egui::RichText::new(meta).font(Type::Meta.font_id()).color(t.text_dim))
|
||||
.truncate()
|
||||
.sense(egui::Sense::click()),
|
||||
);
|
||||
if click_meta.clicked() {
|
||||
next_expanded = Some(row_id_str.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
if resp.response.hovered() {
|
||||
ui.painter().rect_filled(
|
||||
resp.response.rect,
|
||||
egui::CornerRadius::same(radius::ROW as u8),
|
||||
egui::Color32::from_rgba_unmultiplied(255, 255, 255, 8),
|
||||
);
|
||||
}
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
let old = field_text(&row["barcode"]);
|
||||
let draft_id = id.with("barcode-draft");
|
||||
let mut draft = ui.data(|data| data.get_temp::<String>(draft_id)).unwrap_or_else(|| old.clone());
|
||||
ui.columns(2, |columns| {
|
||||
let editor = super::super::creation::wizard_barcode_editor(&mut columns[0], id.with("code"), &mut draft);
|
||||
let code = draft.trim();
|
||||
if code != old {
|
||||
let issue = if used_codes.contains(code) { Some("此条码已录入当前项目") }
|
||||
else if code.is_empty() && !old.is_empty() { Some("请填写条码或移除本条") }
|
||||
else { None };
|
||||
if let Some(issue) = issue {
|
||||
stitch_ui::status_label(&mut columns[0], issue, stitch_ui::StatusTone::Warning);
|
||||
} else if editor.lost_focus() || (editor.has_focus() && columns[0].input(|input| input.key_pressed(egui::Key::Enter))) {
|
||||
used_codes.remove(&old);
|
||||
used_codes.insert(code.to_owned());
|
||||
row["barcode"] = json!(code);
|
||||
action.changed = true;
|
||||
}
|
||||
}
|
||||
action.pending |= row["barcode"] != code && action.remove_index != Some(index);
|
||||
ui_data_draft(&columns[0], draft_id, draft, &row["barcode"]);
|
||||
let color_hint = hint("colorName");
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["colorName"], "花色",
|
||||
if color_hint.is_empty() { "如 原木色" } else { color_hint }, reduce_motion);
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
if let Some(dimensions) = row["dimensions"].as_object_mut() {
|
||||
action.changed |= dimensions_ui(ui, id, dimensions, reduce_motion, &hint);
|
||||
} else {
|
||||
// Compact expanded editor panel (auto-collapses on "完成" or switching to another barcode)
|
||||
ui.add_space(space::XXS);
|
||||
egui::Frame::NONE
|
||||
.fill(t.dock)
|
||||
.stroke(egui::Stroke::new(1.0, t.card_border))
|
||||
.corner_radius(egui::CornerRadius::same(radius::CONTROL as u8))
|
||||
.inner_margin(egui::Margin::symmetric(12, 10))
|
||||
.show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = space::XS;
|
||||
ui.horizontal(|ui| {
|
||||
stitch_kit::label(ui, format!("条码 {} · 编辑中", index + 1), Type::Meta, super::super::stitch_state::Tone::Active);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
if removable && stitch_ui::action_button(ui, "移除条码", stitch_ui::ButtonRole::QuietDanger, true).clicked() {
|
||||
action.remove_index = Some(index);
|
||||
}
|
||||
if stitch_ui::action_button(ui, "完成", stitch_ui::ButtonRole::Secondary, true).clicked() {
|
||||
collapse_requested = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let old = field_text(&row["barcode"]);
|
||||
let draft_id = id.with("barcode-draft");
|
||||
let mut draft = ui.data(|data| data.get_temp::<String>(draft_id)).unwrap_or_else(|| old.clone());
|
||||
|
||||
let row_snapshot = row.clone();
|
||||
let mut render_core_fields = |ui: &mut Ui, row: &mut Value| {
|
||||
ui.columns(2, |columns| {
|
||||
let editor = super::super::creation::wizard_barcode_editor(&mut columns[0], id.with("code"), &mut draft);
|
||||
let code = draft.trim();
|
||||
if code != old {
|
||||
let issue = if used_codes.contains(code) { Some("此条码已录入当前项目") }
|
||||
else if code.is_empty() && !old.is_empty() { Some("请填写条码或移除本条") }
|
||||
else { None };
|
||||
if let Some(issue) = issue {
|
||||
stitch_ui::status_label(&mut columns[0], issue, stitch_ui::StatusTone::Warning);
|
||||
} else if editor.lost_focus() || collapse_requested || (editor.has_focus() && columns[0].input(|input| input.key_pressed(egui::Key::Enter))) {
|
||||
used_codes.remove(&old);
|
||||
used_codes.insert(code.to_owned());
|
||||
row["barcode"] = json!(code);
|
||||
action.changed = true;
|
||||
}
|
||||
}
|
||||
action.pending |= row["barcode"] != code && action.remove_index != Some(index);
|
||||
ui_data_draft(&columns[0], draft_id, draft.clone(), &row["barcode"]);
|
||||
let color_hint = hint("colorName");
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["colorName"], "花色",
|
||||
if color_hint.is_empty() { "如 原木色" } else { color_hint }, reduce_motion);
|
||||
});
|
||||
if let Some(dimensions) = row["dimensions"].as_object_mut() {
|
||||
action.changed |= dimensions_ui(ui, id, dimensions, reduce_motion, &hint);
|
||||
}
|
||||
ui.columns(2, |columns| {
|
||||
action.changed |= edit_text(&mut columns[0], id, &mut row["material"], "材质(选填)", hint("material"), reduce_motion);
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["boardType"], "板材类型(选填)", hint("boardType"), reduce_motion);
|
||||
});
|
||||
};
|
||||
|
||||
if ui.available_width() >= 480.0 {
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::MD;
|
||||
ui.vertical(|ui| {
|
||||
stitch_kit::caption(ui, "图片");
|
||||
render_slot(ui, id.with("edit-thumb"), BarcodeSlotRender::Image { row: &row_snapshot, size: 72.0, editable: true });
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
render_core_fields(ui, row);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ui.horizontal(|ui| {
|
||||
render_slot(ui, id.with("edit-thumb"), BarcodeSlotRender::Image { row: &row_snapshot, size: 56.0, editable: true });
|
||||
stitch_kit::caption(ui, "条码图片");
|
||||
});
|
||||
render_core_fields(ui, row);
|
||||
}
|
||||
render_slot(ui, id, BarcodeSlotRender::Related { row });
|
||||
});
|
||||
ui.add_space(space::XXS);
|
||||
}
|
||||
ui.add_space(space::XS);
|
||||
ui.columns(2, |columns| {
|
||||
action.changed |= edit_text(&mut columns[0], id, &mut row["material"], "材质(选填)", hint("material"), reduce_motion);
|
||||
action.changed |= edit_text(&mut columns[1], id, &mut row["boardType"], "板材类型(选填)", hint("boardType"), reduce_motion);
|
||||
});
|
||||
ui.add_space(space::XS);
|
||||
related_fields(ui, id, row);
|
||||
});
|
||||
}
|
||||
ui.add_space(space::SM);
|
||||
action.add_barcode = stitch_ui::action_button(ui, "添加条码", stitch_ui::ButtonRole::Secondary, rows.len() < 200).clicked();
|
||||
|
||||
if collapse_requested {
|
||||
next_expanded = None;
|
||||
}
|
||||
ui.data_mut(|data| data.insert_temp(expanded_key, next_expanded));
|
||||
action.changed |= action.add_barcode || action.remove_index.is_some();
|
||||
action
|
||||
}
|
||||
@ -459,6 +624,14 @@ pub(crate) enum WizardFooterOutcome {
|
||||
|
||||
pub(crate) fn wizard_footer_ui(
|
||||
ui: &mut Ui, state: WizardFooterState, show_production: bool,
|
||||
on_button: impl FnMut(WizardFooterOutcome, &Response),
|
||||
) -> WizardFooterOutcome {
|
||||
wizard_footer_ui_with_status(ui, state, show_production, |_| {}, on_button)
|
||||
}
|
||||
|
||||
pub(crate) fn wizard_footer_ui_with_status(
|
||||
ui: &mut Ui, state: WizardFooterState, show_production: bool,
|
||||
mut inline_status: impl FnMut(&mut Ui),
|
||||
mut on_button: impl FnMut(WizardFooterOutcome, &Response),
|
||||
) -> WizardFooterOutcome {
|
||||
use WizardFooterOutcome::{Back, Cancel, EnterCanvas, Next, Start};
|
||||
@ -490,20 +663,31 @@ pub(crate) fn wizard_footer_ui(
|
||||
outcome = intent;
|
||||
}
|
||||
};
|
||||
if ui.available_width() >= 420.0 {
|
||||
if ui.available_width() >= 740.0 {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
let split = if state.stage == CreationStage::Source { 1 } else { 2 };
|
||||
for button in &buttons[..split] {
|
||||
draw(ui, *button);
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::SM;
|
||||
for button in buttons[split..].iter().rev() {
|
||||
draw(ui, *button);
|
||||
}
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::XS;
|
||||
inline_status(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::XS;
|
||||
inline_status(ui);
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::XS;
|
||||
for button in buttons {
|
||||
draw(ui, button);
|
||||
}
|
||||
@ -640,7 +824,18 @@ mod tests {
|
||||
|ui, state: &mut (Value, BarcodeCardAction)| {
|
||||
ensure_default_barcode(&mut state.0);
|
||||
let rows = state.0["barcodeEntries"].as_array_mut().unwrap();
|
||||
let action = barcode_cards_section_ui(ui, Id::unique("cards"), rows, true, |_| "", |_, _, _| {});
|
||||
let action = barcode_cards_section_ui(
|
||||
ui,
|
||||
Id::unique("cards"),
|
||||
rows,
|
||||
true,
|
||||
|_| "",
|
||||
|ui, _, slot| {
|
||||
if let BarcodeSlotRender::Image { size, .. } = slot {
|
||||
ui.allocate_exact_size(egui::vec2(size, size), egui::Sense::hover());
|
||||
}
|
||||
},
|
||||
);
|
||||
if let Some(index) = action.remove_index { rows.remove(index); }
|
||||
if action.add_barcode { rows.push(barcode_row("", &Value::Null, &Value::Null, &Value::Null)); }
|
||||
if action != BarcodeCardAction::default() {
|
||||
@ -649,16 +844,25 @@ mod tests {
|
||||
},
|
||||
(json!({"barcodeBindings":{"default":["0001"]},"images":[{"barcode":"0001"}]}), BarcodeCardAction::default()),
|
||||
);
|
||||
// Populated barcode starts collapsed as compact summary row.
|
||||
h.get_by_label("0001");
|
||||
h.get_by_label("编辑").click();
|
||||
h.run();
|
||||
for label in
|
||||
["条码编码", "花色", "尺寸", "长", "宽", "高", "单位", "mm", "材质(选填)", "板材类型(选填)", "添加条码"]
|
||||
["条码编码", "花色", "尺寸", "长", "宽", "高", "单位", "mm", "材质(选填)", "板材类型(选填)", "完成", "添加条码"]
|
||||
{
|
||||
let rect = h.query_all_by_label(label).next().unwrap_or_else(|| panic!("missing {label}")).rect();
|
||||
assert!(rect.left() >= 0.0 && rect.right() <= width, "{label}: {rect:?}");
|
||||
}
|
||||
h.get_by_label("完成").click();
|
||||
h.run();
|
||||
assert!(h.query_by_label("材质(选填)").is_none());
|
||||
h.get_by_label("添加条码").click();
|
||||
h.run();
|
||||
assert!(h.state().1.add_barcode);
|
||||
assert_eq!(h.state().0["barcodeEntries"].as_array().unwrap().len(), 2);
|
||||
// Newly added barcode auto-expands for immediate entry.
|
||||
assert!(h.query_all_by_label("材质(选填)").next().is_some());
|
||||
h.query_all_by_label("移除条码").next().unwrap().click();
|
||||
h.run();
|
||||
assert_eq!(h.state().1.remove_index, Some(0));
|
||||
@ -728,7 +932,18 @@ mod tests {
|
||||
wizard_stepper_ui(ui, &mut stage, true, true, true);
|
||||
ui.add_space(space::MD);
|
||||
ensure_default_barcode(brief);
|
||||
barcode_cards_section_ui(ui, Id::unique("sample"), brief["barcodeEntries"].as_array_mut().unwrap(), true, |_| "", |_, _, _| {});
|
||||
barcode_cards_section_ui(
|
||||
ui,
|
||||
Id::unique("sample"),
|
||||
brief["barcodeEntries"].as_array_mut().unwrap(),
|
||||
true,
|
||||
|_| "",
|
||||
|ui, _, slot| {
|
||||
if let BarcodeSlotRender::Image { size, .. } = slot {
|
||||
ui.allocate_exact_size(egui::vec2(size, size), egui::Sense::hover());
|
||||
}
|
||||
},
|
||||
);
|
||||
ui.add_space(space::MD);
|
||||
stitch_ui::scope_with_motion(ui, true, |ui| {
|
||||
wizard_footer_ui(ui, WizardFooterState { stage, can_continue: false, can_enter_canvas: true, can_start: true }, true, |_, _| {});
|
||||
|
||||
@ -2035,7 +2035,10 @@ pub(super) fn vertical_divider(ui: &mut Ui) -> Response {
|
||||
/// Returns a configurable native text editor; IME, submission and draft state stay with the caller.
|
||||
pub(super) fn text_input<'a>(value: &'a mut String, hint: &'a str, multiline: bool) -> egui::TextEdit<'a> {
|
||||
let input = if multiline { egui::TextEdit::multiline(value) } else { egui::TextEdit::singleline(value) };
|
||||
input.hint_text(hint).desired_width(f32::INFINITY)
|
||||
let hint_text = egui::RichText::new(hint)
|
||||
.font(Type::Meta.font_id())
|
||||
.color(egui::Color32::from_rgba_unmultiplied(180, 184, 194, 88));
|
||||
input.hint_text(hint_text).desired_width(f32::INFINITY)
|
||||
}
|
||||
|
||||
/// A native, selectable field with the shared perimeter light. The owner
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user