mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-25 08:50:46 +01:00
Merge pull request #794 from storytold/context-menu-parity
Align top menus, default workspace, and dialogs
This commit is contained in:
44 files changed
+1551
-770
No files matched your search
Generated
+17
@@ -1603,6 +1603,7 @@ dependencies = [
|
||||
"raw-window-handle",
|
||||
"serde",
|
||||
"web-time",
|
||||
"webbrowser",
|
||||
"windows-sys 0.61.2",
|
||||
"winit",
|
||||
]
|
||||
@@ -6022,6 +6023,22 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webbrowser"
|
||||
version = "1.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73e91ccd4698f2647d6137e8eb17a3f1dcfd63810be9029fb2398f507279b95b"
|
||||
dependencies = [
|
||||
"jni",
|
||||
"log",
|
||||
"ndk-context",
|
||||
"objc2 0.6.5",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-foundation 0.3.2",
|
||||
"url",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-root-certs"
|
||||
version = "1.0.11"
|
||||
|
||||
@@ -15,7 +15,7 @@ texturecraft-engine = { workspace = true }
|
||||
texturecraft-ui-egui = { workspace = true }
|
||||
# The control channel's token, framing and connection limits (shared with `texturecraft-cli serve`).
|
||||
texturecraft-automation = { workspace = true }
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit", "wayland", "x11", "persistence"] }
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit", "wayland", "x11", "persistence", "links"] }
|
||||
egui = { workspace = true }
|
||||
image = { workspace = true }
|
||||
craft-image-codecs = { workspace = true }
|
||||
|
||||
@@ -4,33 +4,59 @@ use crate::log::DEFAULT_SOURCE;
|
||||
use crate::{LogEntry, LogLevel};
|
||||
|
||||
/// The current session's log in occurrence order
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct SessionLog(Vec<LogEntry>);
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct SessionLog {
|
||||
entries: Vec<LogEntry>,
|
||||
// IDs stay in occurrence order and are never reused after a clear or retain.
|
||||
occurrences: Vec<u64>,
|
||||
last_occurrence: u64,
|
||||
}
|
||||
|
||||
impl PartialEq for SessionLog {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.entries == other.entries
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for SessionLog {}
|
||||
|
||||
impl SessionLog {
|
||||
pub fn new() -> SessionLog {
|
||||
SessionLog(Vec::new())
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> &[LogEntry] {
|
||||
&self.0
|
||||
&self.entries
|
||||
}
|
||||
|
||||
/// Entries added after a previous occurrence in this log, in append order.
|
||||
/// Pass zero to start at the beginning.
|
||||
pub fn entries_after(&self, occurrence: u64) -> impl Iterator<Item = (u64, &LogEntry)> {
|
||||
let start = self.occurrences.partition_point(|&id| id <= occurrence);
|
||||
self.occurrences[start..].iter().copied().zip(&self.entries[start..])
|
||||
}
|
||||
|
||||
fn record(&mut self, entry: LogEntry) {
|
||||
self.last_occurrence += 1;
|
||||
self.occurrences.push(self.last_occurrence);
|
||||
self.entries.push(entry);
|
||||
}
|
||||
|
||||
/// An info entry without a source of its own
|
||||
pub fn push(&mut self, message: String) {
|
||||
self.0.push(LogEntry::new(LogLevel::Info, DEFAULT_SOURCE, message));
|
||||
self.record(LogEntry::new(LogLevel::Info, DEFAULT_SOURCE, message));
|
||||
}
|
||||
|
||||
pub fn info(&mut self, source: &str, message: impl Into<String>) {
|
||||
self.0.push(LogEntry::new(LogLevel::Info, source, message));
|
||||
self.record(LogEntry::new(LogLevel::Info, source, message));
|
||||
}
|
||||
|
||||
pub fn warn(&mut self, source: &str, message: impl Into<String>) {
|
||||
self.0.push(LogEntry::new(LogLevel::Warning, source, message));
|
||||
self.record(LogEntry::new(LogLevel::Warning, source, message));
|
||||
}
|
||||
|
||||
pub fn error(&mut self, source: &str, message: impl Into<String>) {
|
||||
self.0.push(LogEntry::new(LogLevel::Error, source, message));
|
||||
self.record(LogEntry::new(LogLevel::Error, source, message));
|
||||
}
|
||||
|
||||
/// Several warnings of one source
|
||||
@@ -42,23 +68,31 @@ impl SessionLog {
|
||||
|
||||
/// Append the entries of another store
|
||||
pub fn append(&mut self, other: SessionLog) {
|
||||
self.0.extend(other.0);
|
||||
for entry in other.entries {
|
||||
self.record(entry);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear();
|
||||
self.entries.clear();
|
||||
self.occurrences.clear();
|
||||
}
|
||||
|
||||
/// Drop the entries for which `keep` is false
|
||||
pub fn retain(&mut self, keep: impl FnMut(&LogEntry) -> bool) {
|
||||
self.0.retain(keep);
|
||||
// Evaluate the predicate once and apply the same decisions to both vectors.
|
||||
let kept: Vec<_> = self.entries.iter().map(keep).collect();
|
||||
let mut decisions = kept.iter().copied();
|
||||
self.entries.retain(|_| decisions.next().unwrap_or_default());
|
||||
let mut decisions = kept.into_iter();
|
||||
self.occurrences.retain(|_| decisions.next().unwrap_or_default());
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SessionLog {
|
||||
type Target = [LogEntry];
|
||||
fn deref(&self) -> &[LogEntry] {
|
||||
&self.0
|
||||
&self.entries
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +100,6 @@ impl<'a> IntoIterator for &'a SessionLog {
|
||||
type Item = &'a LogEntry;
|
||||
type IntoIter = std::slice::Iter<'a, LogEntry>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter()
|
||||
self.entries.iter()
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,7 @@ fn refresh_draft_preferences(draft: &mut Prefs, previous: &Prefs, current: &Pref
|
||||
refresh_fields!(
|
||||
ui_scale,
|
||||
autosave_minutes,
|
||||
recent_projects_limit,
|
||||
language,
|
||||
viewport_texture,
|
||||
brightness,
|
||||
@@ -227,6 +228,7 @@ pub fn handle(app: &mut TextureCraftApp, ctx: &egui::Context, method: &str, para
|
||||
.map(|item| json!({
|
||||
"menu": item.menu, "submenu": item.sub, "label": item.label, "id": item.id, "shortcut": crate::keymap::shortcut_of(&app.ui.keymap, item.id),
|
||||
"implemented": crate::menus::implemented(item.id), "enabled": crate::menus::enabled(app, item.id),
|
||||
"checked": crate::menus::checked(app, item.id),
|
||||
}))
|
||||
.collect::<Vec<_>>()
|
||||
)),
|
||||
@@ -283,6 +285,7 @@ pub fn handle(app: &mut TextureCraftApp, ctx: &egui::Context, method: &str, para
|
||||
refresh_draft_preferences(&mut draft.prefs, &app.ui.prefs, &ui.prefs);
|
||||
}
|
||||
|
||||
ui.trim_recent();
|
||||
app.ui = ui;
|
||||
app.reschedule_autosave_if_changed(previous_autosave_minutes);
|
||||
app.ui.prefs.apply_resource_limits();
|
||||
|
||||
@@ -43,14 +43,16 @@ pub enum Panel {
|
||||
Shader,
|
||||
History,
|
||||
Log,
|
||||
BakingLog,
|
||||
Export,
|
||||
/// The path tracer's settings (Window ▸ Views ▸ Renderer Settings, Rendering mode only)
|
||||
Renderer,
|
||||
}
|
||||
|
||||
/// Window ▸ Views items and the panels they show or hide.
|
||||
pub const VIEWS: [(&str, Panel); 14] = [
|
||||
pub const VIEWS: [(&str, Panel); 15] = [
|
||||
("ui.view.assets", Panel::Assets),
|
||||
("ui.view.bakingLog", Panel::BakingLog),
|
||||
("ui.view.bakeMaps", Panel::MeshMapSettings),
|
||||
("ui.view.bakeSettings", Panel::CommonSettings),
|
||||
("ui.view.display", Panel::Display),
|
||||
@@ -79,7 +81,7 @@ impl Panel {
|
||||
pub(crate) fn available_in(self, mode: crate::state::Mode) -> bool {
|
||||
use crate::state::Mode;
|
||||
match self {
|
||||
Self::MeshMapSettings | Self::CommonSettings | Self::MeshMapBakers => mode == Mode::Baking,
|
||||
Self::MeshMapSettings | Self::CommonSettings | Self::MeshMapBakers | Self::BakingLog => mode == Mode::Baking,
|
||||
Self::Assets | Self::Layers | Self::Properties | Self::TextureSetSettings | Self::Export => mode == Mode::Painting,
|
||||
Self::History => mode != Mode::Rendering,
|
||||
Self::Shader => mode != Mode::Baking,
|
||||
@@ -88,7 +90,7 @@ impl Panel {
|
||||
}
|
||||
}
|
||||
|
||||
pub const ALL: [Panel; 15] = [
|
||||
pub const ALL: [Panel; 16] = [
|
||||
Panel::Viewport,
|
||||
Panel::Assets,
|
||||
Panel::MeshMapSettings,
|
||||
@@ -102,6 +104,7 @@ impl Panel {
|
||||
Panel::Shader,
|
||||
Panel::History,
|
||||
Panel::Log,
|
||||
Panel::BakingLog,
|
||||
Panel::Export,
|
||||
Panel::Renderer,
|
||||
];
|
||||
@@ -121,6 +124,7 @@ impl Panel {
|
||||
Panel::Shader => "Shader Settings",
|
||||
Panel::History => "History",
|
||||
Panel::Log => "Log",
|
||||
Panel::BakingLog => "Baking Log",
|
||||
Panel::Export => "Export",
|
||||
Panel::Renderer => "Renderer Settings",
|
||||
}
|
||||
@@ -135,6 +139,7 @@ impl Panel {
|
||||
Panel::Log => 3.0,
|
||||
Panel::Export => 4.0,
|
||||
Panel::Renderer => 5.0,
|
||||
Panel::BakingLog => 6.0,
|
||||
_ => return None,
|
||||
};
|
||||
Some([960.0, 90.0 + 50.0 * slot, 300.0, 380.0])
|
||||
@@ -576,6 +581,13 @@ pub(crate) fn panel_body(app: &mut TextureCraftApp, ui: &mut Ui, panel: Panel) {
|
||||
Panel::Shader => crate::shader_settings::body(app, ui),
|
||||
Panel::History => crate::windows::history(app, ui),
|
||||
Panel::Log => crate::log_panel::body(app, ui),
|
||||
Panel::BakingLog => {
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
for entry in app.session.log.entries().iter().filter(|entry| entry.source == "Baker") {
|
||||
ui.label(entry.line());
|
||||
}
|
||||
});
|
||||
}
|
||||
Panel::Export => crate::export_panel::body(app, ui),
|
||||
Panel::Renderer => crate::render_mode::settings_body(app, ui),
|
||||
Panel::Viewport => {}
|
||||
|
||||
@@ -18,7 +18,10 @@ use crate::widgets::{chip, icon_button};
|
||||
|
||||
const ICON: f32 = 20.0;
|
||||
const LIST_WIDTH: f32 = 190.0;
|
||||
const INPUTS_WIDTH: f32 = 170.0;
|
||||
/// Width of the input maps column; its naming-pattern row (label, dropdown, info icon) needs about 210
|
||||
const INPUTS_WIDTH: f32 = 210.0;
|
||||
/// Inner margin of an output map's card
|
||||
const CARD_MARGIN: f32 = 6.0;
|
||||
const RENAME_ID: &str = "exp_rename";
|
||||
/// The name "+" gives a new template, as in the reference
|
||||
const NEW_PRESET: &str = "new_export_preset";
|
||||
@@ -423,13 +426,13 @@ pub(crate) fn ask(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut yes = false;
|
||||
let (title, text, yes_label, no_label) = match &question {
|
||||
Ask::Delete(name) => (
|
||||
tr("Delete template"),
|
||||
tr("Delete Template"),
|
||||
trf("Delete the template \"{name}\"? Its file is removed and this cannot be undone.", &[("name", name)]),
|
||||
tr("Delete"),
|
||||
tr("Cancel"),
|
||||
),
|
||||
Ask::Leave(_) => (
|
||||
tr("Unfinished template edit"),
|
||||
tr("Unfinished Template Edit"),
|
||||
trf(
|
||||
"The last edit of the template \"{name}\" is not saved: {error}. Switching away drops it.",
|
||||
&[("name", &app.ui.export.preset), ("error", &unfinished(app).unwrap_or_default())],
|
||||
@@ -438,27 +441,22 @@ pub(crate) fn ask(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
tr("Keep editing"),
|
||||
),
|
||||
};
|
||||
egui::Window::new(title)
|
||||
.id(egui::Id::unique("export_template_ask"))
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.anchor(egui::Align2::CENTER_CENTER, vec2(0.0, 0.0))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_max_width(360.0);
|
||||
ui.label(text);
|
||||
ui.add_space(8.0);
|
||||
ui.horizontal(|ui| {
|
||||
yes = ui.button(yes_label).clicked();
|
||||
cancel |= ui.button(no_label).clicked();
|
||||
});
|
||||
let mut open = true;
|
||||
crate::windows::dialog(ctx, "export_template_ask", title, &mut open).default_width(360.0).show(ctx, |ui| {
|
||||
ui.label(text);
|
||||
ui.add_space(8.0);
|
||||
ui.horizontal(|ui| {
|
||||
yes = ui.button(yes_label).clicked();
|
||||
cancel |= ui.button(no_label).clicked();
|
||||
});
|
||||
});
|
||||
if yes {
|
||||
app.ui.export.ask = None;
|
||||
match question {
|
||||
Ask::Delete(name) => remove(app, name),
|
||||
Ask::Leave(act) => perform(app, ctx, act),
|
||||
}
|
||||
} else if cancel {
|
||||
} else if cancel || !open {
|
||||
app.ui.export.ask = None;
|
||||
}
|
||||
}
|
||||
@@ -634,9 +632,11 @@ fn outputs(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(tr("No outputs yet: add one above, then drag input maps onto its channels.")).color(tokens.text_dim));
|
||||
}
|
||||
ui.add_enabled_ui(editable, |ui| {
|
||||
// Every card takes the column's width, not the width a wider card before it left
|
||||
let card_width = ui.available_width();
|
||||
for (map_index, map) in preset.maps.iter_mut().enumerate() {
|
||||
let file = preview.as_ref().ok().and_then(|names| names.get(map_index).cloned().flatten());
|
||||
changed |= output_card(ui, map_index, map_count, map, file.as_deref(), &mut action);
|
||||
changed |= output_card(ui, card_width, map_index, map_count, map, file.as_deref(), &mut action);
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
});
|
||||
@@ -717,11 +717,11 @@ fn preview_names(app: &mut TextureCraftApp, preset: &ExportPreset) -> Result<Vec
|
||||
}
|
||||
|
||||
/// One output file: name template, format, bit depth, layout and its channel sources.
|
||||
fn output_card(ui: &mut Ui, mi: usize, n: usize, map: &mut MapSpec, file: Option<&str>, action: &mut Option<MapAction>) -> bool {
|
||||
fn output_card(ui: &mut Ui, card_width: f32, mi: usize, n: usize, map: &mut MapSpec, file: Option<&str>, action: &mut Option<MapAction>) -> bool {
|
||||
let tk = Tokens::get(ui.ctx());
|
||||
let mut changed = false;
|
||||
egui::Frame::new().fill(tk.row).corner_radius(tk.radius).inner_margin(6.0).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
egui::Frame::new().fill(tk.row).corner_radius(tk.radius).inner_margin(CARD_MARGIN).show(ui, |ui| {
|
||||
ui.set_width((card_width - 2.0 * CARD_MARGIN).max(0.0));
|
||||
ui.horizontal(|ui| {
|
||||
let width = ui.available_width() - 4.0 * (ICON + ui.spacing().item_spacing.x);
|
||||
changed |= ui
|
||||
|
||||
@@ -21,8 +21,11 @@ mod map_row;
|
||||
use inherited_settings::InheritedSettings;
|
||||
use map_row::MapRow;
|
||||
|
||||
/// Height of the window's tab body, above its buttons
|
||||
/// 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;
|
||||
/// Width of the texture set list
|
||||
const LIST_WIDTH: f32 = 180.0;
|
||||
const ICON: f32 = 20.0;
|
||||
@@ -801,7 +804,7 @@ fn set_list(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
}
|
||||
|
||||
// Many texture sets scroll inside the list; the footer stays in view
|
||||
let list_height = BODY_HEIGHT - header.rect.height() - ui.spacing().item_spacing.y;
|
||||
let list_height = ui.available_height();
|
||||
egui::ScrollArea::vertical().id_salt("export_texture_sets").max_height(list_height.max(0.0)).show(ui, |ui| set_rows(app, ui));
|
||||
}
|
||||
|
||||
@@ -1299,107 +1302,130 @@ 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();
|
||||
crate::windows::dialog("export_textures", tr("Export textures"), &mut open).fixed_size(vec2(900.0, 520.0)).show(ctx, |ui| {
|
||||
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));
|
||||
dialog.show(ctx, |ui| {
|
||||
// Nothing to export without a project
|
||||
if !app.session.project_open {
|
||||
ui.label(tr("No project is open"));
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// The file list opens the destination folder
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if app.ui.export.tab == 2 {
|
||||
// The browser downloads the files instead
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
crate::unavailable::greyed(ui, |ui| ui.button(tr("Open output directory")));
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
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() {
|
||||
app.ui.export.skip.clear();
|
||||
for o in app.ui.export.sets.values_mut() {
|
||||
o.maps.values_mut().for_each(|m| m.enabled = true);
|
||||
}
|
||||
app.ui.export.sets.retain(|_, o| !o.is_default());
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.allocate_ui_with_layout(vec2(ui.available_width(), BODY_HEIGHT), egui::Layout::left_to_right(egui::Align::Min), |ui| {
|
||||
ui.set_height(BODY_HEIGHT);
|
||||
match app.ui.export.tab {
|
||||
1 => {
|
||||
crate::export_templates::tab(app, ui, &presets);
|
||||
return;
|
||||
}
|
||||
2 => {
|
||||
list_tab(app, ui);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(LIST_WIDTH);
|
||||
set_list(app, ui);
|
||||
});
|
||||
ui.separator();
|
||||
ui.vertical(|ui| match app.ui.export.page {
|
||||
Some(ts) if ts < app.session.set_count() => set_page(app, ui, ts, &presets),
|
||||
_ => global_page(app, ui, &presets),
|
||||
});
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
|
||||
// While exporting: the progress and Cancel Export
|
||||
if let Some(job) = &app.ui.export.job {
|
||||
let done = job.total - job.pending.len();
|
||||
let progress = if job.total == 0 { 1.0 } else { done as f32 / job.total as f32 };
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if ui.button(tr("Cancel Export")).clicked() {
|
||||
app.ui.export.job = None;
|
||||
}
|
||||
let percent = format!("{:.0}%", progress * 100.0);
|
||||
ui.add(egui::ProgressBar::new(progress).text(percent));
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
|
||||
// While exporting: the progress and Cancel Export
|
||||
if let Some(job) = &app.ui.export.job {
|
||||
let done = job.total - job.pending.len();
|
||||
let progress = if job.total == 0 { 1.0 } else { done as f32 / job.total as f32 };
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if ui.button(tr("Cancel Export")).clicked() {
|
||||
app.ui.export.job = None;
|
||||
}
|
||||
let percent = format!("{:.0}%", progress * 100.0);
|
||||
ui.add(egui::ProgressBar::new(progress).text(percent));
|
||||
});
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
let selected = 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()
|
||||
{
|
||||
// Keep ownership so Cancel can restore the opening settings
|
||||
let e = &mut app.ui.export;
|
||||
let (opened_with, owner, owner_id) = (e.opened_with.take(), std::mem::take(&mut e.owner), e.owner_id);
|
||||
app.ui.export = ExportUi { opened_with, owner, owner_id, ..ExportUi::default() };
|
||||
}
|
||||
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();
|
||||
if ui
|
||||
.add_enabled(any, primary_button(ui, tr("Export")))
|
||||
.on_hover_text(tr("Write the selected textures using the settings above"))
|
||||
.clicked()
|
||||
{
|
||||
do_export = true;
|
||||
}
|
||||
|
||||
let selected = 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() {
|
||||
// Keep ownership so Cancel can restore the opening settings
|
||||
let e = &mut app.ui.export;
|
||||
let (opened_with, owner, owner_id) = (e.opened_with.take(), std::mem::take(&mut e.owner), e.owner_id);
|
||||
app.ui.export = ExportUi { opened_with, owner, owner_id, ..ExportUi::default() };
|
||||
// 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() {
|
||||
app.ui.windows.export = false;
|
||||
}
|
||||
if ui.button(tr("Cancel")).on_hover_text(tr("Restore the settings from when you opened this window")).clicked() {
|
||||
canceled = true;
|
||||
}
|
||||
ui.label(trf("{n} textures selected for export", &[("n", &selected)]));
|
||||
});
|
||||
});
|
||||
}
|
||||
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();
|
||||
if ui.add_enabled(any, primary_button(ui, tr("Export"))).on_hover_text(tr("Write the selected textures using the settings above")).clicked() {
|
||||
do_export = true;
|
||||
}
|
||||
ui.separator();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
app.ui.windows.export = false;
|
||||
// The file list opens the destination folder
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if app.ui.export.tab == 2 {
|
||||
// The browser downloads the files instead
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
crate::unavailable::greyed(ui, |ui| ui.button(tr("Open output directory")));
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
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() {
|
||||
app.ui.export.skip.clear();
|
||||
for o in app.ui.export.sets.values_mut() {
|
||||
o.maps.values_mut().for_each(|m| m.enabled = true);
|
||||
}
|
||||
app.ui.export.sets.retain(|_, o| !o.is_default());
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
let body = egui::Rect::from_min_size(ui.cursor().min, vec2(ui.available_width(), ui.available_height().max(0.0)));
|
||||
|
||||
// The tabs size their columns from the body's width. A child that cannot widen the
|
||||
// resizable window holds them, so an overflow is clipped instead of growing the window each frame
|
||||
let mut body_ui = ui.new_child(egui::UiBuilder::new().max_rect(body).layout(egui::Layout::left_to_right(egui::Align::Min)));
|
||||
body_ui.shrink_clip_rect(body);
|
||||
ui.advance_cursor_after_rect(body);
|
||||
let ui = &mut body_ui;
|
||||
'tab: {
|
||||
ui.set_height(body.height());
|
||||
match app.ui.export.tab {
|
||||
1 => {
|
||||
crate::export_templates::tab(app, ui, &presets);
|
||||
break 'tab;
|
||||
}
|
||||
2 => {
|
||||
list_tab(app, ui);
|
||||
break 'tab;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(LIST_WIDTH);
|
||||
set_list(app, ui);
|
||||
});
|
||||
ui.separator();
|
||||
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
|
||||
.export
|
||||
.page
|
||||
{
|
||||
Some(ts) if ts < app.session.set_count() => set_page(app, ui, ts, &presets),
|
||||
_ => global_page(app, ui, &presets),
|
||||
});
|
||||
});
|
||||
}
|
||||
if ui.button(tr("Cancel")).on_hover_text(tr("Restore the settings from when you opened this window")).clicked() {
|
||||
canceled = true;
|
||||
}
|
||||
ui.label(trf("{n} textures selected for export", &[("n", &selected)]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,10 +58,7 @@ pub(crate) fn generator_properties(app: &mut TextureCraftApp, ui: &mut Ui, layer
|
||||
});
|
||||
}
|
||||
if !app.session.doc.baked.contains_key(&app.session.ts()) {
|
||||
ui.label(
|
||||
RichText::new(format!("{} {}", ic::WARNING, tr("Bake mesh maps (Ctrl+Shift+B) for curvature, AO and thickness based generators.")))
|
||||
.color(tokens.warning),
|
||||
);
|
||||
ui.label(RichText::new(format!("{} {}", ic::WARNING, tr("Bake mesh maps for curvature, AO and thickness based generators."))).color(tokens.warning));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! File > Import resources...: a window to collect files, set what each is for, and import them
|
||||
//! together. Images become project resources; materials load as smart materials.
|
||||
//! together. Images become project resources; materials load as smart materials and MaterialX
|
||||
//! documents as fill layers.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
@@ -18,6 +19,8 @@ use crate::widgets::primary_button;
|
||||
const WINDOW_WIDTH_POINTS: f32 = 640.0;
|
||||
/// Height of the file list
|
||||
const LIST_HEIGHT_POINTS: f32 = 300.0;
|
||||
// Initial space for the title, file controls, destination and footer
|
||||
const WINDOW_CHROME_HEIGHT_POINTS: f32 = 200.0;
|
||||
/// Width of a row's prefix field and usage dropdown
|
||||
const PREFIX_WIDTH_POINTS: f32 = 160.0;
|
||||
const USAGE_WIDTH_POINTS: f32 = 110.0;
|
||||
@@ -59,9 +62,18 @@ pub(crate) fn keys_in(app: &mut TextureCraftApp, input: &mut egui::InputState, n
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the file is a material (loaded as a smart material, so it has no usage or prefix)
|
||||
fn extension_of(row: &ImportRow) -> String {
|
||||
row.path.extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Whether the file is a MaterialX document (added as a fill layer)
|
||||
fn is_materialx(row: &ImportRow) -> bool {
|
||||
extension_of(row) == crate::windows::MATERIALX_EXT
|
||||
}
|
||||
|
||||
/// Whether the file is a material (a smart material or a MaterialX document, so it has no usage or prefix)
|
||||
fn is_material(row: &ImportRow) -> bool {
|
||||
row.path.extension().and_then(|e| e.to_str()).is_some_and(|e| MATERIAL_EXTS.contains(&e.to_ascii_lowercase().as_str()))
|
||||
MATERIAL_EXTS.contains(&extension_of(row).as_str()) || is_materialx(row)
|
||||
}
|
||||
|
||||
fn file_name(row: &ImportRow) -> String {
|
||||
@@ -114,113 +126,132 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let (mut import, mut cancel, mut add) = (std::mem::take(&mut window.confirm), false, false);
|
||||
let mut remove = false;
|
||||
|
||||
crate::windows::dialog("import_resources", tr("Import resources"), &mut open).default_width(WINDOW_WIDTH_POINTS).show(ctx, |ui| {
|
||||
ui.set_min_width(WINDOW_WIDTH_POINTS);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Choose files and assign their roles"));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.add_enabled_ui(!window.selected.is_empty(), |ui| {
|
||||
remove = ui.button(tr("Remove selected resources")).clicked();
|
||||
});
|
||||
add = ui.button(tr("Add resources")).clicked();
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
let all_label = trf("All files ({count})", &[("count", &window.rows.len())]);
|
||||
let filter_text = match window.filter {
|
||||
None => all_label.clone(),
|
||||
Some(usage) => trf("{usage} ({count})", &[("usage", &usage.name()), ("count", &window.rows.iter().filter(|row| row.usage == usage).count())]),
|
||||
};
|
||||
egui::ComboBox::from_id_salt("import_filter").width(ui.available_width()).selected_text(filter_text).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(window.filter.is_none(), &all_label).clicked() {
|
||||
window.filter = None;
|
||||
}
|
||||
|
||||
// Only usages some row has, so the list is never empty by filter
|
||||
for usage in ResourceUsage::ALL {
|
||||
let count = window.rows.iter().filter(|row| row.usage == usage).count();
|
||||
if count > 0 && ui.selectable_label(window.filter == Some(usage), format!("{} ({count})", usage.name())).clicked() {
|
||||
window.filter = Some(usage);
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
let filter = window.filter;
|
||||
let visible = |row: &ImportRow| filter.is_none_or(|usage| row.usage == usage);
|
||||
let modifiers = ui.input(|i| i.modifiers);
|
||||
let mut clicked = None;
|
||||
|
||||
egui::ScrollArea::vertical().min_scrolled_height(LIST_HEIGHT_POINTS).max_height(LIST_HEIGHT_POINTS).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for row in window.rows.iter_mut().filter(|row| visible(row)) {
|
||||
let material = is_material(row);
|
||||
let selected = window.selected.contains(&row.id);
|
||||
crate::windows::dialog(ctx, "import_resources", tr("Import Resources"), &mut open)
|
||||
.default_size(egui::vec2(WINDOW_WIDTH_POINTS, LIST_HEIGHT_POINTS + WINDOW_CHROME_HEIGHT_POINTS))
|
||||
.show(ctx, |ui| {
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let name_width =
|
||||
(ui.available_width() - PREFIX_WIDTH_POINTS - USAGE_WIDTH_POINTS - 2.0 * ui.spacing().item_spacing.x).max(MIN_NAME_WIDTH_POINTS);
|
||||
let name = ui.add_sized([name_width, ui.spacing().interact_size.y], egui::Button::selectable(selected, file_name(row)).truncate());
|
||||
if name.on_hover_text(row.path.display().to_string()).clicked() {
|
||||
clicked = Some(row.id);
|
||||
}
|
||||
|
||||
let prefix = ui.add_enabled(
|
||||
!material,
|
||||
egui::TextEdit::singleline(&mut row.prefix).hint_text(tr("Optional prefix/path...")).desired_width(PREFIX_WIDTH_POINTS),
|
||||
);
|
||||
if material {
|
||||
prefix.on_disabled_hover_text(tr("Materials keep their own name"));
|
||||
} else {
|
||||
prefix.on_hover_text(tr("Put in front of the resource's name. Characters other than letters, digits and _ . - become _"));
|
||||
}
|
||||
|
||||
ui.add_enabled_ui(!material, |ui| {
|
||||
egui::ComboBox::from_id_salt(("import_usage", row.id)).width(USAGE_WIDTH_POINTS).selected_text(row.usage.name()).show_ui(ui, |ui| {
|
||||
for usage in ResourceUsage::ALL {
|
||||
let item = ui.add_enabled(usage.available(), egui::Button::selectable(row.usage == usage, usage.name()));
|
||||
if usage.available() {
|
||||
if item.clicked() {
|
||||
row.usage = usage;
|
||||
ui.close();
|
||||
}
|
||||
} else {
|
||||
item.on_disabled_hover_text(tr("Not available yet"));
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
cancel = ui.button(tr("Cancel")).clicked();
|
||||
import |= ui.add_enabled(app.session.project_open && !window.rows.is_empty(), primary_button(ui, tr("Import"))).clicked();
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
if !app.session.project_open {
|
||||
ui.label(tr("Open a project to import resources. Importing into the asset library is not available yet."));
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
egui::ComboBox::from_id_salt("import_target").width(TARGET_WIDTH_POINTS).selected_text(tr("Open project")).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(true, tr("Open project")).clicked() {
|
||||
ui.close();
|
||||
}
|
||||
|
||||
ui.add_enabled(false, egui::Button::selectable(false, tr("Asset library"))).on_disabled_hover_text(tr("Not available yet"));
|
||||
});
|
||||
})
|
||||
.response
|
||||
.on_disabled_hover_text(tr("Materials need no usage"));
|
||||
ui.label(tr("Destination"));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Choose files and assign their roles"));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.add_enabled_ui(!window.selected.is_empty(), |ui| {
|
||||
remove = ui.button(tr("Remove selected resources")).clicked();
|
||||
});
|
||||
add = ui.button(tr("Add resources")).clicked();
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
if let Some(id) = clicked {
|
||||
let visible: Vec<u64> = if modifiers.shift { window.rows.iter().filter(|row| visible(row)).map(|row| row.id).collect() } else { Vec::new() };
|
||||
click_row(&mut window, &visible, id, modifiers);
|
||||
}
|
||||
let all_label = trf("All files ({count})", &[("count", &window.rows.len())]);
|
||||
let filter_text = match window.filter {
|
||||
None => all_label.clone(),
|
||||
Some(usage) => {
|
||||
trf("{usage} ({count})", &[("usage", &usage.name()), ("count", &window.rows.iter().filter(|row| row.usage == usage).count())])
|
||||
}
|
||||
};
|
||||
egui::ComboBox::from_id_salt("import_filter").width(ui.available_width()).selected_text(filter_text).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(window.filter.is_none(), &all_label).clicked() {
|
||||
window.filter = None;
|
||||
}
|
||||
|
||||
ui.add_space(8.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
egui::ComboBox::from_id_salt("import_target").width(TARGET_WIDTH_POINTS).selected_text(tr("Open project")).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(true, tr("Open project")).clicked() {
|
||||
ui.close();
|
||||
// Only usages some row has, so the list is never empty by filter
|
||||
for usage in ResourceUsage::ALL {
|
||||
let count = window.rows.iter().filter(|row| row.usage == usage).count();
|
||||
if count > 0 && ui.selectable_label(window.filter == Some(usage), format!("{} ({count})", usage.name())).clicked() {
|
||||
window.filter = Some(usage);
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
let filter = window.filter;
|
||||
let visible = |row: &ImportRow| filter.is_none_or(|usage| row.usage == usage);
|
||||
let modifiers = ui.input(|i| i.modifiers);
|
||||
let mut clicked = None;
|
||||
|
||||
let list_height = ui.available_height().max(0.0);
|
||||
egui::ScrollArea::both().min_scrolled_width(0.0).min_scrolled_height(0.0).max_height(list_height).auto_shrink([false, false]).show(
|
||||
ui,
|
||||
|ui| {
|
||||
for row in window.rows.iter_mut().filter(|row| visible(row)) {
|
||||
let material = is_material(row);
|
||||
let selected = window.selected.contains(&row.id);
|
||||
ui.horizontal(|ui| {
|
||||
let name_width = (ui.available_width() - PREFIX_WIDTH_POINTS - USAGE_WIDTH_POINTS - 2.0 * ui.spacing().item_spacing.x)
|
||||
.max(MIN_NAME_WIDTH_POINTS);
|
||||
let name =
|
||||
ui.add_sized([name_width, ui.spacing().interact_size.y], egui::Button::selectable(selected, file_name(row)).truncate());
|
||||
if name.on_hover_text(row.path.display().to_string()).clicked() {
|
||||
clicked = Some(row.id);
|
||||
}
|
||||
|
||||
let prefix = ui.add_enabled(
|
||||
!material,
|
||||
egui::TextEdit::singleline(&mut row.prefix).hint_text(tr("Optional prefix/path...")).desired_width(PREFIX_WIDTH_POINTS),
|
||||
);
|
||||
if material {
|
||||
prefix.on_disabled_hover_text(tr("Materials keep their own name"));
|
||||
} else {
|
||||
prefix
|
||||
.on_hover_text(tr("Put in front of the resource's name. Characters other than letters, digits and _ . - become _"));
|
||||
}
|
||||
|
||||
ui.add_enabled_ui(!material, |ui| {
|
||||
egui::ComboBox::from_id_salt(("import_usage", row.id))
|
||||
.width(USAGE_WIDTH_POINTS)
|
||||
.selected_text(row.usage.name())
|
||||
.show_ui(ui, |ui| {
|
||||
for usage in ResourceUsage::ALL {
|
||||
let item = ui.add_enabled(usage.available(), egui::Button::selectable(row.usage == usage, usage.name()));
|
||||
if usage.available() {
|
||||
if item.clicked() {
|
||||
row.usage = usage;
|
||||
ui.close();
|
||||
}
|
||||
} else {
|
||||
item.on_disabled_hover_text(tr("Not available yet"));
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.response
|
||||
.on_disabled_hover_text(tr("Materials need no usage"));
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(id) = clicked {
|
||||
let visible: Vec<u64> =
|
||||
if modifiers.shift { window.rows.iter().filter(|row| visible(row)).map(|row| row.id).collect() } else { Vec::new() };
|
||||
click_row(&mut window, &visible, id, modifiers);
|
||||
}
|
||||
|
||||
ui.add_enabled(false, egui::Button::selectable(false, tr("Asset library"))).on_disabled_hover_text(tr("Not available yet"));
|
||||
});
|
||||
ui.label(tr("Destination"));
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
cancel = ui.button(tr("Cancel")).clicked();
|
||||
import |= ui.add_enabled(!window.rows.is_empty(), primary_button(ui, tr("Import"))).clicked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if cancel || !open {
|
||||
return;
|
||||
@@ -235,6 +266,7 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
if add {
|
||||
let mut extensions: Vec<&str> = IMAGE_EXTS.to_vec();
|
||||
extensions.extend_from_slice(MATERIAL_EXTS);
|
||||
extensions.push(crate::windows::MATERIALX_EXT);
|
||||
let opening_id = window.opening_id;
|
||||
app.ask_file(FileDialog::open_many().filter(tr("Resources"), &extensions), Bound::Project, move |app, paths| {
|
||||
let Some(stored) = app.ui.windows.import_resources.as_mut().filter(|stored| stored.opening_id == opening_id) else { return };
|
||||
@@ -250,7 +282,7 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
});
|
||||
}
|
||||
|
||||
if import && !window.rows.is_empty() {
|
||||
if import && app.session.project_open && !window.rows.is_empty() {
|
||||
window.rows.retain(|row| !import_row(app, row));
|
||||
if window.rows.is_empty() {
|
||||
app.ui.dock.focus(crate::docking::Panel::Assets);
|
||||
@@ -272,6 +304,10 @@ fn import_row(app: &mut TextureCraftApp, row: &ImportRow) -> bool {
|
||||
return false;
|
||||
};
|
||||
|
||||
if is_materialx(row) {
|
||||
return crate::windows::import_materialx(app, path);
|
||||
}
|
||||
|
||||
if is_material(row) {
|
||||
return app.run("material.load", json!({ "path": path })).is_some();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ const LISTED_SHORTCUTS: &[ShortcutListEntry] = &[
|
||||
ShortcutListEntry::new("ui.quit", "Quit application", Some("Ctrl+Q")),
|
||||
ShortcutListEntry::new("ui.export", "Export Textures...", Some("Ctrl+Shift+E")),
|
||||
ShortcutListEntry::new("file.reimportMesh", "Reimport mesh", Some("Ctrl+Shift+R")),
|
||||
ShortcutListEntry::new("ui.mode.bake", "Switch to baking mode", Some("Ctrl+Shift+B")),
|
||||
ShortcutListEntry::new("ui.mode.bake", "Switch to baking mode", Some("F8")),
|
||||
ShortcutListEntry::new("ui.mode.paint", "Switch to edition mode", Some("F9")),
|
||||
ShortcutListEntry::new("ui.mode.render", "Switch to rendering mode (path traced)", Some("F10")),
|
||||
ShortcutListEntry::new("ui.wireframe", "Show mesh wireframe", None),
|
||||
@@ -76,6 +76,11 @@ const LISTED_SHORTCUTS: &[ShortcutListEntry] = &[
|
||||
ShortcutListEntry::new("ui.layout.3d", "Viewers layout: 3D only", Some("F2")),
|
||||
ShortcutListEntry::new("ui.layout.2d", "Viewers layout: 2D only", Some("F3")),
|
||||
ShortcutListEntry::new("ui.layout.swap", "Viewers layout: Swap 3D/2D", Some("F4")),
|
||||
ShortcutListEntry::new("ui.layout.saveAs", "Save current layout as...", None),
|
||||
ShortcutListEntry::new("ui.layout.manage", "Manage layouts...", None),
|
||||
ShortcutListEntry::new("ui.resetPanelLayout", "Reset panel layout", None),
|
||||
ShortcutListEntry::new("ui.navButtons", "Navigation buttons", None),
|
||||
ShortcutListEntry::new("ui.uvChecker", "UV checker", None),
|
||||
];
|
||||
|
||||
/// The menu a command without a menu entry is listed under, from its id.
|
||||
@@ -515,7 +520,7 @@ pub fn window(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
app.bindings.sync(&app.ui.keymap, craft_keymap::egui::platform(ctx));
|
||||
let mut filter: String = ctx.data(|d| d.get_temp(filter_id)).unwrap_or_default();
|
||||
let mut open = true;
|
||||
crate::windows::window("keyboard_shortcuts", tr("Keyboard shortcuts"), &mut open).default_width(480.0).show(ctx, |ui| {
|
||||
crate::windows::window("keyboard_shortcuts", tr("Keyboard Shortcuts"), &mut open).default_width(480.0).show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(ic::MAGNIFYING_GLASS).color(tk.text_dim));
|
||||
ui.add(egui::TextEdit::singleline(&mut filter).hint_text(tr("Search commands or keys")).desired_width(300.0));
|
||||
|
||||
@@ -74,6 +74,8 @@ mod material_orb;
|
||||
mod material_preview_image;
|
||||
pub mod menus;
|
||||
mod mesh_export_options;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod mode_layout;
|
||||
mod move_hold;
|
||||
pub mod move_on_model;
|
||||
mod name_error;
|
||||
@@ -128,6 +130,8 @@ pub mod saved_search;
|
||||
mod screen_color_pick;
|
||||
pub mod screen_pick;
|
||||
mod section_page;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod session_log_file;
|
||||
pub mod settings_window;
|
||||
pub mod shader_settings;
|
||||
pub mod shelf;
|
||||
@@ -235,6 +239,8 @@ pub struct Toast {
|
||||
|
||||
pub struct TextureCraftApp {
|
||||
pub session: Session,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) session_log_file: Option<session_log_file::SessionLogFile>,
|
||||
viewport_mesh_bounds: viewport_mesh_bounds::ViewportMeshBounds,
|
||||
/// A smooth move to a saved camera in progress.
|
||||
camera_glide: Option<CameraGlide>,
|
||||
@@ -369,6 +375,7 @@ impl TextureCraftApp {
|
||||
// The first run speaks the OS (or browser) language
|
||||
let mut ui_store = ui_state_store::UiStateStore::new(ui_state_store::FILE.get().cloned());
|
||||
let mut ui = start_ui(ui_store.load(cc.storage), &mut session);
|
||||
ui.trim_recent();
|
||||
|
||||
// No window opens by itself with no project (a saved layout may have left Export open)
|
||||
if !session.project_open {
|
||||
@@ -385,6 +392,8 @@ impl TextureCraftApp {
|
||||
uv_rotation_snap: None,
|
||||
uv_view_reset: false,
|
||||
session,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
session_log_file: None,
|
||||
viewport_mesh_bounds: viewport_mesh_bounds::ViewportMeshBounds::default(),
|
||||
ui,
|
||||
ui_store,
|
||||
@@ -457,6 +466,13 @@ impl TextureCraftApp {
|
||||
// The first window of the process fixes it; a new folder applies on restart
|
||||
let _ = DATA_FOLDER.set(data_folder(&app.ui.prefs.data_folder));
|
||||
|
||||
if cc.winit_window().is_some() {
|
||||
match session_log_file::SessionLogFile::start(&crate::data_dir().join("logs")) {
|
||||
Ok(file) => app.session_log_file = Some(file),
|
||||
Err(error) => app.toast(format!("{}: {error}", i18n::tr("Could not create the session log")), true),
|
||||
}
|
||||
}
|
||||
|
||||
// An export folder still at the default follows the data folder
|
||||
if app.ui.export.dir == data_folder("").join("export").display().to_string() {
|
||||
app.ui.export.dir = user_dir("export").display().to_string();
|
||||
@@ -1132,6 +1148,13 @@ impl eframe::App for TextureCraftApp {
|
||||
}
|
||||
profile::drive(self, ctx);
|
||||
self.toasts.retain(|toast| toast.until > now);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(file) = &mut self.session_log_file
|
||||
&& let Err(error) = file.sync(self.session.log_id, &self.session.log)
|
||||
{
|
||||
self.session_log_file = None;
|
||||
self.toast(format!("{}: {error}", i18n::tr("Could not update the session log")), true);
|
||||
}
|
||||
self.profiler.logic_ms = (now_ms() - logic_start_ms) as f32;
|
||||
|
||||
// Last, so it sees every close request this frame's work made
|
||||
@@ -1152,9 +1175,7 @@ impl eframe::App for TextureCraftApp {
|
||||
titlebar::show(self, ui);
|
||||
banner(self, ui);
|
||||
toolbar::status_bar(self, ui);
|
||||
if self.ui.toolbar_tools {
|
||||
toolbar::tool_shelf(self, ui);
|
||||
}
|
||||
toolbar::tool_shelf(self, ui);
|
||||
self.ui.sync_mode_dock();
|
||||
if self.ui.mode != state::Mode::Baking && self.ui.toolbar_docks {
|
||||
toolbar::rail(self, ui);
|
||||
|
||||
+102
-102
@@ -2,7 +2,7 @@
|
||||
//! texture-painting workflow, with stable ids; an item is live when the engine (or the shell, for `ui.*` ids) implements
|
||||
//! its id. The same catalog drives `docs/parity.md`.
|
||||
|
||||
use egui::{Key, Modifiers};
|
||||
use egui::{Key, Modifiers, class::HasClasses as _};
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::Tool;
|
||||
|
||||
@@ -36,38 +36,36 @@ pub const TOP: [&str; 6] = ["File", "Edit", "Mode", "Window", "Viewport", "Help"
|
||||
|
||||
/// The menu catalog (the target menu tree with our ids).
|
||||
pub const CATALOG: &[Item] = &[
|
||||
it("File", "New project...", "ui.newProject", Some("Ctrl+N")),
|
||||
it("File", "Open...", "file.open", Some("Ctrl+O")),
|
||||
it("File", "New Project", "ui.newProject", Some("Ctrl+N")),
|
||||
it("File", "Open", "file.open", Some("Ctrl+O")),
|
||||
sub("File", "Recent Projects", "Clear", "ui.recent.clear", None),
|
||||
sep("File"),
|
||||
it("File", "Open sample project...", "project.sample", None),
|
||||
it("File", "Open Sample Project", "project.sample", None),
|
||||
sep("File"),
|
||||
it("File", "Close", "file.close", Some("Ctrl+F4")),
|
||||
sep("File"),
|
||||
it("File", "Save", "file.save", Some("Ctrl+S")),
|
||||
it("File", "Save as...", "file.saveAs", Some("Ctrl+Shift+S")),
|
||||
sub("File", "More save options", "Save as template...", "ui.saveAsTemplate", None),
|
||||
sub("File", "More save options", "Save and reduce file size", "ui.saveReduced", None),
|
||||
sub("File", "More save options", "Save as copy...", "file.saveCopy", None),
|
||||
it("File", "Remove unused resources...", "file.removeUnused", None),
|
||||
it("File", "Save As", "file.saveAs", Some("Ctrl+Shift+S")),
|
||||
sub("File", "More Save Options", "Save As Template", "ui.saveAsTemplate", None),
|
||||
sub("File", "More Save Options", "Save and Reduce File Size", "ui.saveReduced", None),
|
||||
sub("File", "More Save Options", "Save As Copy", "file.saveCopy", None),
|
||||
it("File", "Remove Unused Resources", "file.removeUnused", None),
|
||||
sep("File"),
|
||||
it("File", "Import resources...", "resource.import", None),
|
||||
it("File", "Import MaterialX material...", "file.importMaterialX", None),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
it("File", "Import PBR texture folder...", "file.importPbrFolder", None),
|
||||
it("File", "Import material...", "material.load", None),
|
||||
it("File", "Export Textures...", "ui.export", Some("Ctrl+Shift+E")),
|
||||
it("File", "Export Mesh...", "file.exportMesh", None),
|
||||
it("File", "Import Resources", "resource.import", None),
|
||||
it("File", "Export Textures", "ui.export", Some("Ctrl+Shift+E")),
|
||||
it("File", "Export Mesh", "file.exportMesh", None),
|
||||
sep("File"),
|
||||
it("File", "Quit", "ui.quit", Some("Ctrl+Q")),
|
||||
it("Edit", "Undo", "edit.undo", Some("Ctrl+Z")),
|
||||
it("Edit", "Redo", "edit.redo", Some("Ctrl+Y")),
|
||||
it("Edit", "Project Configuration...", "ui.projectConfig", None),
|
||||
it("Edit", "Reimport mesh", "file.reimportMesh", Some("Ctrl+Shift+R")),
|
||||
it("Edit", "Settings...", "ui.settings", None),
|
||||
it("Mode", "Bake Mesh Maps", "ui.mode.bake", Some("Ctrl+Shift+B")),
|
||||
it("Edit", "Project Configuration", "ui.projectConfig", None),
|
||||
it("Edit", "Reimport Mesh", "file.reimportMesh", Some("Ctrl+Shift+R")),
|
||||
it("Edit", "Settings", "ui.settings", None),
|
||||
it("Mode", "Bake Mesh Maps", "ui.mode.bake", Some("F8")),
|
||||
it("Mode", "Painting", "ui.mode.paint", Some("F9")),
|
||||
it("Mode", "Rendering (path traced)", "ui.mode.render", Some("F10")),
|
||||
it("Mode", "Rendering", "ui.mode.render", Some("F10")),
|
||||
sub("Window", "Views", "Assets", "ui.view.assets", None),
|
||||
sub("Window", "Views", "Baking Log", "ui.view.bakingLog", None),
|
||||
sub("Window", "Views", "Common Settings", "ui.view.bakeSettings", None),
|
||||
sub("Window", "Views", "Display Settings", "ui.view.display", None),
|
||||
sub("Window", "Views", "Export", "ui.view.export", None),
|
||||
@@ -77,68 +75,43 @@ pub const CATALOG: &[Item] = &[
|
||||
sub("Window", "Views", "Mesh Map Bakers", "ui.view.meshMapBakers", None),
|
||||
sub("Window", "Views", "Mesh Map Settings", "ui.view.bakeMaps", None),
|
||||
sub("Window", "Views", "Properties", "ui.view.properties", None),
|
||||
sub("Window", "Views", "Python Console", "ui.view.pythonConsole", None),
|
||||
sub("Window", "Views", "Renderer Settings", "ui.view.renderer", None),
|
||||
sub("Window", "Views", "Shader Settings", "ui.view.shader", None),
|
||||
sub("Window", "Views", "Online assets", "ui.view.onlineAssets", None),
|
||||
sub("Window", "Views", "Texture Sets", "ui.view.textureSetList", None),
|
||||
sub("Window", "Views", "Texture Set List", "ui.view.textureSetList", None),
|
||||
sub("Window", "Views", "Texture Set Settings", "ui.view.textureSetSettings", None),
|
||||
sub("Window", "Toolbars", "Docks", "ui.toolbar.docks", None),
|
||||
sub("Window", "Toolbars", "Plugins", "ui.toolbar.plugins", None),
|
||||
sub("Window", "Toolbars", "Tools", "ui.toolbar.tools", None),
|
||||
sep("Window"),
|
||||
sub("Window", "Save UI Layout", "Painting mode", "ui.layout.save.painting", None),
|
||||
sub("Window", "Save UI Layout", "Rendering mode", "ui.layout.save.rendering", None),
|
||||
sub("Window", "Save UI Layout", "Baking mode", "ui.layout.save.baking", None),
|
||||
sub("Window", "Save UI Layout", "Painting Mode", "ui.layout.save.painting", None),
|
||||
sub("Window", "Save UI Layout", "Rendering Mode", "ui.layout.save.rendering", None),
|
||||
sub("Window", "Save UI Layout", "Baking Mode", "ui.layout.save.baking", None),
|
||||
it("Window", "Load UI Layout", "ui.layout.load", None),
|
||||
sub("Window", "Layouts", "Save current layout as...", "ui.layout.saveAs", None),
|
||||
sub("Window", "Layouts", "Manage layouts...", "ui.layout.manage", None),
|
||||
sep("Window"),
|
||||
it("Window", "Hide UI", "ui.hideUi", Some("Tab")),
|
||||
it("Window", "Reset panel layout", "ui.resetPanelLayout", None),
|
||||
it("Window", "Reset UI", "ui.resetUi", None),
|
||||
it("Viewport", "Display material", "viewport.displayMaterial", Some("M")),
|
||||
it("Viewport", "Display next channel", "viewport.nextChannel", Some("C")),
|
||||
it("Viewport", "Display previous channel", "viewport.previousChannel", Some("Shift+C")),
|
||||
it("Viewport", "Display next mesh map", "viewport.nextMeshMap", Some("B")),
|
||||
it("Viewport", "Display previous mesh map", "viewport.previousMeshMap", Some("Shift+B")),
|
||||
it("Viewport", "UV checker", "ui.uvChecker", None),
|
||||
it("Viewport", "Display Material", "viewport.displayMaterial", Some("M")),
|
||||
it("Viewport", "Display Next Channel", "viewport.nextChannel", Some("C")),
|
||||
it("Viewport", "Display Previous Channel", "viewport.previousChannel", Some("Shift+C")),
|
||||
it("Viewport", "Display Next Mesh Map", "viewport.nextMeshMap", Some("B")),
|
||||
it("Viewport", "Display Previous Mesh Map", "viewport.previousMeshMap", Some("Shift+B")),
|
||||
sep("Viewport"),
|
||||
it("Viewport", "Frame texture set", "viewport.frameSelection", Some("Shift+F")),
|
||||
it("Viewport", "Show entire mesh", "viewport.frame", Some("F")),
|
||||
it("Viewport", "Front view", "camera.view.front", None),
|
||||
it("Viewport", "Back view", "camera.view.back", None),
|
||||
it("Viewport", "Left view", "camera.view.left", None),
|
||||
it("Viewport", "Right view", "camera.view.right", None),
|
||||
it("Viewport", "Top view", "camera.view.top", None),
|
||||
it("Viewport", "Bottom view", "camera.view.bottom", None),
|
||||
it("Viewport", "Show Entire Mesh/Path", "viewport.frame", Some("F")),
|
||||
sep("Viewport"),
|
||||
it("Viewport", "Perspective", "camera.perspective", Some("F5")),
|
||||
it("Viewport", "Orthographic", "camera.orthographic", Some("F6")),
|
||||
sep("Viewport"),
|
||||
it("Viewport", "3D/2D views", "ui.layout.split", Some("F1")),
|
||||
it("Viewport", "3D view only", "ui.layout.3d", Some("F2")),
|
||||
it("Viewport", "2D view only", "ui.layout.2d", Some("F3")),
|
||||
it("Viewport", "Swap 3D/2D", "ui.layout.swap", Some("F4")),
|
||||
sep("Viewport"),
|
||||
it("Viewport", "Navigation buttons", "ui.navButtons", None),
|
||||
sep("Viewport"),
|
||||
it("Viewport", "Enable quick mask", "viewport.quickMask", Some("Y")),
|
||||
it("Viewport", "Edit quick mask", "viewport.quickMask.edit", Some("U")),
|
||||
it("Viewport", "Invert quick mask", "viewport.quickMask.invert", Some("Ctrl+Shift+I")),
|
||||
it("Help", "Release notes...", "ui.help.releaseNotes", None),
|
||||
it("Help", "Documentation...", "ui.help.docs", None),
|
||||
it("Help", "Shortcuts list...", "ui.help.shortcuts", None),
|
||||
it("Viewport", "Enable Quick Mask", "viewport.quickMask", Some("Y")),
|
||||
it("Viewport", "Edit Quick Mask", "viewport.quickMask.edit", Some("U")),
|
||||
it("Viewport", "Invert Quick Mask", "viewport.quickMask.invert", Some("Ctrl+Shift+I")),
|
||||
it("Help", "Release Notes", "ui.help.releaseNotes", None),
|
||||
it("Help", "Documentation", "ui.help.docs", None),
|
||||
it("Help", "Shortcuts List", "ui.help.shortcuts", None),
|
||||
sep("Help"),
|
||||
it("Help", "Join the community (Discord)...", "ui.help.discord", None),
|
||||
it("Help", "ArtCraft website...", "ui.help.website", None),
|
||||
it("Help", "Report a bug...", "ui.help.bug", None),
|
||||
it("Help", "Show log...", "ui.view.log", None),
|
||||
it("Help", "Export log...", "ui.help.exportLog", None),
|
||||
it("Help", "Discord", "ui.help.discord", None),
|
||||
it("Help", "Report a Bug", "ui.help.bug", None),
|
||||
it("Help", "Show Log", "ui.help.showLog", None),
|
||||
it("Help", "Export Log", "ui.help.exportLog", None),
|
||||
sep("Help"),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
it("Help", "Check for Updates...", "ui.help.checkForUpdates", None),
|
||||
it("Help", "About TextureCraft...", "ui.about", None),
|
||||
it("Help", "Check for Updates", "ui.help.checkForUpdates", None),
|
||||
it("Help", "About TextureCraft", "ui.about", None),
|
||||
];
|
||||
|
||||
/// Ids the shell handles itself.
|
||||
@@ -179,8 +152,19 @@ pub fn enabled(app: &TextureCraftApp, id: &str) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if id == "ui.recent.clear" {
|
||||
return !app.ui.recent.is_empty();
|
||||
}
|
||||
|
||||
// Opening the import dialog is independent of importing into a project
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if id == "resource.import" {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(panel) = crate::docking::view_panel(id) {
|
||||
return panel.available_in(app.ui.mode);
|
||||
let mode = if app.session.project_open { app.ui.mode } else { Mode::Painting };
|
||||
return panel.available_in(mode);
|
||||
}
|
||||
|
||||
if app.ui.mode != Mode::Painting && (id.starts_with("tool.") || id.starts_with("viewport.quickMask")) {
|
||||
@@ -219,7 +203,7 @@ pub fn invoke(app: &mut TextureCraftApp, ctx: &egui::Context, id: &str) {
|
||||
return;
|
||||
}
|
||||
|
||||
if matches!(id, "file.open" | "file.close" | "project.sample") && crate::windows::ask_to_save(app, crate::state::Unsaved::Command(id.into())) {
|
||||
if matches!(id, "file.open" | "file.close") && crate::windows::ask_to_save(app, crate::state::Unsaved::Command(id.into())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,6 +217,7 @@ pub fn invoke(app: &mut TextureCraftApp, ctx: &egui::Context, id: &str) {
|
||||
}
|
||||
|
||||
match id {
|
||||
"ui.recent.clear" => app.ui.recent.clear(),
|
||||
"ui.newProject" => crate::new_project_advanced::open(app),
|
||||
"ui.export" => app.ui.windows.export = true,
|
||||
|
||||
@@ -274,7 +259,14 @@ pub fn invoke(app: &mut TextureCraftApp, ctx: &egui::Context, id: &str) {
|
||||
"ui.layout.3d" => app.ui.layout = ViewLayout::Only3D,
|
||||
"ui.layout.2d" => app.ui.layout = ViewLayout::Only2D,
|
||||
"ui.layout.swap" => app.ui.swap_views = !app.ui.swap_views,
|
||||
"ui.help.shortcuts" => app.ui.windows.shortcuts = true,
|
||||
"ui.help.shortcuts" => {
|
||||
app.ui.windows.shortcuts = false;
|
||||
app.ui.windows.settings = true;
|
||||
app.ui.windows.settings_page = crate::settings_window::SettingsPage::Shortcuts;
|
||||
if let Some(draft) = &mut app.ui.windows.settings_draft {
|
||||
draft.page = crate::settings_window::SettingsPage::Shortcuts;
|
||||
}
|
||||
}
|
||||
"ui.about" => app.ui.windows.about = true,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
"ui.help.checkForUpdates" => crate::updates_ui::request_check(app, ctx),
|
||||
@@ -282,6 +274,7 @@ pub fn invoke(app: &mut TextureCraftApp, ctx: &egui::Context, id: &str) {
|
||||
"ui.help.website" => ctx.open_url(egui::OpenUrl::new_tab("https://getartcraft.com/apps/texturecraft")),
|
||||
"ui.help.docs" => ctx.open_url(egui::OpenUrl::new_tab("https://github.com/storytold/texturecraft#readme")),
|
||||
"ui.help.releaseNotes" => ctx.open_url(egui::OpenUrl::new_tab("https://github.com/storytold/texturecraft/releases")),
|
||||
"ui.help.showLog" => crate::windows::show_log(app, ctx),
|
||||
"ui.help.exportLog" => crate::windows::export_log(app),
|
||||
"ui.help.bug" => ctx.open_url(egui::OpenUrl::new_tab("https://github.com/storytold/texturecraft/issues")),
|
||||
_ => {
|
||||
@@ -311,13 +304,23 @@ pub fn menu_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
|
||||
current_sub = Some(s);
|
||||
ui.menu_button(tr(s), |ui| {
|
||||
for x in items.iter().filter(|x| x.sub == Some(s)) {
|
||||
menu_item(app, &ctx, ui, x);
|
||||
}
|
||||
if s == "Layouts" {
|
||||
crate::named_layouts::entries(app, ui);
|
||||
}
|
||||
let submenu_enabled = s != "More Save Options" || app.session.project_open;
|
||||
ui.add_enabled_ui(submenu_enabled, |ui| {
|
||||
ui.menu_button((menu_mark(ui, None), tr(s)), |ui| {
|
||||
if s == "Recent Projects" {
|
||||
for path in app.ui.recent.clone() {
|
||||
if ui.button((menu_mark(ui, None), path.as_str())).clicked() {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
crate::windows::open_path(app, &path);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
for x in items.iter().filter(|x| x.sub == Some(s)) {
|
||||
menu_item(app, &ctx, ui, x);
|
||||
}
|
||||
})
|
||||
});
|
||||
continue;
|
||||
}
|
||||
@@ -342,12 +345,10 @@ pub fn menu_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The check mark an item shows: the mode and view items, the toolbars and Hide UI (None: not checkable)
|
||||
/// The check mark an item shows: view items, toolbars and Hide UI (None: not checkable)
|
||||
pub fn checked(app: &TextureCraftApp, id: &str) -> Option<bool> {
|
||||
match id {
|
||||
"ui.mode.paint" => Some(app.ui.mode == Mode::Painting),
|
||||
"ui.mode.bake" => Some(app.ui.mode == Mode::Baking),
|
||||
"ui.mode.render" => Some(app.ui.mode == Mode::Rendering),
|
||||
"viewport.quickMask" => Some(!app.session.project_open || app.session.quick_mask.enabled),
|
||||
"ui.navButtons" => Some(app.ui.nav_buttons),
|
||||
"ui.hideUi" => Some(app.ui.hide_ui),
|
||||
"ui.toolbar.docks" => Some(app.ui.toolbar_docks),
|
||||
@@ -358,15 +359,32 @@ pub fn checked(app: &TextureCraftApp, id: &str) -> Option<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reserve the same checkmark column for actions, submenu headings and recent paths.
|
||||
fn menu_mark(ui: &egui::Ui, checked: Option<bool>) -> egui::Atom<'static> {
|
||||
egui::Atom::paint(egui::Vec2::splat(ui.spacing().icon_width), move |ui, args| {
|
||||
if checked == Some(true) {
|
||||
ui.painter().text(
|
||||
args.rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
egui_phosphor::regular::CHECK,
|
||||
egui::TextStyle::Button.resolve(ui.style()),
|
||||
args.fallback_text_color,
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn menu_item(app: &mut TextureCraftApp, ctx: &egui::Context, ui: &mut egui::Ui, item: &Item) {
|
||||
let on = enabled(app, item.id);
|
||||
let mut b = egui::Button::new(item_label(app, item));
|
||||
let checked = checked(app, item.id);
|
||||
let mut b = egui::Button::new((menu_mark(ui, checked), item_label(app, item)));
|
||||
if let Some(sc) = crate::keymap::shortcut_of(&app.ui.keymap, item.id) {
|
||||
b = b.shortcut_text(sc);
|
||||
}
|
||||
let checked = checked(app, item.id);
|
||||
if let Some(c) = checked {
|
||||
// Keep the accessible checked state; the checkmark supplies the visual state
|
||||
b = b.selected(c);
|
||||
b.set_class(egui::Button::CLASS_SELECTED, false);
|
||||
}
|
||||
let mut response = ui.add_enabled(on, b);
|
||||
if let Some(tip) = tooltip_of(item.id) {
|
||||
@@ -379,24 +397,6 @@ fn menu_item(app: &mut TextureCraftApp, ctx: &egui::Context, ui: &mut egui::Ui,
|
||||
invoke(app, ctx, item.id);
|
||||
ui.close();
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if item.id == "file.open" {
|
||||
ui.add_enabled_ui(!app.ui.recent.is_empty(), |ui| {
|
||||
ui.menu_button(tr("Recent projects"), |ui| {
|
||||
for path in app.ui.recent.clone() {
|
||||
if ui.button(&path).clicked() {
|
||||
crate::windows::open_path(app, &path);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button(tr("Clear recent projects")).clicked() {
|
||||
app.ui.recent.clear();
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Global shortcuts: the catalog's and every engine command's (defaults or the user's keymap),
|
||||
|
||||
@@ -22,7 +22,7 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
|
||||
let mut open = true;
|
||||
let (mut export, mut cancel) = (false, false);
|
||||
crate::windows::dialog("mesh_export_options", tr("Mesh Export Options"), &mut open).show(ctx, |ui| {
|
||||
crate::windows::dialog(ctx, "mesh_export_options", tr("Mesh Export Options"), &mut open).show(ctx, |ui| {
|
||||
// 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"));
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//! A layout file contains one mode's panels and view arrangement, never preferences or recent files.
|
||||
use crate::{
|
||||
docking::Dock,
|
||||
state::{Mode, UiState, ViewLayout},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct ModeLayout {
|
||||
pub mode: Mode,
|
||||
dock: Dock,
|
||||
layout: ViewLayout,
|
||||
swap_views: bool,
|
||||
split_ratio: f32,
|
||||
toolbar_docks: bool,
|
||||
toolbar_tools: bool,
|
||||
}
|
||||
|
||||
impl ModeLayout {
|
||||
pub fn of(ui: &UiState, mode: Mode) -> Self {
|
||||
let mut state = ui.clone();
|
||||
state.mode = mode;
|
||||
state.sync_mode_dock();
|
||||
Self {
|
||||
mode,
|
||||
dock: state.dock,
|
||||
layout: state.layout,
|
||||
swap_views: state.swap_views,
|
||||
split_ratio: state.split_ratio,
|
||||
toolbar_docks: state.toolbar_docks,
|
||||
toolbar_tools: state.toolbar_tools,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply(self, ui: &mut UiState) {
|
||||
ui.mode = self.mode;
|
||||
ui.sync_mode_dock();
|
||||
ui.dock = self.dock;
|
||||
ui.layout = self.layout;
|
||||
ui.swap_views = self.swap_views;
|
||||
ui.split_ratio = self.split_ratio;
|
||||
ui.toolbar_docks = self.toolbar_docks;
|
||||
ui.toolbar_tools = self.toolbar_tools;
|
||||
ui.rail_panel = None;
|
||||
}
|
||||
|
||||
pub fn read(bytes: &[u8]) -> Result<Self, String> {
|
||||
let value: serde_json::Value = serde_json::from_slice(bytes).map_err(|error| error.to_string())?;
|
||||
let layout: Self = if value.get("windows").is_some() {
|
||||
let state: UiState = serde_json::from_value(value).map_err(|error| error.to_string())?;
|
||||
if !crate::ui_state_store::fully_read(&state) {
|
||||
return Err("Invalid UI layout".into());
|
||||
}
|
||||
|
||||
Self::of(&state, state.mode)
|
||||
} else {
|
||||
serde_json::from_value(value).map_err(|error| error.to_string())?
|
||||
};
|
||||
if !layout.split_ratio.is_finite() || !(0.0..=1.0).contains(&layout.split_ratio) || layout.dock.replaced_unreadable() {
|
||||
return Err("Invalid UI layout".into());
|
||||
}
|
||||
|
||||
Ok(layout)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Window > Layouts: panel arrangements saved under a name and switched from the menu.
|
||||
//! Named panel arrangements retained for shortcuts and automation.
|
||||
//!
|
||||
//! A named layout holds the painting and the baking dock (which panels are shown, where, and
|
||||
//! how big). Switching to one touches nothing else: not the mode, the zoom, the wireframes, the
|
||||
@@ -30,7 +30,13 @@ impl UiState {
|
||||
return false;
|
||||
}
|
||||
|
||||
let (painting, baking) = if self.dock_is_baking { (&self.inactive_mode_dock, &self.dock) } else { (&self.dock, &self.inactive_mode_dock) };
|
||||
let (painting, baking) = if self.dock_is_baking {
|
||||
(&self.inactive_mode_dock, &self.dock)
|
||||
} else if self.dock_is_rendering {
|
||||
(self.inactive_render_dock.as_ref().unwrap_or(&self.dock), &self.inactive_mode_dock)
|
||||
} else {
|
||||
(&self.dock, &self.inactive_mode_dock)
|
||||
};
|
||||
let layout = NamedLayout { name: name.to_string(), painting: painting.clone(), baking: baking.clone() };
|
||||
match self.named_layout_index(name) {
|
||||
Some(index) => self.named_layouts[index] = layout,
|
||||
@@ -74,21 +80,6 @@ impl UiState {
|
||||
}
|
||||
}
|
||||
|
||||
/// One entry per saved layout, under the catalog's items of the Layouts submenu
|
||||
pub(crate) fn entries(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
if app.ui.named_layouts.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
for name in app.ui.named_layouts.iter().map(|layout| layout.name.clone()).collect::<Vec<_>>() {
|
||||
if ui.button(&name).clicked() {
|
||||
app.ui.apply_named_layout(&name);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The save, overwrite and manage dialogs
|
||||
pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
forget_finished_focus(app, ctx);
|
||||
@@ -136,7 +127,7 @@ fn focus_once(ui: &egui::Ui, edit: &egui::Response, key: &'static str, what: Str
|
||||
|
||||
fn save_dialog(app: &mut TextureCraftApp, ctx: &egui::Context, open: &mut bool, mut name: String) -> Option<LayoutDialog> {
|
||||
let mut done = None;
|
||||
dialog("save_layout", tr("Save layout"), open).show(ctx, |ui| {
|
||||
dialog(ctx, "save_layout", tr("Save Layout"), open).show(ctx, |ui| {
|
||||
ui.label(tr("Name of the layout"));
|
||||
let edit = ui.add(egui::TextEdit::singleline(&mut name).desired_width(240.0));
|
||||
focus_once(ui, &edit, SAVE_FOCUS, String::new());
|
||||
@@ -167,7 +158,7 @@ fn save_dialog(app: &mut TextureCraftApp, ctx: &egui::Context, open: &mut bool,
|
||||
|
||||
fn overwrite_dialog(app: &mut TextureCraftApp, ctx: &egui::Context, open: &mut bool, name: String) -> Option<LayoutDialog> {
|
||||
let mut answer = None;
|
||||
dialog("overwrite_layout", tr("Replace layout"), open).show(ctx, |ui| {
|
||||
dialog(ctx, "overwrite_layout", tr("Replace Layout"), open).show(ctx, |ui| {
|
||||
ui.label(trf("A layout named {name} already exists. Replace it?", &[("name", &name)]));
|
||||
ui.add_space(8.0);
|
||||
ui.horizontal(|ui| {
|
||||
@@ -199,7 +190,7 @@ fn manage_dialog(
|
||||
mut deleting: Option<String>,
|
||||
) -> Option<LayoutDialog> {
|
||||
let mut finished = false;
|
||||
dialog("manage_layouts", tr("Manage layouts"), open).show(ctx, |ui| {
|
||||
dialog(ctx, "manage_layouts", tr("Manage Layouts"), open).show(ctx, |ui| {
|
||||
ui.set_min_width(320.0);
|
||||
if let Some(name) = deleting.clone() {
|
||||
ui.label(trf("Delete the layout {name}?", &[("name", &name)]));
|
||||
|
||||
@@ -80,28 +80,43 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut open = true;
|
||||
let (mut create, mut cancel) = (false, false);
|
||||
|
||||
// A fixed height keeps the centered window still while its sections lay out
|
||||
// Start with a form that fits the viewport; subsequent sizes follow the user's resize
|
||||
let form_height = (ctx.content_rect().height() - DIALOG_VIEWPORT_MARGIN_POINTS - DIALOG_CHROME_HEIGHT_POINTS)
|
||||
.clamp(crate::project_form::MIN_FORM_HEIGHT_POINTS, crate::project_form::FORM_HEIGHT_POINTS);
|
||||
dialog("new_project", tr("New project"), &mut open).default_width(DIALOG_WIDTH_POINTS).show(ctx, |ui| {
|
||||
ui.set_width(DIALOG_WIDTH_POINTS);
|
||||
egui::ScrollArea::vertical().id_salt("np_form").min_scrolled_height(form_height).max_height(form_height).auto_shrink([false, true]).show(ui, |ui| {
|
||||
basic_settings(app, ui);
|
||||
ui.add_space(8.0);
|
||||
advanced_settings(app, ui);
|
||||
});
|
||||
ui.separator();
|
||||
let can_create = app.ui.new_project.file.is_some();
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
create = ui
|
||||
.add_enabled(can_create, primary_button(ui, tr("Create")).min_size(vec2(BUTTON_WIDTH_POINTS, 0.0)))
|
||||
.on_disabled_hover_text(tr("Select a 3D mesh first"))
|
||||
.clicked();
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
dialog(ctx, "new_project", tr("New Project"), &mut open).default_size(vec2(DIALOG_WIDTH_POINTS, form_height + DIALOG_CHROME_HEIGHT_POINTS)).show(
|
||||
ctx,
|
||||
|ui| {
|
||||
// Lay out the actual footer first so it cannot make the window grow each frame
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
|
||||
let can_create = app.ui.new_project.file.is_some();
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
create = ui
|
||||
.add_enabled(can_create, primary_button(ui, tr("Create")).min_size(vec2(BUTTON_WIDTH_POINTS, 0.0)))
|
||||
.on_disabled_hover_text(tr("Select a 3D mesh first"))
|
||||
.clicked();
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
let form_height = ui.available_height().max(0.0);
|
||||
egui::ScrollArea::both()
|
||||
.id_salt("np_form")
|
||||
.content_margin(crate::windows::dialog_scroll_margin(ui))
|
||||
.min_scrolled_width(0.0)
|
||||
.min_scrolled_height(0.0)
|
||||
.max_height(form_height)
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
basic_settings(app, ui);
|
||||
ui.add_space(8.0);
|
||||
advanced_settings(app, ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
if cancel || !open {
|
||||
app.ui.new_project.baked_maps = Vec::new();
|
||||
|
||||
@@ -100,7 +100,7 @@ pub fn window(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
|
||||
let mut open = true;
|
||||
let (mut import_clicked, mut cancel_clicked) = (false, false);
|
||||
crate::windows::dialog("pbrImport", tr("Import PBR textures"), &mut open).show(ctx, |ui| {
|
||||
crate::windows::dialog(ctx, "pbrImport", tr("Import PBR Textures"), &mut open).show(ctx, |ui| {
|
||||
ui.set_min_width(380.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Layer name"));
|
||||
|
||||
@@ -137,142 +137,154 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut open = true;
|
||||
let (mut ok, mut cancel, mut select) = (std::mem::take(&mut config.confirm), false, false);
|
||||
|
||||
// A fixed height keeps the centered window still while its sections lay out
|
||||
// Start with a form that fits the viewport; subsequent sizes follow the user's resize
|
||||
let form_height = (ctx.content_rect().height() - DIALOG_VIEWPORT_MARGIN_POINTS - DIALOG_CHROME_HEIGHT_POINTS)
|
||||
.clamp(crate::project_form::MIN_FORM_HEIGHT_POINTS, crate::project_form::FORM_HEIGHT_POINTS);
|
||||
let dialog = crate::windows::dialog("project_config", tr("Project configuration"), &mut open).default_width(DEFAULT_DIALOG_WIDTH_POINTS);
|
||||
let dialog = crate::windows::dialog(ctx, "project_config", tr("Project Configuration"), &mut open)
|
||||
.default_size(egui::vec2(DEFAULT_DIALOG_WIDTH_POINTS, form_height + DIALOG_CHROME_HEIGHT_POINTS));
|
||||
|
||||
dialog.show(ctx, |ui| {
|
||||
ui.set_width(DEFAULT_DIALOG_WIDTH_POINTS);
|
||||
egui::ScrollArea::vertical().id_salt("project_config_form").min_scrolled_height(form_height).max_height(form_height).auto_shrink([false, true]).show(ui, |ui| {
|
||||
// Keep the project sections in the order users expect
|
||||
ui.label(caption(tr("3D MESH")));
|
||||
ui.add_space(4.0);
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(ROW_INDENT_POINTS);
|
||||
ui.label(tr("3D mesh"));
|
||||
|
||||
let display_path = chosen_mesh.unwrap_or(mesh_label);
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
let path_width_points = (ui.available_width() - SELECT_BUTTON_WIDTH_POINTS).max(MIN_FIELD_WIDTH_POINTS);
|
||||
let painter = ui.painter().clone();
|
||||
let measure = |text: &str| painter.layout_no_wrap(text.to_string(), font.clone(), egui::Color32::WHITE).rect.width() <= path_width_points;
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
info_icon(ui, tr("The mesh file the project is built on. Select... chooses another one, read when you press OK."));
|
||||
select = ui.button(tr("Select...")).clicked();
|
||||
if display_path.is_empty() {
|
||||
ui.weak(tr("Built-in mesh"));
|
||||
} else {
|
||||
ui.label(elide_start(display_path, measure)).on_hover_text(display_path);
|
||||
}
|
||||
ok |= ui.add(primary_button(ui, tr("OK")).min_size(egui::vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(egui::vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
});
|
||||
});
|
||||
if chosen_mesh.is_none() && !current_mesh_path.is_empty() && !source_file_available {
|
||||
ui.colored_label(ui.visuals().error_fg_color, tr("File not found"));
|
||||
}
|
||||
|
||||
// A selected replacement always reads the mesh again
|
||||
// A missing source file cannot be reimported
|
||||
let mut reimport = config.reimport || chosen_mesh.is_some();
|
||||
let can_reimport_source = chosen_mesh.is_none() && source_file_available;
|
||||
let reimport_checkbox = check_row(
|
||||
ui,
|
||||
Some(tr("Read the mesh file again, keeping the layers and painted strokes")),
|
||||
|ui| ui.add_enabled(can_reimport_source, egui::Checkbox::new(&mut reimport, tr("Reimport mesh"))),
|
||||
|_| {},
|
||||
);
|
||||
|
||||
if can_reimport_source {
|
||||
config.reimport = reimport;
|
||||
} else if chosen_mesh.is_none() {
|
||||
reimport_checkbox.on_disabled_hover_text(tr("There is no mesh file to read again. Select one."));
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
ui.label(caption(tr("PROJECT SETTINGS")));
|
||||
ui.add_space(4.0);
|
||||
let shown_format = config.normal_format.unwrap_or(current_normal_format);
|
||||
row(
|
||||
ui,
|
||||
tr("Normal map format"),
|
||||
Some(tr("Green channel convention of normal maps: OpenGL (Y+) or DirectX (Y-). Imported and exported normal maps follow it.")),
|
||||
|ui| {
|
||||
egui::ComboBox::from_id_salt(tr("Normal map format"))
|
||||
.width(FIELD_WIDTH_POINTS)
|
||||
.wrap_mode(egui::TextWrapMode::Truncate)
|
||||
.selected_text(format_name(shown_format))
|
||||
.show_ui(ui, |ui| {
|
||||
for format in [NormalFormat::OpenGl, NormalFormat::DirectX] {
|
||||
if ui.selectable_label(format == shown_format, format_name(format)).clicked() {
|
||||
config.normal_format = (format != current_normal_format).then_some(format);
|
||||
ui.label(egui::RichText::new(tr("Changing the mesh or normal format can recalculate texture channels.")).color(Tokens::get(ui.ctx()).warning));
|
||||
ui.add_space(8.0);
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
let form_height = ui.available_height().max(0.0);
|
||||
let scroll = egui::ScrollArea::both()
|
||||
.id_salt("project_config_form")
|
||||
.content_margin(crate::windows::dialog_scroll_margin(ui))
|
||||
.min_scrolled_width(0.0)
|
||||
.min_scrolled_height(0.0)
|
||||
.max_height(form_height)
|
||||
.auto_shrink([false, false]);
|
||||
scroll.show(ui, |ui| {
|
||||
// Keep the project sections in the order users expect
|
||||
ui.label(caption(tr("3D MESH")));
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(ROW_INDENT_POINTS);
|
||||
ui.label(tr("3D mesh"));
|
||||
|
||||
let display_path = chosen_mesh.unwrap_or(mesh_label);
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
let path_width_points = (ui.available_width() - SELECT_BUTTON_WIDTH_POINTS).max(MIN_FIELD_WIDTH_POINTS);
|
||||
let painter = ui.painter().clone();
|
||||
let measure = |text: &str| painter.layout_no_wrap(text.to_string(), font.clone(), egui::Color32::WHITE).rect.width() <= path_width_points;
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
info_icon(ui, tr("The mesh file the project is built on. Select... chooses another one, read when you press OK."));
|
||||
select = ui.button(tr("Select...")).clicked();
|
||||
if display_path.is_empty() {
|
||||
ui.weak(tr("Built-in mesh"));
|
||||
} else {
|
||||
ui.label(elide_start(display_path, measure)).on_hover_text(display_path);
|
||||
}
|
||||
});
|
||||
});
|
||||
if chosen_mesh.is_none() && !current_mesh_path.is_empty() && !source_file_available {
|
||||
ui.colored_label(ui.visuals().error_fg_color, tr("File not found"));
|
||||
}
|
||||
|
||||
// A selected replacement always reads the mesh again
|
||||
// A missing source file cannot be reimported
|
||||
let mut reimport = config.reimport || chosen_mesh.is_some();
|
||||
let can_reimport_source = chosen_mesh.is_none() && source_file_available;
|
||||
let reimport_checkbox = check_row(
|
||||
ui,
|
||||
Some(tr("Read the mesh file again, keeping the layers and painted strokes")),
|
||||
|ui| ui.add_enabled(can_reimport_source, egui::Checkbox::new(&mut reimport, tr("Reimport mesh"))),
|
||||
|_| {},
|
||||
);
|
||||
|
||||
if can_reimport_source {
|
||||
config.reimport = reimport;
|
||||
} else if chosen_mesh.is_none() {
|
||||
reimport_checkbox.on_disabled_hover_text(tr("There is no mesh file to read again. Select one."));
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
ui.label(caption(tr("PROJECT SETTINGS")));
|
||||
ui.add_space(4.0);
|
||||
let shown_format = config.normal_format.unwrap_or(current_normal_format);
|
||||
row(
|
||||
ui,
|
||||
tr("Normal map format"),
|
||||
Some(tr("Green channel convention of normal maps: OpenGL (Y+) or DirectX (Y-). Imported and exported normal maps follow it.")),
|
||||
|ui| {
|
||||
egui::ComboBox::from_id_salt(tr("Normal map format"))
|
||||
.width(FIELD_WIDTH_POINTS)
|
||||
.wrap_mode(egui::TextWrapMode::Truncate)
|
||||
.selected_text(format_name(shown_format))
|
||||
.show_ui(ui, |ui| {
|
||||
for format in [NormalFormat::OpenGl, NormalFormat::DirectX] {
|
||||
if ui.selectable_label(format == shown_format, format_name(format)).clicked() {
|
||||
config.normal_format = (format != current_normal_format).then_some(format);
|
||||
}
|
||||
}
|
||||
})
|
||||
.response
|
||||
.on_hover_text(tr(
|
||||
"For the whole project: how normal map images set as mesh maps are read (set them again after a change), and the default for export",
|
||||
));
|
||||
},
|
||||
);
|
||||
tangent_space_row(ui);
|
||||
|
||||
// Texture Set Settings owns UV tile changes
|
||||
ui.add_space(4.0);
|
||||
sub_title(ui, tr("UV Tile settings (UDIMs)"), Some(tr("View the UV tiles assigned to each texture set")));
|
||||
let tiles_hint = tr("Change the UV tiles of a texture set in Texture Set Settings");
|
||||
note(ui, tiles_hint);
|
||||
let mut has_tiles = project.texture_sets.iter().any(|set| !set.uv_tiles.is_empty());
|
||||
|
||||
check_row(ui, None, |ui| ui.add_enabled(false, egui::Checkbox::new(&mut has_tiles, tr("Use UV Tile workflow"))), |_| {})
|
||||
.on_disabled_hover_ui(|ui| {
|
||||
ui.set_max_width(ui.spacing().tooltip_width);
|
||||
if !has_tiles {
|
||||
ui.label(tr("No UV tiles"));
|
||||
}
|
||||
|
||||
for set in project.texture_sets.iter().filter(|set| !set.uv_tiles.is_empty()) {
|
||||
let tiles = set.uv_tiles.iter().map(u32::to_string).collect::<Vec<_>>().join(", ");
|
||||
if project.texture_sets.len() > 1 {
|
||||
ui.label(trf("{set}: {tiles}", &[("set", &set.name), ("tiles", &tiles)]));
|
||||
} else {
|
||||
ui.label(tiles);
|
||||
}
|
||||
}
|
||||
})
|
||||
.response
|
||||
.on_hover_text(tr(
|
||||
"For the whole project: how normal map images set as mesh maps are read (set them again after a change), and the default for export",
|
||||
));
|
||||
},
|
||||
);
|
||||
tangent_space_row(ui);
|
||||
});
|
||||
uv_tile_radios(ui, false, tiles_hint);
|
||||
|
||||
// Texture Set Settings owns UV tile changes
|
||||
ui.add_space(4.0);
|
||||
sub_title(ui, tr("UV Tile settings (UDIMs)"), Some(tr("View the UV tiles assigned to each texture set")));
|
||||
let tiles_hint = tr("Change the UV tiles of a texture set in Texture Set Settings");
|
||||
note(ui, tiles_hint);
|
||||
let mut has_tiles = project.texture_sets.iter().any(|set| !set.uv_tiles.is_empty());
|
||||
ui.add_space(4.0);
|
||||
sub_title(ui, tr("Import settings"), None);
|
||||
check_row(
|
||||
ui,
|
||||
Some(tr("Keep the cameras stored in the mesh file")),
|
||||
|ui| unavailable(ui.add_enabled(false, egui::Checkbox::new(&mut false, tr("Import cameras")))),
|
||||
|_| {},
|
||||
);
|
||||
|
||||
check_row(ui, None, |ui| ui.add_enabled(false, egui::Checkbox::new(&mut has_tiles, tr("Use UV Tile workflow"))), |_| {})
|
||||
.on_disabled_hover_ui(|ui| {
|
||||
ui.set_max_width(ui.spacing().tooltip_width);
|
||||
if !has_tiles {
|
||||
ui.label(tr("No UV tiles"));
|
||||
}
|
||||
// Import settings matter only when a mesh will be read
|
||||
let importing = chosen_mesh.is_some() || (config.reimport && source_file_available);
|
||||
check_row(
|
||||
ui,
|
||||
Some(tr("Painted strokes follow the surface when the new mesh's UVs differ")),
|
||||
|ui| ui.add_enabled(importing, egui::Checkbox::new(&mut config.preserve, tr("Preserve stroke positions on mesh"))),
|
||||
|_| {},
|
||||
);
|
||||
auto_unwrap_row(ui);
|
||||
|
||||
for set in project.texture_sets.iter().filter(|set| !set.uv_tiles.is_empty()) {
|
||||
let tiles = set.uv_tiles.iter().map(u32::to_string).collect::<Vec<_>>().join(", ");
|
||||
if project.texture_sets.len() > 1 {
|
||||
ui.label(trf("{set}: {tiles}", &[("set", &set.name), ("tiles", &tiles)]));
|
||||
} else {
|
||||
ui.label(tiles);
|
||||
}
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
physical_size(ui, "project_config_physical_size", false);
|
||||
color_management(ui, "project_config_color_management", &mut config.color_management);
|
||||
});
|
||||
uv_tile_radios(ui, false, tiles_hint);
|
||||
|
||||
ui.add_space(4.0);
|
||||
sub_title(ui, tr("Import settings"), None);
|
||||
check_row(
|
||||
ui,
|
||||
Some(tr("Keep the cameras stored in the mesh file")),
|
||||
|ui| unavailable(ui.add_enabled(false, egui::Checkbox::new(&mut false, tr("Import cameras")))),
|
||||
|_| {},
|
||||
);
|
||||
|
||||
// Import settings matter only when a mesh will be read
|
||||
let importing = chosen_mesh.is_some() || (config.reimport && source_file_available);
|
||||
check_row(
|
||||
ui,
|
||||
Some(tr("Painted strokes follow the surface when the new mesh's UVs differ")),
|
||||
|ui| ui.add_enabled(importing, egui::Checkbox::new(&mut config.preserve, tr("Preserve stroke positions on mesh"))),
|
||||
|_| {},
|
||||
);
|
||||
auto_unwrap_row(ui);
|
||||
|
||||
ui.add_space(4.0);
|
||||
physical_size(ui, "project_config_physical_size", false);
|
||||
color_management(ui, "project_config_color_management", &mut config.color_management);
|
||||
});
|
||||
|
||||
ui.add_space(8.0);
|
||||
ui.label(egui::RichText::new(tr("Changing the mesh or normal format can recalculate texture channels.")).color(Tokens::get(ui.ctx()).warning));
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ok |= ui.add(primary_button(ui, tr("OK")).min_size(egui::vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(egui::vec2(BUTTON_WIDTH_POINTS, 0.0))).clicked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
//! The current desktop run's rolling log, separate from the clearable Log panel.
|
||||
use std::{
|
||||
fs::{File, OpenOptions},
|
||||
io::{self, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use texturecraft_engine::SessionLog;
|
||||
|
||||
// Retain two segments to bound each run's log while preserving recent history
|
||||
const MAX_LOG_SEGMENT_BYTES: u64 = 8 * 1024 * 1024;
|
||||
/// Runs whose log folders stay in the logs folder, the new run's included, so the folder stays bounded
|
||||
const KEPT_SESSION_FOLDERS: usize = 10;
|
||||
const SESSION_FOLDER_PREFIX: &str = "session-";
|
||||
|
||||
pub(crate) struct SessionLogFile {
|
||||
pub path: PathBuf,
|
||||
file: File,
|
||||
bytes: u64,
|
||||
log_id: u64,
|
||||
cursor: u64,
|
||||
}
|
||||
|
||||
/// Remove all but the `keep` newest session folders in `logs`. Their names start with a UTC time, so
|
||||
/// name order is age order. Errors are ignored: a folder an older run still holds open stays for a later start.
|
||||
fn prune(logs: &Path, keep: usize) {
|
||||
let Ok(entries) = std::fs::read_dir(logs) else { return };
|
||||
let mut folders: Vec<PathBuf> = entries
|
||||
.filter_map(Result::ok)
|
||||
.filter(|entry| entry.file_type().is_ok_and(|kind| kind.is_dir()))
|
||||
.filter(|entry| entry.file_name().to_str().is_some_and(|name| name.starts_with(SESSION_FOLDER_PREFIX)))
|
||||
.map(|entry| entry.path())
|
||||
.collect();
|
||||
folders.sort();
|
||||
let old = folders.len().saturating_sub(keep);
|
||||
for folder in &folders[..old] {
|
||||
let _ = std::fs::remove_dir_all(folder);
|
||||
}
|
||||
}
|
||||
|
||||
impl SessionLogFile {
|
||||
/// Start this run's log in a new session folder under `logs`, after removing the oldest runs' folders.
|
||||
pub fn start(logs: &Path) -> io::Result<Self> {
|
||||
prune(logs, KEPT_SESSION_FOLDERS - 1);
|
||||
let folder = format!("{SESSION_FOLDER_PREFIX}{}-{}", chrono::Utc::now().format("%Y%m%dT%H%M%S%.6fZ"), std::process::id());
|
||||
Self::new(logs.join(folder).join("log.txt"))
|
||||
}
|
||||
|
||||
pub fn new(path: PathBuf) -> io::Result<Self> {
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
|
||||
let file = OpenOptions::new().create_new(true).append(true).open(&path)?;
|
||||
Ok(Self { path, file, bytes: 0, log_id: 0, cursor: 0 })
|
||||
}
|
||||
|
||||
pub fn text(&mut self) -> io::Result<String> {
|
||||
self.file.flush()?;
|
||||
let previous = self.path.with_file_name("log.previous.txt");
|
||||
let mut text = match std::fs::read_to_string(previous) {
|
||||
Ok(text) => text,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => String::new(),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
text.push_str(&std::fs::read_to_string(&self.path)?);
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
pub fn sync(&mut self, log_id: u64, log: &SessionLog) -> io::Result<()> {
|
||||
if self.log_id != log_id {
|
||||
self.log_id = log_id;
|
||||
self.cursor = 0;
|
||||
}
|
||||
for (occurrence, entry) in log.entries_after(self.cursor) {
|
||||
let text = crate::windows::log_text(std::slice::from_ref(entry));
|
||||
let line = text.split_once('\n').map(|(_, line)| line).unwrap_or_default();
|
||||
|
||||
// Keep one previous segment when the active log rolls
|
||||
if self.bytes.saturating_add(line.len() as u64) > MAX_LOG_SEGMENT_BYTES {
|
||||
self.file.flush()?;
|
||||
std::fs::copy(&self.path, self.path.with_file_name("log.previous.txt"))?;
|
||||
self.file.set_len(0)?;
|
||||
self.bytes = 0;
|
||||
}
|
||||
self.file.write_all(line.as_bytes())?;
|
||||
self.bytes = self.bytes.saturating_add(line.len() as u64);
|
||||
self.cursor = occurrence;
|
||||
}
|
||||
self.file.flush()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn temp_log() -> SessionLogFile {
|
||||
let dir = std::env::temp_dir().join(format!("texturecraft-session-log-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join(format!("{}.txt", chrono::Utc::now().timestamp_nanos_opt().unwrap()));
|
||||
SessionLogFile::new(path).unwrap()
|
||||
}
|
||||
|
||||
fn remove_log(file: SessionLogFile) {
|
||||
let path = file.path.clone();
|
||||
drop(file);
|
||||
std::fs::remove_file(path).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starting_a_run_removes_only_the_oldest_session_folders() {
|
||||
let logs = std::env::temp_dir().join(format!("texturecraft-session-prune-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&logs);
|
||||
let older: Vec<PathBuf> = (0..KEPT_SESSION_FOLDERS + 2).map(|i| logs.join(format!("{SESSION_FOLDER_PREFIX}20260101T0000{i:02}.000000Z-1"))).collect();
|
||||
for folder in &older {
|
||||
std::fs::create_dir_all(folder).unwrap();
|
||||
}
|
||||
let other = logs.join("kept-by-the-user");
|
||||
std::fs::create_dir_all(&other).unwrap();
|
||||
|
||||
let file = SessionLogFile::start(&logs).unwrap();
|
||||
|
||||
let survivors = older.iter().filter(|folder| folder.exists()).count();
|
||||
assert_eq!(survivors + 1, KEPT_SESSION_FOLDERS, "the new run and the newest earlier runs remain");
|
||||
assert!(!older[0].exists() && older.last().unwrap().exists(), "the oldest go first");
|
||||
assert!(other.exists() && file.path.exists(), "other folders and the new log stay");
|
||||
drop(file);
|
||||
std::fs::remove_dir_all(logs).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_file_keeps_messages_after_panel_clear_and_across_projects() {
|
||||
let mut file = temp_log();
|
||||
let mut log = SessionLog::new();
|
||||
log.push("first".into());
|
||||
file.sync(1, &log).unwrap();
|
||||
file.sync(1, &log).unwrap();
|
||||
log.clear();
|
||||
file.sync(1, &log).unwrap();
|
||||
log.error("UI", "second");
|
||||
file.sync(1, &log).unwrap();
|
||||
let mut next_project = SessionLog::new();
|
||||
next_project.info("UI", "new project");
|
||||
file.sync(2, &next_project).unwrap();
|
||||
let text = file.text().unwrap();
|
||||
assert_eq!(text.matches("first").count(), 1);
|
||||
assert!(text.contains("second") && text.contains("new project"));
|
||||
remove_log(file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_the_tail_does_not_hide_an_earlier_timestamp_append() {
|
||||
let mut file = temp_log();
|
||||
let mut pending = SessionLog::new();
|
||||
pending.push("deferred message".into());
|
||||
|
||||
let mut log = SessionLog::new();
|
||||
log.push("kept message".into());
|
||||
log.push("removed tail".into());
|
||||
file.sync(1, &log).unwrap();
|
||||
|
||||
assert!(pending[0].time <= log[1].time);
|
||||
log.retain(|entry| entry.message != "removed tail");
|
||||
log.append(pending);
|
||||
file.sync(1, &log).unwrap();
|
||||
|
||||
let text = file.text().unwrap();
|
||||
for message in ["deferred message", "kept message", "removed tail"] {
|
||||
assert_eq!(text.matches(message).count(), 1, "{message}");
|
||||
}
|
||||
remove_log(file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_an_earlier_timestamp_tail_does_not_replay_the_survivors() {
|
||||
let mut file = temp_log();
|
||||
let mut pending = SessionLog::new();
|
||||
pending.push("removed tail".into());
|
||||
|
||||
let mut log = SessionLog::new();
|
||||
log.push("kept message".into());
|
||||
log.append(pending);
|
||||
assert!(log[0].time >= log[1].time);
|
||||
file.sync(1, &log).unwrap();
|
||||
|
||||
log.retain(|entry| entry.message != "removed tail");
|
||||
file.sync(1, &log).unwrap();
|
||||
file.sync(1, &log).unwrap();
|
||||
|
||||
let text = file.text().unwrap();
|
||||
assert_eq!(text.matches("kept message").count(), 1);
|
||||
assert_eq!(text.matches("removed tail").count(), 1);
|
||||
remove_log(file);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use crate::TextureCraftApp;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::file_dialogs::{Bound, FileDialog};
|
||||
use crate::i18n::{LANGUAGES, SYSTEM_LANGUAGE, n_, tr, trf};
|
||||
use crate::state::{CAMERA_SPEED_RANGE, LibraryLocation, Prefs};
|
||||
use crate::state::{CAMERA_SPEED_RANGE, LibraryLocation, MAX_RECENT_PROJECTS, Prefs};
|
||||
use crate::theme::{Accent, Brightness, Tokens, caption};
|
||||
use crate::unavailable::NOT_AVAILABLE;
|
||||
use crate::widgets::icon_button;
|
||||
@@ -75,77 +75,84 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
crate::keymap::follow(&mut app.settings_bindings, &draft.keymap, ctx);
|
||||
let shortcut_conflict = crate::keymap::has_conflict(&app.settings_bindings);
|
||||
|
||||
crate::windows::window("settings", tr("Settings"), &mut open).resizable(false).show(ctx, |ui| {
|
||||
// Keep the footer inside the viewport when the fixed-width controls need to scroll
|
||||
ui.set_max_width(content_width);
|
||||
ui.horizontal_top(|ui| {
|
||||
egui::ScrollArea::vertical().id_salt("settings_navigation").min_scrolled_height(0.0).max_height(page_height).show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(PAGE_BUTTON.x);
|
||||
for page in SettingsPage::ALL {
|
||||
let warn = page == SettingsPage::Shortcuts && shortcut_conflict;
|
||||
if page_button(ui, page, draft.page == page, warn).clicked() {
|
||||
draft.page = page;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
crate::windows::window("settings", tr("Settings"), &mut open)
|
||||
.default_size(vec2(content_width + frame_width, page_height + WINDOW_CHROME_HEIGHT_POINTS))
|
||||
.show(ctx, |ui| {
|
||||
// Measure the footer through layout, then let the pages use only what remains
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
|
||||
// Recheck after drawing the page as well, before accepting any edits
|
||||
let conflict = crate::keymap::has_conflict(&app.settings_bindings);
|
||||
ui.horizontal(|ui| {
|
||||
if conflict {
|
||||
let danger = Tokens::get(ui.ctx()).danger;
|
||||
ui.label(RichText::new(format!("{} {}", ic::WARNING, tr(SHORTCUT_ERRORS))).color(danger));
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(vec2(100.0, 0.0))).clicked();
|
||||
ok = ui.add_enabled(!conflict, egui::Button::new(tr("OK")).min_size(vec2(100.0, 0.0))).clicked();
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
egui::ScrollArea::both()
|
||||
.id_salt(("settings_page", draft.page as u8))
|
||||
.auto_shrink([false, false])
|
||||
.min_scrolled_width(0.0)
|
||||
.min_scrolled_height(page_height)
|
||||
.max_height(page_height)
|
||||
.show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(PAGE_WIDTH);
|
||||
match draft.page {
|
||||
SettingsPage::General => {
|
||||
general(
|
||||
ui,
|
||||
&mut draft.prefs,
|
||||
&drawable,
|
||||
gpu.as_deref(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
resources,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
&mut pick,
|
||||
);
|
||||
}
|
||||
SettingsPage::Shortcuts => {
|
||||
crate::keymap::actions_page(ui, &mut draft.keymap, &app.bindings, &mut app.settings_bindings);
|
||||
}
|
||||
SettingsPage::Libraries => {
|
||||
libraries(
|
||||
ui,
|
||||
&mut draft,
|
||||
project_open,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
&mut pick,
|
||||
);
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
let page_height = ui.available_height().max(0.0);
|
||||
ui.horizontal_top(|ui| {
|
||||
egui::ScrollArea::vertical().id_salt("settings_navigation").min_scrolled_height(0.0).max_height(page_height).show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(PAGE_BUTTON.x);
|
||||
for page in SettingsPage::ALL {
|
||||
let warn = page == SettingsPage::Shortcuts && shortcut_conflict;
|
||||
if page_button(ui, page, draft.page == page, warn).clicked() {
|
||||
draft.page = page;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
egui::ScrollArea::both()
|
||||
.id_salt(("settings_page", draft.page as u8))
|
||||
.content_margin(crate::windows::dialog_scroll_margin(ui))
|
||||
.auto_shrink([false, false])
|
||||
.min_scrolled_width(0.0)
|
||||
.min_scrolled_height(0.0)
|
||||
.max_height(page_height)
|
||||
.show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_min_width(PAGE_WIDTH);
|
||||
match draft.page {
|
||||
SettingsPage::General => {
|
||||
general(
|
||||
ui,
|
||||
&mut draft.prefs,
|
||||
&drawable,
|
||||
gpu.as_deref(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
resources,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
&mut pick,
|
||||
);
|
||||
}
|
||||
SettingsPage::Shortcuts => {
|
||||
crate::keymap::actions_page(ui, &mut draft.keymap, &app.bindings, &mut app.settings_bindings);
|
||||
}
|
||||
SettingsPage::Libraries => {
|
||||
libraries(
|
||||
ui,
|
||||
&mut draft,
|
||||
project_open,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
&mut pick,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
|
||||
// The page has brought the checker up to date, so OK follows this frame's edits
|
||||
let conflict = crate::keymap::has_conflict(&app.settings_bindings);
|
||||
ui.horizontal(|ui| {
|
||||
if conflict {
|
||||
let danger = Tokens::get(ui.ctx()).danger;
|
||||
ui.label(RichText::new(format!("{} {}", ic::WARNING, tr(SHORTCUT_ERRORS))).color(danger));
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(vec2(100.0, 0.0))).clicked();
|
||||
ok = ui.add_enabled(!conflict, egui::Button::new(tr("OK")).min_size(vec2(100.0, 0.0))).clicked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ok &= !crate::keymap::has_conflict(&app.settings_bindings);
|
||||
app.ui.windows.settings_page = draft.page;
|
||||
if draft.page != SettingsPage::Shortcuts || ok || cancel || !open {
|
||||
crate::keymap::stop_settings_capture(ctx);
|
||||
@@ -169,6 +176,7 @@ fn apply(app: &mut TextureCraftApp, draft: SettingsDraft) {
|
||||
let previous_autosave_minutes = app.ui.prefs.autosave_minutes;
|
||||
|
||||
app.ui.prefs = draft.prefs;
|
||||
app.ui.trim_recent();
|
||||
app.reschedule_autosave_if_changed(previous_autosave_minutes);
|
||||
|
||||
let ids: std::collections::BTreeSet<&String> = draft.keymap.keys().chain(draft.keymap_at_open.keys()).collect();
|
||||
@@ -354,6 +362,12 @@ fn general(
|
||||
});
|
||||
});
|
||||
|
||||
row(ui, tr("Recent projects limit"), |ui, label| {
|
||||
ui.add(egui::DragValue::new(&mut p.recent_projects_limit).range(0..=MAX_RECENT_PROJECTS))
|
||||
.labelled_by(label)
|
||||
.on_hover_text(tr("Number of recent projects to remember. 0 disables recent-project history."));
|
||||
});
|
||||
|
||||
section(ui, n_("LAYER STACK OPTIONS"));
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(12.0);
|
||||
|
||||
@@ -146,6 +146,8 @@ pub struct Prefs {
|
||||
pub ui_scale: f32,
|
||||
/// Minutes between autosaves of a modified project (0: off; desktop).
|
||||
pub autosave_minutes: u32,
|
||||
/// Maximum recent projects retained (0 disables the history, capped at 100).
|
||||
pub recent_projects_limit: u16,
|
||||
/// UI language code (`i18n::LANGUAGES`), or `i18n::SYSTEM_LANGUAGE` to follow the system.
|
||||
pub language: String,
|
||||
/// Viewport texture resolution: 0 full, 1 half, 2 quarter of each texture set's size (lighter
|
||||
@@ -197,6 +199,7 @@ impl Default for Prefs {
|
||||
Prefs {
|
||||
ui_scale: 1.0,
|
||||
autosave_minutes: 10,
|
||||
recent_projects_limit: 10,
|
||||
language: "en".into(),
|
||||
viewport_texture: 0,
|
||||
brightness: crate::theme::Brightness::default(),
|
||||
@@ -517,6 +520,11 @@ pub struct UiState {
|
||||
pub(crate) inactive_mode_dock: Dock,
|
||||
#[serde(default)]
|
||||
pub(crate) dock_is_baking: bool,
|
||||
/// Rendering's saved dock, or Painting's while Rendering is active. Older states start from Painting.
|
||||
#[serde(default)]
|
||||
pub(crate) inactive_render_dock: Option<Dock>,
|
||||
#[serde(default)]
|
||||
pub(crate) dock_is_rendering: bool,
|
||||
/// Window ▸ Toolbars ▸ Docks: the right bar of panel icons
|
||||
#[serde(default = "default_true")]
|
||||
pub toolbar_docks: bool,
|
||||
@@ -632,9 +640,23 @@ pub struct UiState {
|
||||
pub log_id: u64,
|
||||
}
|
||||
|
||||
pub(crate) const MAX_RECENT_PROJECTS: u16 = 100;
|
||||
|
||||
impl UiState {
|
||||
/// Keep recent-file history bounded, including values supplied through automation or old settings.
|
||||
pub(crate) fn trim_recent(&mut self) {
|
||||
self.prefs.recent_projects_limit = self.prefs.recent_projects_limit.min(MAX_RECENT_PROJECTS);
|
||||
self.recent.truncate(usize::from(self.prefs.recent_projects_limit));
|
||||
}
|
||||
|
||||
/// Replace an outdated or unreadable saved bake dock by the bake layout, then give the mode its dock
|
||||
pub(crate) fn sync_mode_dock(&mut self) {
|
||||
if self.dock_is_rendering {
|
||||
if let Some(other) = self.inactive_render_dock.as_mut() {
|
||||
std::mem::swap(&mut self.dock, other);
|
||||
}
|
||||
self.dock_is_rendering = false;
|
||||
}
|
||||
self.reset_outdated_bake_dock();
|
||||
|
||||
let baking = self.mode == Mode::Baking;
|
||||
@@ -642,6 +664,11 @@ impl UiState {
|
||||
std::mem::swap(&mut self.dock, &mut self.inactive_mode_dock);
|
||||
self.dock_is_baking = baking;
|
||||
}
|
||||
if self.mode == Mode::Rendering {
|
||||
let other = self.inactive_render_dock.get_or_insert_with(|| self.dock.clone());
|
||||
std::mem::swap(&mut self.dock, other);
|
||||
self.dock_is_rendering = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace a bake dock saved with an older bake layout, or one that could not be read, by the bake default
|
||||
@@ -655,11 +682,12 @@ impl UiState {
|
||||
self.bake_layout_version = BAKE_LAYOUT_VERSION;
|
||||
}
|
||||
|
||||
/// Put the panels, tabs and floating panels of both modes back to their defaults; the view split,
|
||||
/// Put the panels, tabs and floating panels of every mode back to their defaults; the view split,
|
||||
/// zoom, wireframes, symmetry display, mode and every setting stay as they are
|
||||
pub fn reset_panel_layout(&mut self) {
|
||||
let (painting, baking) = (Dock::default(), Dock::for_baking());
|
||||
(self.dock, self.inactive_mode_dock) = if self.dock_is_baking { (baking, painting) } else { (painting, baking) };
|
||||
self.inactive_render_dock = self.dock_is_rendering.then(Dock::default);
|
||||
self.bake_layout_version = BAKE_LAYOUT_VERSION;
|
||||
self.rail_panel = None;
|
||||
}
|
||||
@@ -708,6 +736,8 @@ impl Default for UiState {
|
||||
rail_panel: None,
|
||||
inactive_mode_dock: Dock::for_baking(),
|
||||
dock_is_baking: false,
|
||||
inactive_render_dock: None,
|
||||
dock_is_rendering: false,
|
||||
toolbar_docks: true,
|
||||
toolbar_tools: true,
|
||||
bake_layout_version: BAKE_LAYOUT_VERSION,
|
||||
|
||||
@@ -6,7 +6,6 @@ use serde_json::json;
|
||||
use texturecraft_engine::Tool;
|
||||
|
||||
use crate::TextureCraftApp;
|
||||
use crate::docking::Panel;
|
||||
use crate::drawn_icon::DrawnIcon;
|
||||
use crate::i18n::{tr, trf};
|
||||
use crate::keymap::{shortcut_of, tip};
|
||||
@@ -459,10 +458,14 @@ pub fn tool_shelf(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
ui.spacing_mut().item_spacing.y = SHELF_BUTTON_SPACING;
|
||||
|
||||
// Rendering has nothing to paint, so its shelf keeps only the buttons below the tools
|
||||
let tools: &[Tool] = match app.ui.mode {
|
||||
Mode::Painting => &SHELF_TOOLS,
|
||||
Mode::Baking => &BAKING_SHELF_TOOLS,
|
||||
Mode::Rendering => &[],
|
||||
let tools: &[Tool] = if !app.ui.toolbar_tools {
|
||||
&[]
|
||||
} else {
|
||||
match app.ui.mode {
|
||||
Mode::Painting => &SHELF_TOOLS,
|
||||
Mode::Baking => &BAKING_SHELF_TOOLS,
|
||||
Mode::Rendering => &[],
|
||||
}
|
||||
};
|
||||
if !tools.is_empty() {
|
||||
for &tool in tools {
|
||||
@@ -496,26 +499,10 @@ pub fn tool_shelf(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
}
|
||||
|
||||
let quick_mask = &app.session.quick_mask;
|
||||
for (command, icon, label, selected) in [
|
||||
("viewport.quickMask", ic::SELECTION_BACKGROUND, tr("Quick mask"), quick_mask.enabled),
|
||||
("viewport.quickMask.edit", ic::SELECTION, tr("Edit quick mask"), quick_mask.editing),
|
||||
("viewport.quickMask.invert", ic::SELECTION_INVERSE, tr("Invert quick mask"), quick_mask.inverted),
|
||||
] {
|
||||
let hint = tip(&app.ui.keymap, label, command);
|
||||
let button = ui.add_enabled_ui(crate::menus::enabled(app, command), |ui| icon_button(ui, icon, &hint, selected, SHELF_BUTTON_SIZE)).inner;
|
||||
if button.on_disabled_hover_text(label).clicked() {
|
||||
app.run(command, json!({}));
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
ui.separator();
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
let painting = app.ui.mode == Mode::Painting;
|
||||
if ui.add_enabled_ui(painting, |ui| icon_button(ui, ic::SPHERE, tr("Add smart material from the shelf"), false, SHELF_BUTTON_SIZE)).inner.clicked()
|
||||
{
|
||||
app.ui.dock.focus(Panel::Assets);
|
||||
for (icon, label) in [(ic::HOURGLASS, "Snooze Autosave"), (ic::ARROWS_CLOCKWISE, "Resources Updater")] {
|
||||
ui.add_enabled_ui(false, |ui| icon_button(ui, icon, tr(label), false, SHELF_BUTTON_SIZE))
|
||||
.inner
|
||||
.on_disabled_hover_text(tr(crate::unavailable::NOT_AVAILABLE));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -243,9 +243,10 @@ fn read_bytes(_file: &Path) -> std::io::Result<Vec<u8>> {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::Unsupported, "UI settings use browser storage"))
|
||||
}
|
||||
|
||||
/// Whether every dock, the two in use and those of the named layouts, was read rather than replaced by a default
|
||||
fn fully_read(ui: &UiState) -> bool {
|
||||
!ui.dock.replaced_unreadable()
|
||||
/// Whether every mode's dock and the named layouts were read rather than replaced by a default
|
||||
pub(crate) fn fully_read(ui: &UiState) -> bool {
|
||||
ui.inactive_render_dock.as_ref().is_none_or(|dock| !dock.replaced_unreadable())
|
||||
&& !ui.dock.replaced_unreadable()
|
||||
&& !ui.inactive_mode_dock.replaced_unreadable()
|
||||
&& ui.named_layouts.iter().all(|layout| !layout.painting.replaced_unreadable() && !layout.baking.replaced_unreadable())
|
||||
}
|
||||
|
||||
@@ -190,13 +190,13 @@ mod tests {
|
||||
assert_eq!(h.state().ui.mode, Mode::Painting);
|
||||
offer(&mut h);
|
||||
assert!(crate::docking::input_blocked(h.state(), &h.ctx), "floating panels stop taking input");
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND | egui::Modifiers::SHIFT, egui::Key::B);
|
||||
h.key_press(egui::Key::F8);
|
||||
h.step();
|
||||
assert_eq!(h.state().ui.mode, Mode::Painting, "the prompt holds the keyboard");
|
||||
h.get_by_label("LATER").click();
|
||||
h.run_steps(2);
|
||||
assert!(!crate::docking::input_blocked(h.state(), &h.ctx));
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND | egui::Modifiers::SHIFT, egui::Key::B);
|
||||
h.key_press(egui::Key::F8);
|
||||
h.step();
|
||||
assert_eq!(h.state().ui.mode, Mode::Baking, "the key works once the prompt is closed");
|
||||
}
|
||||
|
||||
@@ -241,8 +241,8 @@ fn zip_files(files: Vec<ExportedFile>) -> Result<Vec<u8>, String> {
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use web::{
|
||||
download, export_mesh, export_textures, import_bake_mesh, import_environment, import_images, import_material, import_preset, open, pick_new_project_mesh,
|
||||
save_project, sync_unsaved, unsaved,
|
||||
download, export_mesh, export_textures, import_bake_mesh, import_environment, import_images, import_material, import_preset, open, open_sample_project,
|
||||
pick_new_project_mesh, save_project, sync_unsaved, unsaved,
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -269,6 +269,11 @@ mod web {
|
||||
pick(ctx, tr("Projects and meshes"), OPEN_EXTS, false, Pick::Open);
|
||||
}
|
||||
|
||||
/// File > Open Sample Project: choose a saved TextureCraft project.
|
||||
pub fn open_sample_project(ctx: &egui::Context) {
|
||||
pick(ctx, tr("TextureCraft project"), &[PROJECT_EXT], false, Pick::Open);
|
||||
}
|
||||
|
||||
/// File › Import material: pick materials; they add as layers on a later frame.
|
||||
pub fn import_material(ctx: &egui::Context) {
|
||||
pick(ctx, tr("Materials"), MATERIAL_EXTS, true, Pick::Open);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! Floating windows and the dockable History panel
|
||||
|
||||
use egui::{RichText, Ui, vec2};
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
use egui::vec2;
|
||||
use egui::{RichText, Ui};
|
||||
use egui_phosphor::regular as ic;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -50,8 +52,8 @@ fn reset_ui(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
|
||||
let mut open = true;
|
||||
let (mut reset, mut cancel) = (false, false);
|
||||
dialog("reset_ui", tr("Reset UI"), &mut open).show(ctx, |ui| {
|
||||
ui.label(tr("Reset the panels, view layout, zoom and every other view setting to their defaults? Settings and shortcuts stay. To reset only the panels, use Reset panel layout."));
|
||||
dialog(ctx, "reset_ui", tr("Reset UI"), &mut open).show(ctx, |ui| {
|
||||
ui.label(tr("Reset the panels, view layout, zoom and every other view setting to their defaults? Settings and shortcuts stay."));
|
||||
ui.add_space(8.0);
|
||||
|
||||
// One row keeps the window to its contents; a bare right-to-left layout fills the screen height
|
||||
@@ -123,7 +125,7 @@ fn unsaved(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
} else {
|
||||
trf("Save the changes to {name} first?", &question_args)
|
||||
};
|
||||
dialog("unsaved", tr("Unsaved changes"), &mut open).show(ctx, |ui| {
|
||||
dialog(ctx, "unsaved", tr("Unsaved Changes"), &mut open).show(ctx, |ui| {
|
||||
ui.label(question);
|
||||
ui.add_space(8.0);
|
||||
|
||||
@@ -199,14 +201,29 @@ pub(crate) fn window<'a>(id: &str, title: &str, open: &'a mut bool) -> egui::Win
|
||||
.default_width(300.0)
|
||||
}
|
||||
|
||||
/// A centered dialog; `id` keeps its place across UI languages.
|
||||
pub(crate) fn dialog<'a>(id: &str, title: &str, open: &'a mut bool) -> egui::Window<'a> {
|
||||
/// A movable, resizable dialog, initially centered; `id` keeps its place across UI languages.
|
||||
pub(crate) fn dialog<'a>(ctx: &egui::Context, id: &str, title: &str, open: &'a mut bool) -> egui::Window<'a> {
|
||||
egui::Window::new(title.to_owned())
|
||||
.id(egui::Id::unique(id))
|
||||
.open(open)
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.anchor(egui::Align2::CENTER_CENTER, vec2(0.0, 0.0))
|
||||
.resizable(true)
|
||||
.default_height(0.0)
|
||||
.default_pos(ctx.content_rect().center())
|
||||
.pivot(egui::Align2::CENTER_CENTER)
|
||||
}
|
||||
|
||||
/// Keep form controls clear of the scrollbar even when its floating handle expands.
|
||||
pub(crate) fn dialog_scroll_margin(ui: &egui::Ui) -> egui::Margin {
|
||||
let scroll = &ui.spacing().scroll;
|
||||
let mut margin = scroll.content_margin;
|
||||
let clearance = (scroll.bar_width + ui.spacing().item_spacing.x).ceil() as i8;
|
||||
if ui.style().right_to_left {
|
||||
margin.left = margin.left.max(clearance);
|
||||
} else {
|
||||
margin.right = margin.right.max(clearance);
|
||||
}
|
||||
margin
|
||||
}
|
||||
|
||||
/// The History panel body (a dock tab)
|
||||
@@ -271,7 +288,7 @@ fn export_mesh(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
|
||||
let mut open = true;
|
||||
let mut picked = None;
|
||||
dialog("export_mesh", tr("Export mesh"), &mut open).show(ctx, |ui| {
|
||||
dialog(ctx, "export_mesh", tr("Export Mesh"), &mut open).show(ctx, |ui| {
|
||||
ui.label(crate::theme::caption(tr("Download as")));
|
||||
for (extension, label, hint) in formats {
|
||||
if ui.add_sized(vec2(220.0, ui.spacing().interact_size.y), egui::Button::new(label)).on_hover_text(hint).clicked() {
|
||||
@@ -290,7 +307,7 @@ fn export_mesh(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
fn about(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let tk = Tokens::get(ctx);
|
||||
let mut open = app.ui.windows.about;
|
||||
dialog("about", tr("About TextureCraft"), &mut open).show(ctx, |ui| {
|
||||
dialog(ctx, "about", tr("About TextureCraft"), &mut open).show(ctx, |ui| {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label(RichText::new("TextureCraft").size(22.0).strong().color(tk.text_strong));
|
||||
ui.label(trf("Version {version}", &[("version", &texturecraft_engine::VERSION)]));
|
||||
@@ -308,7 +325,7 @@ fn about(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
/// Render the session log as text, preserving each entry's occurrence time, severity and source.
|
||||
fn log_text(entries: &[texturecraft_engine::LogEntry]) -> String {
|
||||
pub(crate) fn log_text(entries: &[texturecraft_engine::LogEntry]) -> String {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
const UTC_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.6fZ";
|
||||
@@ -328,11 +345,43 @@ fn log_text(entries: &[texturecraft_engine::LogEntry]) -> String {
|
||||
text
|
||||
}
|
||||
|
||||
/// Open the current run's log in the desktop's text-file handler.
|
||||
pub(crate) fn show_log(app: &mut TextureCraftApp, _ctx: &egui::Context) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let result = match app.session_log_file.as_mut() {
|
||||
Some(file) => file.sync(app.session.log_id, &app.session.log).map(|()| file.path.clone()),
|
||||
None => Err(std::io::Error::other(tr("No session log file is available"))),
|
||||
};
|
||||
match result.and_then(|path| app.file_dialogs.show_folder(&path)) {
|
||||
Ok(()) => {}
|
||||
Err(error) => app.toast(trf("Could not open the log: {error}", &[("error", &error)]), true),
|
||||
}
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
export_log(app);
|
||||
}
|
||||
|
||||
/// Help ▸ Export log...: saves the whole log to a text file chosen in a save dialog.
|
||||
pub(crate) fn export_log(app: &mut TextureCraftApp) {
|
||||
let text = log_text(app.session.log.entries());
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
app.ask_file(FileDialog::save().filter(tr("Text file"), &["txt"]).file_name("texturecraft-log.txt"), Bound::App, move |app, paths| {
|
||||
let text = if let Some(file) = &mut app.session_log_file {
|
||||
match file.sync(app.session.log_id, &app.session.log).and_then(|()| file.text()) {
|
||||
Ok(lines) => format!("{}{lines}", log_text(&[])),
|
||||
Err(error) => {
|
||||
app.toast(trf("Could not export the log: {error}", &[("error", &error)]), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text
|
||||
};
|
||||
let backend = app.render_state.as_ref().map(|state| format!("{:?}", state.adapter.get_info().backend)).unwrap_or_else(|| "CPU".into());
|
||||
let name =
|
||||
format!("Log_TextureCraft_{}_{}_{}_{}.txt", env!("CARGO_PKG_VERSION"), chrono::Utc::now().format("%Y-%m-%d_%H-%M-%S"), std::env::consts::OS, backend);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
app.ask_file(FileDialog::save().filter(tr("Text file"), &["txt"]).file_name(&name), Bound::App, move |app, paths| {
|
||||
let Some(path) = paths.first() else { return };
|
||||
match std::fs::write(path, &text) {
|
||||
Ok(()) => app.toast(trf("Exported the log to {path}", &[("path", &path.display().to_string())]), false),
|
||||
@@ -340,7 +389,7 @@ pub(crate) fn export_log(app: &mut TextureCraftApp) {
|
||||
}
|
||||
});
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
match crate::web_files::download("texturecraft-log.txt", text.as_bytes()) {
|
||||
match crate::web_files::download(&name, text.as_bytes()) {
|
||||
Ok(()) => app.toast(tr("Exported the log"), false),
|
||||
Err(e) => app.toast(trf("Could not export the log: {error}", &[("error", &e)]), true),
|
||||
}
|
||||
@@ -357,7 +406,7 @@ pub fn file_dialogs_available() -> bool {
|
||||
pub fn remember(app: &mut TextureCraftApp, path: &str) {
|
||||
app.ui.recent.retain(|p| p != path);
|
||||
app.ui.recent.insert(0, path.to_string());
|
||||
app.ui.recent.truncate(10);
|
||||
app.ui.trim_recent();
|
||||
}
|
||||
|
||||
/// Start a save picker in its library folder when available.
|
||||
@@ -387,9 +436,7 @@ pub fn save_layout(app: &mut TextureCraftApp, mode: crate::state::Mode) {
|
||||
app.ask_file(dialog, Bound::App, move |app, paths| {
|
||||
let Some(path) = paths.first() else { return };
|
||||
|
||||
// The file carries both docks; the mode's own is the one in use when it is loaded
|
||||
let mut layout = crate::UiState { recent: Vec::new(), named_layouts: Vec::new(), mode, ..app.ui.clone() };
|
||||
layout.sync_mode_dock();
|
||||
let layout = crate::mode_layout::ModeLayout::of(&app.ui, mode);
|
||||
let result = serde_json::to_vec_pretty(&layout)
|
||||
.map_err(|error| error.to_string())
|
||||
.and_then(|bytes| texturecraft_engine::formats::write_atomic(path, &bytes).map_err(|error| error.to_string()))
|
||||
@@ -408,13 +455,10 @@ pub fn load_layout(app: &mut TextureCraftApp) {
|
||||
let dialog = FileDialog::open().title(tr("Select a UI layout file.")).filter(tr("UI layout"), &["json"]).directory(dir);
|
||||
app.ask_file(dialog, Bound::App, move |app, paths| {
|
||||
let Some(path) = paths.first() else { return };
|
||||
let result = std::fs::read(path)
|
||||
.map_err(|e| e.to_string())
|
||||
.and_then(|bytes| serde_json::from_slice::<crate::UiState>(&bytes).map_err(|e| e.to_string()))
|
||||
.map(|layout| {
|
||||
app.ui.adopt_layout(layout);
|
||||
trf("Loaded UI layout {path}", &[("path", &path.display())])
|
||||
});
|
||||
let result = std::fs::read(path).map_err(|e| e.to_string()).and_then(|bytes| crate::mode_layout::ModeLayout::read(&bytes)).map(|layout| {
|
||||
layout.apply(&mut app.ui);
|
||||
trf("Loaded UI layout {path}", &[("path", &path.display())])
|
||||
});
|
||||
match result {
|
||||
Ok(msg) => app.toast(msg, false),
|
||||
Err(e) => app.toast(trf("UI layout: {error}", &[("error", &e)]), true),
|
||||
@@ -472,12 +516,35 @@ pub fn load_layout(app: &mut TextureCraftApp) {
|
||||
app.toast(tr("Saving UI layouts to files is available in the desktop app"), false);
|
||||
}
|
||||
|
||||
/// The extension of MaterialX documents (`file.importMaterialX`)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) const MATERIALX_EXT: &str = "mtlx";
|
||||
|
||||
/// Add the MaterialX material at `path` as a layer, logging what it could not read. Returns whether it was added.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn import_materialx(app: &mut TextureCraftApp, path: &str) -> bool {
|
||||
let Some(result) = app.run("file.importMaterialX", json!({"path": path})) else { return false };
|
||||
|
||||
let name = result["material"].as_str().unwrap_or_default();
|
||||
for warning in result["warnings"].as_array().into_iter().flatten().filter_map(serde_json::Value::as_str) {
|
||||
app.session.log.warn(texturecraft_engine::log::LIBRARY_SOURCE, format!("MaterialX {name}: {warning}"));
|
||||
}
|
||||
app.toast(trf("Imported {name}", &[("name", &name)]), false);
|
||||
app.ui.dock.focus(crate::docking::Panel::Layers);
|
||||
true
|
||||
}
|
||||
|
||||
/// File menu actions that need dialogs. Returns true when handled.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn file_action(app: &mut TextureCraftApp, _ctx: &egui::Context, id: &str) -> bool {
|
||||
match id {
|
||||
"file.open" => {
|
||||
app.ask_file(FileDialog::open().filter(tr("TextureCraft project or mesh"), crate::web_files::OPEN_EXTS), Bound::App, |app, paths| {
|
||||
"file.open" | "project.sample" => {
|
||||
let dialog = if id == "project.sample" {
|
||||
FileDialog::open().title(tr("Open Sample Project")).filter(tr("TextureCraft project"), &[texturecraft_engine::core::PROJECT_EXT])
|
||||
} else {
|
||||
FileDialog::open().filter(tr("TextureCraft project or mesh"), crate::web_files::OPEN_EXTS)
|
||||
};
|
||||
app.ask_file(dialog, Bound::App, |app, paths| {
|
||||
if let Some(path) = paths.first() {
|
||||
open_path(app, &path.display().to_string());
|
||||
}
|
||||
@@ -512,16 +579,9 @@ pub fn file_action(app: &mut TextureCraftApp, _ctx: &egui::Context, id: &str) ->
|
||||
true
|
||||
}
|
||||
"file.importMaterialX" => {
|
||||
app.ask_file(FileDialog::open().filter(tr("MaterialX materials"), &["mtlx"]), Bound::Project, |app, paths| {
|
||||
if let Some(path) = paths.first()
|
||||
&& let Some(result) = app.run("file.importMaterialX", json!({"path": path.display().to_string()}))
|
||||
{
|
||||
let name = result["material"].as_str().unwrap_or_default();
|
||||
for warning in result["warnings"].as_array().into_iter().flatten().filter_map(serde_json::Value::as_str) {
|
||||
app.session.log.warn(texturecraft_engine::log::LIBRARY_SOURCE, format!("MaterialX {name}: {warning}"));
|
||||
}
|
||||
app.toast(trf("Imported {name}", &[("name", &name)]), false);
|
||||
app.ui.dock.focus(crate::docking::Panel::Layers);
|
||||
app.ask_file(FileDialog::open().filter(tr("MaterialX materials"), &[MATERIALX_EXT]), Bound::Project, |app, paths| {
|
||||
if let Some(path) = paths.first() {
|
||||
import_materialx(app, &path.display().to_string());
|
||||
}
|
||||
});
|
||||
true
|
||||
@@ -623,6 +683,7 @@ pub fn open_path(app: &mut TextureCraftApp, path: &str) {
|
||||
pub fn file_action(app: &mut TextureCraftApp, ctx: &egui::Context, id: &str) -> bool {
|
||||
match id {
|
||||
"file.open" => crate::web_files::open(ctx),
|
||||
"project.sample" => crate::web_files::open_sample_project(ctx),
|
||||
"file.importResources" | "resource.import" => crate::web_files::import_images(ctx),
|
||||
"material.load" => crate::web_files::import_material(ctx),
|
||||
"file.save" | "file.saveAs" | "file.saveCopy" => crate::web_files::save_project(app),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! F5 and F6 switch the projection, the Viewport menu goes to fixed views, and Alt+Shift+drag orbits
|
||||
//! F5 and F6 switch the projection, bound shortcuts go to fixed views, and Alt+Shift+drag orbits
|
||||
//! in 90° steps.
|
||||
|
||||
use std::f32::consts::FRAC_PI_2;
|
||||
@@ -54,7 +54,7 @@ fn f6_switches_to_orthographic_and_f5_back_to_perspective_keeping_the_view() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_viewport_menu_goes_to_the_front_view_and_orbit_works_afterwards() {
|
||||
fn a_bound_front_view_shortcut_keeps_orbit_working_afterwards() {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("camera.set", json!({"yaw": 70, "pitch": 30, "ortho": true}));
|
||||
h.run_steps(2);
|
||||
@@ -62,7 +62,11 @@ fn the_viewport_menu_goes_to_the_front_view_and_orbit_works_afterwards() {
|
||||
// The menu bar's "Viewport", above the dock's tab of the same name
|
||||
h.get_all_by_label("Viewport").min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).unwrap().click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label_contains("Front view").click();
|
||||
assert!(h.query_by_label_contains("Front view").is_none(), "fixed views are absent from the menu");
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(2);
|
||||
h.state_mut().ui.keymap.insert("camera.view.front".into(), "F12".into());
|
||||
h.key_press(Key::F12);
|
||||
|
||||
// The UI glides there over about a third of a second
|
||||
h.run_steps(6);
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
//! Empty-project menu behavior and the layout restored by Reset UI.
|
||||
use egui::accesskit::Toggled;
|
||||
use egui_kittest::{
|
||||
Harness,
|
||||
kittest::{NodeT, Queryable},
|
||||
};
|
||||
use texturecraft_engine::Session;
|
||||
use texturecraft_ui_egui::{TextureCraftApp, docking::Panel, menus};
|
||||
|
||||
fn app() -> Harness<'static, TextureCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|cc| TextureCraftApp::new(cc, Session::closed().unwrap()));
|
||||
h.state_mut().ui.prefs.language = "en".into();
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recent_projects_stays_openable_and_clear_tracks_the_list() {
|
||||
let mut h = app();
|
||||
h.get_by_label("File").click();
|
||||
h.run_steps(3);
|
||||
let recent = h.get_by_label("Recent Projects");
|
||||
assert!(!recent.accesskit_node().is_disabled());
|
||||
recent.click();
|
||||
h.run_steps(3);
|
||||
assert!(h.get_by_label("Clear").accesskit_node().is_disabled());
|
||||
h.state_mut().ui.recent.push("/projects/painted-crate.tcraft".into());
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label("/projects/painted-crate.tcraft").is_some());
|
||||
assert!(!h.get_by_label("Clear").accesskit_node().is_disabled());
|
||||
h.get_by_label("Clear").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().ui.recent.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shortcuts_list_opens_settings_on_the_shortcuts_page() {
|
||||
let mut h = app();
|
||||
h.get_by_label("Help").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Shortcuts List").click();
|
||||
h.run_steps(4);
|
||||
assert!(h.state().ui.windows.settings);
|
||||
assert!(!h.state().ui.windows.shortcuts);
|
||||
assert!(h.query_by_label("Mouse shortcuts").is_some());
|
||||
assert!(h.query_by_label("General").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_file_menu_disables_the_save_group_and_opens_import() {
|
||||
let mut h = app();
|
||||
h.get_by_label("File").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.get_by_label("More Save Options").accesskit_node().is_disabled());
|
||||
let import = h.get_all_by_label("Import Resources").find(|node| node.accesskit_node().toggled().is_none()).unwrap();
|
||||
assert!(!import.accesskit_node().is_disabled());
|
||||
import.click();
|
||||
h.run_steps(4);
|
||||
assert!(h.state().ui.windows.import_resources.is_some());
|
||||
assert!(h.get_by_label("Import").accesskit_node().is_disabled());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_restores_the_empty_workspace_and_checked_disabled_quick_mask() {
|
||||
let mut h = app();
|
||||
h.state_mut().ui.dock.close(Panel::Assets);
|
||||
h.state_mut().ui.dock.focus(Panel::History);
|
||||
h.state_mut().ui.toolbar_tools = false;
|
||||
h.state_mut().ui.toolbar_docks = false;
|
||||
let ctx = h.ctx.clone();
|
||||
menus::invoke(h.state_mut(), &ctx, "ui.resetUi");
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Reset").click();
|
||||
h.run_steps(4);
|
||||
for panel in [Panel::Assets, Panel::Layers, Panel::Properties, Panel::TextureSetList, Panel::TextureSetSettings] {
|
||||
assert!(h.state().ui.dock.is_open(panel));
|
||||
}
|
||||
for panel in [Panel::History, Panel::Display, Panel::Shader, Panel::Log, Panel::Export] {
|
||||
assert!(!h.state().ui.dock.is_open(panel));
|
||||
}
|
||||
assert!(h.state().ui.toolbar_tools && h.state().ui.toolbar_docks);
|
||||
h.get_all_by_label("Viewport").min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).unwrap().click();
|
||||
h.run_steps(3);
|
||||
let quick = h.get_by_label_contains("Enable Quick Mask");
|
||||
assert!(quick.accesskit_node().is_disabled());
|
||||
assert_eq!(quick.accesskit_node().toggled(), Some(Toggled::True));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tools_hides_painting_controls_but_keeps_disabled_utilities() {
|
||||
let mut h = app();
|
||||
let ctx = h.ctx.clone();
|
||||
for visible in [true, false, true] {
|
||||
if h.state().ui.toolbar_tools != visible {
|
||||
menus::invoke(h.state_mut(), &ctx, "ui.toolbar.tools");
|
||||
}
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.query_by_label_contains("Eraser").is_some(), visible);
|
||||
for label in ["Snooze Autosave", "Resources Updater"] {
|
||||
assert!(h.get_by_label(label).accesskit_node().is_disabled(), "{label}");
|
||||
}
|
||||
assert!(h.query_by_label_contains("Online assets").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loading_a_mode_layout_preserves_the_other_modes_and_preferences() {
|
||||
use texturecraft_ui_egui::{file_dialogs::Answer, state::Mode};
|
||||
let dir = super::temp_dir::TempDir::new("mode-layout-isolation");
|
||||
let file = dir.join("rendering.json");
|
||||
let mut h = app();
|
||||
h.state_mut().run("project.new", serde_json::json!({"mesh":"cube", "resolution":128})).unwrap();
|
||||
h.state_mut().ui.mode = Mode::Rendering;
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.dock.focus(Panel::Renderer);
|
||||
let target = file.clone();
|
||||
h.state_mut().file_dialogs.set_override(Some(Box::new(move |_| Answer::Paths(vec![target.clone()]))));
|
||||
let ctx = h.ctx.clone();
|
||||
menus::invoke(h.state_mut(), &ctx, "ui.layout.save.rendering");
|
||||
h.run_steps(4);
|
||||
h.state_mut().ui.mode = Mode::Painting;
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.dock.close(Panel::Assets);
|
||||
h.state_mut().ui.prefs.autosave_minutes = 17;
|
||||
h.state_mut().ui.mode = Mode::Baking;
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.dock.close(Panel::MeshMapBakers);
|
||||
menus::invoke(h.state_mut(), &ctx, "ui.layout.load");
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().ui.mode, Mode::Rendering);
|
||||
assert!(h.state().ui.dock.is_open(Panel::Renderer));
|
||||
assert_eq!(h.state().ui.prefs.autosave_minutes, 17);
|
||||
h.state_mut().ui.mode = Mode::Painting;
|
||||
h.run_steps(3);
|
||||
assert!(!h.state().ui.dock.is_open(Panel::Assets));
|
||||
h.state_mut().ui.mode = Mode::Baking;
|
||||
h.run_steps(3);
|
||||
assert!(!h.state().ui.dock.is_open(Panel::MeshMapBakers));
|
||||
}
|
||||
@@ -83,14 +83,23 @@ fn project_items_are_disabled_without_a_project() {
|
||||
"layer.add.fill",
|
||||
"layer.remove",
|
||||
"bake.run",
|
||||
"resource.import",
|
||||
"material.load",
|
||||
] {
|
||||
assert!(!menus::enabled(app, id), "{id} needs a project");
|
||||
}
|
||||
for id in
|
||||
["ui.newProject", "file.open", "project.sample", "ui.settings", "ui.about", "ui.quit", "ui.hideUi", "ui.resetUi", "viewport.frame", "ui.layout.split"]
|
||||
{
|
||||
for id in [
|
||||
"resource.import",
|
||||
"ui.newProject",
|
||||
"file.open",
|
||||
"project.sample",
|
||||
"ui.settings",
|
||||
"ui.about",
|
||||
"ui.quit",
|
||||
"ui.hideUi",
|
||||
"ui.resetUi",
|
||||
"viewport.frame",
|
||||
"ui.layout.split",
|
||||
] {
|
||||
assert!(menus::enabled(app, id), "{id} works without a project");
|
||||
}
|
||||
let open = open_project();
|
||||
@@ -155,11 +164,18 @@ fn creating_or_opening_a_project_from_the_empty_state_works() {
|
||||
|
||||
assert!(harness.state().ui.windows.new_project, "New project opens its dialog from the empty state");
|
||||
|
||||
let directory = super::temp_dir::TempDir::new("picked-sample");
|
||||
let file = directory.join("sample.tcraft");
|
||||
let sample = Session::new_project("Chosen sample", texturecraft_engine::geom::primitives::cube(1.0), "builtin:cube", None, 128).unwrap();
|
||||
std::fs::write(&file, sample.to_project_bytes().unwrap()).unwrap();
|
||||
let mut harness = empty();
|
||||
let picked = file.clone();
|
||||
harness.state_mut().file_dialogs.set_override(Some(Box::new(move |_| texturecraft_ui_egui::file_dialogs::Answer::Paths(vec![picked.clone()]))));
|
||||
|
||||
invoke(&mut harness, "project.sample");
|
||||
|
||||
assert!(harness.state().session.project_open && harness.state().session.set_count() == 2, "the sample is still one menu click away");
|
||||
assert!(harness.state().session.project_open);
|
||||
assert_eq!(harness.state().session.doc.project.name, sample.doc.project.name, "the selected sample project opens");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -75,6 +75,25 @@ fn a_canceled_dialog_changes_nothing() {
|
||||
assert_eq!(h.state().file_dialogs.pending(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_sample_picker_asks_to_save_only_after_a_path_is_chosen() {
|
||||
let mut h = harness(true);
|
||||
answer(&mut h, |_| Answer::Cancelled);
|
||||
invoke(&mut h, "project.sample");
|
||||
assert_eq!(h.state().file_dialogs.pending(), 1);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().ui.windows.unsaved.is_none());
|
||||
assert!(h.state().session.modified);
|
||||
|
||||
let path = PathBuf::from("chosen.tcraft");
|
||||
let selected = path.clone();
|
||||
answer(&mut h, move |_| Answer::Paths(vec![selected.clone()]));
|
||||
invoke(&mut h, "project.sample");
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().ui.windows.unsaved, Some(Unsaved::Open(path.display().to_string())));
|
||||
assert!(h.state().session.modified);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dialog_that_cannot_show_is_reported() {
|
||||
let mut h = harness(false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Help > Export log... saves the log with each entry's time and level.
|
||||
//! Help > Export Log saves the log with each entry's time and level.
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
@@ -32,7 +32,7 @@ fn export_log_writes_every_line_with_time_and_level() {
|
||||
let file = dir.join("log.txt");
|
||||
let answer = file.clone();
|
||||
h.state_mut().file_dialogs.set_override(Some(Box::new(move |_| Answer::Paths(vec![answer.clone()]))));
|
||||
click_help_item(&mut h, "Export log...");
|
||||
click_help_item(&mut h, "Export Log");
|
||||
|
||||
let text = std::fs::read_to_string(&file).expect("the log file was written");
|
||||
let lines: Vec<&str> = text.lines().collect();
|
||||
|
||||
@@ -12,7 +12,7 @@ use texturecraft_ui_egui::file_dialogs::{Answer, Request};
|
||||
|
||||
use super::temp_dir::TempDir;
|
||||
|
||||
const TITLE: &str = "Import resources";
|
||||
const TITLE: &str = "Import Resources";
|
||||
/// The prefix field's tooltip, which is its accessible label.
|
||||
const PREFIX_HINT: &str = "Put in front of the resource's name. Characters other than letters, digits and _ . - become _";
|
||||
|
||||
@@ -208,6 +208,33 @@ fn the_engine_command_still_imports_a_path_with_an_optional_prefix() {
|
||||
assert_eq!(prefixed["name"], "a_b_tile.png");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_materialx_document_imports_as_a_layer() {
|
||||
let dir = TempDir::new("import-resources-materialx");
|
||||
let file = dir.join("paint.mtlx");
|
||||
std::fs::write(
|
||||
&file,
|
||||
r#"<?xml version="1.0"?>
|
||||
<materialx version="1.39">
|
||||
<open_pbr_surface name="S" type="surfaceshader">
|
||||
<input name="base_color" type="color3" value="0.8, 0.2, 0.1" />
|
||||
</open_pbr_surface>
|
||||
<surfacematerial name="Paint" type="material"><input name="surfaceshader" type="surfaceshader" nodename="S" /></surfacematerial>
|
||||
</materialx>"#,
|
||||
)
|
||||
.unwrap();
|
||||
let mut h = app();
|
||||
let layers = h.state().session.doc.project.layers.len();
|
||||
invoke(&mut h);
|
||||
add(&mut h, &[file]);
|
||||
|
||||
click(&mut h, "Import");
|
||||
|
||||
assert!(!is_open(&h), "the document was imported");
|
||||
assert!(h.state().session.doc.project.layers.len() > layers, "the material became a layer");
|
||||
assert!(resources(&h).is_empty(), "the document itself is not an image resource");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_failed_rows_remain_after_a_partial_import() {
|
||||
let dir = TempDir::new("import-resources-retry");
|
||||
|
||||
@@ -19,6 +19,7 @@ mod display_environment;
|
||||
mod display_post_effects;
|
||||
mod effect_rows;
|
||||
mod effect_sliders;
|
||||
mod empty_menus;
|
||||
mod empty_start;
|
||||
mod export_file_types;
|
||||
mod export_map_overrides;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Window > Layouts: save the panel arrangement under a name and switch to it from the menu.
|
||||
//! Saved named-layout commands remain available to shortcuts and automation after their menu is removed.
|
||||
|
||||
use egui::Role;
|
||||
use egui_kittest::Harness;
|
||||
@@ -15,14 +15,23 @@ fn app() -> Harness<'static, TextureCraftApp> {
|
||||
harness
|
||||
}
|
||||
|
||||
/// Open Window > Layouts, click `entry`, and let the app answer
|
||||
/// Exercise the existing dialog through a bound shortcut; named layouts are no longer in the menu.
|
||||
fn layouts_menu(harness: &mut Harness<'_, TextureCraftApp>, entry: &str) {
|
||||
harness.get_by_role_and_label(Role::Button, "Window").click();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_role_and_label(Role::Button, "Layouts").click();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_role_and_label(Role::Button, entry).click();
|
||||
let id = match entry {
|
||||
"Save current layout as..." => "ui.layout.saveAs",
|
||||
"Manage layouts..." => "ui.layout.manage",
|
||||
name => {
|
||||
let reply = invoke(harness, serde_json::json!({"id": "ui.layout.apply", "name": name}));
|
||||
assert_eq!(reply["ok"], true);
|
||||
harness.run_steps(3);
|
||||
return;
|
||||
}
|
||||
};
|
||||
harness.state_mut().ui.keymap.insert(id.into(), "F12".into());
|
||||
harness.run_steps(2);
|
||||
harness.key_press(egui::Key::F12);
|
||||
harness.run_steps(3);
|
||||
harness.state_mut().ui.keymap.remove(id);
|
||||
}
|
||||
|
||||
/// The dialog's text field: the one nearest the window center, where dialogs open (the shelf search is another)
|
||||
@@ -43,7 +52,7 @@ fn save_as(harness: &mut Harness<'_, TextureCraftApp>, name: &str) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layout_saved_from_the_menu_comes_back_from_the_menu() {
|
||||
fn a_layout_saved_from_a_shortcut_comes_back_through_automation() {
|
||||
let mut harness = app();
|
||||
harness.state_mut().ui.dock.close(Panel::Assets);
|
||||
save_as(&mut harness, "No shelf");
|
||||
|
||||
@@ -324,7 +324,7 @@ fn create_asks_before_discarding_edits_made_after_the_form_opened() {
|
||||
h.get_by_role_and_label(Role::Button, "Create").click();
|
||||
h.run_steps(3);
|
||||
|
||||
assert!(h.query_by_label("Unsaved changes").is_some());
|
||||
assert!(h.query_by_label("Unsaved Changes").is_some());
|
||||
assert_eq!(h.state().session.doc.project.name, "Open");
|
||||
|
||||
h.get_by_role_and_label(Role::Button, "Don't save").click();
|
||||
|
||||
@@ -15,7 +15,7 @@ const QUAD: &str = "v 0 0 0\nv 1 0 0\nv 1 1 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 1 1\n
|
||||
const TRIANGLE: &str = "v 0 0 0\nv 1 0 0\nv 0 1 0\nvt 0 0\nvt 1 0\nvt 0 1\nf 1/1 2/2 3/3\n";
|
||||
/// The format combo's tooltip, which is its accessible label.
|
||||
const FORMAT_HINT: &str = "For the whole project: how normal map images set as mesh maps are read (set them again after a change), and the default for export";
|
||||
const TITLE: &str = "Project configuration";
|
||||
const TITLE: &str = "Project Configuration";
|
||||
|
||||
fn temp_dir(test: &str) -> TempDir {
|
||||
TempDir::new(test)
|
||||
|
||||
@@ -117,7 +117,7 @@ fn the_blank_screen_menus_match_the_measured_enabled_states() {
|
||||
assert!(menus::enabled(app, id), "{id} is enabled on the blank screen");
|
||||
}
|
||||
for id in ["ui.view.bakeSettings", "ui.view.bakeMaps", "ui.view.meshMapBakers"] {
|
||||
assert!(!menus::enabled(app, id), "{id} belongs to Baking mode");
|
||||
assert!(!menus::enabled(app, id), "{id} belongs to Baking Mode");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -445,3 +445,31 @@ fn the_baking_options_say_when_there_is_no_gpu_to_trace_on() {
|
||||
let no_gpu = h.query_by_label("no GPU").is_some();
|
||||
assert_eq!(h.query_by_label(GPU_RAYTRACING_UNAVAILABLE).is_some(), no_gpu, "the note shows with no GPU and only then");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recent_project_limit_applies_on_ok_and_persists() {
|
||||
let mut h = harness(Session::closed().unwrap());
|
||||
h.state_mut().ui.recent = (0..8).map(|i| format!("/projects/{i}.tcraft")).collect();
|
||||
open_settings(&mut h);
|
||||
h.get_by_label("Recent projects limit").scroll_to_me();
|
||||
h.run_steps(3);
|
||||
assert!(!h.get_by_label("Recent projects limit").accesskit_node().is_disabled());
|
||||
h.state_mut().ui.windows.settings_draft.as_mut().unwrap().prefs.recent_projects_limit = 3;
|
||||
click(&mut h, "Cancel");
|
||||
assert_eq!(h.state().ui.recent.len(), 8);
|
||||
open_settings(&mut h);
|
||||
h.state_mut().ui.windows.settings_draft.as_mut().unwrap().prefs.recent_projects_limit = 3;
|
||||
click(&mut h, "OK");
|
||||
assert_eq!(h.state().ui.recent, ["/projects/0.tcraft", "/projects/1.tcraft", "/projects/2.tcraft"]);
|
||||
texturecraft_ui_egui::windows::remember(h.state_mut(), "/projects/new.tcraft");
|
||||
assert_eq!(h.state().ui.recent, ["/projects/new.tcraft", "/projects/0.tcraft", "/projects/1.tcraft"]);
|
||||
let mut storage = MemoryStorage::default();
|
||||
eframe::App::save(h.state_mut(), &mut storage);
|
||||
let restored: UiState = serde_json::from_str(&storage.values["ui.json"]).unwrap();
|
||||
assert_eq!(restored.prefs.recent_projects_limit, 3);
|
||||
let ctx = h.ctx.clone();
|
||||
let reply = texturecraft_ui_egui::control::handle(h.state_mut(), &ctx, "ui.set", &serde_json::json!({"prefs":{"recent_projects_limit":0}}));
|
||||
assert_eq!(reply["ok"], true);
|
||||
texturecraft_ui_egui::windows::remember(h.state_mut(), "/projects/another.tcraft");
|
||||
assert!(h.state().ui.recent.is_empty());
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Project templates: File > More save options (Save as template..., Save and reduce file size,
|
||||
//! Save as copy...), the New project list's reference names and the remembered template
|
||||
//! Project templates: File > More Save Options (Save As Template, Save and Reduce File Size,
|
||||
//! Save As Copy), the New project list's reference names and the remembered template
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
@@ -23,7 +23,7 @@ fn app() -> Harness<'static, TextureCraftApp> {
|
||||
fn open_more_save_options(h: &mut Harness<'_, TextureCraftApp>) {
|
||||
h.get_by_label("File").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("More save options").click();
|
||||
h.get_by_label("More Save Options").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ fn save_as_template_asks_in_the_templates_folder_and_saves_without_a_message() {
|
||||
})));
|
||||
|
||||
open_more_save_options(&mut h);
|
||||
h.get_by_label_contains("Save as template...").click();
|
||||
h.get_by_label_contains("Save As Template").click();
|
||||
h.run_steps(4);
|
||||
|
||||
let asked = asked.borrow();
|
||||
@@ -83,12 +83,12 @@ fn a_saved_template_appears_in_new_project_with_the_your_assets_suffix() {
|
||||
fn save_and_reduce_file_size_is_greyed_with_the_hint() {
|
||||
let mut h = app();
|
||||
open_more_save_options(&mut h);
|
||||
let item = h.get_by_label_contains("Save and reduce file size");
|
||||
let item = h.get_by_label_contains("Save and Reduce File Size");
|
||||
let at = item.rect().center();
|
||||
h.hover_at(at);
|
||||
h.run_steps(30);
|
||||
assert!(h.query_by_label(NOT_AVAILABLE).is_some(), "the hint shows on hover");
|
||||
assert!(h.get_by_label_contains("Save and reduce file size").accesskit_node().is_disabled(), "the item is greyed");
|
||||
assert!(h.get_by_label_contains("Save and Reduce File Size").accesskit_node().is_disabled(), "the item is greyed");
|
||||
assert!(!menus::enabled(h.state(), "ui.saveReduced"));
|
||||
assert!(!menus::implemented("ui.saveReduced"));
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ fn narrow_toolbars_keep_scroll_arrows_and_mode_buttons_separate() {
|
||||
harness.run_steps(4);
|
||||
let left = harness.get_by_label("Scroll left").rect();
|
||||
let right = harness.get_by_label("Scroll right").rect();
|
||||
let bake = harness.get_by_label("Bake Mesh Maps (Ctrl+Shift+B)").rect();
|
||||
let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect();
|
||||
let (_, clip) = size_label(&harness);
|
||||
for button in [left, right, bake] {
|
||||
assert_eq!(button.size(), egui::Vec2::splat(button_size));
|
||||
@@ -135,10 +135,8 @@ fn compact_view_buttons_can_be_scrolled_into_view_and_clicked() {
|
||||
#[test]
|
||||
fn mode_buttons_keep_their_order_and_dispatch_commands() {
|
||||
let mut harness = toolbar_harness(700.0, Tool::Paint);
|
||||
for (label, mode) in
|
||||
[("Bake Mesh Maps (Ctrl+Shift+B)", Mode::Baking), ("Rendering (path traced) (F10)", Mode::Rendering), ("Painting (F9)", Mode::Painting)]
|
||||
{
|
||||
let bake = harness.get_by_label("Bake Mesh Maps (Ctrl+Shift+B)").rect();
|
||||
for (label, mode) in [("Bake Mesh Maps (F8)", Mode::Baking), ("Rendering (path traced) (F10)", Mode::Rendering), ("Painting (F9)", Mode::Painting)] {
|
||||
let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect();
|
||||
let paint = harness.get_by_label("Painting (F9)").rect();
|
||||
let render = harness.get_by_label("Rendering (path traced) (F10)").rect();
|
||||
assert!(bake.right() < paint.left() && paint.right() < render.left());
|
||||
|
||||
@@ -10,7 +10,6 @@ use std::rc::Rc;
|
||||
use texturecraft_engine::Session;
|
||||
use texturecraft_ui_egui::file_dialogs::{Answer, Request};
|
||||
use texturecraft_ui_egui::state::Mode;
|
||||
use texturecraft_ui_egui::unavailable::NOT_AVAILABLE;
|
||||
use texturecraft_ui_egui::{TextureCraftApp, menus};
|
||||
|
||||
use super::temp_dir::TempDir;
|
||||
@@ -37,25 +36,16 @@ fn open_sub(h: &mut Harness<'_, TextureCraftApp>, name: &str) {
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn hover_hint(h: &mut Harness<'_, TextureCraftApp>, label: &str) -> bool {
|
||||
let at = h.get_by_label_contains(label).rect().center();
|
||||
h.hover_at(egui::pos2(1.0, 1.0));
|
||||
h.run_steps(2);
|
||||
h.hover_at(at);
|
||||
h.run_steps(30);
|
||||
h.query_by_label(NOT_AVAILABLE).is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn views_lists_renderer_settings_and_the_greyed_entries_with_a_hint() {
|
||||
let mut h = app();
|
||||
fn views_omit_unrequested_entries_and_disable_mode_specific_panels() {
|
||||
let mut h = app_with(Session::closed().unwrap());
|
||||
open_sub(&mut h, "Views");
|
||||
assert!(h.query_by_label_contains("Renderer Settings").is_some());
|
||||
for label in ["Baking Log", "Common Settings", "Mesh Map Bakers", "Mesh Map Settings", "Renderer Settings"] {
|
||||
assert!(h.get_by_label_contains(label).accesskit_node().is_disabled(), "{label}");
|
||||
}
|
||||
for label in ["Python Console", "Online assets"] {
|
||||
assert!(h.get_by_label_contains(label).accesskit_node().is_disabled(), "{label} is greyed");
|
||||
assert!(h.query_by_label_contains(label).is_none());
|
||||
}
|
||||
assert!(hover_hint(&mut h, "Python Console"), "Python Console says it is not available yet");
|
||||
assert!(hover_hint(&mut h, "Online assets"), "Online assets says it is not available yet");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -71,14 +61,13 @@ fn properties_names_the_tool_while_a_project_is_open() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toolbars_lists_docks_plugins_and_tools() {
|
||||
fn toolbars_lists_only_docks_and_tools() {
|
||||
let mut h = app();
|
||||
open_sub(&mut h, "Toolbars");
|
||||
for label in ["Docks", "Tools"] {
|
||||
assert!(!h.get_by_label_contains(label).accesskit_node().is_disabled(), "{label}");
|
||||
}
|
||||
assert!(h.get_by_label_contains("Plugins").accesskit_node().is_disabled());
|
||||
assert!(hover_hint(&mut h, "Plugins"));
|
||||
assert!(h.query_by_label_contains("Plugins").is_none());
|
||||
|
||||
assert!(h.state().ui.toolbar_docks && h.state().ui.toolbar_tools, "both bars start shown");
|
||||
h.get_by_label_contains("Docks").click();
|
||||
@@ -116,9 +105,9 @@ fn hide_ui_shows_its_check_mark() {
|
||||
fn save_ui_layout_has_one_entry_per_mode_and_writes_that_modes_layout() {
|
||||
let dir = TempDir::new("layout-per-mode");
|
||||
for (item, file, mode, baking) in [
|
||||
("Painting mode", "p.json", Mode::Painting, false),
|
||||
("Rendering mode", "r.json", Mode::Rendering, false),
|
||||
("Baking mode", "b.json", Mode::Baking, true),
|
||||
("Painting Mode", "p.json", Mode::Painting, false),
|
||||
("Rendering Mode", "r.json", Mode::Rendering, false),
|
||||
("Baking Mode", "b.json", Mode::Baking, true),
|
||||
] {
|
||||
let mut h = app();
|
||||
let path = dir.join(file);
|
||||
@@ -130,7 +119,10 @@ fn save_ui_layout_has_one_entry_per_mode_and_writes_that_modes_layout() {
|
||||
|
||||
let saved: serde_json::Value = serde_json::from_slice(&std::fs::read(&path).unwrap_or_else(|e| panic!("{item}: {e}"))).unwrap();
|
||||
assert_eq!(saved["mode"], serde_json::to_value(mode).unwrap(), "{item}");
|
||||
assert_eq!(saved["dock_is_baking"], baking, "{item}: the file's dock is the mode's own");
|
||||
assert!(saved.get("inactive_mode_dock").is_none(), "only one mode is saved");
|
||||
assert!(saved.get("prefs").is_none(), "preferences are not a layout");
|
||||
let dock = texturecraft_ui_egui::docking::Dock::from_value(saved["dock"].clone());
|
||||
assert_eq!(dock.is_open(texturecraft_ui_egui::docking::Panel::MeshMapBakers), baking);
|
||||
assert_eq!(h.state().ui.mode, Mode::Painting, "saving does not switch the mode");
|
||||
}
|
||||
}
|
||||
@@ -152,7 +144,7 @@ fn the_legacy_layout_save_command_saves_the_active_mode() {
|
||||
assert_eq!(reply["ok"], true);
|
||||
let saved: serde_json::Value = serde_json::from_slice(&std::fs::read(path).unwrap()).unwrap();
|
||||
assert_eq!(saved["mode"], serde_json::to_value(Mode::Baking).unwrap());
|
||||
assert_eq!(saved["dock_is_baking"], true);
|
||||
assert!(saved.get("inactive_mode_dock").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use texturecraft_engine::core::{BakeResolution, BakedMap, CurvatureMethod, HeightNormalization};
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
use texturecraft_ui_egui::docking::Panel;
|
||||
@@ -40,6 +40,16 @@ fn save(harness: &mut Harness<'_, TextureCraftApp>, dir: &Path, name: &str) {
|
||||
let img = harness.render().unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
let path = dir.join(format!("{name}.png"));
|
||||
img.save(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
||||
let tree = [egui::Role::Button, egui::Role::SpinButton, egui::Role::CheckBox]
|
||||
.into_iter()
|
||||
.flat_map(|role| harness.get_all_by_role(role))
|
||||
.filter_map(|button| {
|
||||
let node = button.accesskit_node();
|
||||
node.label().map(|label| format!("{label}: disabled={}, checked={:?}", node.is_disabled(), node.toggled()))
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
std::fs::write(dir.join(format!("{name}.txt")), tree).unwrap();
|
||||
eprintln!("wrote {}", path.display());
|
||||
}
|
||||
|
||||
@@ -53,6 +63,28 @@ fn empty_start_snapshot() {
|
||||
harness.state_mut().ui.prefs.language = "en".into();
|
||||
|
||||
save(&mut harness, &output_dir, "empty-start");
|
||||
for top in ["File", "Edit", "Mode", "Window", "Viewport", "Help"] {
|
||||
harness.get_by_label(top).click();
|
||||
harness.run_steps(4);
|
||||
save(&mut harness, &output_dir, &format!("empty-menu-{top}"));
|
||||
if top == "Window" {
|
||||
harness.get_by_label("Views").click();
|
||||
save(&mut harness, &output_dir, "empty-menu-views");
|
||||
}
|
||||
harness.key_press(egui::Key::Escape);
|
||||
harness.key_press(egui::Key::Escape);
|
||||
harness.run_steps(3);
|
||||
}
|
||||
harness.state_mut().ui.toolbar_tools = false;
|
||||
save(&mut harness, &output_dir, "empty-tools-off");
|
||||
for label in ["Snooze Autosave", "Resources Updater"] {
|
||||
assert!(harness.get_by_label(label).accesskit_node().is_disabled());
|
||||
}
|
||||
harness.get_by_label("Edit").click();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_label("Settings").click();
|
||||
save(&mut harness, &output_dir, "settings-recent-project-limit");
|
||||
assert!(!harness.get_by_label("Recent projects limit").accesskit_node().is_disabled());
|
||||
}
|
||||
|
||||
/// Closing rejects a same-frame capture, then releases both rendered view targets.
|
||||
|
||||
+23
-11
@@ -221,21 +221,32 @@ keeps its state in a throwaway file.
|
||||
| `command.list` | `{filter?}` | `[{id, label, menu, shortcut, params, enabled}]` |
|
||||
| `session.inspect` | | project, mesh, texture sets, layer stack, tool, camera, display, history |
|
||||
| `ui.inspect` | | UI state, viewport rect, fps, bake progress (`baking`, 0..1), the running bake's stage (`bakeStatus`, e.g. "Baking Ambient Occlusion (2/4)") and live preview (`bakePreview`, see *Live bake preview*), toasts, `titleBar` (who draws the title bar this run: `app`, `integrated` on macOS, or `system`) |
|
||||
| `ui.menu.list` | | the menu catalog: `{menu, submenu, label, id, shortcut, implemented, enabled}` |
|
||||
| `ui.menu.invoke` | `{id}` | behaves like a menu click (may open a window; `ui.resetUi` opens its question; `file.exportMesh` opens the Mesh Export Options prompt, whose Export asks for the file; `ui.view.export` opens the right bar's Export panel). `{"id": "ui.layout.apply", "name": "<layout>"}` switches to a panel layout saved under Window > Layouts (panels only; mode, zoom and wireframes stay) and errors when no layout has that name. `ui.layout.save` still saves the active mode; `ui.layout.save.painting`, `ui.layout.save.rendering` and `ui.layout.save.baking` ask where to save that mode's layout as a JSON file, `ui.layout.load` asks for one to load ("Select a UI layout file."); `ui.toolbar.docks` and `ui.toolbar.tools` show or hide the right bar and the tool shelf (`ui.toolbar.plugins`, `ui.view.pythonConsole` and `ui.view.onlineAssets` are listed as not implemented and not enabled); `ui.view.renderer` toggles the Renderer Settings panel (Rendering mode only). `{"id": "ui.layout.swap"}` swaps the 3D and 2D views of the split layout (F4) |
|
||||
| `ui.menu.invoke` id `ui.saveAsTemplate` | `{id}` | File > More save options > Save as template... opens a save dialog in the user templates folder. The choice supplies the file path and template name to `project.template.save`. `ui.saveReduced` (Save and reduce file size) is listed as not implemented and not enabled |
|
||||
| `ui.menu.invoke` ids `ui.help.releaseNotes`, `ui.help.exportLog` | `{id}` | Help > Release notes... opens the releases page in the browser; Help > Export log... exports the session log with each entry’s recorded UTC time, severity and source (a save dialog on desktop, a download on the web) |
|
||||
| `ui.menu.invoke` id `ui.wireframe` | `{id}` | Show mesh wireframe: shows or hides the mesh wireframe in the 3D and 2D views (the Display Settings check box). It has no menu entry and no default key; bind it in Settings > Shortcuts. The key bindings `camera.next` and `camera.previous` (Select next camera `>`, Select previous camera `<`) and `ui.mode.bake` (Ctrl+Shift+B) run the same commands as before |
|
||||
| `ui.menu.list` | | the menu catalog: `{menu, submenu, label, id, shortcut, implemented, enabled, checked}` |
|
||||
| `ui.menu.invoke` | `{id}` | behaves like a menu click (may open a window; `ui.resetUi` opens its question; `file.exportMesh` opens the Mesh Export Options prompt, whose Export asks for the file; `ui.view.export` opens the right bar's Export panel). `{"id": "ui.layout.apply", "name": "<layout>"}` switches to a legacy named panel layout (still accessible through assigned shortcuts) (panels only; mode, zoom and wireframes stay) and errors when no layout has that name. `ui.layout.save` still saves the active mode; `ui.layout.save.painting`, `ui.layout.save.rendering` and `ui.layout.save.baking` ask where to save only that mode's panels and view arrangement as a JSON file (without preferences or recent projects); loading preserves the other modes, `ui.layout.load` asks for one to load ("Load UI Layout"); `ui.toolbar.docks` and `ui.toolbar.tools` show or hide the right bar and the painting tools; the disabled Snooze Autosave and Resources Updater buttons stay visible when Tools is off; `ui.view.renderer` toggles the Renderer Settings panel (Rendering Mode only). `{"id": "ui.layout.swap"}` swaps the 3D and 2D views of the split layout (F4) |
|
||||
| `ui.menu.invoke` id `project.sample` | `{id}` | File > Open Sample Project opens a file picker for a `.tcraft` project. The direct `project.sample` engine command still creates the generated sample for automation. |
|
||||
| `ui.menu.invoke` id `ui.saveAsTemplate` | `{id}` | File > More Save Options > Save As Template opens a save dialog in the user templates folder. The choice supplies the file path and template name to `project.template.save`. `ui.saveReduced` (Save and Reduce File Size) is listed as not implemented and not enabled |
|
||||
| `ui.menu.invoke` ids `ui.help.releaseNotes`, `ui.help.showLog`, `ui.help.exportLog` | `{id}` | Help > Release Notes opens the releases page in the browser; Help > Show Log opens the current desktop run's rolling `log.txt` in the system text-file handler; Help > Export Log exports the session log with each entry’s recorded UTC time, severity and source (a save dialog on desktop with a `Log_TextureCraft_<version>_<date>_<os>_<gpuMode>.txt` name, a download on the web) |
|
||||
| `ui.menu.invoke` id `ui.wireframe` | `{id}` | Show mesh wireframe: shows or hides the mesh wireframe in the 3D and 2D views (the Display Settings check box). It has no menu entry and no default key; bind it in Settings > Shortcuts. The key bindings `camera.next` and `camera.previous` (Select next camera `>`, Select previous camera `<`) and `ui.mode.bake` (F8) run the same commands as before |
|
||||
| `ui.reset` | | resets the panels, view layout, zoom and every other view setting at once, without the question the Reset UI menu item asks; settings and shortcuts stay |
|
||||
| `ui.bake.start` | `{ts?: index \| [indices]}` (default: the sets ticked in Bake mode) | Opens Bake mode and bakes in the background like the Bake button: the 3D view shows the maps landing on the model as they finish (see *Live bake preview*). → the `bake.preview` state. Errors when a bake is already running |
|
||||
| `ui.bake.cancel` | | Stops the running bake; the set being baked keeps the maps it had, sets already finished stay applied, and the previous view mode comes back |
|
||||
| `ui.set` | fields of the UI state, e.g. `{"layout": "Only3D"}`; `dock` is the panel layout, a craft-ui docking `Workspace` (`{version, layout: {root, floating}, hidden}`; `root` is a tree of `Split`, `Tabs` and `Stack` nodes over the panels `Viewport`, `Assets`, `TextureSetList`, `Layers`, `TextureSetSettings`, `Properties`, `Display`, `Shader`, `History`, `Log`, `Export` and `Renderer` (a floating window holding one right-bar panel is that panel undocked); `hidden` lists where each closed panel was, so reopening it puts it back; a layout that does not read or has no docked `Viewport` becomes the default), `prefs` the settings (`{"language": "ja", "viewport_texture": 1, "brightness": "light", "accent": "blue"}`; missing fields take their defaults; `brightness` is `dark`, `mediumDark` (default), `mediumLight` or `light`, `accent` `copper` (default), `coral`, `blue`, `violet`, `green`, `amber` or `pink`, applied on the next frame; `system_title_bar` `true` has the system draw the title bar from the next start), `keymap` the custom shortcuts (`{"file.save": "F5"}`, `""` unbinds), `log_channel` the Log panel's tab (`General` or `Assets`) | `null` |
|
||||
| `ui.set` | fields of the UI state, e.g. `{"layout": "Only3D"}`; `dock` is the panel layout, a craft-ui docking `Workspace` (`{version, layout: {root, floating}, hidden}`; `root` is a tree of `Split`, `Tabs` and `Stack` nodes over the panels `Viewport`, `Assets`, `TextureSetList`, `Layers`, `TextureSetSettings`, `Properties`, `Display`, `Shader`, `History`, `Log`, `BakingLog`, `MeshMapBakers`, `BakeMaps`, `BakeSettings`, `Export` and `Renderer` (a floating window holding one right-bar panel is that panel undocked); `hidden` lists where each closed panel was, so reopening it puts it back; a layout that does not read or has no docked `Viewport` becomes the default), `prefs` the settings (`{"language": "ja", "viewport_texture": 1, "brightness": "light", "accent": "blue"}`; missing fields take their defaults; `brightness` is `dark`, `mediumDark` (default), `mediumLight` or `light`, `accent` `copper` (default), `coral`, `blue`, `violet`, `green`, `amber` or `pink`, applied on the next frame; `system_title_bar` `true` has the system draw the title bar from the next start), `keymap` the custom shortcuts (`{"file.save": "F5"}`, `""` unbinds), `log_channel` the Log panel's tab (`General` or `Assets`) | `null` |
|
||||
| `viewport.screenshot` | `{view?: "3d" \| "2d"}` | `{width, height, png}` (PNG, base64) |
|
||||
| `ui.screenshot` | | `{width, height, png}` of the whole window, after the next frame |
|
||||
| `ui.resize` | `{width, height}` | Sets the window's inner size in points (640–7680), leaving maximized state; for recordings and screenshots at a fixed size |
|
||||
| `debug.paintTest` | `{from: [x, y], to: [x, y], frames?: 120}` | Paints a straight stroke through the real frame loop (viewport pixels, one point per frame) for performance work |
|
||||
| `debug.frames` | | Frame timing since the last call (then cleared): `{frames, intervalMs, uiMs, syncMs, logicMs}` each `{avg, p95, max}`; `syncMs` is compositing plus display tile conversion, `logicMs` input, control requests and scripted strokes before the UI is built; `worst` breaks down the slowest frame; `strokeEnd` lists the frame that committed a `debug.paintTest` stroke and the one after it (null without one) |
|
||||
|
||||
The empty-project menus keep Recent Projects openable with Clear disabled when the list is empty.
|
||||
`ui.recent.clear` clears that list. More Save Options is disabled until a project is open.
|
||||
Help > Shortcuts list opens Settings on its Shortcuts page. Window > Reset UI restores the
|
||||
Assets, Layers, Properties, Texture Set List and Texture Set Settings panels and both toolbars.
|
||||
Baking Log and the bake/render settings views are disabled without a project. Import resources
|
||||
can open its dialog on desktop without a project; importing still requires an open project,
|
||||
and the dialog explains that asset-library import is not available yet.
|
||||
|
||||
Settings > General > Recent Projects limit controls the retained history (default 10, range 0–100; 0 disables history). Automation uses `ui.set {"prefs":{"recent_projects_limit":10}}`. A lower limit trims the oldest paths immediately.
|
||||
|
||||
Example session:
|
||||
|
||||
```text
|
||||
@@ -509,9 +520,10 @@ Maps are found by file name, case-insensitively, from the last known word in the
|
||||
import is an error that changes nothing. `maps` describes detection; `channels` and `resources`
|
||||
describe the successful import. Scan validates import options without decoding pixels.
|
||||
|
||||
In the app: File › Import PBR texture folder... or drop a folder, a `.zip` or several map files on the
|
||||
window. The dialog shows the maps found, lets you pick between candidates, set the normal convention and
|
||||
projection, and keep the material in the library (shelf › Materials).
|
||||
In the app: drop a folder, a `.zip` or several map files on the window. The dialog shows the maps found,
|
||||
lets you pick between candidates, set the normal convention and projection, and keep the material in the
|
||||
library (shelf › Materials). A `.mtlx` added in File › Import Resources is imported as `file.importMaterialX`
|
||||
does it.
|
||||
|
||||
## Smart masks
|
||||
|
||||
@@ -575,13 +587,13 @@ In the app, `viewport.frame` also resets the 2D view (pan, zoom and rotation), a
|
||||
|
||||
`camera.view {view}` looks at the mesh from one side (`front` from +Z, `back`, `left` from -X,
|
||||
`right`, `top` and `bottom` at the orbit's ±89° pitch limit) and frames it; the projection stays.
|
||||
`camera.view.front` … `camera.view.bottom` do the same without params (Viewport menu, no default
|
||||
`camera.view.front` … `camera.view.bottom` do the same without params (no default
|
||||
shortcut, bindable in Settings ▸ Shortcuts). `camera.perspective` (F5) and `camera.orthographic` (F6)
|
||||
change only the projection; position and rotation stay. None of them is an undo step. In the 3D
|
||||
view, Alt+Shift+left drag orbits in 90° steps.
|
||||
|
||||
`camera.rotation {mode: constrained|free}` (or `camera.rotation.constrained` / `camera.rotation.free`,
|
||||
Viewport menu and the rotation dropdown of the top bar) picks the orbit: constrained (the default) keeps
|
||||
the rotation dropdown of the top bar) picks the orbit: constrained (the default) keeps
|
||||
the horizon level and stops at the poles; free is a trackball that turns the camera about its own axes,
|
||||
so the model can be turned over and rolled. `camera.get` shows it as `rotation`; `camera.set` takes
|
||||
`rotation` too. Switching keeps the direction of view; going back to constrained drops the roll.
|
||||
|
||||
+41
-64
@@ -2,28 +2,26 @@
|
||||
|
||||
Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Each row is a menu item of the target menu layout with TextureCraft's command id; **live** means the id is implemented. Feature parity beyond menus is tracked in [`ROADMAP.md`](../ROADMAP.md).
|
||||
|
||||
**83 of 87 menu items live (95%).**
|
||||
**63 of 64 menu items live (98%).**
|
||||
|
||||
## File
|
||||
|
||||
| Item | Id | Shortcut | Status |
|
||||
|---|---|---|---|
|
||||
| New project... | `ui.newProject` | Ctrl+N | live |
|
||||
| Open... | `file.open` | Ctrl+O | live |
|
||||
| Open sample project... | `project.sample` | | live |
|
||||
| New Project | `ui.newProject` | Ctrl+N | live |
|
||||
| Open | `file.open` | Ctrl+O | live |
|
||||
| Recent Projects ▸ Clear | `ui.recent.clear` | | live |
|
||||
| Open Sample Project | `project.sample` | | live |
|
||||
| Close | `file.close` | Ctrl+F4 | live |
|
||||
| Save | `file.save` | Ctrl+S | live |
|
||||
| Save as... | `file.saveAs` | Ctrl+Shift+S | live |
|
||||
| More save options ▸ Save as template... | `ui.saveAsTemplate` | | live |
|
||||
| More save options ▸ Save and reduce file size | `ui.saveReduced` | | missing |
|
||||
| More save options ▸ Save as copy... | `file.saveCopy` | | live |
|
||||
| Remove unused resources... | `file.removeUnused` | | live |
|
||||
| Import resources... | `resource.import` | | live |
|
||||
| Import MaterialX material... | `file.importMaterialX` | | live |
|
||||
| Import PBR texture folder... | `file.importPbrFolder` | | live |
|
||||
| Import material... | `material.load` | | live |
|
||||
| Export Textures... | `ui.export` | Ctrl+Shift+E | live |
|
||||
| Export Mesh... | `file.exportMesh` | | live |
|
||||
| Save As | `file.saveAs` | Ctrl+Shift+S | live |
|
||||
| More Save Options ▸ Save As Template | `ui.saveAsTemplate` | | live |
|
||||
| More Save Options ▸ Save and Reduce File Size | `ui.saveReduced` | | missing |
|
||||
| More Save Options ▸ Save As Copy | `file.saveCopy` | | live |
|
||||
| Remove Unused Resources | `file.removeUnused` | | live |
|
||||
| Import Resources | `resource.import` | | live |
|
||||
| Export Textures | `ui.export` | Ctrl+Shift+E | live |
|
||||
| Export Mesh | `file.exportMesh` | | live |
|
||||
| Quit | `ui.quit` | Ctrl+Q | live |
|
||||
|
||||
## Edit
|
||||
@@ -32,23 +30,24 @@ Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Eac
|
||||
|---|---|---|---|
|
||||
| Undo | `edit.undo` | Ctrl+Z | live |
|
||||
| Redo | `edit.redo` | Ctrl+Y | live |
|
||||
| Project Configuration... | `ui.projectConfig` | | live |
|
||||
| Reimport mesh | `file.reimportMesh` | Ctrl+Shift+R | live |
|
||||
| Settings... | `ui.settings` | | live |
|
||||
| Project Configuration | `ui.projectConfig` | | live |
|
||||
| Reimport Mesh | `file.reimportMesh` | Ctrl+Shift+R | live |
|
||||
| Settings | `ui.settings` | | live |
|
||||
|
||||
## Mode
|
||||
|
||||
| Item | Id | Shortcut | Status |
|
||||
|---|---|---|---|
|
||||
| Bake Mesh Maps | `ui.mode.bake` | Ctrl+Shift+B | live |
|
||||
| Bake Mesh Maps | `ui.mode.bake` | F8 | live |
|
||||
| Painting | `ui.mode.paint` | F9 | live |
|
||||
| Rendering (path traced) | `ui.mode.render` | F10 | live |
|
||||
| Rendering | `ui.mode.render` | F10 | live |
|
||||
|
||||
## Window
|
||||
|
||||
| Item | Id | Shortcut | Status |
|
||||
|---|---|---|---|
|
||||
| Views ▸ Assets | `ui.view.assets` | | live |
|
||||
| Views ▸ Baking Log | `ui.view.bakingLog` | | live |
|
||||
| Views ▸ Common Settings | `ui.view.bakeSettings` | | live |
|
||||
| Views ▸ Display Settings | `ui.view.display` | | live |
|
||||
| Views ▸ Export | `ui.view.export` | | live |
|
||||
@@ -58,66 +57,44 @@ Generated by `TC_UPDATE_PARITY=1 cargo test -p texturecraft-ui-egui parity`. Eac
|
||||
| Views ▸ Mesh Map Bakers | `ui.view.meshMapBakers` | | live |
|
||||
| Views ▸ Mesh Map Settings | `ui.view.bakeMaps` | | live |
|
||||
| Views ▸ Properties | `ui.view.properties` | | live |
|
||||
| Views ▸ Python Console | `ui.view.pythonConsole` | | missing |
|
||||
| Views ▸ Renderer Settings | `ui.view.renderer` | | live |
|
||||
| Views ▸ Shader Settings | `ui.view.shader` | | live |
|
||||
| Views ▸ Online assets | `ui.view.onlineAssets` | | missing |
|
||||
| Views ▸ Texture Sets | `ui.view.textureSetList` | | live |
|
||||
| Views ▸ Texture Set List | `ui.view.textureSetList` | | live |
|
||||
| Views ▸ Texture Set Settings | `ui.view.textureSetSettings` | | live |
|
||||
| Toolbars ▸ Docks | `ui.toolbar.docks` | | live |
|
||||
| Toolbars ▸ Plugins | `ui.toolbar.plugins` | | missing |
|
||||
| Toolbars ▸ Tools | `ui.toolbar.tools` | | live |
|
||||
| Save UI Layout ▸ Painting mode | `ui.layout.save.painting` | | live |
|
||||
| Save UI Layout ▸ Rendering mode | `ui.layout.save.rendering` | | live |
|
||||
| Save UI Layout ▸ Baking mode | `ui.layout.save.baking` | | live |
|
||||
| Save UI Layout ▸ Painting Mode | `ui.layout.save.painting` | | live |
|
||||
| Save UI Layout ▸ Rendering Mode | `ui.layout.save.rendering` | | live |
|
||||
| Save UI Layout ▸ Baking Mode | `ui.layout.save.baking` | | live |
|
||||
| Load UI Layout | `ui.layout.load` | | live |
|
||||
| Layouts ▸ Save current layout as... | `ui.layout.saveAs` | | live |
|
||||
| Layouts ▸ Manage layouts... | `ui.layout.manage` | | live |
|
||||
| Hide UI | `ui.hideUi` | Tab | live |
|
||||
| Reset panel layout | `ui.resetPanelLayout` | | live |
|
||||
| Reset UI | `ui.resetUi` | | live |
|
||||
|
||||
## Viewport
|
||||
|
||||
| Item | Id | Shortcut | Status |
|
||||
|---|---|---|---|
|
||||
| Display material | `viewport.displayMaterial` | M | live |
|
||||
| Display next channel | `viewport.nextChannel` | C | live |
|
||||
| Display previous channel | `viewport.previousChannel` | Shift+C | live |
|
||||
| Display next mesh map | `viewport.nextMeshMap` | B | live |
|
||||
| Display previous mesh map | `viewport.previousMeshMap` | Shift+B | live |
|
||||
| UV checker | `ui.uvChecker` | | live |
|
||||
| Frame texture set | `viewport.frameSelection` | Shift+F | live |
|
||||
| Show entire mesh | `viewport.frame` | F | live |
|
||||
| Front view | `camera.view.front` | | live |
|
||||
| Back view | `camera.view.back` | | live |
|
||||
| Left view | `camera.view.left` | | live |
|
||||
| Right view | `camera.view.right` | | live |
|
||||
| Top view | `camera.view.top` | | live |
|
||||
| Bottom view | `camera.view.bottom` | | live |
|
||||
| Perspective | `camera.perspective` | F5 | live |
|
||||
| Orthographic | `camera.orthographic` | F6 | live |
|
||||
| 3D/2D views | `ui.layout.split` | F1 | live |
|
||||
| 3D view only | `ui.layout.3d` | F2 | live |
|
||||
| 2D view only | `ui.layout.2d` | F3 | live |
|
||||
| Swap 3D/2D | `ui.layout.swap` | F4 | live |
|
||||
| Navigation buttons | `ui.navButtons` | | live |
|
||||
| Enable quick mask | `viewport.quickMask` | Y | live |
|
||||
| Edit quick mask | `viewport.quickMask.edit` | U | live |
|
||||
| Invert quick mask | `viewport.quickMask.invert` | Ctrl+Shift+I | live |
|
||||
| Display Material | `viewport.displayMaterial` | M | live |
|
||||
| Display Next Channel | `viewport.nextChannel` | C | live |
|
||||
| Display Previous Channel | `viewport.previousChannel` | Shift+C | live |
|
||||
| Display Next Mesh Map | `viewport.nextMeshMap` | B | live |
|
||||
| Display Previous Mesh Map | `viewport.previousMeshMap` | Shift+B | live |
|
||||
| Show Entire Mesh/Path | `viewport.frame` | F | live |
|
||||
| Enable Quick Mask | `viewport.quickMask` | Y | live |
|
||||
| Edit Quick Mask | `viewport.quickMask.edit` | U | live |
|
||||
| Invert Quick Mask | `viewport.quickMask.invert` | Ctrl+Shift+I | live |
|
||||
|
||||
## Help
|
||||
|
||||
| Item | Id | Shortcut | Status |
|
||||
|---|---|---|---|
|
||||
| Release notes... | `ui.help.releaseNotes` | | live |
|
||||
| Documentation... | `ui.help.docs` | | live |
|
||||
| Shortcuts list... | `ui.help.shortcuts` | | live |
|
||||
| Join the community (Discord)... | `ui.help.discord` | | live |
|
||||
| ArtCraft website... | `ui.help.website` | | live |
|
||||
| Report a bug... | `ui.help.bug` | | live |
|
||||
| Show log... | `ui.view.log` | | live |
|
||||
| Export log... | `ui.help.exportLog` | | live |
|
||||
| Check for Updates... | `ui.help.checkForUpdates` | | live |
|
||||
| About TextureCraft... | `ui.about` | | live |
|
||||
| Release Notes | `ui.help.releaseNotes` | | live |
|
||||
| Documentation | `ui.help.docs` | | live |
|
||||
| Shortcuts List | `ui.help.shortcuts` | | live |
|
||||
| Discord | `ui.help.discord` | | live |
|
||||
| Report a Bug | `ui.help.bug` | | live |
|
||||
| Show Log | `ui.help.showLog` | | live |
|
||||
| Export Log | `ui.help.exportLog` | | live |
|
||||
| Check for Updates | `ui.help.checkForUpdates` | | live |
|
||||
| About TextureCraft | `ui.about` | | live |
|
||||
|
||||
Reference in new issue
Block a user