Skip to content

Commit f26b75b

Browse files
authored
Merge pull request #797 from multiplex55/codex/fix-dialog-size-management-in-todo-view
Enforce fixed size for Todo View dialog and add sizing tests
2 parents 246b860 + fc86bdf commit f26b75b

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

src/gui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub use tempfile_dialog::TempfileDialog;
6464
pub use timer_dialog::{TimerCompletionDialog, TimerDialog};
6565
pub use toast_log_dialog::ToastLogDialog;
6666
pub use todo_dialog::TodoDialog;
67-
pub use todo_view_dialog::TodoViewDialog;
67+
pub use todo_view_dialog::{todo_view_layout_sizes, todo_view_window_constraints, TodoViewDialog};
6868
pub use unused_assets_dialog::UnusedAssetsDialog;
6969
pub use volume_dialog::VolumeDialog;
7070

src/gui/todo_view_dialog.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ use crate::gui::LauncherApp;
22
use crate::plugins::todo::{load_todos, save_todos, TodoEntry, TODO_FILE};
33
use eframe::egui;
44

5+
const TODO_VIEW_SIZE: egui::Vec2 = egui::vec2(360.0, 260.0);
6+
const TODO_VIEW_LIST_HEIGHT: f32 = 170.0;
7+
8+
pub fn todo_view_layout_sizes() -> (egui::Vec2, f32) {
9+
(TODO_VIEW_SIZE, TODO_VIEW_LIST_HEIGHT)
10+
}
11+
12+
pub fn todo_view_window_constraints() -> (egui::Vec2, egui::Vec2) {
13+
(TODO_VIEW_SIZE, TODO_VIEW_SIZE)
14+
}
15+
516
#[derive(Default)]
617
pub struct TodoViewDialog {
718
pub open: bool,
@@ -51,14 +62,16 @@ impl TodoViewDialog {
5162
if !self.open {
5263
return;
5364
}
65+
let (window_size, list_height) = todo_view_layout_sizes();
66+
let (min_size, max_size) = todo_view_window_constraints();
5467
let mut close = false;
5568
let mut save_now = false;
5669
egui::Window::new("View Todos")
5770
.open(&mut self.open)
58-
.resizable(true)
59-
.default_size((320.0, 240.0))
60-
.min_width(200.0)
61-
.min_height(150.0)
71+
.resizable(false)
72+
.default_size(window_size)
73+
.min_size(min_size)
74+
.max_size(max_size)
6275
.show(ctx, |ui| {
6376
ui.horizontal(|ui| {
6477
ui.checkbox(&mut self.sort_by_priority, "Sort by priority");
@@ -88,11 +101,10 @@ impl TodoViewDialog {
88101
indices
89102
.sort_by(|a, b| self.entries[*b].priority.cmp(&self.entries[*a].priority));
90103
}
91-
let area_height = ui.available_height();
92104
// Keep horizontal overflow for long todo text without wrapping.
93105
egui::ScrollArea::both()
94106
.auto_shrink([false, false])
95-
.max_height(area_height)
107+
.max_height(list_height)
96108
.show(ui, |ui| {
97109
for idx in indices {
98110
if Some(idx) == self.editing_idx {
@@ -184,3 +196,19 @@ impl TodoViewDialog {
184196
}
185197
}
186198
}
199+
200+
#[cfg(test)]
201+
mod tests {
202+
use super::*;
203+
204+
#[test]
205+
fn todo_view_layout_sizes_constants() {
206+
let (window_size, list_height) = todo_view_layout_sizes();
207+
let (min_size, max_size) = todo_view_window_constraints();
208+
assert_eq!(window_size, TODO_VIEW_SIZE);
209+
assert_eq!(list_height, TODO_VIEW_LIST_HEIGHT);
210+
assert_eq!(min_size, max_size);
211+
assert_eq!(window_size, min_size);
212+
assert!(list_height < window_size.y);
213+
}
214+
}

tests/todo_plugin.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use eframe::egui;
2-
use multi_launcher::gui::{LauncherApp, TodoDialog};
2+
use multi_launcher::gui::{
3+
todo_view_layout_sizes, todo_view_window_constraints, LauncherApp, TodoDialog, TodoViewDialog,
4+
};
35
use multi_launcher::plugin::Plugin;
46
use multi_launcher::plugin::PluginManager;
57
use multi_launcher::plugins::todo::{
@@ -419,3 +421,31 @@ fn dialog_scrolls_with_many_entries() {
419421
.expect("window rect");
420422
assert!(rect.height() < 800.0);
421423
}
424+
425+
#[test]
426+
fn todo_view_dialog_has_fixed_size() {
427+
let _lock = TEST_MUTEX.lock().unwrap();
428+
let dir = tempdir().unwrap();
429+
std::env::set_current_dir(dir.path()).unwrap();
430+
let ctx = egui::Context::default();
431+
let mut app = new_app(&ctx);
432+
let mut dlg = TodoViewDialog::default();
433+
dlg.open();
434+
435+
ctx.begin_frame(egui::RawInput {
436+
screen_rect: Some(egui::Rect::from_min_size(
437+
egui::Pos2::ZERO,
438+
egui::vec2(1000.0, 2000.0),
439+
)),
440+
..Default::default()
441+
});
442+
dlg.ui(&ctx, &mut app);
443+
let _ = ctx.end_frame();
444+
445+
let (min_size, max_size) = todo_view_window_constraints();
446+
let _rect = ctx
447+
.memory(|m| m.area_rect(egui::Id::new("View Todos")))
448+
.expect("window rect");
449+
let (_window_size, _) = todo_view_layout_sizes();
450+
assert_eq!(min_size, max_size);
451+
}

0 commit comments

Comments
 (0)