Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #937 from nanox333/codex/fix-828-gpu-info-dialog

Brandon Thomasbfb282d47c9c
diff --cc crates/ui-egui/src/panels/dialogs.rs
index 8ec8bb0b2,71ee85db6..6f86bc784
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@@ -152,23 -149,17 +152,31 @@@ pub fn route_layer_settings(app: &mut E
}
}
+/// The room a modal dialog may take: the window less a margin.
+fn modal_space(ctx: &egui::Context) -> egui::Vec2 {
+ (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0))
+}
+
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
+ modal_with_scroll(ctx, title, size, t, false, body);
+ }
+
+ pub(crate) fn modal_vertical(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
+ modal_with_scroll(ctx, title, size, t, true, body);
+ }
+
+ fn modal_with_scroll(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, vertical_only: bool, body: impl FnOnce(&mut egui::Ui)) {
- let available = (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0));
- let size = size.min(available);
+ let max_height = (modal_space(ctx).y - 84.0).max(40.0);
+ modal_fit(ctx, title, size, t, |ui, _| {
+ egui::ScrollArea::both().max_height(max_height).auto_shrink([false, true]).show(ui, body);
+ });
+}
+
+/// [`modal`] without its scroll area, for a dialog that keeps its buttons in view and scrolls
+/// only its content: `body` gets the height left under the title, with `size` kept within the
+/// window.
+pub(crate) fn modal_fit(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui, f32)) {
+ let size = size.min(modal_space(ctx));
egui::Modal::new(egui::Id::new(("modal", title)))
.backdrop_color(Color32::from_black_alpha(120))
.frame(egui::Frame::window(&ctx.style_of(ctx.theme())).fill(t.panel_bg).inner_margin(egui::Margin::same(18)))
@@@ -178,8 -169,8 +186,9 @@@
// The id stays keyed on the untranslated source, so switching language cannot move it.
ui.label(egui::RichText::new(tr(title)).font(Tokens::semibold(15.0)).color(t.tab_text_active));
ui.add_space(10.0);
- let title_h = ui.cursor().top() - ui.min_rect().top();
- let scroll = if vertical_only { egui::ScrollArea::vertical() } else { egui::ScrollArea::both() };
- scroll.max_height((available.y - 84.0).max(40.0)).auto_shrink([false, true]).show(ui, body);
++ let scroll = if vertical_only { egui::ScrollArea::vertical() } else { let title_h = ui.cursor() };
++ scroll.top() - ui.min_rect().top();
+ body(ui, (size.y - 36.0 - title_h).max(40.0));
});
}
diff --cc crates/ui-egui/tests/ui_settings_info.rs
index f110ce0f7,d231064b1..9d87eb049
--- a/crates/ui-egui/tests/ui_settings_info.rs
+++ b/crates/ui-egui/tests/ui_settings_info.rs
@@@ -116,21 -112,22 +116,41 @@@ fn gpu_information_escape_returns_to_se
check_info_transaction(true);
}
+/// GPU Information names the adapter the window got and says why the compositor is off, so a
+/// card that the compositor could not use does not look undetected (#596).
+#[test]
+fn gpu_information_names_the_adapter_and_why_the_gpu_is_off() {
+ let session = Session {
+ accel_note: Some("GPU compositor unavailable: no compute shaders".into()),
+ window_adapter: Some("NVIDIA GeForce RTX 4070 (Dx12, DiscreteGpu)".into()),
+ ..Default::default()
+ };
+ let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session));
+ h.run_steps(4);
+ let ctx = h.ctx.clone();
+ menus::invoke(h.state_mut(), &ctx, "app.gpuInfo", json!({})).unwrap();
+ h.run_steps(3);
+ assert_eq!(h.state().dialog, Some(Dialog::Info));
+ assert!(h.query_by_label_contains("Window graphics: NVIDIA GeForce RTX 4070").is_some(), "the window's adapter is shown");
+ assert!(h.query_by_label_contains("GPU compositing is off: GPU compositor unavailable").is_some(), "the reason is shown");
+}
++
+ #[test]
+ fn gpu_information_dialog_stays_in_place() {
+ let mut session = Session::default();
+ session.prefs.appearance.ui_scale = 125;
+ session.execute("comp.new", json!({"width":32,"height":32,"duration":2})).unwrap();
+ let mut h = Harness::builder().with_size(vec2(1280.0, 720.0)).build_eframe(|_| EffectcraftApp::new(session));
+ h.run_steps(4);
+ let ctx = h.ctx.clone();
+ menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page":"previews"})).unwrap();
+ h.run_steps(3);
+ let button = rect(&h, "settings.button.GPU Information").center();
+ click(&mut h, button);
+ let start = h.get_by_label("GPU Information").rect();
+ for _ in 0..20 {
+ h.step();
+ let current = h.get_by_label("GPU Information").rect();
+ assert!((current.min - start.min).length() < 1.0, "GPU Information dialog moved");
+ }
+ }