mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-25 08:50:46 +01:00
Merge pull request #790 from vangel76/feat/789-export-ui-parity
Export dock and window follow the reference layout, in our own words
This commit is contained in:
22 files changed
+2099
-421
No files matched your search
@@ -546,7 +546,8 @@ fn layout<'m>(set: &TextureSet, map: &'m MapSpec) -> Vec<(Dest, &'m SourceRef)>
|
||||
out
|
||||
}
|
||||
|
||||
fn channel_label(map: &MapSpec) -> &'static str {
|
||||
/// What `$channel` becomes in `map`'s file names: the id of its first non-constant source.
|
||||
pub fn channel_label(map: &MapSpec) -> &'static str {
|
||||
map.channels
|
||||
.iter()
|
||||
.find_map(|(_, s)| match s {
|
||||
|
||||
@@ -1,57 +1,35 @@
|
||||
//! The Export panel on the rail: where to send the project, then Export Mesh and Export Textures
|
||||
//! The Export panel on the rail: Export Mesh and Export Textures
|
||||
|
||||
use egui::{RichText, Ui};
|
||||
use egui_phosphor::regular as ic;
|
||||
use egui::Ui;
|
||||
|
||||
use crate::TextureCraftApp;
|
||||
use crate::i18n::tr;
|
||||
use crate::theme::{Tokens, caption};
|
||||
use crate::unavailable;
|
||||
use crate::widgets::primary_button;
|
||||
|
||||
/// The SEND TO rows: none has a counterpart in TextureCraft yet
|
||||
pub const SEND_TO: [&str; 3] = ["Export to image editor", "Send to compositing app", "Send to 3D staging app"];
|
||||
/// Space around each button's text, so the buttons are as wide as their text as in the reference
|
||||
const EXPORT_BUTTON_PADDING: egui::Vec2 = egui::vec2(18.0, 5.0);
|
||||
|
||||
/// Width of the Export Mesh and Export Textures buttons
|
||||
const EXPORT_BUTTON_WIDTH: f32 = 176.0;
|
||||
|
||||
/// Size of the Configure button beside a SEND TO row
|
||||
const CONFIGURE_SIZE: f32 = 20.0;
|
||||
|
||||
/// Space between the SEND TO and EXPORT parts
|
||||
const PART_GAP: f32 = 12.0;
|
||||
/// Gap between the Export Mesh and Export Textures buttons
|
||||
const EXPORT_BUTTON_GAP: f32 = 12.0;
|
||||
|
||||
/// The Export panel body (a rail popup or dock tab); its buttons need an open project
|
||||
pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
ui.label(caption(&tr("Send to").to_uppercase()));
|
||||
for (index, target) in SEND_TO.into_iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
unavailable::greyed(ui, |ui| ui.add(egui::Button::new(tr(target)).frame(false)));
|
||||
|
||||
// The reference's second row has a Configure button
|
||||
if index == 1 {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
unavailable::greyed(ui, |ui| {
|
||||
ui.add(
|
||||
egui::Button::new(RichText::new(ic::GEAR).color(tokens.text_dim)).frame(false).min_size(egui::vec2(CONFIGURE_SIZE, CONFIGURE_SIZE)),
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(PART_GAP);
|
||||
ui.label(caption(&tr("Export").to_uppercase()));
|
||||
let project_open = app.session.project_open;
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
ui.vertical_centered(|ui| {
|
||||
let size = [EXPORT_BUTTON_WIDTH, ui.spacing().interact_size.y];
|
||||
if ui.add_enabled(project_open, egui::Button::new(tr("Export Mesh...")).min_size(size.into())).clicked() {
|
||||
ui.spacing_mut().button_padding = EXPORT_BUTTON_PADDING;
|
||||
ui.spacing_mut().item_spacing.y = EXPORT_BUTTON_GAP;
|
||||
|
||||
// Fully rounded: Export Mesh outlined, Export Textures filled
|
||||
let pill = ui.spacing().interact_size.y + 2.0 * EXPORT_BUTTON_PADDING.y;
|
||||
let outlined = egui::Button::new(tr("Export Mesh...")).fill(egui::Color32::TRANSPARENT).stroke(egui::Stroke::new(1.0, tokens.button_border));
|
||||
if ui.add_enabled(project_open, outlined.corner_radius(pill / 2.0)).clicked() {
|
||||
app.ui.windows.mesh_export_options = Some(app.session.project_id);
|
||||
app.ui.rail_panel = None;
|
||||
}
|
||||
if ui.add_enabled(project_open, primary_button(ui, tr("Export Textures...")).min_size(size.into())).clicked() {
|
||||
if ui.add_enabled(project_open, primary_button(ui, tr("Export Textures...")).corner_radius(pill / 2.0)).clicked() {
|
||||
app.ui.windows.export = true;
|
||||
app.ui.rail_panel = None;
|
||||
}
|
||||
|
||||
+1053
-274
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,24 @@
|
||||
use texturecraft_engine::formats::Dest;
|
||||
|
||||
/// The channel swatch of an output map that a map was dropped on.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum ChannelTarget {
|
||||
/// The single RGB swatch: R, G and B together.
|
||||
Rgb,
|
||||
/// One destination channel: R, G, B, A or the gray channel.
|
||||
One(Dest),
|
||||
}
|
||||
|
||||
impl ChannelTarget {
|
||||
/// The destination channels the swatch writes.
|
||||
pub fn dests(self) -> &'static [Dest] {
|
||||
match self {
|
||||
ChannelTarget::Rgb => &[Dest::R, Dest::G, Dest::B],
|
||||
ChannelTarget::One(Dest::R) => &[Dest::R],
|
||||
ChannelTarget::One(Dest::G) => &[Dest::G],
|
||||
ChannelTarget::One(Dest::B) => &[Dest::B],
|
||||
ChannelTarget::One(Dest::A) => &[Dest::A],
|
||||
ChannelTarget::One(Dest::L) => &[Dest::L],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/// The drag payload of an output map row's grip: the row's index.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct MapDrag(pub usize);
|
||||
@@ -0,0 +1,102 @@
|
||||
//! The maps the Output templates tab lists for dragging onto output channels. Maps TextureCraft
|
||||
//! has carry its own names; the input maps it does not have yet carry OpenPBR parameter names
|
||||
//! (OpenPBR Surface specification, Academy Software Foundation) and are listed greyed.
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use texturecraft_engine::core::{BakedMap, Channel};
|
||||
use texturecraft_engine::formats::{SourceRef, VirtualMap};
|
||||
|
||||
use crate::i18n::n_;
|
||||
|
||||
/// One entry of a map list: its name and what it reads (None: not available yet).
|
||||
pub type MapEntry = (&'static str, Option<SourceRef>);
|
||||
|
||||
/// A group of the Input maps pane: its name and entries.
|
||||
pub type MapGroup = (&'static str, Vec<MapEntry>);
|
||||
|
||||
/// A TextureCraft channel, under its own name
|
||||
fn channel(channel: Channel) -> MapEntry {
|
||||
(channel.label(), Some(SourceRef::Channel { channel, component: 0 }))
|
||||
}
|
||||
|
||||
/// An OpenPBR input TextureCraft has no channel for yet
|
||||
fn missing(name: &'static str) -> MapEntry {
|
||||
(name, None)
|
||||
}
|
||||
|
||||
/// Input maps in the OpenPBR parameter groups, then TextureCraft's channels outside OpenPBR
|
||||
pub static INPUT_MAPS: LazyLock<Vec<MapGroup>> = LazyLock::new(|| {
|
||||
vec![
|
||||
(n_("Base"), vec![missing(n_("Base weight")), channel(Channel::BaseColor), channel(Channel::Metallic), missing(n_("Base diffuse roughness"))]),
|
||||
(
|
||||
n_("Specular"),
|
||||
vec![
|
||||
missing(n_("Specular weight")),
|
||||
missing(n_("Specular color")),
|
||||
channel(Channel::Roughness),
|
||||
channel(Channel::SpecularLevel),
|
||||
channel(Channel::AnisotropyLevel),
|
||||
channel(Channel::AnisotropyAngle),
|
||||
],
|
||||
),
|
||||
(n_("Transmission"), vec![channel(Channel::Transmission), missing(n_("Transmission color"))]),
|
||||
(n_("Subsurface"), vec![channel(Channel::ScatterWeight), missing(n_("Subsurface color")), missing(n_("Subsurface radius"))]),
|
||||
(
|
||||
n_("Coat"),
|
||||
vec![
|
||||
channel(Channel::CoatWeight),
|
||||
missing(n_("Coat color")),
|
||||
channel(Channel::CoatRoughness),
|
||||
missing(n_("Coat roughness anisotropy")),
|
||||
missing(n_("Coat IOR")),
|
||||
channel(Channel::CoatNormal),
|
||||
missing(n_("Coat tangent")),
|
||||
],
|
||||
),
|
||||
(n_("Sheen"), vec![channel(Channel::SheenWeight), channel(Channel::SheenColor), channel(Channel::SheenRoughness)]),
|
||||
(n_("Emission"), vec![channel(Channel::Emissive)]),
|
||||
(n_("Thin film"), vec![missing(n_("Thin film weight")), missing(n_("Thin film thickness"))]),
|
||||
(
|
||||
n_("Geometry"),
|
||||
vec![channel(Channel::Opacity), channel(Channel::Height), channel(Channel::Normal), missing(n_("Tangent")), channel(Channel::AmbientOcclusion)],
|
||||
),
|
||||
(n_("Other"), vec![channel(Channel::Glossiness), channel(Channel::Specular)]),
|
||||
]
|
||||
});
|
||||
|
||||
/// Mesh maps, under the names the bake panel gives them.
|
||||
pub static MESH_MAPS: LazyLock<Vec<MapEntry>> =
|
||||
LazyLock::new(|| BakedMap::ALL.iter().map(|&map| (crate::i18n::baked_map_label(map), Some(SourceRef::Baked { map, component: 0 }))).collect());
|
||||
|
||||
/// Converted maps: the maps TextureCraft computes from others when it exports.
|
||||
pub static CONVERTED_MAPS: LazyLock<Vec<MapEntry>> =
|
||||
LazyLock::new(|| VirtualMap::ALL.iter().map(|&map| (map.label(), Some(SourceRef::Virtual { map, component: 0 }))).collect());
|
||||
|
||||
/// The listed name of `source` (any component), or None for a constant.
|
||||
pub fn name_of(source: &SourceRef) -> Option<&'static str> {
|
||||
let lists = INPUT_MAPS.iter().flat_map(|(_, entries)| entries.iter()).chain(MESH_MAPS.iter()).chain(CONVERTED_MAPS.iter());
|
||||
let mut entries = lists.filter_map(|(name, entry)| entry.as_ref().map(|entry| (*name, entry)));
|
||||
entries.find(|(_, entry)| super::same_source(entry, source)).map(|(name, _)| name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn every_channel_and_map_can_be_dragged() {
|
||||
let entries = INPUT_MAPS.iter().flat_map(|(_, entries)| entries.iter()).chain(MESH_MAPS.iter()).chain(CONVERTED_MAPS.iter());
|
||||
let listed: Vec<SourceRef> = entries.filter_map(|(_, source)| source.clone()).collect();
|
||||
|
||||
for channel in Channel::ALL {
|
||||
assert!(listed.contains(&SourceRef::Channel { channel, component: 0 }), "{channel:?}");
|
||||
}
|
||||
for map in BakedMap::ALL {
|
||||
assert!(listed.contains(&SourceRef::Baked { map, component: 0 }), "{map:?}");
|
||||
}
|
||||
for map in VirtualMap::ALL {
|
||||
assert!(listed.contains(&SourceRef::Virtual { map, component: 0 }), "{map:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use texturecraft_engine::formats::SourceRef;
|
||||
|
||||
use super::ChannelTarget;
|
||||
|
||||
/// A map dropped on an output channel, waiting for the user to pick which of its channels to use.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PendingDrop {
|
||||
/// The output map, by index into the template's maps.
|
||||
pub map: usize,
|
||||
pub target: ChannelTarget,
|
||||
pub source: SourceRef,
|
||||
/// Where the popup opens.
|
||||
pub position: egui::Pos2,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
use super::{MapAction, PendingDrop};
|
||||
|
||||
/// What the output map rows asked for in this frame.
|
||||
#[derive(Default)]
|
||||
pub(super) struct RowEdit {
|
||||
pub(super) action: Option<MapAction>,
|
||||
/// A map dropped on a channel swatch, to ask which of its channels to use.
|
||||
pub(super) pending: Option<PendingDrop>,
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/// What a choice of the drop popup ("Which part of <map>?") reads from the dropped map.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(super) enum SourcePick {
|
||||
/// "Red, green and blue": the map's R, G and B into the swatch's R, G and B.
|
||||
AllRgb,
|
||||
/// One component of the map in every channel of the swatch.
|
||||
Component(u8),
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
use egui::Color32;
|
||||
|
||||
/// How a channel swatch is drawn.
|
||||
pub(super) struct SwatchLook {
|
||||
/// The source map's colour (None: empty or a constant).
|
||||
pub(super) fill: Option<Color32>,
|
||||
/// One bar per channel of the source the swatch reads.
|
||||
pub(super) bars: Vec<Color32>,
|
||||
pub(super) inverted: bool,
|
||||
}
|
||||
@@ -12,25 +12,44 @@ use crate::TextureCraftApp;
|
||||
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, primary_button};
|
||||
use crate::widgets::icon_button;
|
||||
|
||||
mod inherited_settings;
|
||||
mod map_row;
|
||||
use inherited_settings::InheritedSettings;
|
||||
use map_row::MapRow;
|
||||
|
||||
/// Initial height of the window's tab body, above its buttons
|
||||
const BODY_HEIGHT: f32 = 440.0;
|
||||
const DEFAULT_WINDOW_WIDTH_POINTS: f32 = 900.0;
|
||||
// Initial space for the tabs, separators and footer
|
||||
const WINDOW_CHROME_HEIGHT_POINTS: f32 = 80.0;
|
||||
/// The reference window's size; a smaller screen gets a smaller window
|
||||
const REFERENCE_WINDOW_SIZE_POINTS: egui::Vec2 = egui::vec2(1100.0, 740.0);
|
||||
/// Space kept free around the content on a small screen: the title bar, the frame and a gap
|
||||
const WINDOW_VIEWPORT_MARGIN_POINTS: f32 = 72.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 = 126.0;
|
||||
/// Width of the keyboard focus outline on the window's drawn controls
|
||||
const FOCUS_OUTLINE_WIDTH: f32 = 2.0;
|
||||
|
||||
/// The output sizes the Size list offers, in texels per side
|
||||
pub(crate) const SIZES: [u32; 7] = [128, 256, 512, 1024, 2048, 4096, 8192];
|
||||
@@ -71,12 +90,12 @@ pub(crate) const FILE_TYPES: [(&str, Option<FileFormat>); 14] = [
|
||||
|
||||
/// The bit depths `format` is written with, as the bit depth list offers them: (bits,
|
||||
/// dithering)
|
||||
fn depth_options(format: FileFormat) -> Vec<(u8, bool)> {
|
||||
pub(crate) fn depth_options(format: FileFormat) -> Vec<(u8, bool)> {
|
||||
format.bit_depths().iter().flat_map(|&d| if d == 8 && !format.holds_float(8) { vec![(8, false), (8, true)] } else { vec![(d, false)] }).collect()
|
||||
}
|
||||
|
||||
/// A bit depth as listed: "8 bits", "8 bits + dithering", "16 bits", "16f bits", "32f bits"
|
||||
fn depth_label(format: Option<FileFormat>, bit_depth: u8, dithering: bool) -> String {
|
||||
pub(crate) fn depth_label(format: Option<FileFormat>, bit_depth: u8, dithering: bool) -> String {
|
||||
match (bit_depth, dithering) {
|
||||
(8, true) => tr("8 bits + dithering").to_string(),
|
||||
(16, _) if format == Some(FileFormat::Exr) => tr("16f bits").to_string(),
|
||||
@@ -99,7 +118,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() {
|
||||
@@ -125,7 +144,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);
|
||||
@@ -290,7 +311,7 @@ fn start_export(app: &mut TextureCraftApp) {
|
||||
crate::web_files::export_textures(app, &jobs);
|
||||
}
|
||||
|
||||
/// Write the next texture set of the running export, logging the steps as the reference does;
|
||||
/// Write the next texture set of the running export, logging each step;
|
||||
/// the last one finishes the export. A failed command (its error already shown) stops it.
|
||||
fn export_step(app: &mut TextureCraftApp, frame: u64) {
|
||||
let Some(job) = app.ui.export.job.as_mut() else { return };
|
||||
@@ -520,7 +541,11 @@ 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", texturecraft_engine::formats::export::channel_label(m)))
|
||||
.unwrap_or_default();
|
||||
rows.push(MapRow { map, pattern, inherited: FileType { format: file_type_name(&format), bit_depth, dithering } });
|
||||
}
|
||||
rows
|
||||
@@ -596,6 +621,43 @@ fn selected_texture_count(app: &mut TextureCraftApp) -> usize {
|
||||
count
|
||||
}
|
||||
|
||||
/// The keyboard focus outline of a drawn control: inside `response`'s rect, in the strong text
|
||||
/// colour, so it differs from the accent of the selected one and the fill of the hovered one
|
||||
fn paint_focus(ui: &Ui, response: &egui::Response) {
|
||||
if response.has_focus() {
|
||||
let stroke = egui::Stroke::new(FOCUS_OUTLINE_WIDTH, Tokens::get(ui.ctx()).text_strong);
|
||||
ui.painter().rect_stroke(response.rect, 0.0, stroke, egui::StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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);
|
||||
paint_focus(ui, &response);
|
||||
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))
|
||||
}
|
||||
|
||||
/// A header with a menu or tool at its right end
|
||||
fn header(ui: &mut Ui, title: &str, right: impl FnOnce(&mut Ui)) {
|
||||
ui.horizontal(|ui| {
|
||||
@@ -654,11 +716,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 {
|
||||
@@ -666,7 +735,7 @@ fn dilation_button(ui: &mut Ui, padding: &str, dilation: &mut u32) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A greyed reference checkbox with its tooltip and the "not available" hint
|
||||
/// A greyed checkbox with its tooltip and the "not available" hint
|
||||
fn unavailable_checkbox(ui: &mut Ui, label: &str, tooltip: &str) {
|
||||
let mut off = false;
|
||||
ui.add_enabled(false, egui::Checkbox::new(&mut off, label)).on_disabled_hover_ui(|ui| {
|
||||
@@ -712,7 +781,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);
|
||||
@@ -741,7 +810,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));
|
||||
}
|
||||
@@ -753,11 +823,16 @@ fn global_page(app: &mut TextureCraftApp, ui: &mut Ui, builtins: &[ExportPreset]
|
||||
|
||||
// The browser downloads the textures only, so it has no USD asset to add
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
ui.checkbox(&mut app.ui.export.usd_asset, tr("Export USD asset")).on_hover_text(tr("Package the mesh, materials and textures together as USD"));
|
||||
ui.checkbox(&mut app.ui.export.usd_asset, tr("Export USD asset"))
|
||||
.on_hover_text(tr("Also write <mesh>.usd next to the textures: the whole mesh, with a material per texture set that reads the exported textures"));
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
unavailable_checkbox(ui, tr("Export USD asset"), tr("Package the mesh, materials and textures together as USD"));
|
||||
unavailable_checkbox(
|
||||
ui,
|
||||
tr("Export USD asset"),
|
||||
tr("Also write <mesh>.usd next to the textures: the whole mesh, with a material per texture set that reads the exported textures"),
|
||||
);
|
||||
|
||||
// The browser downloads the textures only
|
||||
// The MaterialX export sits below the USD one; the browser downloads the textures only
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
ui.checkbox(&mut app.ui.export.materialx, tr("Export MaterialX"));
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -766,7 +841,7 @@ fn global_page(app: &mut TextureCraftApp, ui: &mut Ui, builtins: &[ExportPreset]
|
||||
// Unavailable export controls stay disabled
|
||||
unavailable_checkbox(ui, tr("Export shader settings"), tr("Save the settings of each shader instance in a JSON file"));
|
||||
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() {
|
||||
@@ -798,7 +873,7 @@ fn set_list(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
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;
|
||||
}
|
||||
@@ -808,6 +883,24 @@ fn set_list(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
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);
|
||||
paint_focus(ui, &response);
|
||||
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() {
|
||||
@@ -830,6 +923,7 @@ fn set_rows(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,7 +1003,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 {
|
||||
@@ -980,8 +1074,19 @@ fn set_page(app: &mut TextureCraftApp, ui: &mut Ui, ts: usize, builtins: &[Expor
|
||||
}
|
||||
}
|
||||
|
||||
/// Width of the LIST OF EXPORTS console
|
||||
/// The LIST OF EXPORTS console's and file tree's least width, as in the reference
|
||||
const CONSOLE_WIDTH: f32 = 300.0;
|
||||
const MIN_TREE_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 {
|
||||
@@ -993,25 +1098,44 @@ fn success(tk: &Tokens) -> egui::Color32 {
|
||||
fn list_tab(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
let tk = Tokens::get(ui.ctx());
|
||||
let hidden = app.ui.export.console_hidden;
|
||||
let tree_width = ui.available_width() - if hidden { 24.0 } else { CONSOLE_WIDTH + 24.0 };
|
||||
|
||||
// Tree and console keep at least their reference width
|
||||
let spacing = ui.spacing().item_spacing.x;
|
||||
let room = ui.available_width() - SPLITTER_WIDTH - 2.0 * spacing;
|
||||
let console_width = app.ui.export.console_width.min(room - MIN_TREE_WIDTH).max(CONSOLE_WIDTH);
|
||||
let tree_width = if hidden { room } else { room - console_width };
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(tree_width);
|
||||
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
|
||||
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 r = if hidden { r } else { r.on_hover_text(tr("Hide Console")) };
|
||||
if r.clicked() {
|
||||
// The strip at the console's left edge: a click hides or shows the console, a drag resizes it
|
||||
let (strip, response) = ui.allocate_exact_size(vec2(SPLITTER_WIDTH, ui.available_height()), egui::Sense::click_and_drag());
|
||||
let tooltip = if hidden { tr("Show Console") } else { tr("Hide Console") };
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tooltip));
|
||||
let glyph = if hidden { ic::CARET_DOUBLE_LEFT } else { ic::CARET_DOUBLE_RIGHT };
|
||||
let glyph_color = if response.hovered() { tk.text_strong } else { tk.text };
|
||||
ui.painter().rect_filled(strip, 0.0, tk.chrome);
|
||||
ui.painter().text(strip.center(), egui::Align2::CENTER_CENTER, glyph, egui::TextStyle::Body.resolve(ui.style()), glyph_color);
|
||||
paint_focus(ui, &response);
|
||||
let response = response.on_hover_text(tooltip);
|
||||
if !hidden && (response.hovered() || response.dragged()) {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
|
||||
}
|
||||
if response.dragged() && !hidden {
|
||||
app.ui.export.console_width = (console_width - response.drag_delta().x).min(room - MIN_TREE_WIDTH).max(CONSOLE_WIDTH);
|
||||
} else if response.clicked() {
|
||||
app.ui.export.console_hidden = !hidden;
|
||||
}
|
||||
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| {
|
||||
ui.set_width(console_width);
|
||||
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) => {
|
||||
@@ -1038,7 +1162,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
|
||||
}
|
||||
@@ -1071,9 +1195,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());
|
||||
@@ -1096,6 +1222,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) {
|
||||
@@ -1257,6 +1398,7 @@ fn cancel(app: &mut TextureCraftApp) {
|
||||
before.draft = None;
|
||||
before.renaming = None;
|
||||
before.ask = None;
|
||||
before.pending_drop = None;
|
||||
|
||||
// A template deleted since keeps the default instead
|
||||
if app.session.export_preset(&before.preset).is_none() {
|
||||
@@ -1278,6 +1420,7 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let e = &mut app.ui.export;
|
||||
e.job = None;
|
||||
e.ask = None;
|
||||
e.pending_drop = None;
|
||||
e.opened_with = None;
|
||||
e.tab = 0;
|
||||
e.page = None;
|
||||
@@ -1292,6 +1435,11 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
keep_file_type_visible(&mut app.ui.export);
|
||||
follow_texture_sets(app);
|
||||
|
||||
// A map waiting for its source channel belongs to the OUTPUT TEMPLATES tab
|
||||
if app.ui.export.tab != 1 {
|
||||
app.ui.export.pending_drop = None;
|
||||
}
|
||||
if app.ui.export.opened_with.is_none() {
|
||||
let mut now = app.ui.export.clone();
|
||||
now.draft = None;
|
||||
@@ -1302,8 +1450,14 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut do_export = false;
|
||||
let mut canceled = false;
|
||||
let presets = texturecraft_engine::formats::builtin_presets();
|
||||
let dialog = crate::windows::dialog(ctx, "export_textures", tr("Export Textures"), &mut open)
|
||||
.default_size(vec2(DEFAULT_WINDOW_WIDTH_POINTS, BODY_HEIGHT + WINDOW_CHROME_HEIGHT_POINTS));
|
||||
// The reference size on a screen that has room for it, smaller on a smaller one; resizable from there.
|
||||
// The window's size counts its frame and title bar, the reference size only the content
|
||||
let style = ctx.global_style();
|
||||
let title_height = ctx.fonts_mut(|fonts| fonts.row_height(&egui::TextStyle::Heading.resolve(&style))) + style.spacing.item_spacing.y;
|
||||
let chrome = egui::Frame::window(&style).total_margin().sum() + vec2(0.0, title_height);
|
||||
let window_size =
|
||||
(REFERENCE_WINDOW_SIZE_POINTS + chrome).min(ctx.content_rect().size() - vec2(WINDOW_VIEWPORT_MARGIN_POINTS, WINDOW_VIEWPORT_MARGIN_POINTS));
|
||||
let dialog = crate::windows::dialog(ctx, "export_textures", tr("Export Textures"), &mut open).default_size(window_size);
|
||||
dialog.show(ctx, |ui| {
|
||||
// Nothing to export without a project
|
||||
if !app.session.project_open {
|
||||
@@ -1326,10 +1480,13 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
let selected = selected_texture_count(app);
|
||||
// OUTPUT TEMPLATES edits the templates only: no count, nothing to reset, save or export there
|
||||
let templates_tab = app.ui.export.tab == 1;
|
||||
let selected = if templates_tab { 0 } else { selected_texture_count(app) };
|
||||
ui.horizontal(|ui| {
|
||||
// Not on LIST OF EXPORTS
|
||||
if app.ui.export.tab != 2 && ui.button(tr("Reset all")).on_hover_text(tr("Restore the export defaults and select every texture")).clicked()
|
||||
// Only on SETTINGS
|
||||
if app.ui.export.tab == 0
|
||||
&& ui.add(footer_button(tr("Reset all"))).on_hover_text(tr("Restore the export defaults and select every texture")).clicked()
|
||||
{
|
||||
// Keep ownership so Cancel can restore the opening settings
|
||||
let e = &mut app.ui.export;
|
||||
@@ -1338,23 +1495,26 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
// Nothing to write without a ticked texture set
|
||||
let any = !export_selection(app).is_empty();
|
||||
let any = !export_selection(app).is_empty() && !templates_tab;
|
||||
if ui
|
||||
.add_enabled(any, primary_button(ui, tr("Export")))
|
||||
.on_hover_text(tr("Write the selected textures using the settings above"))
|
||||
.add_enabled(any, footer_button(tr("Export")))
|
||||
.on_hover_text(tr("Write the selected textures, and the extra files ticked in the settings"))
|
||||
.clicked()
|
||||
{
|
||||
do_export = true;
|
||||
}
|
||||
|
||||
// Saving closes the window without starting an export
|
||||
if ui.button(tr("Save settings")).on_hover_text(tr("Keep these settings for the next export")).clicked() {
|
||||
let save = ui.add_enabled(!templates_tab, footer_button(tr("Save settings")));
|
||||
if save.on_hover_text(tr("Keep these settings for the next export and close the window")).clicked() {
|
||||
app.ui.windows.export = false;
|
||||
}
|
||||
if ui.button(tr("Cancel")).on_hover_text(tr("Restore the settings from when you opened this window")).clicked() {
|
||||
if ui.add(footer_button(tr("Cancel"))).on_hover_text(tr("Close the window and go back to the settings it opened with")).clicked() {
|
||||
canceled = true;
|
||||
}
|
||||
ui.label(trf("{n} textures selected for export", &[("n", &selected)]));
|
||||
if !templates_tab {
|
||||
ui.label(trf("{n} textures selected for export", &[("n", &selected)]));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1362,11 +1522,15 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
ui.add_space(8.0);
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
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| {
|
||||
@@ -1378,7 +1542,9 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
if ui.button(tr("Open output directory")).clicked() {
|
||||
open_output_directory(app);
|
||||
}
|
||||
} else if ui.button(tr("Include all")).on_hover_text(tr("Select every texture set, UV tile and output map")).clicked() {
|
||||
} else if app.ui.export.tab == 1 {
|
||||
crate::export_templates::naming_pattern(ui);
|
||||
} else if ui.add(footer_button(tr("Include all"))).on_hover_text(tr("Select every texture set, UV tile and output map")).clicked() {
|
||||
app.ui.export.skip.clear();
|
||||
for o in app.ui.export.sets.values_mut() {
|
||||
o.maps.values_mut().for_each(|m| m.enabled = true);
|
||||
@@ -1415,6 +1581,8 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
set_list(app, ui);
|
||||
});
|
||||
ui.separator();
|
||||
|
||||
// A short or narrow window scrolls the settings, so the footer and every control stay reachable
|
||||
ui.vertical(|ui| {
|
||||
egui::ScrollArea::both().id_salt("export_settings_page").auto_shrink([false, false]).min_scrolled_height(0.0).show(ui, |ui| match app
|
||||
.ui
|
||||
|
||||
@@ -4,14 +4,23 @@ use egui::Ui;
|
||||
|
||||
use crate::TextureCraftApp;
|
||||
use crate::i18n::tr;
|
||||
use crate::theme::Tokens;
|
||||
use crate::unavailable;
|
||||
use crate::widgets::primary_button;
|
||||
|
||||
/// Indent of an option's checkbox under its choice
|
||||
const OPTION_INDENT: f32 = 20.0;
|
||||
|
||||
/// Width of the Cancel and Export buttons
|
||||
const BUTTON_WIDTH: f32 = 130.0;
|
||||
const BUTTON_WIDTH: f32 = 110.0;
|
||||
|
||||
/// The reference dialog's content width
|
||||
const DIALOG_WIDTH: f32 = 500.0;
|
||||
|
||||
/// Width of an info icon's tooltip, as in the reference
|
||||
const INFO_TOOLTIP_WIDTH: f32 = 250.0;
|
||||
|
||||
/// Gap between the two option groups, as in the reference
|
||||
const GROUP_GAP: f32 = 25.0;
|
||||
|
||||
/// The prompt, while File > Export Mesh waits on it
|
||||
pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
@@ -23,18 +32,37 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut open = true;
|
||||
let (mut export, mut cancel) = (false, false);
|
||||
crate::windows::dialog(ctx, "mesh_export_options", tr("Mesh Export Options"), &mut open).show(ctx, |ui| {
|
||||
ui.set_width(DIALOG_WIDTH);
|
||||
|
||||
// TextureCraft exports the mesh as it is: triangulated, without displacement
|
||||
ui.add(egui::RadioButton::new(true, tr("Without displacement/tessellation")));
|
||||
option(ui, true, tr("Apply triangulation"));
|
||||
option(
|
||||
ui,
|
||||
true,
|
||||
tr("Apply triangulation"),
|
||||
&[
|
||||
tr("Splits every face with more than three corners into triangles; triangles stay as they are."),
|
||||
tr("TextureCraft keeps meshes as triangles, so the exported mesh is always triangulated."),
|
||||
],
|
||||
);
|
||||
ui.add_space(GROUP_GAP);
|
||||
unavailable::greyed(ui, |ui| ui.add(egui::RadioButton::new(false, tr("With displacement/tessellation"))));
|
||||
option(ui, true, tr("Recompute vertex normals"));
|
||||
option(
|
||||
ui,
|
||||
true,
|
||||
tr("Recompute vertex normals"),
|
||||
&[
|
||||
tr("Replaces the mesh's vertex normals with newly computed ones in the exported file."),
|
||||
tr("TextureCraft cannot do this yet: it writes the vertex normals the mesh has in the project."),
|
||||
],
|
||||
);
|
||||
ui.add_space(8.0);
|
||||
|
||||
// One row keeps the window to its contents; a bare right-to-left layout fills the screen height
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let size = egui::vec2(BUTTON_WIDTH, ui.spacing().interact_size.y);
|
||||
export = ui.add(primary_button(ui, tr("Export")).min_size(size)).clicked();
|
||||
export = ui.add(egui::Button::new(tr("Export")).min_size(size)).clicked();
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(size)).clicked();
|
||||
});
|
||||
});
|
||||
@@ -48,10 +76,23 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A greyed option under a choice, ticked as the reference shows it
|
||||
fn option(ui: &mut Ui, checked: bool, label: &str) {
|
||||
/// A greyed option under a choice, ticked as the reference shows it, with an info icon at the
|
||||
/// row's right end whose tooltip has the paragraphs `info`
|
||||
fn option(ui: &mut Ui, checked: bool, label: &str, info: &[&str]) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(OPTION_INDENT);
|
||||
unavailable::checkbox(ui, checked, label);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let icon = ui.label(egui::RichText::new(egui_phosphor::regular::INFO).color(Tokens::get(ui.ctx()).text_dim));
|
||||
icon.on_hover_ui(|ui| {
|
||||
ui.set_max_width(INFO_TOOLTIP_WIDTH);
|
||||
for (k, paragraph) in info.iter().enumerate() {
|
||||
if k > 0 {
|
||||
ui.add_space(ui.text_style_height(&egui::TextStyle::Body));
|
||||
}
|
||||
ui.label(*paragraph);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -394,6 +394,17 @@ pub struct ExportUi {
|
||||
/// Output templates tab: the saved template `draft_maps` counts from.
|
||||
#[serde(skip)]
|
||||
pub draft_base: Option<texturecraft_engine::formats::ExportPreset>,
|
||||
/// Output templates tab: for each map of `draft`, whether its R, G and B show as separate
|
||||
/// channel swatches (R+G+B) instead of one RGB swatch.
|
||||
#[serde(skip)]
|
||||
pub draft_split: Vec<bool>,
|
||||
/// LIST OF EXPORTS: the console's width, set by dragging the strip at its left edge.
|
||||
#[serde(skip, default = "default_console_width")]
|
||||
pub console_width: f32,
|
||||
/// Output templates tab: a map dropped on an output channel, waiting for the source channel
|
||||
/// ("Which part of <map>?").
|
||||
#[serde(skip)]
|
||||
pub pending_drop: Option<crate::export_templates::PendingDrop>,
|
||||
/// Output templates tab: the new name while renaming the selected preset.
|
||||
#[serde(skip)]
|
||||
pub renaming: Option<String>,
|
||||
@@ -440,6 +451,9 @@ impl Default for ExportUi {
|
||||
draft: None,
|
||||
draft_maps: Vec::new(),
|
||||
draft_base: None,
|
||||
draft_split: Vec::new(),
|
||||
console_width: default_console_width(),
|
||||
pending_drop: None,
|
||||
renaming: None,
|
||||
rename_key: false,
|
||||
ask: None,
|
||||
@@ -451,6 +465,11 @@ impl Default for ExportUi {
|
||||
}
|
||||
}
|
||||
|
||||
/// The LIST OF EXPORTS console's width when the window opens, as in the reference
|
||||
fn default_console_width() -> f32 {
|
||||
300.0
|
||||
}
|
||||
|
||||
fn default_export_dir() -> String {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,16 @@ fn mtlx_files(dir: &std::path::Path) -> Vec<std::path::PathBuf> {
|
||||
files
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_materialx_sits_directly_below_the_usd_option() {
|
||||
let (app_harness, _dir) = harness("order");
|
||||
let usd = app_harness.get_by_label("Export USD asset").rect().min.y;
|
||||
let materialx = checkbox(&app_harness).rect().min.y;
|
||||
let shaders = app_harness.get_by_label("Export shader settings").rect().min.y;
|
||||
|
||||
assert!(usd < materialx && materialx < shaders, "USD {usd}, MaterialX {materialx}, shaders {shaders}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_window_offers_export_materialx_off_by_default() {
|
||||
let (app_harness, _dir) = harness("offer");
|
||||
|
||||
@@ -139,14 +139,13 @@ fn the_list_is_a_tree_per_texture_set_with_the_console_beside_it() {
|
||||
h.run_steps(30);
|
||||
assert!(h.query_by_label(&dir.join(&file).display().to_string()).is_some());
|
||||
|
||||
// The console's toggle hides it
|
||||
let toggle = h.get_by_label(egui_phosphor::regular::CARET_DOUBLE_RIGHT).rect().center();
|
||||
h.hover_at(toggle);
|
||||
h.run_steps(30);
|
||||
assert!(h.query_by_label("Hide Console").is_some());
|
||||
click(&mut h, egui_phosphor::regular::CARET_DOUBLE_RIGHT);
|
||||
h.run_steps(2);
|
||||
// The strip at the console's edge hides it, then shows it again
|
||||
h.get_by_role_and_label(egui::Role::Button, "Hide Console").click();
|
||||
h.run_steps(4);
|
||||
assert!(h.state().ui.export.console_hidden && h.query_by_label("CONSOLE").is_none());
|
||||
h.get_by_role_and_label(egui::Role::Button, "Show Console").click();
|
||||
h.run_steps(4);
|
||||
assert!(!h.state().ui.export.console_hidden);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
//! Export textures window (texturecraft #789): the reference's size, and the tooltips of the bottom
|
||||
//! bar's buttons and of the settings' checkboxes.
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT as _, Queryable as _};
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
|
||||
/// The reference window's content size in points
|
||||
const REFERENCE_WINDOW_WIDTH_POINTS: f32 = 1100.0;
|
||||
const REFERENCE_WINDOW_HEIGHT_POINTS: f32 = 740.0;
|
||||
|
||||
/// How far the measured content may differ from the reference size (item spacing, borders)
|
||||
const SIZE_TOLERANCE_POINTS: f32 = 40.0;
|
||||
|
||||
/// The right bar is the last 38 points of the window
|
||||
const RAIL_WIDTH_POINTS: f32 = 38.0;
|
||||
|
||||
/// The Export textures window open on SETTINGS in a screen of `screen_size`
|
||||
fn harness(screen_size: egui::Vec2) -> Harness<'static, TextureCraftApp> {
|
||||
let session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let mut h = Harness::builder().with_size(screen_size).build_eframe(|cc| TextureCraftApp::new(cc, session));
|
||||
h.state_mut().ui.prefs.language = "en".into();
|
||||
h.run_steps(4);
|
||||
h.state_mut().ui.windows.export = true;
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// The rectangle of the window's button named `label`; the rail has an Export icon of its own
|
||||
fn window_button_rect(h: &Harness<'_, TextureCraftApp>, label: &str, screen_width: f32) -> egui::Rect {
|
||||
h.get_all_by_role(egui::Role::Button)
|
||||
.filter(|button| button.rect().max.x < screen_width - RAIL_WIDTH_POINTS && button.accesskit_node().label().as_deref() == Some(label))
|
||||
.map(|button| button.rect())
|
||||
.next_back()
|
||||
.unwrap_or_else(|| panic!("no {label} button in the window"))
|
||||
}
|
||||
|
||||
/// Hover the window's button `label` and check that its tooltip says `tooltip`
|
||||
fn tooltip_is(h: &mut Harness<'_, TextureCraftApp>, label: &str, tooltip: &str) {
|
||||
let screen_width = h.ctx.content_rect().width();
|
||||
h.hover_at(window_button_rect(h, label, screen_width).center());
|
||||
h.run_steps(30);
|
||||
|
||||
assert!(h.query_all_by_label(tooltip).next().is_some(), "{label}: {tooltip}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_window_has_the_reference_size() {
|
||||
let h = harness(egui::vec2(1600.0, 960.0));
|
||||
let reset = window_button_rect(&h, "Reset all", 1600.0);
|
||||
let export = window_button_rect(&h, "Export", 1600.0);
|
||||
let tabs = h.get_by_label("SETTINGS").rect();
|
||||
|
||||
let width = export.max.x - reset.min.x;
|
||||
let height = export.max.y - tabs.min.y;
|
||||
|
||||
assert!((width - REFERENCE_WINDOW_WIDTH_POINTS).abs() < SIZE_TOLERANCE_POINTS, "width {width}");
|
||||
assert!((height - REFERENCE_WINDOW_HEIGHT_POINTS).abs() < SIZE_TOLERANCE_POINTS, "height {height}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_a_small_screen_the_window_fits_with_its_buttons_in_view() {
|
||||
let screen = egui::vec2(1000.0, 700.0);
|
||||
let h = harness(screen);
|
||||
|
||||
for label in ["Reset all", "Cancel", "Save settings", "Export"] {
|
||||
let rect = window_button_rect(&h, label, screen.x);
|
||||
assert!(rect.min.x >= 0.0 && rect.max.x <= screen.x, "{label} {rect:?}");
|
||||
assert!(rect.min.y >= 0.0 && rect.max.y <= screen.y, "{label} {rect:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_buttons_carry_tooltips_saying_what_they_do() {
|
||||
let mut h = harness(egui::vec2(1600.0, 960.0));
|
||||
tooltip_is(&mut h, "Include all", "Select every texture set, UV tile and output map");
|
||||
tooltip_is(&mut h, "Reset all", "Restore the export defaults and select every texture");
|
||||
tooltip_is(&mut h, "Cancel", "Close the window and go back to the settings it opened with");
|
||||
tooltip_is(&mut h, "Save settings", "Keep these settings for the next export and close the window");
|
||||
tooltip_is(&mut h, "Export", "Write the selected textures, and the extra files ticked in the settings");
|
||||
}
|
||||
|
||||
/// Hover the checkbox `label` and check that its tooltip says `tooltip`
|
||||
fn checkbox_tooltip_is(h: &mut Harness<'_, TextureCraftApp>, label: &str, tooltip: &str) {
|
||||
let center = h.get_by_role_and_label(egui::Role::CheckBox, label).rect().center();
|
||||
h.hover_at(center);
|
||||
h.run_steps(30);
|
||||
|
||||
assert!(h.query_all_by_label(tooltip).next().is_some(), "{label}: {tooltip}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_extra_file_checkboxes_carry_tooltips_saying_what_they_write() {
|
||||
let mut h = harness(egui::vec2(1600.0, 960.0));
|
||||
checkbox_tooltip_is(
|
||||
&mut h,
|
||||
"Export USD asset",
|
||||
"Also write <mesh>.usd next to the textures: the whole mesh, with a material per texture set that reads the exported textures",
|
||||
);
|
||||
checkbox_tooltip_is(&mut h, "Export shader settings", "Save the settings of each shader instance in a JSON file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bottom_bar_buttons_share_one_width() {
|
||||
let h = harness(egui::vec2(1600.0, 960.0));
|
||||
|
||||
let widths: Vec<f32> = ["Reset all", "Cancel", "Save settings", "Export"].iter().map(|label| window_button_rect(&h, label, 1600.0).width()).collect();
|
||||
|
||||
assert!(widths.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 1.0), "{widths:?}");
|
||||
}
|
||||
|
||||
/// The Size list of the Global settings page
|
||||
fn size_list<'a>(h: &'a Harness<'_, TextureCraftApp>) -> egui_kittest::Node<'a> {
|
||||
h.get_all_by_role(egui::Role::ComboBox)
|
||||
.find(|list| list.accesskit_node().value().as_deref() == Some("Based on each Texture Set's size"))
|
||||
.expect("the Size list")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_a_short_narrow_screen_the_settings_scroll_and_the_footer_stays_in_view() {
|
||||
let screen = egui::vec2(800.0, 480.0);
|
||||
let mut h = harness(screen);
|
||||
for label in ["Cancel", "Export"] {
|
||||
let rect = window_button_rect(&h, label, screen.x);
|
||||
assert!(rect.max.x <= screen.x && rect.max.y <= screen.y, "{label} {rect:?}");
|
||||
}
|
||||
let export = window_button_rect(&h, "Export", screen.x);
|
||||
|
||||
// The last setting and the right end of the value lists scroll into the window, above the footer
|
||||
h.get_by_label("Color space").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
let color_space = h.get_by_label("Color space").rect();
|
||||
assert!(color_space.max.y < export.min.y, "Color space {color_space:?}, footer {export:?}");
|
||||
|
||||
size_list(&h).scroll_to_me();
|
||||
h.run_steps(4);
|
||||
let size = size_list(&h).rect();
|
||||
assert!(size.max.x <= export.max.x, "Size {size:?}, window right end {}", export.max.x);
|
||||
}
|
||||
@@ -26,6 +26,7 @@ mod export_map_overrides;
|
||||
mod export_materialx;
|
||||
mod export_overrides;
|
||||
mod export_progress;
|
||||
mod export_reference_texts;
|
||||
mod export_settings;
|
||||
mod export_template_guards;
|
||||
mod export_usd_asset;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
//! Export textures › OUTPUT TEMPLATES (texturecraft #674): the reference's layout, names and the
|
||||
//! preset list's right-click menu and F2.
|
||||
|
||||
use egui::{Event, Modifiers, PointerButton};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT as _, Queryable as _};
|
||||
use serde_json::json;
|
||||
use texturecraft_engine::core::Channel;
|
||||
use texturecraft_engine::formats::{Dest, SourceRef};
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
use texturecraft_ui_egui::file_dialogs::Answer;
|
||||
use texturecraft_ui_egui::state::{MapExport, SetExport};
|
||||
|
||||
#[path = "output_template/template_library.rs"]
|
||||
@@ -30,11 +34,54 @@ fn harness(library: &TemplateLibrary) -> Harness<'static, TextureCraftApp> {
|
||||
h
|
||||
}
|
||||
|
||||
/// Left edge of the right rail in the 1600 point wide harness
|
||||
const RAIL_LEFT_EDGE: f32 = 1560.0;
|
||||
|
||||
fn click(h: &mut Harness<'_, TextureCraftApp>, label: &str) {
|
||||
h.get_all_by_label(label).last().unwrap_or_else(|| panic!("no {label}")).click();
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// Right-click the grip of output map `index` and pick `item` ("Move up" or "Move down")
|
||||
fn move_map(h: &mut Harness<'_, TextureCraftApp>, index: usize, item: &str) {
|
||||
h.get_all_by_label("Reorder").nth(index).unwrap_or_else(|| panic!("no grip {index}")).click_secondary();
|
||||
h.run_steps(4);
|
||||
h.get_by_label(item).click();
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// The file name field of output map `index`: the text field on its grip's row
|
||||
fn name_field(h: &Harness<'_, TextureCraftApp>, index: usize) -> egui::Rect {
|
||||
let grip = h.get_all_by_label("Reorder").nth(index).unwrap_or_else(|| panic!("no grip {index}")).rect();
|
||||
h.get_all_by_role(egui::Role::TextInput)
|
||||
.map(|field| field.rect())
|
||||
.find(|field| (field.center().y - grip.center().y).abs() < 6.0 && field.left() > grip.right())
|
||||
.unwrap_or_else(|| panic!("no file name field on row {index}"))
|
||||
}
|
||||
|
||||
/// Hover the file name field of output map `index` until its tooltip shows
|
||||
fn hover_name_field(h: &mut Harness<'_, TextureCraftApp>, index: usize) {
|
||||
let field = name_field(h, index);
|
||||
h.hover_at(field.center());
|
||||
h.run_steps(30);
|
||||
}
|
||||
|
||||
/// The last button labelled `label` in the window (the newest output map's swatch)
|
||||
fn last_window_button<'h>(h: &'h Harness<'_, TextureCraftApp>, label: &str) -> egui_kittest::Node<'h> {
|
||||
h.get_all_by_role(egui::Role::Button)
|
||||
.rfind(|button| button.rect().max.x < RAIL_LEFT_EDGE && button.accesskit_node().label().as_deref() == Some(label))
|
||||
.unwrap_or_else(|| panic!("no {label} button"))
|
||||
}
|
||||
|
||||
/// Drop `source` on the point `at`, as a drag from the map lists ends there
|
||||
fn drop_on(h: &mut Harness<'_, TextureCraftApp>, source: SourceRef, at: egui::Pos2) {
|
||||
egui::DragAndDrop::set_payload(&h.ctx, source);
|
||||
h.hover_at(at);
|
||||
h.run_steps(2);
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// Right-click the Presets list's `label` (listed before the selected one's name in the middle)
|
||||
fn right_click(h: &mut Harness<'_, TextureCraftApp>, label: &str) {
|
||||
h.get_all_by_label(label).next().unwrap_or_else(|| panic!("no {label}")).click_secondary();
|
||||
@@ -144,7 +191,13 @@ fn the_preview_ignores_a_texture_sets_output_map_settings() {
|
||||
h.state_mut().ui.export.preset = "Two".into();
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label_contains("Not saved").is_none(), "the preview plans the template on show");
|
||||
assert!(h.query_all_by_label_contains(egui_phosphor::regular::ARROW_RIGHT).count() >= 2, "both maps show their files");
|
||||
let plan = h.state_mut().run("export.plan", json!({"preset": "Two", "ts": ts})).unwrap();
|
||||
for index in 0..2 {
|
||||
let file = plan.as_array().unwrap().iter().find(|f| f["map"] == index).unwrap()["file"].as_str().unwrap().to_string();
|
||||
hover_name_field(&mut h, index);
|
||||
let planned = format!("{} {file}", egui_phosphor::regular::ARROW_RIGHT);
|
||||
assert!(h.query_all_by_label(&planned).next().is_some(), "map {index} shows its own file {file}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -202,7 +255,8 @@ fn the_footer_counts_only_the_maps_the_texture_set_exports() {
|
||||
let ts = h.state().session.ts();
|
||||
let plan = h.state_mut().run("export.plan", json!({"preset": "Mine", "ts": ts})).unwrap();
|
||||
assert_eq!(plan.as_array().unwrap().len(), 1, "the sample set has no sheen: {plan}");
|
||||
assert!(h.query_all_by_label_contains("Not exported").next().is_some(), "the sheen card says so");
|
||||
hover_name_field(&mut h, 1);
|
||||
assert!(h.query_all_by_label_contains("Not exported").next().is_some(), "the sheen row says so");
|
||||
assert!(h.query_by_label("1 output maps will be exported.").is_some());
|
||||
assert!(h.query_by_label("2 output maps will be exported.").is_none());
|
||||
}
|
||||
@@ -217,8 +271,7 @@ fn per_map_settings_follow_their_map_when_the_template_reorders_it() {
|
||||
h.state_mut().ui.export.sets.insert(0, SetExport { maps_template: "Mine".into(), maps: [(0, off.clone())].into(), ..SetExport::default() });
|
||||
h.run_steps(2);
|
||||
let first = h.state().session.export_preset("Mine").unwrap().maps[0].file.clone();
|
||||
h.get_all_by_label("Move down").next().unwrap().click();
|
||||
h.run_steps(4);
|
||||
move_map(&mut h, 0, "Move down");
|
||||
assert_eq!(h.state().session.export_preset("Mine").unwrap().maps[1].file, first, "the map moved down");
|
||||
let maps = h.state().ui.export.sets.get(&0).map(|o| o.maps.clone()).unwrap_or_default();
|
||||
assert_eq!(maps, [(1, off)].into(), "the setting moved with its map");
|
||||
@@ -237,8 +290,7 @@ fn a_draft_in_the_same_order_as_the_external_save_remaps_from_that_order() {
|
||||
// An unfinished edit (an empty file name is not saved) moves the first map down
|
||||
h.state_mut().ui.export.draft.as_mut().unwrap().maps[last].file.clear();
|
||||
h.run_steps(2);
|
||||
h.get_all_by_label("Move down").next().unwrap().click();
|
||||
h.run_steps(4);
|
||||
move_map(&mut h, 0, "Move down");
|
||||
|
||||
// An agent saves the template in that order meanwhile: overrides now count from it
|
||||
let mut agent = saved.clone();
|
||||
@@ -249,8 +301,7 @@ fn a_draft_in_the_same_order_as_the_external_save_remaps_from_that_order() {
|
||||
// Stabilize the layout after fixing the draft so the next click hits the move button
|
||||
h.state_mut().ui.export.draft.as_mut().unwrap().maps[last].file = saved.maps[last].file.clone();
|
||||
h.run_steps(2);
|
||||
h.get_all_by_label("Move down").next().unwrap().click();
|
||||
h.run_steps(4);
|
||||
move_map(&mut h, 0, "Move down");
|
||||
let now = h.state().session.export_preset("Mine").unwrap();
|
||||
assert_eq!(now.maps[1].file, saved.maps[1].file, "{:?}", now.maps.iter().map(|m| &m.file).collect::<Vec<_>>());
|
||||
let maps = h.state().ui.export.sets.get(&0).map(|o| o.maps.clone()).unwrap_or_default();
|
||||
@@ -272,15 +323,290 @@ fn a_retained_draft_keeps_overrides_with_maps_after_an_external_reorder() {
|
||||
harness.run_steps(3);
|
||||
|
||||
// Repair the invalid first filename through the editor so the draft commits on that frame
|
||||
let first_row = harness.get_all_by_label("Move down").next().unwrap().rect().center().y;
|
||||
harness
|
||||
.get_all_by_role(egui::Role::TextInput)
|
||||
.find(|field| (field.rect().center().y - first_row).abs() < 4.0)
|
||||
.unwrap()
|
||||
.set_text_value_accesskit(&saved.maps[0].file);
|
||||
let first_field = name_field(&harness, 0);
|
||||
harness.get_all_by_role(egui::Role::TextInput).find(|field| field.rect() == first_field).unwrap().set_text_value_accesskit(&saved.maps[0].file);
|
||||
harness.run_steps(4);
|
||||
|
||||
let current = harness.state().session.export_preset("Mine").unwrap();
|
||||
assert_eq!(current, saved, "the corrected draft was saved in its own order");
|
||||
assert_eq!(harness.state().ui.export.sets[&0].maps, [(1, disabled)].into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tab_row_holds_the_naming_pattern_and_the_bottom_bar_only_cancels() {
|
||||
let library = TemplateLibrary::new("bottom-bar");
|
||||
let h = harness(&library);
|
||||
|
||||
let naming = h.get_by_label("Naming pattern").rect();
|
||||
let tabs = h.get_by_label("OUTPUT TEMPLATES").rect();
|
||||
let presets = h.get_by_label("Presets").rect();
|
||||
|
||||
assert!(naming.center().y < presets.top() && (naming.center().y - tabs.center().y).abs() < tabs.height(), "on the tab row: {naming:?}");
|
||||
assert!(naming.left() > presets.right(), "at the right end");
|
||||
for absent in ["Include all", "Reset all"] {
|
||||
assert!(h.query_by_label(absent).is_none(), "{absent}");
|
||||
}
|
||||
assert!(h.query_by_label_contains("textures selected for export").is_none());
|
||||
for greyed in ["Save settings", "Export"] {
|
||||
// The rail at the right edge has an Export button of its own
|
||||
let button =
|
||||
h.get_all_by_role(egui::Role::Button).rfind(|b| b.rect().max.x < RAIL_LEFT_EDGE && b.accesskit_node().label().as_deref() == Some(greyed)).unwrap();
|
||||
assert!(button.accesskit_node().is_disabled(), "{greyed}");
|
||||
}
|
||||
assert!(!h.get_all_by_label("Cancel").last().unwrap().accesskit_node().is_disabled());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_presets_row_holds_copy_minus_and_plus_without_tooltips() {
|
||||
let library = TemplateLibrary::new("preset-icons");
|
||||
let mut h = harness(&library);
|
||||
|
||||
let presets = h.get_by_label("Presets").rect();
|
||||
let icons = ["Duplicate the selected template", "Delete the selected template", "New template"].map(|label| h.get_by_label(label).rect());
|
||||
|
||||
assert!(icons.iter().all(|icon| (icon.center().y - presets.center().y).abs() < presets.height()), "on the Presets row: {icons:?}");
|
||||
assert!(icons.windows(2).all(|pair| pair[0].center().x < pair[1].center().x), "copy, minus, plus from left to right");
|
||||
h.hover_at(icons[2].center());
|
||||
h.run_steps(30);
|
||||
assert_eq!(h.query_all_by_label("New template").count(), 1, "no tooltip repeats the name");
|
||||
assert!(h.query_by_label("Import a template (.json)").is_none(), "no import button");
|
||||
|
||||
right_click(&mut h, "Mine");
|
||||
assert!(h.query_by_label("Import a template (.json)").is_some(), "import and export stay in the right-click menu");
|
||||
assert!(h.query_by_label("Export the selected template (.json)").is_some());
|
||||
}
|
||||
|
||||
/// Press `key` with no pointer event
|
||||
fn press(h: &mut Harness<'_, TextureCraftApp>, key: egui::Key) {
|
||||
h.key_press(key);
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_and_export_are_reachable_from_the_keyboard_alone() {
|
||||
let library = TemplateLibrary::new("keyboard-actions");
|
||||
let mut h = harness(&library);
|
||||
let file = library.0.join("exported_template.json");
|
||||
let answer = file.clone();
|
||||
h.state_mut().file_dialogs.set_override(Some(Box::new(move |_| Answer::Paths(vec![answer.clone()]))));
|
||||
let templates_before = h.state().session.export_presets.list.len();
|
||||
|
||||
// The actions menu is a named button the keyboard focus reaches
|
||||
h.get_by_role_and_label(egui::Role::Button, "Template actions").focus();
|
||||
h.run_steps(2);
|
||||
press(&mut h, egui::Key::Enter);
|
||||
let import = h.get_by_label("Import a template (.json)");
|
||||
assert!(import.accesskit_node().is_focused(), "the menu opens with Import focused");
|
||||
|
||||
press(&mut h, egui::Key::Tab);
|
||||
assert!(h.get_by_label("Export the selected template (.json)").accesskit_node().is_focused(), "Tab moves on to Export");
|
||||
press(&mut h, egui::Key::Enter);
|
||||
assert!(std::fs::read_to_string(&file).unwrap().contains("\"Mine\""), "Export wrote the selected template");
|
||||
|
||||
assert!(h.query_by_label("Import a template (.json)").is_none(), "the menu closes after the action");
|
||||
|
||||
h.get_by_role_and_label(egui::Role::Button, "Template actions").focus();
|
||||
h.run_steps(2);
|
||||
press(&mut h, egui::Key::Enter);
|
||||
press(&mut h, egui::Key::Enter);
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().session.export_presets.list.len(), templates_before + 1, "Import added the exported template");
|
||||
assert!(h.state().toasts.iter().any(|toast| toast.text.starts_with("Imported template")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_map_lists_stand_in_three_panes_with_their_groups_and_names() {
|
||||
let library = TemplateLibrary::new("panes");
|
||||
let h = harness(&library);
|
||||
|
||||
let input = h.get_by_label("Input maps").rect();
|
||||
// A built-in template is called "Mesh maps" too: the pane's title comes after the Presets list
|
||||
let mesh = h.get_all_by_label("Mesh maps").last().unwrap().rect();
|
||||
let converted = h.get_by_label("Converted maps").rect();
|
||||
|
||||
assert!(mesh.left() > input.right(), "Mesh maps stand in a column right of Input maps");
|
||||
assert!(converted.top() > mesh.bottom() && (converted.left() - mesh.left()).abs() < 2.0, "Converted maps stand below Mesh maps");
|
||||
for group in ["Transmission", "Subsurface", "Sheen", "Thin film", "Other"] {
|
||||
assert!(h.query_all_by_label(group).next().is_some(), "group {group}");
|
||||
}
|
||||
for name in ["Specular level", "Sheen weight", "Coat normal", "Emissive", "World Space Normal", "Bent Normals", "Normal DirectX", "F0 from specular level"]
|
||||
{
|
||||
let entry = h.query_all_by_label(name).next().unwrap_or_else(|| panic!("{name}"));
|
||||
assert!(!entry.accesskit_node().is_disabled(), "{name} can be dragged");
|
||||
}
|
||||
for name in ["Base weight", "Coat tangent", "Thin film weight", "Subsurface radius"] {
|
||||
let entry = h.query_all_by_label(name).next().unwrap_or_else(|| panic!("{name}"));
|
||||
assert!(entry.accesskit_node().is_disabled(), "{name} is listed greyed");
|
||||
}
|
||||
for gone in ["Drag onto an output channel", "Texture set channels", "Constants", "Emission color"] {
|
||||
assert!(h.query_by_label(gone).is_none(), "{gone}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_map_dropped_on_a_channel_asks_which_of_its_channels_to_use() {
|
||||
let library = TemplateLibrary::new("drop");
|
||||
let mut h = harness(&library);
|
||||
click(&mut h, "R+G+B+A");
|
||||
let last = h.state().session.export_preset("Mine").unwrap().maps.len() - 1;
|
||||
|
||||
let green = last_window_button(&h, "G: Empty (writes black)").rect().center();
|
||||
drop_on(&mut h, SourceRef::Channel { channel: Channel::BaseColor, component: 0 }, green);
|
||||
|
||||
assert!(h.query_by_label("Which part of Base color?").is_some(), "the popup names the dropped map");
|
||||
assert!(h.query_by_label("Red, green and blue").is_none(), "only the RGB swatch offers all three");
|
||||
for choice in ["Red channel", "Green channel", "Blue channel"] {
|
||||
assert!(!h.get_by_label(choice).accesskit_node().is_disabled(), "{choice}");
|
||||
}
|
||||
for greyed in ["Gray value", "Alpha channel"] {
|
||||
assert!(h.get_by_label(greyed).accesskit_node().is_disabled(), "{greyed}");
|
||||
}
|
||||
h.get_by_label("Blue channel").click();
|
||||
h.run_steps(4);
|
||||
|
||||
let map = h.state().session.export_preset("Mine").unwrap().maps[last].clone();
|
||||
assert!(map.channels.contains(&(Dest::G, SourceRef::Channel { channel: Channel::BaseColor, component: 2 })), "{:?}", map.channels);
|
||||
assert!(h.query_by_label("Which part of Base color?").is_none(), "the popup closed");
|
||||
assert!(h.query_all_by_label("G: Base color, blue channel").next().is_some(), "the swatch names its map and channel");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_color_map_dropped_on_the_rgb_swatch_offers_rgb_channels() {
|
||||
let library = TemplateLibrary::new("drop-rgb");
|
||||
let mut h = harness(&library);
|
||||
click(&mut h, "RGB+A");
|
||||
let last = h.state().session.export_preset("Mine").unwrap().maps.len() - 1;
|
||||
|
||||
let rgb = last_window_button(&h, "RGB: Empty (writes black)").rect().center();
|
||||
drop_on(&mut h, SourceRef::Channel { channel: Channel::BaseColor, component: 0 }, rgb);
|
||||
h.get_by_label("Red, green and blue").click();
|
||||
h.run_steps(4);
|
||||
|
||||
let map = h.state().session.export_preset("Mine").unwrap().maps[last].clone();
|
||||
let spread: Vec<_> = (0..3).map(|component| SourceRef::Channel { channel: Channel::BaseColor, component }).collect();
|
||||
assert_eq!(map.channels.iter().take(3).map(|(_, source)| source.clone()).collect::<Vec<_>>(), spread);
|
||||
assert!(h.query_all_by_label("RGB: Base color, RGB").next().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escape_closes_the_from_popup_without_assigning() {
|
||||
let library = TemplateLibrary::new("drop-escape");
|
||||
let mut h = harness(&library);
|
||||
click(&mut h, "Gray");
|
||||
let before = h.state().session.export_preset("Mine").unwrap();
|
||||
|
||||
let gray = last_window_button(&h, "Gr: Empty (writes black)").rect().center();
|
||||
drop_on(&mut h, SourceRef::Channel { channel: Channel::Metallic, component: 0 }, gray);
|
||||
assert!(h.query_by_label("Which part of Metallic?").is_some());
|
||||
assert!(!h.get_by_label("Gray value").accesskit_node().is_disabled());
|
||||
assert!(h.get_by_label("Alpha channel").accesskit_node().is_disabled());
|
||||
assert!(h.query_by_label("Red channel").is_none(), "a gray map has no R, G or B");
|
||||
|
||||
h.key_press(egui::Key::Escape);
|
||||
h.run_steps(4);
|
||||
|
||||
assert!(h.query_by_label("Which part of Metallic?").is_none(), "Escape closes the popup");
|
||||
assert!(h.state().ui.export.pending_drop.is_none());
|
||||
assert_eq!(h.state().session.export_preset("Mine").unwrap(), before, "nothing was assigned");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_a_grip_onto_another_row_moves_that_map_there() {
|
||||
let library = TemplateLibrary::new("grip-drag");
|
||||
let mut h = harness(&library);
|
||||
let files = |h: &Harness<'_, TextureCraftApp>| h.state().session.export_preset("Mine").unwrap().maps.iter().map(|m| m.file.clone()).collect::<Vec<_>>();
|
||||
let before = files(&h);
|
||||
|
||||
let from = h.get_all_by_label("Reorder").last().unwrap().rect().center();
|
||||
let to = h.get_all_by_label("Reorder").next().unwrap().rect().center();
|
||||
h.hover_at(from);
|
||||
h.event(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
for step in 1..=4 {
|
||||
h.hover_at(from + (to - from) * (step as f32 / 4.0));
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.event(Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(4);
|
||||
|
||||
let mut expected = before.clone();
|
||||
let moved = expected.pop().unwrap();
|
||||
expected.insert(0, moved);
|
||||
assert_eq!(files(&h), expected, "the last map is first now");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_a_channel_offers_clear_and_split_or_collapse_and_a_right_click_invert() {
|
||||
let library = TemplateLibrary::new("swatch-menu");
|
||||
let mut h = harness(&library);
|
||||
click(&mut h, "RGB");
|
||||
let last = h.state().session.export_preset("Mine").unwrap().maps.len() - 1;
|
||||
let file = &h.state().session.export_preset("Mine").unwrap().maps[last].file;
|
||||
assert!(file.ends_with("_RGB"), "a new RGB row is named after its layout: {file}");
|
||||
assert!(file.contains("$textureSet"), "each texture set writes a file of its own: {file}");
|
||||
|
||||
last_window_button(&h, "RGB: Empty (writes black)").click();
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label("Clear channel").is_some());
|
||||
h.get_by_label("Separate R, G and B").click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().ui.export.draft_split.get(last), Some(&true), "R, G and B show apart");
|
||||
|
||||
let green = last_window_button(&h, "G: Empty (writes black)");
|
||||
let at = green.rect().center();
|
||||
green.click_secondary();
|
||||
h.run_steps(4);
|
||||
|
||||
// The properties panel has Invert controls of its own: take the menu's, next to the swatch
|
||||
let invert = h.get_all_by_label("Invert").min_by(|a, b| a.rect().center().distance(at).total_cmp(&b.rect().center().distance(at))).unwrap();
|
||||
invert.click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().session.export_preset("Mine").unwrap().maps[last].inverted, vec![Dest::G]);
|
||||
assert!(h.query_all_by_label("G: Empty (writes white), inverted").next().is_some(), "the swatch says it is inverted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_a_small_screen_an_rgba_row_keeps_its_controls_in_the_window() {
|
||||
let session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let library = TemplateLibrary::new("small-screen");
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_eframe(|cc| TextureCraftApp::new(cc, session));
|
||||
h.state_mut().ui.prefs.language = "en".into();
|
||||
h.run_steps(4);
|
||||
h.state_mut().session.load_export_presets(library.0.clone());
|
||||
let base = texturecraft_engine::formats::builtin_preset("Unreal Engine (Packed)").unwrap();
|
||||
h.state_mut().run("export.preset.save", json!({ "preset": texturecraft_engine::formats::ExportPreset { name: "Mine".into(), ..base } })).unwrap();
|
||||
let ui = &mut h.state_mut().ui;
|
||||
ui.windows.export = true;
|
||||
ui.export.tab = 1;
|
||||
ui.export.preset = "Mine".into();
|
||||
h.run_steps(4);
|
||||
click(&mut h, "R+G+B+A");
|
||||
|
||||
let input_maps = h.get_by_label("Input maps").rect();
|
||||
let removes: Vec<egui::Rect> = h.get_all_by_label("Remove this output").map(|node| node.rect()).collect();
|
||||
let alpha = last_window_button(&h, "A: Empty (writes white)").rect();
|
||||
|
||||
assert!(!removes.is_empty());
|
||||
for remove in removes {
|
||||
assert!(remove.right() < input_maps.left(), "a row's × stays left of the Input maps pane: {remove:?} {input_maps:?}");
|
||||
}
|
||||
assert!(alpha.right() < input_maps.left(), "the last swatch too: {alpha:?}");
|
||||
|
||||
// Each row stays one line: its controls do not wrap into a tall row
|
||||
let grips: Vec<egui::Rect> = h.get_all_by_label("Reorder").map(|grip| grip.rect()).collect();
|
||||
for pair in grips.windows(2) {
|
||||
assert!(pair[1].top() - pair[0].top() < 2.5 * pair[0].height(), "row height {pair:?}");
|
||||
}
|
||||
|
||||
// The row's file format list starts right of its last swatch instead of covering it
|
||||
let format =
|
||||
h.get_all_by_role(egui::Role::Button).rfind(|button| button.accesskit_node().label().is_some_and(|label| label.starts_with("png"))).unwrap().rect();
|
||||
assert!(alpha.right() <= format.left(), "the swatches and the lists do not overlap: {alpha:?} {format:?}");
|
||||
|
||||
// The panes stay inside the window: the side pane ends where the bottom bar's buttons end
|
||||
let cancel = h.get_all_by_label("Cancel").last().unwrap().rect();
|
||||
let export = last_window_button(&h, "Export").rect();
|
||||
let converted = h.get_by_label("Converted maps").rect();
|
||||
assert!(cancel.max.x <= 1000.0 && cancel.max.y <= 700.0, "{cancel:?}");
|
||||
assert!(converted.left() < export.right() && converted.right() <= export.right() + 1.0, "{converted:?} {export:?}");
|
||||
}
|
||||
@@ -101,10 +101,12 @@ fn the_export_panel_leads_to_export_textures_and_the_mesh_options() {
|
||||
|
||||
assert_eq!(harness.state().ui.rail_panel, Some(Panel::Export));
|
||||
assert!(!harness.state().ui.windows.export, "the rail opens the Export panel, not a window");
|
||||
for label in ["SEND TO", "EXPORT", "Export to image editor", "Send to compositing app", "Send to 3D staging app"] {
|
||||
assert!(harness.query_all_by_label(label).next().is_some(), "{label}");
|
||||
assert!(harness.query_all_by_label("EXPORT").next().is_some(), "the EXPORT caption");
|
||||
for label in ["SEND TO", "Export to image editor", "Send to compositing app", "Send to 3D staging app"] {
|
||||
assert!(harness.query_all_by_label(label).next().is_none(), "the dock has no {label} row");
|
||||
}
|
||||
assert!(says_not_available(&mut harness, "Send to compositing app"));
|
||||
assert!(harness.query_all_by_label_contains("Send to").next().is_none(), "no SEND TO text at all");
|
||||
button_left_of_rail(&harness, "Export Mesh...");
|
||||
|
||||
button_left_of_rail(&harness, "Export Textures...").click();
|
||||
harness.run_steps(SETTLE_FRAMES);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Export dialog › Output templates: each output channel has an Invert toggle that is saved in the template.
|
||||
//! Export dialog › Output templates: each output channel can be inverted from its swatch's
|
||||
//! right-click menu, and the inversion is saved in the template.
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
@@ -26,12 +27,17 @@ fn harness() -> (Harness<'static, TextureCraftApp>, Library) {
|
||||
(h, Library(dir))
|
||||
}
|
||||
|
||||
/// The channel toggles of the open dialog (the dialog sits left of the properties panel, which has its own Invert controls)
|
||||
fn toggles<'h>(h: &'h Harness<'_, TextureCraftApp>) -> Vec<egui_kittest::Node<'h>> {
|
||||
h.get_all_by_label("Invert").filter(|n| n.rect().max.x < DIALOG_RIGHT_EDGE).collect()
|
||||
}
|
||||
/// Right-click the swatch `swatch` and click the Invert of its menu (the properties panel has Invert controls of its own)
|
||||
fn toggle_invert(h: &mut Harness<'_, TextureCraftApp>, swatch: &str) {
|
||||
let node = h.get_all_by_label(swatch).next().unwrap_or_else(|| panic!("no {swatch} swatch"));
|
||||
let at = node.rect().center();
|
||||
node.click_secondary();
|
||||
h.run_steps(4);
|
||||
|
||||
const DIALOG_RIGHT_EDGE: f32 = 1200.0;
|
||||
let invert = h.get_all_by_label("Invert").min_by(|a, b| a.rect().center().distance(at).total_cmp(&b.rect().center().distance(at))).unwrap();
|
||||
invert.click();
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
fn template() -> ExportPreset {
|
||||
let ch = |channel| SourceRef::Channel { channel, component: 0 };
|
||||
@@ -60,12 +66,12 @@ fn invert_toggle_changes_the_saved_template() {
|
||||
let saved = |h: &Harness<'_, TextureCraftApp>| h.state().session.export_preset(TEMPLATE).unwrap().maps[0].inverted.clone();
|
||||
assert!(saved(&h).is_empty());
|
||||
|
||||
// One Invert toggle per channel: R, G, B
|
||||
assert_eq!(toggles(&h).len(), 3);
|
||||
toggles(&h)[1].click();
|
||||
h.run_steps(4);
|
||||
// Three maps in R, G and B: one swatch per channel
|
||||
for swatch in ["R: Roughness, gray value", "G: Metallic, gray value", "B: Constant 0.50"] {
|
||||
assert!(h.query_all_by_label(swatch).next().is_some(), "{swatch}");
|
||||
}
|
||||
toggle_invert(&mut h, "G: Metallic, gray value");
|
||||
assert_eq!(saved(&h), vec![Dest::G], "the second channel (G) is inverted");
|
||||
toggles(&h)[1].click();
|
||||
h.run_steps(4);
|
||||
toggle_invert(&mut h, "G: Metallic, gray value, inverted");
|
||||
assert!(saved(&h).is_empty(), "a second click turns it off");
|
||||
}
|
||||
+40
-12
@@ -63,9 +63,8 @@ when it is not docked). Each opens a popup beside the bar with its title in capi
|
||||
button that turns it into a floating window, and *Close*. A floating rail panel has a *Dock* button
|
||||
that closes it back onto the bar; the float is saved with the UI state.
|
||||
|
||||
- **Export:** SEND TO lists three targets and a Configure button, all greyed with "Not available
|
||||
yet". The reference names other products there; TextureCraft says *Export to image editor*,
|
||||
*Send to compositing app* and *Send to 3D staging app*. EXPORT has *Export Mesh...* (the
|
||||
- **Export:** the dock shows EXPORT only (the reference's SEND TO part has no counterpart here and
|
||||
is left out, [#789](https://github.com/storytold/texturecraft/issues/789)). EXPORT has *Export Mesh...* (the
|
||||
*Mesh Export Options* prompt, then the file choice) and *Export Textures...* (the Export textures
|
||||
window: *Global settings* above the texture sets, *General Export Parameters*, *Export USD asset*
|
||||
(off by default; it adds `usdAsset` to the last texture set's export, which writes `<mesh>.usd`
|
||||
@@ -292,15 +291,16 @@ that numbers hide once a tile is under 40 points on screen.
|
||||
adds "Maximum size for all Texture Sets" and 128. Padding uses the reference order; the
|
||||
dilation width is a button with a "Dilation (pixels)" slider, greyed for paddings without a
|
||||
width. Include all, Reset all, Cancel, Save settings, Export and the two greyed checkboxes carry
|
||||
tooltips explaining which settings are applied, kept or restored.
|
||||
tooltips saying what they select, write, keep or restore. The window is 1100 x 740 as in the reference
|
||||
([#789](https://github.com/storytold/texturecraft/issues/789)).
|
||||
Cancel, and closing the window, go back to the settings the window opened with; the window
|
||||
always opens on SETTINGS.
|
||||
- **Texture set pages** ([#669](https://github.com/storytold/texturecraft/issues/669)): a click
|
||||
on a texture set row shows its *General Export Parameters*: Output template, File type, Size and
|
||||
Padding with the inherited value as text (for example "1024x1024 (Texture Set size)"). The
|
||||
pencil button ("Enable override") turns a row into its list; a set with an override gets "*"
|
||||
("Override(s) active"). The header menu has *Override every item* and *Disable
|
||||
override for all items*. The template list leaves out the entries the reference leaves out
|
||||
("Override(s) active"). The header menu has *Override every item* and *Clear all
|
||||
overrides*. The template list leaves out the entries the reference leaves out
|
||||
there; sizes read "128x128" ... "8192x8192". Export, the footer count and LIST OF EXPORTS use
|
||||
each set's own settings. Ticks and overrides belong to the project and follow each texture set
|
||||
by name (another project starts without them); renaming a template on OUTPUT TEMPLATES takes
|
||||
@@ -339,9 +339,37 @@ that numbers hide once a tile is under 40 points on screen.
|
||||
list is titled *Presets* and lists the templates sorted by name, without the template list's
|
||||
first group. A right click on a preset offers *Rename*, *Duplicate* and *Remove* (Rename and
|
||||
Remove are greyed for built-in templates, which are read-only); F2 renames the selected one.
|
||||
"+" creates "new_export_preset", Duplicate "<name>_copy". *Naming pattern* (*OpenPBR*; the
|
||||
reference's second pattern names another vendor's material and is left out) with its info
|
||||
tooltip sits above the input maps. The middle reads "Current preset: <name>", *Output maps*
|
||||
with *Create:* Gray, RGB, R+G+B, RGB+A, R+G+B+A, and a footer with drag-and-drop guidance and the number of output maps. TextureCraft keeps its
|
||||
own list tools (rename, import, export) and asks before deleting; R+G+B and R+G+B+A create the
|
||||
same maps as RGB and RGB+A (each channel takes its own source in either).
|
||||
"+" creates "new_export_preset", Duplicate "<name>_copy". The *Presets* row holds copy, "−"
|
||||
and "+" without tooltips ([#789](https://github.com/storytold/texturecraft/issues/789)).
|
||||
*Naming pattern* (*OpenPBR*; the reference's second pattern names another vendor's material and
|
||||
is left out) with its info tooltip sits at the right end of the tab row; this tab has no
|
||||
*Include all*, *Reset all* or texture count, and *Save settings* and *Export* are greyed. The
|
||||
middle reads "Current preset: <name>", *Output maps* with *Create:* Gray, RGB, R+G+B, RGB+A,
|
||||
R+G+B+A on the same row, and a footer with drag-and-drop guidance and the number of output
|
||||
maps. Each output map is one row: a drag grip (drag it onto another row to move the map), the
|
||||
file name, "$" ("Insert a variable": $project,
|
||||
$mesh, $textureSet, $udim, $uvTileName greyed, $colorSpace, then TextureCraft's $channel), the
|
||||
channel swatches (Gr, RGB or R, G, B, then A), the file format ("File format") and bit depth
|
||||
("Bit depth"; "8 bits + dithering" greyed, templates do not keep it) lists, duplicate and "×".
|
||||
Create names new rows "Gray", "RGB" and "RGBA" after "$mesh_$textureSet_", so the
|
||||
texture sets of one export do not write the same file, with "_1", "_2" when taken. An
|
||||
empty swatch's tooltip reads "Empty (writes black)" ("Empty (writes white)" for A, the other
|
||||
way round when the swatch is inverted), a filled one
|
||||
"<map>, <part>", e.g. "Base color, red channel" or "Metallic, gray value". Dropping a map on a
|
||||
swatch asks "Which part of <map>?": a gray map offers *Gray value* and *Alpha channel*, a colour map
|
||||
*Gray value*, *Red channel*, *Green channel*, *Blue channel* and *Alpha channel*, on the RGB swatch first *Red, green and blue*; Escape assigns
|
||||
nothing. TextureCraft cannot read a map's gray or alpha yet, so those choices are greyed. A
|
||||
click on a swatch offers *Clear channel*, on RGB, R, G and B also *Separate R, G and B*; R, G
|
||||
and B that read different maps or are inverted differently cannot be joined (the item is greyed). The right side has the
|
||||
*Input maps* pane in the OpenPBR parameter groups (Base ... Geometry, then Other for
|
||||
TextureCraft's channels outside OpenPBR), each map TextureCraft has under its own name,
|
||||
and a pane with *Mesh maps* above *Converted maps* (highlighted). Maps the selected template
|
||||
uses get a square in their swatch's colour. OpenPBR inputs TextureCraft has no channel for
|
||||
are greyed and cannot be dragged; *Converted maps* lists the maps TextureCraft computes. TextureCraft keeps
|
||||
some things the reference does not have, out of the way: Import and Export of template files
|
||||
at the end of a preset's right-click menu and in a *Template actions* button (three dots, left of
|
||||
copy on the *Presets* row) that the keyboard reaches, with Import focused when it opens; a swatch's right-click menu with Invert (an inverted
|
||||
swatch has a corner mark), Black, Gray 50%, White, the constant's value and the map's layout
|
||||
(RGB, RGBA, Gray, Gray + A); *Move up* and *Move down* in the grip's right-click menu and the
|
||||
arrow keys on a focused grip; the planned file name in the file name's tooltip; and
|
||||
converted maps of its own such as Normal from height, Roughness from glossiness and Sheen color × weight. Built-in templates stay read-only and deleting asks first.
|
||||
Reference in new issue
Block a user