mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 17:19:24 +01:00
Toggle Auto-rebake from a Mesh Map Bakers row
Each row gets an Auto-rebake icon at its right end. It stays shown and bright on the set's auto-rebake map; on the other rows it shows dim while the row is hovered, and bright while the icon is hovered or has focus. Clicking it makes that map the set's auto-rebake map, or turns Auto-rebake off.
This commit is contained in:
1 parent
7f3b16d434
commit
23f27ba16d
9 files changed
+193
-74
No files matched your search
@@ -1,10 +1,11 @@
|
||||
use egui::{Align, Align2, CornerRadius, FontId, Layout, Pos2, Rect, RichText, Role, Sense, Stroke, Ui, UiBuilder, WidgetInfo, pos2, vec2};
|
||||
use egui_phosphor::regular as icon;
|
||||
use serde_json::json;
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::ViewMode;
|
||||
use texturecraft_engine::core::{BakeChange, BakeSettings, BakeSyncGroup, BakedMap};
|
||||
|
||||
use super::glyph_look::GlyphLook;
|
||||
use super::row_click::RowClick;
|
||||
use super::set_picker::SetPicker;
|
||||
use super::set_picker_purpose::SetPickerPurpose;
|
||||
use crate::TextureCraftApp;
|
||||
@@ -34,8 +35,13 @@ const ROW_INSET: f32 = 6.0;
|
||||
/// Side of a row's map thumbnail, and the air on its sides
|
||||
const THUMBNAIL_SIZE: f32 = 22.0;
|
||||
const THUMBNAIL_AIR: f32 = 9.0;
|
||||
/// Side of a row's icon buttons and of the list menu button
|
||||
/// Side of the header icon slots and of the list menu button
|
||||
const ROW_BUTTON_SIZE: f32 = 20.0;
|
||||
/// Side of a row's hover icons, and the air right of each: four icons stay right of the row's middle in the Bakers column, so a click there selects the row
|
||||
const ROW_ICON_SIZE: f32 = 18.0;
|
||||
const ROW_ICON_GAP: f32 = 1.0;
|
||||
/// Radius of the out-of-date clock on a thumbnail's corner
|
||||
const CLOCK_BADGE_RADIUS: f32 = 6.0;
|
||||
/// Size of a row's glyphs
|
||||
const ROW_GLYPH_SIZE: f32 = 14.0;
|
||||
/// Size of the map names
|
||||
@@ -49,7 +55,7 @@ const RULE_AIR: f32 = 4.0;
|
||||
/// Size of a row icon's tooltip title and reasons
|
||||
const TOOLTIP_TEXT_SIZE: f32 = 12.0;
|
||||
|
||||
/// The Common Settings button (with the sync icon when there are several texture sets), Check All with the list menu, and one row per map (checkbox enables, click selects)
|
||||
/// The Common Settings button (with the sync icon when there are several texture sets), Check All with the list menu, and one row per map (checkbox enables, click selects, a hover icon toggles Auto-rebake)
|
||||
pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSettings) {
|
||||
let several_sets = app.session.doc.project.texture_sets.len() > 1;
|
||||
ui.add_space(HEADER_AIR);
|
||||
@@ -87,12 +93,18 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe
|
||||
let drag_from_id = ui.scope_id().with("check_drag_from");
|
||||
let mut check_drag: Option<bool> = ui.data(|data| data.get_temp(check_drag_id));
|
||||
let drag_from: Option<Pos2> = ui.data(|data| data.get_temp(drag_from_id));
|
||||
let out_of_date = app.session.out_of_date_maps(app.session.ts());
|
||||
let texture_set = app.session.ts();
|
||||
for map in BakedMap::ALL {
|
||||
let changes = out_of_date.get(&map).map_or(&[][..], Vec::as_slice);
|
||||
if ui.push_id(map, |ui| row(app, ui, map, settings, map == selected, changes, &mut check_drag, drag_from)).inner {
|
||||
app.ui.selected_baked_map = Some(map);
|
||||
app.ui.dock.focus(Panel::MeshMapSettings);
|
||||
match ui.push_id(map, |ui| row(app, ui, map, settings, map == selected, &mut check_drag, drag_from)).inner {
|
||||
Some(RowClick::Row) => {
|
||||
app.ui.selected_baked_map = Some(map);
|
||||
app.ui.dock.focus(Panel::MeshMapSettings);
|
||||
}
|
||||
Some(RowClick::AutoRebake) => {
|
||||
let map = if auto_rebake_map(app, texture_set) == Some(map) { Value::Null } else { json!(map.id()) };
|
||||
app.run("bake.autoRebake", json!({ "ts": texture_set, "map": map }));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,17 +255,16 @@ fn copy_items(app: &mut TextureCraftApp, ui: &mut Ui, opener: &egui::Response, w
|
||||
}
|
||||
}
|
||||
|
||||
/// One baker row, with a clock at its right end while `changes` make the map out of date (`check_drag`: the state a pressed check gives those the pointer then crosses; `drag_from`: where that drag's pointer was last frame); returns whether the row itself was clicked
|
||||
/// One baker row: its hover icons end in the Auto-rebake toggle, which stays while on, and an out-of-date map's thumbnail carries a clock (`check_drag`: the state a pressed check gives those the pointer then crosses; `drag_from`: where that drag's pointer was last frame); returns what was clicked, if not the check
|
||||
fn row(
|
||||
app: &mut TextureCraftApp,
|
||||
ui: &mut Ui,
|
||||
map: BakedMap,
|
||||
settings: &mut BakeSettings,
|
||||
is_selected: bool,
|
||||
changes: &[BakeChange],
|
||||
check_drag: &mut Option<bool>,
|
||||
drag_from: Option<Pos2>,
|
||||
) -> bool {
|
||||
) -> Option<RowClick> {
|
||||
let several_sets = app.session.doc.project.texture_sets.len() > 1;
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
let name = tr(baked_map_label(map));
|
||||
@@ -284,27 +295,36 @@ fn row(
|
||||
let thumbnail_rect = Rect::from_min_size(pos2(check.right() + THUMBNAIL_AIR, rect.center().y - THUMBNAIL_SIZE / 2.0), vec2(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
|
||||
thumbnail(ui, thumbnail_rect, texture.as_ref());
|
||||
|
||||
let mut icons_left = rect.right();
|
||||
let texture_set = app.session.ts();
|
||||
let changes = app.session.bake_changes(texture_set, map);
|
||||
if !changes.is_empty() {
|
||||
let clock = icon_slot(&mut icons_left, rect.center().y);
|
||||
out_of_date_mark(ui, clock, name, changes);
|
||||
out_of_date_mark(ui, thumbnail_rect, name, &changes);
|
||||
}
|
||||
|
||||
// From the right: sync (with several sets), Auto-rebake, bolt, eye; Auto-rebake alone stays while on
|
||||
let focus_in_row = || {
|
||||
ui.memory(|memory| memory.focused())
|
||||
.and_then(|id| ui.ctx().read_response(id))
|
||||
.is_some_and(|widget| widget.layer_id == ui.layer_id() && rect.contains(widget.rect.center()))
|
||||
};
|
||||
if is_selected || hovered || focus_in_row() {
|
||||
let mut next_icon = || icon_slot(&mut icons_left, rect.center().y);
|
||||
if several_sets {
|
||||
let is_active = is_selected || hovered || focus_in_row();
|
||||
let is_auto_rebake = auto_rebake_map(app, texture_set) == Some(map);
|
||||
let mut icons_left = rect.right();
|
||||
let mut next_icon = || icon_slot(&mut icons_left, rect.center().y);
|
||||
let sync_slot = several_sets.then(&mut next_icon);
|
||||
let toggle = next_icon();
|
||||
let mut toggled = false;
|
||||
if is_active {
|
||||
if let Some(slot) = sync_slot {
|
||||
let shares = settings.sync.shares(BakeSyncGroup::Map(map));
|
||||
let look = if shares { GlyphLook::Lit } else { GlyphLook::Plain };
|
||||
let glyph = if shares { icon::LINK } else { icon::LINK_BREAK };
|
||||
let sync = glyph_button(ui, next_icon(), glyph, &trf("Synchronize {map} Settings", &[("map", &name)]), look);
|
||||
let sync = glyph_button(ui, slot, glyph, &trf("Synchronize {map} Settings", &[("map", &name)]), look);
|
||||
if sync.clicked() {
|
||||
SetPicker::open(app, &sync, SetPickerPurpose::Sync(BakeSyncGroup::Map(map)));
|
||||
}
|
||||
}
|
||||
toggled = auto_rebake_toggle(ui, toggle, name, is_auto_rebake).clicked();
|
||||
let baking = app.bake_progress().is_some();
|
||||
let bolt = next_icon();
|
||||
let bolt_label = trf("Bake {map} Only", &[("map", &name)]);
|
||||
@@ -318,6 +338,10 @@ fn row(
|
||||
let mode = if shown { "material".to_owned() } else { format!("map:{}", map.id()) };
|
||||
app.run("viewport.view", json!({ "mode": mode }));
|
||||
}
|
||||
} else if is_auto_rebake {
|
||||
toggled = auto_rebake_toggle(ui, toggle, name, true).clicked();
|
||||
} else {
|
||||
icons_left = rect.right();
|
||||
}
|
||||
|
||||
let name_left = thumbnail_rect.right() + THUMBNAIL_AIR;
|
||||
@@ -360,7 +384,35 @@ fn row(
|
||||
response.request_focus();
|
||||
}
|
||||
|
||||
response.clicked()
|
||||
if toggled {
|
||||
Some(RowClick::AutoRebake)
|
||||
} else if response.clicked() {
|
||||
Some(RowClick::Row)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// The map texture set `texture_set` rebakes on its own, if any
|
||||
fn auto_rebake_map(app: &TextureCraftApp, texture_set: usize) -> Option<BakedMap> {
|
||||
app.session.doc.project.texture_sets.get(texture_set).and_then(|set| set.auto_rebake)
|
||||
}
|
||||
|
||||
/// The Auto-rebake toggle in `rect`: bright while on or pointed at, dim while off
|
||||
fn auto_rebake_toggle(ui: &mut Ui, rect: Rect, name: &str, is_on: bool) -> egui::Response {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
let response = ui.interact(rect, ui.scope_id().with("auto_rebake"), Sense::click());
|
||||
let title = tr("Auto-rebake");
|
||||
let label = trf("Auto-rebake {map}", &[("map", &name)]);
|
||||
response.widget_info(|| WidgetInfo::selected(Role::Button, true, is_on, &label));
|
||||
|
||||
let is_pointed = response.hovered() || response.has_focus();
|
||||
let color = if is_on || is_pointed { tokens.text_strong } else { tokens.text_dim };
|
||||
ui.painter().text(rect.center(), Align2::CENTER_CENTER, icon::ARROWS_CLOCKWISE, FontId::proportional(ROW_GLYPH_SIZE), color);
|
||||
crate::property_sheet::paint_keyboard_focus(ui, &response, &tokens);
|
||||
response.on_hover_ui(|ui| {
|
||||
ui.label(RichText::new(title).font(semibold(TOOLTIP_TEXT_SIZE)).color(tokens.text));
|
||||
})
|
||||
}
|
||||
|
||||
/// Start a checkbox drag at a primary press on `checkbox`; returns whether the drag's pointer crossed this row's checkbox column (the whole row height counts) since `drag_from`
|
||||
@@ -435,14 +487,16 @@ fn header_button(ui: &mut Ui, glyph: &str, text: &str) -> egui::Response {
|
||||
response
|
||||
}
|
||||
|
||||
/// The yellow clock in `rect` of a map that `changes` made out of date since its bake; hover tells what changed
|
||||
fn out_of_date_mark(ui: &mut Ui, rect: Rect, name: &str, changes: &[BakeChange]) {
|
||||
/// The yellow clock on the corner of `thumbnail`, of a map that `changes` made out of date since its bake; hovering the thumbnail tells what changed
|
||||
fn out_of_date_mark(ui: &mut Ui, thumbnail: Rect, name: &str, changes: &[BakeChange]) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
let response = ui.interact(rect, ui.scope_id().with("out_of_date"), Sense::hover());
|
||||
let response = ui.interact(thumbnail, ui.scope_id().with("out_of_date"), Sense::hover());
|
||||
let title = tr("Out of date");
|
||||
let label = trf("Out of date: {map}", &[("map", &name)]);
|
||||
response.widget_info(|| WidgetInfo::labeled(Role::Label, true, &label));
|
||||
ui.painter().text(rect.center(), Align2::CENTER_CENTER, icon::CLOCK, FontId::proportional(ROW_GLYPH_SIZE), tokens.warning);
|
||||
let badge = thumbnail.right_bottom() - vec2(CLOCK_BADGE_RADIUS, CLOCK_BADGE_RADIUS) * 0.5;
|
||||
ui.painter().circle_filled(badge, CLOCK_BADGE_RADIUS, tokens.panel);
|
||||
ui.painter().text(badge, Align2::CENTER_CENTER, icon::CLOCK, FontId::proportional(CLOCK_BADGE_RADIUS * 2.0), tokens.warning);
|
||||
|
||||
response.on_hover_ui(|ui| {
|
||||
ui.label(RichText::new(title).font(semibold(TOOLTIP_TEXT_SIZE)).color(tokens.text));
|
||||
@@ -454,7 +508,7 @@ fn out_of_date_mark(ui: &mut Ui, rect: Rect, name: &str, changes: &[BakeChange])
|
||||
|
||||
/// The next icon slot leftwards from `icons_left`, centred on `center_y`; moves `icons_left` past it
|
||||
fn icon_slot(icons_left: &mut f32, center_y: f32) -> Rect {
|
||||
let slot = Rect::from_center_size(pos2(*icons_left - ROW_BUTTON_SIZE / 2.0 - ROW_INSET / 2.0, center_y), vec2(ROW_BUTTON_SIZE, ROW_BUTTON_SIZE));
|
||||
*icons_left = slot.left() - ROW_INSET / 2.0;
|
||||
let slot = Rect::from_center_size(pos2(*icons_left - ROW_ICON_SIZE / 2.0 - ROW_ICON_GAP, center_y), vec2(ROW_ICON_SIZE, ROW_ICON_SIZE));
|
||||
*icons_left = slot.left();
|
||||
slot
|
||||
}
|
||||
@@ -23,6 +23,7 @@ mod map_settings;
|
||||
mod map_thumbnails;
|
||||
mod mesh_map_bakers;
|
||||
pub use map_thumbnails::MapThumbnails;
|
||||
mod row_click;
|
||||
mod set_picker;
|
||||
mod set_picker_purpose;
|
||||
mod set_picker_row;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/// What a click on a Mesh Map Bakers row hit
|
||||
pub(super) enum RowClick {
|
||||
Row,
|
||||
AutoRebake,
|
||||
}
|
||||
@@ -124,7 +124,7 @@ pub(crate) fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
|
||||
|
||||
/// Show `map`'s settings of `texture_set` in Mesh Map Settings, as picking it in Mesh Map Bakers does
|
||||
fn open_map_settings(app: &mut TextureCraftApp, texture_set: usize, map: BakedMap) {
|
||||
// The set may have been deleted since the bake
|
||||
// A guard against a row naming a set the session no longer has
|
||||
if texture_set >= app.session.set_count() {
|
||||
return;
|
||||
}
|
||||
@@ -226,16 +226,19 @@ fn no_issues(ui: &mut Ui, tab: BakingLogTab) {
|
||||
ui.allocate_rect(area, Sense::hover());
|
||||
}
|
||||
|
||||
/// What the Matching by Name tab says when no texture set of the latest bake matched by mesh name: the setting's name in SemiBold
|
||||
/// What the Matching by Name tab says when no texture set of the latest bake matched by mesh name: the setting and its value in SemiBold
|
||||
fn matching_not_enabled(ui: &mut Ui) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
let mut text = egui::text::LayoutJob::default();
|
||||
let format = |font| egui::TextFormat { font_id: font, color: tokens.text, ..Default::default() };
|
||||
// One sentence to translate, its setting kept apart to set it in SemiBold
|
||||
let sentence = tr("{setting} was off for this bake.");
|
||||
let (before, after) = sentence.split_once("{setting}").unwrap_or(("", sentence));
|
||||
// One sentence to translate, its setting and value kept apart to set them in SemiBold
|
||||
let sentence = tr("Set {setting} to {value} to pair parts by name.");
|
||||
let (before, rest) = sentence.split_once("{setting}").unwrap_or(("", sentence));
|
||||
let (between, after) = rest.split_once("{value}").unwrap_or((rest, ""));
|
||||
text.append(before, 0.0, format(FontId::proportional(NAME_SIZE)));
|
||||
text.append(tr("Matching by name"), 0.0, format(semibold(NAME_SIZE)));
|
||||
text.append(tr("Match"), 0.0, format(semibold(NAME_SIZE)));
|
||||
text.append(between, 0.0, format(FontId::proportional(NAME_SIZE)));
|
||||
text.append(tr("By Mesh Name"), 0.0, format(semibold(NAME_SIZE)));
|
||||
text.append(after, 0.0, format(FontId::proportional(NAME_SIZE)));
|
||||
|
||||
let area = ui.available_rect_before_wrap();
|
||||
|
||||
@@ -16,7 +16,10 @@ fn harness(resolution: u32) -> Harness<'static, TextureCraftApp> {
|
||||
execute(&mut session, "bake.run", &json!({ "resolution": resolution, "maps": ["position", "id"], "dilation": 0 })).unwrap();
|
||||
execute(&mut session, "bake.autoRebake", &json!({ "map": "position" })).unwrap();
|
||||
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
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
|
||||
@@ -26,27 +29,14 @@ fn change_settings(harness: &mut Harness<'static, TextureCraftApp>, params: serd
|
||||
execute(&mut harness.state_mut().session, "bake.settings", ¶ms).unwrap();
|
||||
}
|
||||
|
||||
/// Step frames until `done` holds, up to a generous limit
|
||||
fn step_until(harness: &mut Harness<'static, TextureCraftApp>, what: &str, done: impl Fn(&TextureCraftApp) -> bool) {
|
||||
for _ in 0..4000 {
|
||||
harness.run_steps(1);
|
||||
if done(harness.state()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(2));
|
||||
}
|
||||
panic!("{what} did not happen");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_settings_change_rebakes_only_the_auto_rebake_map_without_a_toast() {
|
||||
let mut harness = harness(64);
|
||||
let id_before = harness.state().session.baked(0).unwrap().maps[&BakedMap::Id].clone();
|
||||
change_settings(&mut harness, json!({ "positionMode": "boundingBox" }));
|
||||
|
||||
step_until(&mut harness, "the rebake", |app| app.bake.is_some());
|
||||
step_until(&mut harness, "the end of the rebake", |app| app.bake.is_none());
|
||||
super::step_until(&mut harness, "the rebake", |app| app.bake.is_some());
|
||||
super::step_until(&mut harness, "the end of the rebake", |app| app.bake.is_none());
|
||||
|
||||
let app = harness.state();
|
||||
assert!(app.session.bake_changes(0, BakedMap::Position).is_empty(), "{:?}", app.session.bake_changes(0, BakedMap::Position));
|
||||
@@ -76,14 +66,36 @@ fn a_change_while_the_rebake_runs_cancels_it_so_the_newest_settings_win() {
|
||||
|
||||
// A slow rebake, so the next change lands while it runs
|
||||
change_settings(&mut harness, json!({ "resolution": 2048, "ao": { "rays": 256 } }));
|
||||
step_until(&mut harness, "the rebake", |app| app.bake.as_ref().is_some_and(|job| job.current.is_some()));
|
||||
super::step_until(&mut harness, "the rebake", |app| app.bake.as_ref().is_some_and(|job| job.current.is_some()));
|
||||
change_settings(&mut harness, json!({ "ao": { "rays": 128 } }));
|
||||
harness.run_steps(1);
|
||||
|
||||
let app = harness.state();
|
||||
assert!(app.bake.is_none(), "the outdated rebake stopped");
|
||||
assert_eq!(app.session.bake_log.maps[0].state, BakeMapState::Canceled);
|
||||
execute(&mut harness.state_mut().session, "bake.autoRebake", &json!({ "map": null })).unwrap();
|
||||
let ambient_occlusion = app.session.bake_log.maps.iter().find(|row| row.map == BakedMap::AmbientOcclusion).map(|row| row.state.clone());
|
||||
assert_eq!(ambient_occlusion, Some(BakeMapState::Canceled));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_canceled_rebake_holds_back_only_its_own_texture_set() {
|
||||
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
execute(&mut session, "bake.run", &json!({ "ts": "all", "resolution": 32, "maps": ["position"], "dilation": 0 })).unwrap();
|
||||
for set in [0, 1] {
|
||||
execute(&mut session, "bake.autoRebake", &json!({ "ts": set, "map": "position" })).unwrap();
|
||||
}
|
||||
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);
|
||||
let rebaking = |app: &TextureCraftApp, set: usize| app.bake.as_ref().and_then(|job| job.rebake.as_ref()).is_some_and(|rebake| rebake.0 == set);
|
||||
|
||||
change_settings(&mut harness, json!({ "ts": "all", "positionMode": "boundingBox" }));
|
||||
super::step_until(&mut harness, "the first set's rebake", |app| rebaking(app, 0));
|
||||
harness.state_mut().cancel_bake();
|
||||
|
||||
super::step_until(&mut harness, "the second set's rebake", |app| rebaking(app, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -104,8 +116,8 @@ fn a_skew_stroke_rebakes_the_auto_rebake_map_inside_the_stroke() {
|
||||
assert!(harness.state().bake.is_none(), "up to date after the bake");
|
||||
|
||||
execute(&mut harness.state_mut().session, "bake.skew.paint", &json!({ "points": [[0.5, 0.5]], "radius": 0.05, "size": 64 })).unwrap();
|
||||
step_until(&mut harness, "the rebake", |app| app.bake.is_some());
|
||||
step_until(&mut harness, "the end of the rebake", |app| app.bake.is_none());
|
||||
super::step_until(&mut harness, "the rebake", |app| app.bake.is_some());
|
||||
super::step_until(&mut harness, "the end of the rebake", |app| app.bake.is_none());
|
||||
|
||||
let app = harness.state();
|
||||
assert!(app.session.auto_rebake_painted().is_empty(), "the rebake took the stroke");
|
||||
@@ -113,3 +125,26 @@ fn a_skew_stroke_rebakes_the_auto_rebake_map_inside_the_stroke() {
|
||||
assert_eq!(rows, [(BakedMap::Position, BakeMapState::Baked)]);
|
||||
assert!(app.toasts.is_empty(), "a rebake that went well is quiet");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_rows_icon_turns_auto_rebake_on_for_its_map_and_off_again() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
let mut harness = harness(64);
|
||||
let auto_rebake = |harness: &Harness<'static, TextureCraftApp>| harness.state().session.doc.project.texture_sets[0].auto_rebake;
|
||||
assert_eq!(auto_rebake(&harness), Some(BakedMap::Position));
|
||||
|
||||
assert!(harness.query_by_label("Auto-rebake Normal").is_none(), "off: shown only on a hovered, focused or selected row");
|
||||
harness.get_by_role_and_label(egui::Role::Button, "Normal").hover();
|
||||
harness.run_steps(2);
|
||||
harness.get_by_label("Auto-rebake Normal");
|
||||
|
||||
// ID is the selected row (the first checked map), which shows its icons
|
||||
harness.get_by_label("Auto-rebake ID").click();
|
||||
harness.run_steps(2);
|
||||
assert_eq!(auto_rebake(&harness), Some(BakedMap::Id), "one map per set: ID replaces Position");
|
||||
|
||||
harness.get_by_label("Auto-rebake ID").click();
|
||||
harness.run_steps(2);
|
||||
assert_eq!(auto_rebake(&harness), None);
|
||||
}
|
||||
@@ -698,6 +698,24 @@ fn picking_material_while_painting_keeps_bake_modes_neutral_material() {
|
||||
assert!(harness.state().ui.bake_visualization.neutral_shown, "bake mode still opens on the neutral material");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_the_middle_of_an_out_of_date_row_selects_its_map_and_bakes_nothing() {
|
||||
use serde_json::json;
|
||||
use texturecraft_engine::execute;
|
||||
|
||||
// Two sets show every hover icon (sync, Auto-rebake, bolt, eye) and the changed settings add the out-of-date clock
|
||||
let mut harness = harness(None);
|
||||
execute(&mut harness.state_mut().session, "bake.settings", &json!({ "dilation": 4 })).unwrap();
|
||||
harness.state_mut().ui.dock.focus(Panel::CommonSettings);
|
||||
harness.run_steps(3);
|
||||
harness.get_by_label("Out of date: Ambient Occlusion");
|
||||
|
||||
select_map(&mut harness, "Ambient Occlusion");
|
||||
assert!(harness.state().bake_progress().is_none(), "the click landed on the row, not its Bake Only icon");
|
||||
assert!(harness.state().ui.dock.is_visible(Panel::MeshMapSettings), "selecting a map fronts its settings");
|
||||
harness.get_by_label("Attenuation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_baked_maps_row_shows_out_of_date_once_its_settings_change() {
|
||||
use serde_json::json;
|
||||
|
||||
@@ -25,17 +25,10 @@ fn harness() -> Harness<'static, TextureCraftApp> {
|
||||
harness
|
||||
}
|
||||
|
||||
/// Run frames until the bake ends, then a few more for its result to show
|
||||
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");
|
||||
super::step_until(harness, "the end of the bake", |app| app.bake.is_none());
|
||||
harness.run_steps(super::SETTLE_FRAMES);
|
||||
}
|
||||
|
||||
/// Bake sets 0 and 1, where set 1 has no tile left to bake, so its bake fails
|
||||
@@ -199,9 +192,9 @@ fn the_matching_tab_says_when_no_set_matched_by_name() {
|
||||
let mut harness = harness();
|
||||
harness.get_by_label("Matching by Name").click();
|
||||
harness.run_steps(3);
|
||||
assert!(harness.query_by_label("Matching by name was off for this bake.").is_none(), "nothing baked yet: nothing to say");
|
||||
assert!(harness.query_by_label("Set Match to By Mesh Name to pair parts by name.").is_none(), "nothing baked yet: nothing to say");
|
||||
|
||||
log_a_bake(&mut harness, BakeMapState::Baked);
|
||||
|
||||
harness.get_by_label("Matching by name was off for this bake.");
|
||||
harness.get_by_label("Set Match to By Mesh Name to pair parts by name.");
|
||||
}
|
||||
@@ -31,17 +31,10 @@ fn harness() -> Harness<'static, TextureCraftApp> {
|
||||
harness
|
||||
}
|
||||
|
||||
/// Run frames until the bake ends, then a few more for its result to show
|
||||
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");
|
||||
super::step_until(harness, "the end of the bake", |app| app.bake.is_none());
|
||||
harness.run_steps(super::SETTLE_FRAMES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -196,6 +196,23 @@ fn assert_list_leaves_the_wheel_and_closes(harness: &mut Harness<'_, TextureCraf
|
||||
assert!(!egui::Popup::is_any_open(&harness.ctx), "a click outside closes the list");
|
||||
}
|
||||
|
||||
/// Most frames [`step_until`] waits, and its pause between them for background work
|
||||
const STEP_UNTIL_FRAMES: usize = 4000;
|
||||
const STEP_UNTIL_PAUSE: std::time::Duration = std::time::Duration::from_millis(2);
|
||||
|
||||
/// Step frames until `done` holds, up to a generous limit
|
||||
fn step_until(harness: &mut Harness<'_, TextureCraftApp>, what: &str, done: impl Fn(&TextureCraftApp) -> bool) {
|
||||
for _ in 0..STEP_UNTIL_FRAMES {
|
||||
harness.run_steps(1);
|
||||
if done(harness.state()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread::sleep(STEP_UNTIL_PAUSE);
|
||||
}
|
||||
panic!("{what} did not happen");
|
||||
}
|
||||
|
||||
/// Presses and releases the primary button at `at` without moving, as a pointer click does
|
||||
fn click_at(harness: &mut Harness<'_, TextureCraftApp>, at: egui::Pos2) {
|
||||
harness.hover_at(at);
|
||||
|
||||
Reference in new issue
Block a user