mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 17:19:24 +01:00
Output templates: the reference's columns and swatch colours, aligned map cards and a used map's square
The tab lays out on the reference's columns: Presets (built-in templates with a locked file glyph, the selected one in the frame colour and bold, no accent), the outputs 10 px from both dividers, and the Input maps and Mesh/Converted maps panes keeping their width at the window's right. Output map cards are 48 px with a 6 px inset: grip, name field cut at the front while not typed in, "$", the channel swatches in the reference's colours moved onto TextureCraft's window colour with their channel's underline, then file type over bit depth on one column beside duplicate and remove. A built-in template's cards keep their full look (its lock says it is read-only). A map an output reads shows a small square of its colour; Converted maps are plain text. The drag hint is the map entries' tooltip, and the count strip reads "N output maps will be exported".
This commit is contained in:
1 parent
a0d996fc0c
commit
bde768fdf7
7 files changed
+602
-403
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
/// An output map card's index, the card count (for the grip's moves) and the width its lists' values line up on
|
||||
pub(super) struct OutputCard {
|
||||
pub(super) index: usize,
|
||||
pub(super) count: usize,
|
||||
pub(super) value_width: f32,
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use egui::Color32;
|
||||
pub(super) struct SwatchLook {
|
||||
/// The source map's colour (None: empty or a constant).
|
||||
pub(super) fill: Option<Color32>,
|
||||
/// One bar per channel of the source the swatch reads.
|
||||
pub(super) bars: Vec<Color32>,
|
||||
/// The underline in the colour of the channel the swatch's letters name (None: a constant)
|
||||
pub(super) bar: Option<Color32>,
|
||||
pub(super) inverted: bool,
|
||||
}
|
||||
@@ -1758,13 +1758,7 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let right = window.right() - RIGHT_MARGIN;
|
||||
let row_y = window.top() + TAB_ROW_CONTROLS_Y;
|
||||
match app.ui.export.tab {
|
||||
1 => {
|
||||
let strip = egui::Rect::from_min_max(egui::pos2(window.center().x, window.top()), egui::pos2(right, body.top()));
|
||||
ui.scope_builder(
|
||||
egui::UiBuilder::new().max_rect(strip).layout(egui::Layout::right_to_left(egui::Align::Center)),
|
||||
crate::export_templates::naming_pattern,
|
||||
);
|
||||
}
|
||||
1 => crate::export_templates::naming_pattern(ui, window.right(), row_y),
|
||||
2 => {
|
||||
let width = drawn::text_width(ui, tr("Open output directory"), false) + OPEN_DIRECTORY_PADDING;
|
||||
let rect = drawn::control_rect(window.right() - OPEN_DIRECTORY_FROM_RIGHT - width, window.right() - OPEN_DIRECTORY_FROM_RIGHT, row_y);
|
||||
@@ -1800,7 +1794,7 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
let mut row = ui.new_child(egui::UiBuilder::new().max_rect(body).layout(egui::Layout::left_to_right(egui::Align::Min)));
|
||||
row.set_height(body.height());
|
||||
match app.ui.export.tab {
|
||||
1 => crate::export_templates::tab(app, &mut row, &presets),
|
||||
1 => crate::export_templates::tab(app, ui, body, &presets),
|
||||
2 => list_tab(app, &mut row),
|
||||
_ => settings_tab(app, ui, window, body, &presets),
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The Export textures window's own controls, drawn at the places its layout gives them: tabs,
|
||||
//! checks, dropdowns, buttons and icon buttons in the window's colours ([`ExportLook`])
|
||||
|
||||
use egui::{Align2, Color32, FontId, Id, Pos2, Rect, Response, Role, Sense, Stroke, StrokeKind, Ui, WidgetInfo, pos2, vec2};
|
||||
use egui::{Align2, Color32, CornerRadius, FontId, Id, Pos2, Rect, Response, Role, Sense, Stroke, StrokeKind, Ui, WidgetInfo, pos2, vec2};
|
||||
use egui_phosphor::regular as ic;
|
||||
|
||||
use super::export_look::{CONTROL_HEIGHT, CONTROL_RADIUS, ExportLook, TEXT_SIZE};
|
||||
@@ -34,6 +34,10 @@ const TAB_GAP: f32 = 3.0;
|
||||
/// How far a tab reaches under the divider, where the body's colour covers its lower corners
|
||||
const TAB_OVERLAP: f32 = 4.0;
|
||||
|
||||
/// A quiet dropdown's hover face: its padding round the value and chevron, and half its height
|
||||
const TEXT_DROPDOWN_PADDING: f32 = 3.0;
|
||||
const TEXT_DROPDOWN_HALF_HEIGHT: f32 = 9.0;
|
||||
|
||||
/// Hit area of an icon button around its glyph
|
||||
const ICON_HIT_SIZE: f32 = 20.0;
|
||||
|
||||
@@ -303,3 +307,24 @@ pub(crate) fn icon_button(ui: &mut Ui, centre: Pos2, icon: &str, size: f32, name
|
||||
paint_focus(ui, &response);
|
||||
response
|
||||
}
|
||||
|
||||
/// A card's quiet dropdown: its value from `value_left` and a chevron at `chevron_x`, no box
|
||||
pub(crate) fn text_dropdown(ui: &mut Ui, id: Id, value_left: f32, chevron_x: f32, y: f32, value: &str) -> Response {
|
||||
let look = ExportLook::get(ui.ctx());
|
||||
let enabled = ui.is_enabled();
|
||||
let rect = Rect::from_min_max(
|
||||
pos2(value_left - TEXT_DROPDOWN_PADDING, y - TEXT_DROPDOWN_HALF_HEIGHT),
|
||||
pos2(chevron_x + CHEVRON_SIZE / 2.0 + TEXT_DROPDOWN_PADDING, y + TEXT_DROPDOWN_HALF_HEIGHT),
|
||||
);
|
||||
let response = ui.interact(rect, id, if enabled { Sense::click() } else { Sense::hover() });
|
||||
let name = format!("{value} {}", ic::CARET_DOWN);
|
||||
response.widget_info(|| WidgetInfo::labeled(Role::Button, enabled, &name));
|
||||
if response.hovered() && enabled {
|
||||
ui.painter().rect_filled(rect, CornerRadius::same(CONTROL_RADIUS), look.raised);
|
||||
}
|
||||
let color = if looks_disabled(ui, enabled) { look.text_dim } else { look.text };
|
||||
text_at(ui, value_left, y, value, color, false);
|
||||
glyph(ui, pos2(chevron_x, y), ic::CARET_DOWN, CHEVRON_SIZE, color);
|
||||
paint_focus(ui, &response);
|
||||
response
|
||||
}
|
||||
@@ -23,6 +23,9 @@ const SCROLL_BAR_MARGIN: f32 = 4.0;
|
||||
/// How far the dividers sit below the frame colour, so they read on it
|
||||
const DIVIDER_DARKENING: f32 = 0.26;
|
||||
|
||||
/// How far the Presets list's names sit from the text colour towards the dim one
|
||||
const LIST_TEXT_DIMMING: f32 = 0.37;
|
||||
|
||||
/// The Export textures window's colours from the theme: controls a step darker than the window, raised faces a step lighter
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct ExportLook {
|
||||
@@ -36,7 +39,9 @@ pub(crate) struct ExportLook {
|
||||
pub(crate) outline: Color32,
|
||||
pub(crate) text: Color32,
|
||||
pub(crate) text_dim: Color32,
|
||||
pub(crate) list_text: Color32,
|
||||
pub(crate) accent: Color32,
|
||||
pub(crate) dark: bool,
|
||||
}
|
||||
|
||||
impl ExportLook {
|
||||
@@ -52,7 +57,9 @@ impl ExportLook {
|
||||
outline: tokens.button_border,
|
||||
text: tokens.text,
|
||||
text_dim: tokens.text_dim,
|
||||
list_text: lerp_color(tokens.text, tokens.text_dim, LIST_TEXT_DIMMING),
|
||||
accent: tokens.accent,
|
||||
dark: tokens.dark,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,15 +95,23 @@ fn right_click(h: &mut Harness<'_, TextureCraftApp>, label: &str) {
|
||||
fn the_tab_shows_the_preset_tools_and_map_editor() {
|
||||
let library = TemplateLibrary::new("layout");
|
||||
let mut h = harness(&library);
|
||||
for text in ["Presets", "Naming pattern", "Current preset:", "Output maps", "Create:", "Drop an input map onto a channel to assign it to that output."] {
|
||||
for text in ["Presets", "Naming pattern", "Current preset:", "Output maps", "Create:"] {
|
||||
assert!(h.query_by_label(text).is_some(), "{text}");
|
||||
}
|
||||
let hint = "Drop an input map onto a channel to assign it to that output.";
|
||||
assert!(h.query_by_label(hint).is_none(), "the drag hint is no line under the cards");
|
||||
let metallic = h.get_by_role_and_label(egui::Role::ListItem, "Metallic").rect().center();
|
||||
h.hover_at(metallic);
|
||||
h.run_steps(30);
|
||||
assert!(h.query_by_label(hint).is_some(), "a map entry's tooltip says how to use it");
|
||||
h.hover_at(egui::pos2(1.0, 1.0));
|
||||
h.run_steps(4);
|
||||
assert!(h.get_all_by_role(egui::Role::ComboBox).any(|c| c.value().as_deref() == Some("OpenPBR")));
|
||||
let maps = h.state().session.export_preset("Mine").unwrap().maps.len();
|
||||
let ts = h.state().session.ts();
|
||||
let plan = h.state_mut().run("export.plan", json!({"preset": "Mine", "ts": ts})).unwrap();
|
||||
let exported = plan.as_array().unwrap().len();
|
||||
assert!(h.query_by_label(&format!("{exported} output maps will be exported.")).is_some());
|
||||
assert!(h.query_by_label(&format!("{exported} output maps will be exported")).is_some());
|
||||
for create in ["Gray", "RGB", "R+G+B", "RGB+A", "R+G+B+A"] {
|
||||
assert!(h.query_by_label(create).is_some(), "{create}");
|
||||
}
|
||||
@@ -262,8 +270,8 @@ fn the_footer_counts_only_the_maps_the_texture_set_exports() {
|
||||
assert_eq!(plan.as_array().unwrap().len(), 1, "the sample set has no sheen: {plan}");
|
||||
hover_name_field(&mut h, 1);
|
||||
assert!(h.query_all_by_label_contains("Not exported").next().is_some(), "the sheen row says so");
|
||||
assert!(h.query_by_label("1 output maps will be exported.").is_some());
|
||||
assert!(h.query_by_label("2 output maps will be exported.").is_none());
|
||||
assert!(h.query_by_label("1 output maps will be exported").is_some());
|
||||
assert!(h.query_by_label("2 output maps will be exported").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user