mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 10:18:05 +00:00
Merge pull request #3433 from dotCooCoo/fix/shortcuts-open-size
This commit is contained in:
@@ -287,6 +287,10 @@ pub struct Options {
|
||||
/// The window title [`ShortcutsDialog::show`] draws and the summary's heading, already translated.
|
||||
/// `None`: the dialog's own "Keyboard Shortcuts".
|
||||
pub title: Option<String>,
|
||||
/// `None`: an editable dialog opens at the room the window gives it, and a read-only one at a moderate fixed size.
|
||||
/// Otherwise the dialog opens at this size, in points, until the user resizes it; a size that is not finite is
|
||||
/// ignored.
|
||||
pub size: Option<egui::Vec2>,
|
||||
/// true; false shows the table read-only with Close and Summarize.
|
||||
pub editable: bool,
|
||||
/// The name, already translated, that edits of a built-in set are saved under. `None`: the dialog's own
|
||||
@@ -333,6 +337,7 @@ impl Default for Options {
|
||||
fn default() -> Options {
|
||||
Options {
|
||||
title: None,
|
||||
size: None,
|
||||
editable: true,
|
||||
custom_set_name: None,
|
||||
conflicts: ConflictMode::Ask,
|
||||
@@ -618,10 +623,15 @@ fn frame(ui: &mut Ui, env: &mut Env<'_>, state: &mut DialogState) -> ShortcutsOu
|
||||
// A read-only reference opens at a fixed, moderate height (production's key list scrolls inside it), not at the
|
||||
// window's; the user's own resize is still remembered.
|
||||
let reference = !env.options.editable;
|
||||
let asked = env.options.size.filter(|size| size.is_finite());
|
||||
let size = asked.or(reference.then_some(egui::vec2(READ_ONLY_WIDTH, READ_ONLY_HEIGHT)));
|
||||
let session = RefCell::new(Session { env, state });
|
||||
let shown = Dialog::new(title)
|
||||
.resizable(true)
|
||||
.overlay(|overlay| if reference { overlay.size(egui::vec2(READ_ONLY_WIDTH, READ_ONLY_HEIGHT)) } else { overlay })
|
||||
.overlay(|overlay| match size {
|
||||
Some(size) => overlay.size(size),
|
||||
None => overlay,
|
||||
})
|
||||
.remember(SaveKey::new("craft_menu.shortcuts"))
|
||||
.outer_gesture(true)
|
||||
.collection_body()
|
||||
|
||||
@@ -22,3 +22,22 @@ fn a_read_only_dialog_opens_at_a_moderate_height() {
|
||||
let close = rig.fixture.by_label("Close").expect("the close button");
|
||||
assert!(close.rect.bottom() < 560.0, "the dialog's footer sits within a moderate height, not the 700-point window: {:?}", close.rect);
|
||||
}
|
||||
|
||||
/// The editable dialog's bounds, opened with `size` in the rig's 1000 by 700 point window.
|
||||
fn dialog_bounds(size: Option<egui::Vec2>) -> egui::Rect {
|
||||
let rig = Rig::tuned(Platform::Windows, |options| options.size = size);
|
||||
rig.fixture.by_role(craft_ui::contract::Role::DIALOG).first().expect("the dialog").rect
|
||||
}
|
||||
|
||||
/// An editable dialog opens at the size the app gives, larger or smaller than its own, and ignores a size that is not
|
||||
/// finite.
|
||||
#[trial]
|
||||
fn an_editable_dialog_opens_at_the_size_the_app_gives() {
|
||||
let own = dialog_bounds(None).size();
|
||||
for asked in [own + egui::vec2(200.0, 120.0), egui::vec2(own.x + 80.0, own.y - 60.0)] {
|
||||
let opened = dialog_bounds(Some(asked)).size();
|
||||
assert!((opened - asked).abs().max_elem() < 1.0, "asked {asked:?}, opened {opened:?}, own {own:?}");
|
||||
}
|
||||
let endless = dialog_bounds(Some(egui::vec2(f32::INFINITY, f32::NAN))).size();
|
||||
assert_eq!(endless, own, "a size that is not finite opens the dialog as without one");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user