Export textures: boxed tabs, full-width Global settings, reference label column, dilation arrow, console header band and bold set names, one name per output map row

This commit is contained in:
vangel76 committed 2026-11-23 23:44:49 +01:00
1 parent 043de59f34
commit 2cea24fe71
2 files changed
+148 -24

No files matched your search

+137 -24
View File
@@ -5,14 +5,14 @@
use egui::{RichText, Ui, vec2};
use egui_phosphor::regular as ic;
use serde_json::json;
use texturecraft_engine::formats::{ExportPreset, FileFormat};
use texturecraft_engine::formats::{ExportPreset, FileFormat, MapSpec, SourceRef};
use crate::TextureCraftApp;
#[cfg(not(target_arch = "wasm32"))]
use crate::file_dialogs::{Bound, FileDialog};
use crate::i18n::{n_, tr, trf};
use crate::state::{ConsoleLine, ExportSetPlan, ExportUi, FileType, MapExport, SIZE_OF_LARGEST_SET, SetExport};
use crate::theme::{Tokens, caption};
use crate::theme::{Tokens, caption, semibold};
use crate::unavailable::NOT_AVAILABLE;
use crate::widgets::icon_button;
@@ -30,10 +30,26 @@ const WINDOW_CHROME_HEIGHT_POINTS: f32 = 80.0;
/// The smallest tab body, so the lists and pages stay usable
const MIN_BODY_HEIGHT_POINTS: f32 = 160.0;
/// Width of the texture set list
const LIST_WIDTH: f32 = 180.0;
const LIST_WIDTH: f32 = 250.0;
const ICON: f32 = 20.0;
/// Width of the label column of the parameter rows, as in the reference
const LABEL_COLUMN_WIDTH: f32 = 200.0;
/// Width of the value column of the parameter rows
const VALUE_WIDTH: f32 = 360.0;
/// Width of the first File type list; the bit depth list fills the rest of the row
const FILE_TYPE_WIDTH: f32 = 166.0;
/// Width of the dilation button, with room for its drop-down arrow
const DILATION_BUTTON_WIDTH: f32 = 60.0;
/// Size of a drop-down arrow, and its distance from the button's right edge
const CARET_SIZE: f32 = 10.0;
const CARET_INSET: f32 = 6.0;
/// A tab: padding around its name, the accent line on top of the open one, the name's size
const TAB_PADDING: egui::Vec2 = egui::vec2(10.0, 6.0);
const TAB_ACCENT_HEIGHT: f32 = 2.0;
const TAB_TEXT_SIZE: f32 = 12.5;
/// Height of a full-width row of the texture set list and where its text starts
const LIST_ROW_HEIGHT: f32 = 24.0;
const LIST_ROW_INDENT: f32 = 16.0;
/// Width of the bottom bar's buttons, the same for all as in the reference
const FOOTER_BUTTON_WIDTH: f32 = 125.0;
@@ -104,7 +120,7 @@ fn file_type_lists(ui: &mut Ui, id: (&str, usize, usize), from_template: bool, f
let shown = if format.is_empty() { tr("Based on output template").to_string() } else { file_type_name(format) };
// Tall enough for the whole list
let list = egui::ComboBox::from_id_salt(("type", id)).width(if from_template { 166.0 } else { 90.0 }).height(f32::INFINITY);
let list = egui::ComboBox::from_id_salt(("type", id)).width(if from_template { FILE_TYPE_WIDTH } else { 90.0 }).height(f32::INFINITY);
list.selected_text(shown).show_ui(ui, |ui| {
if from_template {
if ui.selectable_label(format.is_empty(), tr("Based on output template")).clicked() {
@@ -130,7 +146,9 @@ fn file_type_lists(ui: &mut Ui, id: (&str, usize, usize), from_template: bool, f
let options = parsed.map(depth_options).unwrap_or_default();
let shown = if parsed.is_some() { depth_label(parsed, *bit_depth, *dithering) } else { String::new() };
ui.add_enabled_ui(options.len() > 1, |ui| {
egui::ComboBox::from_id_salt(("bits", id)).width(if from_template { 160.0 } else { 120.0 }).selected_text(shown).show_ui(ui, |ui| {
// On the global page the bit depth list fills the row
let width = if from_template { VALUE_WIDTH - FILE_TYPE_WIDTH - ui.spacing().item_spacing.x } else { 120.0 };
egui::ComboBox::from_id_salt(("bits", id)).width(width).selected_text(shown).show_ui(ui, |ui| {
for (d, dither) in options {
if ui.selectable_label((*bit_depth, *dithering) == (d, dither), depth_label(parsed, d, dither)).clicked() {
(*bit_depth, *dithering) = (d, dither);
@@ -510,12 +528,23 @@ fn map_rows(app: &mut TextureCraftApp, ts: usize) -> Vec<MapRow> {
let format = f.get("format").and_then(serde_json::Value::as_str).unwrap_or("png").to_string();
let bit_depth = f.get("bitDepth").and_then(serde_json::Value::as_u64).unwrap_or(8) as u8;
let dithering = f.get("dithering").and_then(serde_json::Value::as_bool).unwrap_or(false);
let pattern = preset.as_ref().and_then(|p| p.maps.get(map)).map(|m| m.file.clone()).unwrap_or_default();
let pattern = preset.as_ref().and_then(|p| p.maps.get(map)).map(|m| m.file.replace("$channel", channel_id(m))).unwrap_or_default();
rows.push(MapRow { map, pattern, inherited: FileType { format: file_type_name(&format), bit_depth, dithering } });
}
rows
}
/// What `$channel` becomes in `map`'s file name: the id of its first map, as the export names it
fn channel_id(map: &MapSpec) -> &'static str {
let first = map.channels.iter().find_map(|(_, source)| match source {
SourceRef::Channel { channel, .. } => Some(channel.id()),
SourceRef::Virtual { map, .. } => Some(map.id()),
SourceRef::Baked { map, .. } => Some(map.id()),
SourceRef::Constant(_) => None,
});
first.unwrap_or("constant")
}
/// The Output maps section of texture set `ts`'s page
fn output_maps(app: &mut TextureCraftApp, ui: &mut Ui, ts: usize) {
let rows = map_rows(app, ts);
@@ -586,6 +615,28 @@ fn selected_texture_count(app: &mut TextureCraftApp) -> usize {
count
}
/// A window tab: a box, lighter and with an accent line on top when open
fn tab_button(ui: &mut Ui, label: &str, selected: bool) -> egui::Response {
let tokens = Tokens::get(ui.ctx());
let color = if selected { tokens.text_strong } else { tokens.text };
let galley = ui.painter().layout_no_wrap(label.to_string(), semibold(TAB_TEXT_SIZE), color);
let (rect, response) = ui.allocate_exact_size(galley.size() + 2.0 * TAB_PADDING, egui::Sense::click());
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Tab, true, selected, label));
let painter = ui.painter();
let fill = match (selected, response.hovered()) {
(true, _) => tokens.panel,
(false, true) => tokens.row_hover,
(false, false) => tokens.row,
};
painter.rect(rect, 0.0, fill, egui::Stroke::new(1.0, tokens.separator), egui::StrokeKind::Inside);
if selected {
painter.rect_filled(egui::Rect::from_min_size(rect.min, vec2(rect.width(), TAB_ACCENT_HEIGHT)), 0.0, tokens.accent);
}
painter.galley(rect.min + TAB_PADDING, galley, color);
response
}
/// A bottom bar button, as wide as the others
fn footer_button(text: &str) -> egui::Button<'_> {
egui::Button::new(text).min_size(vec2(FOOTER_BUTTON_WIDTH, 0.0))
@@ -649,11 +700,18 @@ fn dilation_button(ui: &mut Ui, padding: &str, dilation: &mut u32) {
// The menu stays open while the slider is used
let config = egui::containers::menu::MenuConfig::new().close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside);
let r = ui.add_enabled_ui(enabled, |ui| {
egui::containers::menu::MenuButton::new(dilation.to_string()).config(config).ui(ui, |ui| {
let button = egui::Button::new(dilation.to_string()).min_size(vec2(DILATION_BUTTON_WIDTH, 0.0));
egui::containers::menu::MenuButton::from_button(button).config(config).ui(ui, |ui| {
ui.label(tr("Dilation (pixels)"));
ui.add(egui::Slider::new(dilation, 0..=256).step_by(1.0));
})
});
// The drop-down arrow is drawn apart, so the button's name stays the number
let tokens = Tokens::get(ui.ctx());
let arrow_color = if enabled { tokens.text } else { tokens.text_dim };
let arrow_at = r.response.rect.right_center() - vec2(CARET_INSET, 0.0);
ui.painter().text(arrow_at, egui::Align2::RIGHT_CENTER, ic::CARET_DOWN, egui::FontId::proportional(CARET_SIZE), arrow_color);
if enabled {
r.response.on_hover_text(tr("Dilation in pixels"));
} else {
@@ -705,7 +763,7 @@ fn global_page(app: &mut TextureCraftApp, ui: &mut Ui, builtins: &[ExportPreset]
crate::export_templates::select(app, defaults.preset);
}
let (first, rest) = template_groups(app, builtins);
egui::Grid::new("exp_grid").num_columns(2).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
egui::Grid::new("exp_grid").num_columns(2).min_col_width(LABEL_COLUMN_WIDTH).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
// The browser downloads the files instead
#[cfg(not(target_arch = "wasm32"))]
output_directory(app, ui);
@@ -734,7 +792,8 @@ fn global_page(app: &mut TextureCraftApp, ui: &mut Ui, builtins: &[ExportPreset]
ui.end_row();
ui.label(tr("Padding"));
ui.horizontal(|ui| {
egui::ComboBox::from_id_salt("exp_pad").width(260.0).selected_text(tr(padding_label(&settings.padding))).show_ui(ui, |ui| {
let width = VALUE_WIDTH - DILATION_BUTTON_WIDTH - ui.spacing().item_spacing.x;
egui::ComboBox::from_id_salt("exp_pad").width(width).selected_text(tr(padding_label(&settings.padding))).show_ui(ui, |ui| {
for (value, label) in PADDINGS {
ui.selectable_value(&mut settings.padding, value.to_string(), tr(label));
}
@@ -758,7 +817,7 @@ fn global_page(app: &mut TextureCraftApp, ui: &mut Ui, builtins: &[ExportPreset]
crate::unavailable::checkbox(ui, false, tr("Export MaterialX"));
unavailable_checkbox(ui, tr("Export shaders parameters"), tr("Exports a JSON file with the settings for all shader instances"));
ui.add_space(8.0);
egui::Grid::new("exp_grid_more").num_columns(2).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
egui::Grid::new("exp_grid_more").num_columns(2).min_col_width(LABEL_COLUMN_WIDTH).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
let settings = &mut app.ui.export;
ui.label(tr("Normal map format"));
let normal_label = match settings.normal_format.as_str() {
@@ -790,7 +849,7 @@ fn set_list(app: &mut TextureCraftApp, ui: &mut Ui, body_height: f32) {
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| list_menu(ui, |ui| set_checks_menu(app, ui)));
});
let header = ui.selectable_label(app.ui.export.page.is_none(), RichText::new(tr("Global settings")).strong());
let header = list_row(ui, tr("Global settings"), app.ui.export.page.is_none());
if header.clicked() {
app.ui.export.page = None;
}
@@ -800,6 +859,23 @@ fn set_list(app: &mut TextureCraftApp, ui: &mut Ui, body_height: f32) {
egui::ScrollArea::vertical().id_salt("export_texture_sets").max_height(list_height.max(0.0)).show(ui, |ui| set_rows(app, ui));
}
/// A row across the whole list, its name in bold; the selected one framed
fn list_row(ui: &mut Ui, text: &str, selected: bool) -> egui::Response {
let tokens = Tokens::get(ui.ctx());
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), LIST_ROW_HEIGHT), egui::Sense::click());
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, selected, text));
let painter = ui.painter();
if selected {
painter.rect(rect, 0.0, tokens.row_selected, egui::Stroke::new(1.0, tokens.accent), egui::StrokeKind::Inside);
} else if response.hovered() {
painter.rect_filled(rect, 0.0, tokens.row_hover);
}
let font = semibold(egui::TextStyle::Body.resolve(ui.style()).size);
painter.text(rect.left_center() + vec2(LIST_ROW_INDENT, 0.0), egui::Align2::LEFT_CENTER, text, font, tokens.text_strong);
response
}
/// A row per texture set: its export tick, its name and the override mark
fn set_rows(app: &mut TextureCraftApp, ui: &mut Ui) {
for i in 0..app.session.set_count() {
@@ -822,6 +898,7 @@ fn set_rows(app: &mut TextureCraftApp, ui: &mut Ui) {
});
}
});
ui.separator();
}
}
@@ -901,7 +978,7 @@ fn set_page(app: &mut TextureCraftApp, ui: &mut Ui, ts: usize, builtins: &[Expor
});
});
let mut toggled = None;
egui::Grid::new(("exp_set_grid", ts)).num_columns(2).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
egui::Grid::new(("exp_set_grid", ts)).num_columns(2).min_col_width(LABEL_COLUMN_WIDTH).spacing(vec2(12.0, 8.0)).show(ui, |ui| {
let on = o.preset.is_some();
if override_row(ui, tr("Output template"), on, &from.preset, |ui| {
if let Some(p) = &mut o.preset {
@@ -974,6 +1051,16 @@ fn set_page(app: &mut TextureCraftApp, ui: &mut Ui, ts: usize, builtins: &[Expor
/// Width of the LIST OF EXPORTS console
const CONSOLE_WIDTH: f32 = 300.0;
/// Width of the strip between the file tree and the console
const SPLITTER_WIDTH: f32 = 14.0;
/// Padding of the CONSOLE header band, about 45 points high as in the reference
const CONSOLE_HEADER_MARGIN_X: i8 = 12;
const CONSOLE_HEADER_MARGIN_Y: i8 = 14;
/// The file tree: indent of the file rows under their texture set, and the row height
const TREE_INDENT: f32 = 35.0;
const TREE_ROW_HEIGHT: f32 = 17.0;
/// Half the width of the tree's chevron
const CHEVRON_HALF_WIDTH: f32 = 4.0;
/// Green of the console's success lines
fn success(tk: &Tokens) -> egui::Color32 {
@@ -991,9 +1078,11 @@ fn list_tab(app: &mut TextureCraftApp, ui: &mut Ui) {
egui::ScrollArea::vertical().id_salt("exp_list").auto_shrink([false; 2]).show(ui, |ui| export_tree(app, ui, &tk));
});
// The thin toggle at the console's left edge
// The thin toggle at the console's left edge, on a strip the whole height
let toggle = if hidden { ic::CARET_DOUBLE_LEFT } else { ic::CARET_DOUBLE_RIGHT };
let r = ui.add_sized(vec2(14.0, ui.available_height()), egui::Button::new(toggle).frame(false));
let strip = egui::Rect::from_min_size(ui.cursor().min, vec2(SPLITTER_WIDTH, ui.available_height()));
ui.painter().rect_filled(strip, 0.0, tk.chrome);
let r = ui.add_sized(strip.size(), egui::Button::new(toggle).frame(false));
let r = if hidden { r } else { r.on_hover_text(tr("Hide Console")) };
if r.clicked() {
app.ui.export.console_hidden = !hidden;
@@ -1001,9 +1090,12 @@ fn list_tab(app: &mut TextureCraftApp, ui: &mut Ui) {
if !hidden {
ui.vertical(|ui| {
ui.set_width(CONSOLE_WIDTH);
ui.label(caption(&tr("Console").to_uppercase()).strong());
ui.separator();
egui::ScrollArea::vertical().id_salt("exp_console").auto_shrink([false; 2]).stick_to_bottom(true).show(ui, |ui| {
egui::Frame::new().fill(tk.row).inner_margin(egui::Margin::symmetric(CONSOLE_HEADER_MARGIN_X, CONSOLE_HEADER_MARGIN_Y)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.label(caption(&tr("Console").to_uppercase()).strong());
});
let console = egui::ScrollArea::vertical().id_salt("exp_console").auto_shrink([false; 2]).stick_to_bottom(true);
console.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible).show(ui, |ui| {
for line in &app.ui.export.console {
match line {
ConsoleLine::Step(t) => {
@@ -1030,7 +1122,7 @@ fn set_line(ui: &Ui, name: &str, tk: &Tokens) -> egui::text::LayoutJob {
let plain = egui::TextFormat::simple(font.clone(), tk.text);
let mut job = egui::text::LayoutJob::default();
job.append(before, 0.0, plain.clone());
job.append(name, 0.0, egui::TextFormat::simple(font, tk.text_strong));
job.append(name, 0.0, egui::TextFormat::simple(semibold(font.size), tk.text_strong));
job.append(after, 0.0, plain);
job
}
@@ -1063,9 +1155,11 @@ fn plan_set(app: &mut TextureCraftApp, index: usize, params: &serde_json::Value)
}
fn export_tree_set(ui: &mut Ui, index: usize, set: &ExportSetPlan, directory: &str, tokens: &Tokens) {
egui::CollapsingHeader::new(&set.name).id_salt(("exp_tree", index)).default_open(true).show(ui, |ui| match &set.files {
ui.spacing_mut().indent = TREE_INDENT;
let header = egui::CollapsingHeader::new(&set.name).id_salt(("exp_tree", index)).default_open(true).icon(chevron);
header.show(ui, |ui| match &set.files {
Ok(files) => {
egui::Grid::new(("exp_tree_grid", index)).num_columns(4).spacing(vec2(12.0, 4.0)).show(ui, |ui| {
egui::Grid::new(("exp_tree_grid", index)).num_columns(4).min_row_height(TREE_ROW_HEIGHT).spacing(vec2(12.0, 4.0)).show(ui, |ui| {
for output in files.as_array().into_iter().flatten() {
let file = output.get("file").and_then(serde_json::Value::as_str).unwrap_or_default();
let format = FileFormat::from_extension(output.get("format").and_then(serde_json::Value::as_str).unwrap_or_default());
@@ -1088,6 +1182,21 @@ fn export_tree_set(ui: &mut Ui, index: usize, set: &ExportSetPlan, directory: &s
});
}
/// The tree's outline chevron: pointing down when open, right (left in right-to-left) when closed
fn chevron(ui: &mut Ui, openness: f32, response: &egui::Response) {
let color = Tokens::get(ui.ctx()).text;
let center = response.rect.center();
let half = CHEVRON_HALF_WIDTH;
let points = if openness > 0.5 {
[center + vec2(-half, -half / 2.0), center + vec2(0.0, half / 2.0), center + vec2(half, -half / 2.0)]
} else if ui.style().right_to_left {
[center + vec2(half / 2.0, -half), center + vec2(-half / 2.0, 0.0), center + vec2(half / 2.0, half)]
} else {
[center + vec2(-half / 2.0, -half), center + vec2(half / 2.0, 0.0), center + vec2(-half / 2.0, half)]
};
ui.painter().add(egui::Shape::line(points.to_vec(), egui::Stroke::new(1.5, color)));
}
/// Show the output folder in the system's file manager (created first when missing)
#[cfg(not(target_arch = "wasm32"))]
fn open_output_directory(app: &mut TextureCraftApp) {
@@ -1295,11 +1404,15 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
}
ui.horizontal(|ui| {
for (i, t) in [tr("Settings"), tr("Output templates"), tr("List of exports")].iter().enumerate() {
if ui.selectable_label(app.ui.export.tab == i as u8, caption(&t.to_uppercase())).clicked() {
app.ui.export.tab = i as u8;
// Boxed tabs side by side
ui.scope(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
for (i, t) in [tr("Settings"), tr("Output templates"), tr("List of exports")].iter().enumerate() {
if tab_button(ui, &t.to_uppercase(), app.ui.export.tab == i as u8).clicked() {
app.ui.export.tab = i as u8;
}
}
}
});
// The file list opens the destination folder
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
@@ -152,3 +152,14 @@ fn a_map_the_template_no_longer_has_is_ignored() {
h.run_steps(3);
assert_eq!(selected(&h), before, "the export still plans every file");
}
#[test]
fn each_row_names_its_own_map() {
let h = harness();
// The default template names its maps with $channel: each row shows the map it writes
assert!(h.query_all_by_label_contains("$channel").next().is_none(), "the channel variable is filled in");
for id in ["baseColor", "metallic", "roughness"] {
assert!(h.query_all_by_label_contains(&format!("_{id}")).next().is_some(), "a row for {id}");
}
}