Auto: Keep Settings buttons visible on short viewports

Fit the Settings page and navigation above the footer, retaining the 520-point page height cap. Allow horizontal page scrolling when the fixed-width controls exceed the viewport.

Verify both footer buttons at 960×600 and 150% interface scale, and check that the tabs stay in a vertical column.
This commit is contained in:
chasse20 committed 2026-11-19 06:27:15 +00:00
1 parent c344ddc2e3
commit 549e6a3754
3 files changed
+60 -14

No files matched your search

+25 -13
View File
@@ -30,7 +30,11 @@ pub const PROJECT_OPEN_NOTE: &str = n_("Library locations can't be added/removed
const LABEL_WIDTH: f32 = 176.0;
const CONTROL_WIDTH: f32 = 340.0;
const PAGE_WIDTH: f32 = 560.0;
const PAGE_HEIGHT: f32 = 520.0;
const MAX_PAGE_HEIGHT_POINTS: f32 = 520.0;
// Reserve room for the title bar, window margins, separator and footer buttons
const WINDOW_CHROME_HEIGHT_POINTS: f32 = 112.0;
// Leave room for the column gap, layout spacing and scroll bar
const CONTENT_WIDTH_ALLOWANCE_POINTS: f32 = 32.0;
/// The page buttons of the left column.
const PAGE_BUTTON: egui::Vec2 = vec2(84.0, 80.0);
const PAGE_ICON_SIZE: f32 = 44.0;
@@ -56,25 +60,33 @@ pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) {
#[cfg(not(target_arch = "wasm32"))]
let resources = settings_resources(ctx);
let viewport = ctx.content_rect();
let page_height = (viewport.height() - WINDOW_CHROME_HEIGHT_POINTS).clamp(0.0, MAX_PAGE_HEIGHT_POINTS);
let frame_width = egui::Frame::window(&ctx.global_style()).total_margin().sum().x;
let content_width = (viewport.width() - frame_width).clamp(0.0, PAGE_BUTTON.x + PAGE_WIDTH + CONTENT_WIDTH_ALLOWANCE_POINTS);
crate::windows::window("settings", tr("Settings"), &mut open).resizable(false).show(ctx, |ui| {
// The window keeps to the column and the page; the OK and Cancel row would widen it otherwise
ui.set_max_width(PAGE_BUTTON.x + PAGE_WIDTH + 32.0);
// Keep the footer inside the viewport when the fixed-width controls need to scroll
ui.set_max_width(content_width);
ui.horizontal_top(|ui| {
ui.vertical(|ui| {
ui.set_width(PAGE_BUTTON.x);
for page in SettingsPage::ALL {
if page_button(ui, page, draft.page == page).clicked() {
draft.page = page;
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 {
if page_button(ui, page, draft.page == page).clicked() {
draft.page = page;
}
ui.add_space(6.0);
}
ui.add_space(6.0);
}
});
});
ui.add_space(8.0);
egui::ScrollArea::vertical()
egui::ScrollArea::both()
.id_salt(("settings_page", draft.page as u8))
.auto_shrink([false, false])
.min_scrolled_height(PAGE_HEIGHT)
.max_height(PAGE_HEIGHT)
.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);
@@ -73,6 +73,13 @@ fn type_into(h: &mut Harness<'_, TextureCraftApp>, label: &str, text: &str) {
fn the_left_column_switches_between_the_three_pages() {
let mut h = harness(texturecraft_engine::sample_session(128, 32).unwrap());
open_settings(&mut h);
let tab_center = |label| h.get_by_role_and_label(Role::Tab, label).rect().center();
let [general, shortcuts, libraries] = ["General", "Shortcuts", "Libraries"].map(tab_center);
assert_eq!(general.x, shortcuts.x);
assert_eq!(shortcuts.x, libraries.x);
assert!(general.y < shortcuts.y && shortcuts.y < libraries.y);
assert_eq!(page(&h), Some(SettingsPage::General));
assert!(toggled(&h, "General"), "the chosen page is highlighted");
assert!(!toggled(&h, "Shortcuts"));
@@ -217,6 +224,28 @@ fn cancel_drops_the_changes_and_ok_applies_and_keeps_them() {
assert_eq!(restored.prefs, prefs, "the settings are kept between runs");
}
#[test]
fn settings_footer_is_clickable_in_a_short_zoomed_window() {
let mut h = harness(Session::closed().unwrap());
h.set_size(egui::vec2(960.0, 600.0));
h.state_mut().ui.prefs.ui_scale = 1.5;
h.run_steps(4);
assert_eq!(h.ctx.zoom_factor(), 1.5);
assert_eq!(h.ctx.content_rect().size(), egui::vec2(640.0, 400.0));
for label in ["Cancel", "OK"] {
open_settings(&mut h);
let button = h.get_by_role_and_label(Role::Button, label);
let viewport = h.ctx.content_rect();
assert!(viewport.contains_rect(button.rect()), "{label} must fit in {viewport:?}, got {:?}", button.rect());
button.click();
h.run_steps(4);
assert!(!h.state().ui.windows.settings, "{label} closes Settings without scrolling the page");
}
}
#[test]
fn a_shortcut_edited_on_the_shortcuts_page_applies_on_ok() {
let mut h = harness(texturecraft_engine::sample_session(128, 32).unwrap());
+6 -1
View File
@@ -858,7 +858,7 @@ fn tile_generator_gradient_map_snapshot() {
save(&mut harness, &output_dir, "tile-generator-gradient-map");
}
/// Edit > Settings: the General page, then the Shortcuts and Libraries pages
/// Edit > Settings: the three pages and a compact window at 150% scale
#[test]
#[ignore]
fn settings_pages_snapshot() {
@@ -892,4 +892,9 @@ fn settings_pages_snapshot() {
}
save(&mut harness, &output_dir, name);
}
harness.set_size(egui::vec2(960.0, 600.0));
harness.state_mut().ui.prefs.ui_scale = 1.5;
harness.state_mut().ui.windows.settings_draft.as_mut().unwrap().page = SettingsPage::General;
save(&mut harness, &output_dir, "settings-compact");
}