Show the latest bake in the Baking Log's tabs

The Baking Log gets the three tabs from the issue's mock-ups (Baking
Process, High Poly Parameters, Matching by Name) in the Properties
section-tab look. Baking Process lists one row per texture set and map: a
tick when baked, orange dots and bold for the map being baked (kept in
view), dim while waiting, a red cross or a warning when not kept, with the
reason on hover. The tab's icon turns into orange dots while a bake runs.
This commit is contained in:
Rebornim committed 2026-11-27 06:12:35 +00:00
1 parent 03600e447a
commit e24f4e28d8
10 files changed
+253 -10

No files matched your search

+146
View File
@@ -0,0 +1,146 @@
//! The Baking Log panel: the latest bake under three tabs, read from the session's bake record
use egui::{Align2, CornerRadius, FontId, Id, Rect, Role, Sense, Ui, WidgetInfo, pos2, vec2};
use egui_phosphor::regular as ic;
use texturecraft_engine::bake::{BakeLogMap, BakeMapState};
use crate::TextureCraftApp;
use crate::i18n::{baked_map_label, tr};
use crate::property_sheet::{SIDE_PADDING_POINTS, TAB_GAP, TAB_ICON_CENTER, TAB_ICON_SIZE, TAB_NAME_LEFT, TAB_PADDING, TAB_TEXT_SIZE, TAB_TOP, shown_tab_box};
use crate::theme::{Tokens, semibold};
mod baking_log_tab;
pub use baking_log_tab::BakingLogTab;
/// Height of the tab strip, as the Properties section tabs
const STRIP_HEIGHT: f32 = 30.0;
/// How far the first tab reaches left of the rows' side padding, as the Properties section tabs
const FIRST_TAB_OUTDENT: f32 = 4.0;
/// Height of one row of a list
const ROW_HEIGHT: f32 = 24.0;
/// Air above the first row
const LIST_TOP: f32 = 4.0;
/// How far a hovered row's fill stays inside the panel's sides
const HOVER_INSET: f32 = 3.0;
/// From the panel's left edge to a row's glyph centre, and to its name
const GLYPH_CENTER: f32 = SIDE_PADDING_POINTS + 6.0;
const NAME_LEFT: f32 = SIDE_PADDING_POINTS + 22.0;
/// Size of a row's glyph and of its name
const GLYPH_SIZE: f32 = 13.0;
const NAME_SIZE: f32 = 12.0;
pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
let running = app.session.bake_log.is_running();
if let Some(tab) = tab_strip(ui, app.ui.baking_log_tab, running) {
app.ui.baking_log_tab = tab;
}
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
ui.add_space(LIST_TOP);
if app.ui.baking_log_tab == BakingLogTab::BakingProcess {
baking_process(ui, &app.session.bake_log.maps);
}
});
}
/// The tabs on the panel's top edge, as the Properties section tabs; a tab with work in progress shows dots for its icon
fn tab_strip(ui: &mut Ui, shown: BakingLogTab, running: bool) -> Option<BakingLogTab> {
let tokens = Tokens::get(ui.ctx());
let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), STRIP_HEIGHT), Sense::hover());
ui.painter().rect_filled(strip, CornerRadius::ZERO, tokens.chrome);
let mut picked = None;
let mut left = strip.left() + SIDE_PADDING_POINTS - FIRST_TAB_OUTDENT;
for tab in BakingLogTab::ALL {
let name = tr(tab.name());
let on = tab == shown;
let width = ui.painter().layout_no_wrap(name.to_owned(), semibold(TAB_TEXT_SIZE), tokens.text).size().x + TAB_PADDING;
let rect = Rect::from_min_max(pos2(left, strip.top() + TAB_TOP), pos2(left + width, strip.bottom()));
let response = ui.interact(rect, ui.scope_id().with(("baking_log_tab", tab)), Sense::click());
response.widget_info(|| WidgetInfo::selected(Role::Tab, true, on, name));
if response.clicked() {
picked = Some(tab);
}
let painter = ui.painter();
if on {
shown_tab_box(painter, &tokens, rect);
}
let color = if on || response.hovered() { tokens.text } else { tokens.text_dim };
let in_progress = running && tab == BakingLogTab::BakingProcess;
let (icon, icon_color) = if in_progress { (ic::DOTS_THREE, tokens.accent) } else { (tab.icon(), color) };
let center_y = strip.center().y + TAB_TOP / 2.0;
painter.text(pos2(left + TAB_ICON_CENTER, center_y), Align2::CENTER_CENTER, icon, FontId::proportional(TAB_ICON_SIZE), icon_color);
let font = if on { semibold(TAB_TEXT_SIZE) } else { FontId::proportional(TAB_TEXT_SIZE) };
painter.text(pos2(left + TAB_NAME_LEFT, center_y), Align2::LEFT_CENTER, name, font, color);
if response.has_focus() {
crate::property_sheet::paint_focus_outline(painter, response.rect, tokens.text_strong);
}
left += width + TAB_GAP;
}
picked
}
/// One row per texture set and map, in bake order; the map being baked stays in view
fn baking_process(ui: &mut Ui, maps: &[BakeLogMap]) {
let followed = maps.iter().position(|row| row.state == BakeMapState::Baking);
let follow_id = Id::unique("baking_log_followed_map");
let newly_followed = followed.is_some() && ui.data(|data| data.get_temp::<Option<usize>>(follow_id)) != Some(followed);
ui.data_mut(|data| data.insert_temp(follow_id, followed));
for (index, row) in maps.iter().enumerate() {
let rect = map_row(ui, row);
if newly_followed && followed == Some(index) {
ui.scroll_to_rect(rect, None);
}
}
}
/// A map's row: its state's glyph, then "<texture set> <map>"; a map that was not baked tells why on hover
fn map_row(ui: &mut Ui, row: &BakeLogMap) -> Rect {
let tokens = Tokens::get(ui.ctx());
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_HEIGHT), Sense::hover());
let name = format!("{} {}", row.set_name, tr(baked_map_label(row.map)));
let (glyph, glyph_color, state) = match &row.state {
BakeMapState::Waiting => (ic::CIRCLE_DASHED, tokens.text_dim, tr("Waiting")),
BakeMapState::Baking => (ic::DOTS_THREE, tokens.accent, tr("Baking")),
BakeMapState::Baked => (ic::CHECK, tokens.text, tr("Baked")),
BakeMapState::Failed(_) => (ic::X_CIRCLE, tokens.danger, tr("Not baked")),
BakeMapState::Canceled => (ic::WARNING, tokens.warning, tr("Canceled")),
};
response.widget_info(|| WidgetInfo::labeled(Role::Label, true, format!("{name}, {state}")));
let painter = ui.painter();
if response.hovered() {
painter.rect_filled(rect.shrink2(vec2(HOVER_INSET, 0.0)), CornerRadius::ZERO, tokens.row_hover);
}
let center_y = rect.center().y;
painter.text(pos2(rect.left() + GLYPH_CENTER, center_y), Align2::CENTER_CENTER, glyph, FontId::proportional(GLYPH_SIZE), glyph_color);
let (font, color) = match row.state {
BakeMapState::Baking => (semibold(NAME_SIZE), tokens.text),
BakeMapState::Waiting => (FontId::proportional(NAME_SIZE), tokens.text_dim),
_ => (FontId::proportional(NAME_SIZE), tokens.text),
};
painter.text(pos2(rect.left() + NAME_LEFT, center_y), Align2::LEFT_CENTER, name, font, color);
let reason = match &row.state {
BakeMapState::Failed(reason) => Some(reason.as_str()),
BakeMapState::Canceled => Some(tr("The bake was canceled before this map was kept.")),
_ => None,
};
if let Some(reason) = reason {
response.on_hover_ui(|ui| {
ui.label(egui::RichText::new(state).font(semibold(NAME_SIZE)).color(tokens.text));
ui.label(egui::RichText::new(reason).size(NAME_SIZE).color(tokens.text_dim));
});
}
rect
}
@@ -0,0 +1,36 @@
use egui_phosphor::regular as ic;
use serde::{Deserialize, Serialize};
use crate::i18n::n_;
/// The Baking Log panel's tabs
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BakingLogTab {
/// Every map of the latest bake and how it went
#[default]
BakingProcess,
/// The high poly files each texture set bakes from
HighPolyParameters,
/// Which low poly part bakes from which high poly part
MatchingByName,
}
impl BakingLogTab {
pub const ALL: [BakingLogTab; 3] = [BakingLogTab::BakingProcess, BakingLogTab::HighPolyParameters, BakingLogTab::MatchingByName];
pub fn name(self) -> &'static str {
match self {
BakingLogTab::BakingProcess => n_("Baking Process"),
BakingLogTab::HighPolyParameters => n_("High Poly Parameters"),
BakingLogTab::MatchingByName => n_("Matching by Name"),
}
}
pub(crate) fn icon(self) -> &'static str {
match self {
BakingLogTab::BakingProcess => ic::LIST_CHECKS,
BakingLogTab::HighPolyParameters => ic::CUBE,
BakingLogTab::MatchingByName => ic::ARROWS_LEFT_RIGHT,
}
}
}
+1 -7
View File
@@ -612,13 +612,7 @@ 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::BakingLog => crate::baking_log::body(app, ui),
Panel::Export => crate::export_panel::body(app, ui),
Panel::Renderer => crate::render_mode::settings_body(app, ui),
Panel::Viewport => {}
+1
View File
@@ -14,6 +14,7 @@ mod ask;
mod autosave_name;
mod bake_job;
pub mod bake_mode;
pub mod baking_log;
mod bake_preset;
pub mod bake_presets;
mod bake_report;
+2 -1
View File
@@ -75,13 +75,14 @@ pub(crate) use properties_scroll::{PropertiesScroll, PropertiesSelection};
pub(crate) use row_lead::RowLead;
pub(crate) use section_tabs::{
SectionScope, TAB_GAP, TAB_ICON_CENTER, TAB_ICON_SIZE, TAB_NAME_LEFT, TAB_PADDING, TAB_ROUNDING, TAB_TEXT_SIZE, TAB_TOP, forget_sections, in_scope,
room_past_end, section_tabs,
room_past_end, section_tabs, shown_tab_box,
};
pub(crate) use sheet::PropertySheet;
pub(crate) use size_columns_response::SizeColumnsResponse;
pub(crate) use slot_response::SlotResponse;
pub(crate) use stack_slider::StackSlider;
pub(crate) use stacked_rows::{CHECK_SIZE, paint_check};
pub(crate) use switch_control::paint_focus_outline;
pub(crate) fn paint_keyboard_focus(ui: &egui::Ui, response: &egui::Response, tokens: &crate::theme::Tokens) {
if response.has_focus() {
@@ -110,7 +110,7 @@ fn tab_rect(strip: Rect, left: f32, right: f32) -> Rect {
}
/// The shown tab's box over `tab`: the panel's colour, rounded, so it rises from the panel below the strip
fn shown_tab_box(painter: &Painter, tokens: &Tokens, tab: Rect) {
pub(crate) fn shown_tab_box(painter: &Painter, tokens: &Tokens, tab: Rect) {
painter.rect_filled(tab, CornerRadius::same(TAB_ROUNDING), tokens.panel);
}
@@ -63,7 +63,7 @@ pub(super) fn untinted(_index: usize) -> &'static [Color32] {
&[]
}
pub(super) fn paint_focus_outline(painter: &Painter, rect: Rect, color: Color32) {
pub(crate) fn paint_focus_outline(painter: &Painter, rect: Rect, color: Color32) {
painter.rect_stroke(rect, CornerRadius::same(CONTROL_RADIUS), Stroke::new(FOCUS_OUTLINE_WIDTH, color), StrokeKind::Inside);
}
+4
View File
@@ -681,6 +681,9 @@ pub struct UiState {
/// The Log panel's shown channel tab
#[serde(default)]
pub log_channel: crate::log_panel::LogChannel,
/// The Baking Log panel's shown tab
#[serde(default)]
pub baking_log_tab: crate::baking_log::BakingLogTab,
/// The project template the last New project was created from (name or label)
#[serde(default)]
pub last_template: String,
@@ -844,6 +847,7 @@ impl Default for UiState {
bake_preset_name: String::new(),
layout_dialog: None,
log_channel: crate::log_panel::LogChannel::default(),
baking_log_tab: crate::baking_log::BakingLogTab::default(),
last_template: String::new(),
log_selection: Default::default(),
log_anchor: None,
+60
View File
@@ -0,0 +1,60 @@
//! The Baking Log panel: the latest bake, map by map
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use texturecraft_engine::core::{BakeResolution, BakedMap};
use texturecraft_ui_egui::TextureCraftApp;
use texturecraft_ui_egui::docking::Panel;
use texturecraft_ui_egui::state::Mode;
fn harness() -> Harness<'static, TextureCraftApp> {
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
for texture_set in &mut session.doc.project.texture_sets {
texture_set.bake = Default::default();
texture_set.bake.common.resolution = BakeResolution::R64;
texture_set.bake.maps.select([BakedMap::Id, BakedMap::Position]);
}
let mut harness = Harness::builder()
.with_size(egui::vec2(1600.0, 1000.0))
.with_context_setup(texturecraft_ui_egui::framework::install_headless)
.build_eframe(|context| TextureCraftApp::new(context, session));
harness.state_mut().ui.mode = Mode::Baking;
harness.run_steps(4);
harness
}
fn run_to_the_end(harness: &mut Harness<'static, TextureCraftApp>) {
for _ in 0..4000 {
harness.run_steps(1);
if harness.state().bake.is_none() {
harness.run_steps(2);
return;
}
std::thread::sleep(std::time::Duration::from_millis(2));
}
panic!("the bake did not finish");
}
#[test]
fn the_baking_process_tab_lists_each_set_and_map_with_how_it_went() {
let mut harness = harness();
{
// Set 1 has no tile left to bake, so its bake fails
let set = &mut harness.state_mut().session.doc.project.texture_sets[1];
set.uv_tiles = vec![1001];
set.bake_excluded_tiles.insert(1001);
set.bake.maps.select([BakedMap::Id]);
}
assert!(harness.state().ui.dock.is_visible(Panel::BakingLog), "the bake layout shows the Baking Log");
harness.state_mut().start_bake(vec![0, 1]);
run_to_the_end(&mut harness);
let names: Vec<String> = harness.state().session.doc.project.texture_sets.iter().map(|set| set.name.clone()).collect();
for map in ["ID", "Position"] {
assert!(harness.query_by_label(&format!("{} {map}, Baked", names[0])).is_some(), "set 0's {map} row is ticked");
}
assert!(harness.query_by_label(&format!("{} ID, Not baked", names[1])).is_some(), "set 1's row failed");
}
+1
View File
@@ -10,6 +10,7 @@ mod bake_mode;
mod bake_presets;
mod bake_reset_menus;
mod bake_sync;
mod baking_log;
mod brush_drag;
mod brush_section_reset;
mod camera_views;