Export textures and Mesh Export Options: plain Export buttons, fixed footer widths, reference dock buttons

This commit is contained in:
vangel76 committed 2026-11-23 23:29:18 +01:00
1 parent 81627ab8c7
commit cfc4b8b3a7
4 files changed
+47 -14

No files matched your search

+15 -6
View File
@@ -4,23 +4,32 @@ use egui::Ui;
use crate::TextureCraftApp;
use crate::i18n::tr;
use crate::theme::caption;
use crate::theme::{Tokens, caption};
use crate::widgets::primary_button;
/// Width of the Export Mesh and Export Textures buttons
const EXPORT_BUTTON_WIDTH: f32 = 176.0;
/// Space around each button's text, so the buttons are as wide as their text as in the reference
const EXPORT_BUTTON_PADDING: egui::Vec2 = egui::vec2(18.0, 5.0);
/// Gap between the Export Mesh and Export Textures buttons
const EXPORT_BUTTON_GAP: f32 = 12.0;
/// The Export panel body (a rail popup or dock tab); its buttons need an open project
pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
ui.label(caption(&tr("Export").to_uppercase()));
let project_open = app.session.project_open;
let tokens = Tokens::get(ui.ctx());
ui.vertical_centered(|ui| {
let size = [EXPORT_BUTTON_WIDTH, ui.spacing().interact_size.y];
if ui.add_enabled(project_open, egui::Button::new(tr("Export Mesh...")).min_size(size.into())).clicked() {
ui.spacing_mut().button_padding = EXPORT_BUTTON_PADDING;
ui.spacing_mut().item_spacing.y = EXPORT_BUTTON_GAP;
// Fully rounded: Export Mesh outlined, Export Textures filled
let pill = ui.spacing().interact_size.y + 2.0 * EXPORT_BUTTON_PADDING.y;
let outlined = egui::Button::new(tr("Export Mesh...")).fill(egui::Color32::TRANSPARENT).stroke(egui::Stroke::new(1.0, tokens.button_border));
if ui.add_enabled(project_open, outlined.corner_radius(pill / 2.0)).clicked() {
app.ui.windows.mesh_export_options = Some(app.session.project_id);
app.ui.rail_panel = None;
}
if ui.add_enabled(project_open, primary_button(ui, tr("Export Textures...")).min_size(size.into())).clicked() {
if ui.add_enabled(project_open, primary_button(ui, tr("Export Textures...")).corner_radius(pill / 2.0)).clicked() {
app.ui.windows.export = true;
app.ui.rail_panel = None;
}
+12 -5
View File
@@ -14,7 +14,7 @@ use crate::i18n::{n_, tr, trf};
use crate::state::{ConsoleLine, ExportSetPlan, ExportUi, FileType, MapExport, SIZE_OF_LARGEST_SET, SetExport};
use crate::theme::{Tokens, caption};
use crate::unavailable::NOT_AVAILABLE;
use crate::widgets::{icon_button, primary_button};
use crate::widgets::icon_button;
mod inherited_settings;
mod map_row;
@@ -34,6 +34,8 @@ const LIST_WIDTH: f32 = 180.0;
const ICON: f32 = 20.0;
/// Width of the value column of the parameter rows
const VALUE_WIDTH: f32 = 360.0;
/// Width of the bottom bar's buttons, the same for all as in the reference
const FOOTER_BUTTON_WIDTH: f32 = 125.0;
/// The output sizes the Size list offers, in texels per side
pub(crate) const SIZES: [u32; 7] = [128, 256, 512, 1024, 2048, 4096, 8192];
@@ -584,6 +586,11 @@ fn selected_texture_count(app: &mut TextureCraftApp) -> usize {
count
}
/// A bottom bar button, as wide as the others
fn footer_button(text: &str) -> egui::Button<'_> {
egui::Button::new(text).min_size(vec2(FOOTER_BUTTON_WIDTH, 0.0))
}
/// A header with a menu or tool at its right end
fn header(ui: &mut Ui, title: &str, right: impl FnOnce(&mut Ui)) {
ui.horizontal(|ui| {
@@ -1359,7 +1366,7 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
ui.horizontal(|ui| {
// Not on LIST OF EXPORTS
if app.ui.export.tab != 2
&& ui.button(tr("Reset all")).on_hover_text(tr("Resets all settings to their default values, including all textures.")).clicked()
&& ui.add(footer_button(tr("Reset all"))).on_hover_text(tr("Resets all settings to their default values, including all textures.")).clicked()
{
// Keep ownership so Cancel can restore the opening settings
let e = &mut app.ui.export;
@@ -1369,15 +1376,15 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// Nothing to write without a ticked texture set
let any = !export_selection(app).is_empty();
if ui.add_enabled(any, primary_button(ui, tr("Export"))).on_hover_text(tr("Exports all selected textures and additional files")).clicked() {
if ui.add_enabled(any, footer_button(tr("Export"))).on_hover_text(tr("Exports all selected textures and additional files")).clicked() {
do_export = true;
}
// Saving closes the window without starting an export
if ui.button(tr("Save settings")).on_hover_text(tr("Closes the export window and saves changes")).clicked() {
if ui.add(footer_button(tr("Save settings"))).on_hover_text(tr("Closes the export window and saves changes")).clicked() {
app.ui.windows.export = false;
}
if ui.button(tr("Cancel")).on_hover_text(tr("Closes the export window and undoes all recent changes")).clicked() {
if ui.add(footer_button(tr("Cancel"))).on_hover_text(tr("Closes the export window and undoes all recent changes")).clicked() {
canceled = true;
}
ui.label(trf("{n} textures selected for export", &[("n", &selected)]));
+11 -3
View File
@@ -5,13 +5,18 @@ use egui::Ui;
use crate::TextureCraftApp;
use crate::i18n::tr;
use crate::unavailable;
use crate::widgets::primary_button;
/// Indent of an option's checkbox under its choice
const OPTION_INDENT: f32 = 20.0;
/// Width of the Cancel and Export buttons
const BUTTON_WIDTH: f32 = 130.0;
const BUTTON_WIDTH: f32 = 110.0;
/// The reference dialog's content width
const DIALOG_WIDTH: f32 = 510.0;
/// Gap between the two option groups, as in the reference
const GROUP_GAP: f32 = 25.0;
/// The prompt, while File > Export Mesh waits on it
pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
@@ -23,9 +28,12 @@ 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| {
ui.set_width(DIALOG_WIDTH);
// TextureCraft exports the mesh as it is: triangulated, without displacement
ui.add(egui::RadioButton::new(true, tr("Without displacement/tessellation")));
option(ui, true, tr("Apply triangulation"));
ui.add_space(GROUP_GAP);
unavailable::greyed(ui, |ui| ui.add(egui::RadioButton::new(false, tr("With displacement/tessellation"))));
option(ui, true, tr("Recompute vertex normals"));
ui.add_space(8.0);
@@ -34,7 +42,7 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let size = egui::vec2(BUTTON_WIDTH, ui.spacing().interact_size.y);
export = ui.add(primary_button(ui, tr("Export")).min_size(size)).clicked();
export = ui.add(egui::Button::new(tr("Export")).min_size(size)).clicked();
cancel = ui.add(egui::Button::new(tr("Cancel")).min_size(size)).clicked();
});
});
@@ -99,3 +99,12 @@ fn the_unavailable_checkboxes_carry_the_reference_texts() {
);
checkbox_tooltip_is(&mut h, "Export shaders parameters", "Exports a JSON file with the settings for all shader instances");
}
#[test]
fn the_bottom_bar_buttons_share_one_width() {
let h = harness(egui::vec2(1600.0, 960.0));
let widths: Vec<f32> = ["Reset all", "Cancel", "Save settings", "Export"].iter().map(|label| window_button_rect(&h, label, 1600.0).width()).collect();
assert!(widths.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 1.0), "{widths:?}");
}