Merge pull request #17076

Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
davidmann4andautocraft-bot[bot] authored and autocraft-bot[bot] committed 2026-12-02 08:06:59 +00:00
commit 79c6a46c1a
3 files changed
+39 -2

No files matched your search

+17 -1
View File
@@ -6,12 +6,13 @@
//! [`open_prompt`] (a second open is refused, not replaced) and tags its prompt with its own type.
//! [`prompt_tagged`] and [`prompt_tag`] find the open prompt by that tag.
use craft::behavior::IconId;
use craft::ui::dialog::{Alert, DialogId, HostedAlert, PromptAnswer, PromptChoice, StackDialog, StandardPrompt};
use serde_json::{Value, json};
use crate::PhotocraftApp;
/// The tag of an alert opened by [`alert_once`]: the dialog preference its "Don't show again" box sets.
/// The tag of an alert opened by [`alert_once`] or [`info_once`]: the dialog preference its "Don't show again" box sets.
pub(crate) struct AlertOnce {
pref: &'static str,
}
@@ -56,6 +57,21 @@ pub fn dismissed(app: &PhotocraftApp, pref: &str) -> bool {
app.session.prefs().dialogs.get(pref).and_then(|v| v.get("skip")).and_then(Value::as_bool) == Some(true)
}
/// [`alert_once`] with the catalog's info icon beside the message, as the reference shows for the
/// Content-Aware Fill workspace's Custom sampling alert (#16693). The other alerts keep their look.
pub fn info_once(app: &mut PhotocraftApp, message: impl Into<String>, pref: &'static str) -> Option<DialogId> {
if dismissed(app, pref) {
return None;
}
let prompt = StandardPrompt::custom(message.into())
.title(TITLE)
.icon(IconId::new("info"))
.button(PromptChoice::Proceed, tl!("OK").to_owned())
.dont_show_again()
.tag(AlertOnce { pref });
open_prompt(app, prompt).ok().or_else(|| prompt_tagged::<AlertOnce>(app))
}
/// Keeps "Don't show again" for the question remembered as `pref`, with the other dialog preferences.
pub fn remember_skip(app: &mut PhotocraftApp, pref: &str) {
remember_skip_or(app, pref, tl!("The preference could not be saved: {error}"));
@@ -2,7 +2,9 @@
//! reference's info alert, "Use the Sampling Brush Tool to add to the sampling area in order to
//! fill the selected region.", with "Don't show again" and OK, once per choice. OK closes it and the
//! Sampling Brush adds. With "Don't show again" ticked it stays closed. Other choices show nothing.
//! #16693: the alert shows an info icon beside its text.
use egui::accesskit::Role;
use egui_kittest::kittest::Queryable;
use serde_json::{Value, json};
@@ -94,6 +96,25 @@ fn choosing_custom_shows_the_alert_once_and_ok_leaves_the_brush_adding() {
assert_eq!((d["settings"]["sampling"].as_str(), d["brushMode"].as_str()), (Some("custom"), Some("add")));
}
#[test]
fn the_alert_shows_an_icon_beside_its_text() {
let mut app = app();
open(&mut app).unwrap();
choose(&mut app, "custom");
let mut h = egui_kittest::Harness::builder()
.with_size(egui::vec2(1440.0, 900.0))
.with_max_steps(16)
.with_context(app.ctx().clone())
.build_ui_state(|ui, app: &mut Box<PhotocraftApp>| crate::dialogs::run(app, ui), app);
PhotocraftApp::setup_context(&h.ctx, Default::default());
h.run_steps(4);
let title = h.get_by_role_and_label(Role::Heading, "PhotoCraft").rect();
let message = h.get_by_label_contains(CUSTOM_SAMPLING_ALERT).rect();
// The prompt draws the icon unnamed, so it shows in the layout: the title starts at the content's start, the
// message after the icon on its row.
assert!(message.left() > title.left() + 8.0, "the message starts after the icon: {message:?} vs title {title:?}");
}
#[test]
fn each_choice_of_custom_shows_it() {
let mut app = app();
@@ -316,7 +316,7 @@ pub(crate) fn take(app: &mut PhotocraftApp, ctx: &egui::Context) {
}
if custom_chosen {
let _ = crate::dialogs::alerts::alert_once(app, tl!(CUSTOM_SAMPLING_ALERT), CUSTOM_SAMPLING_PREF);
let _ = crate::dialogs::alerts::info_once(app, tl!(CUSTOM_SAMPLING_ALERT), CUSTOM_SAMPLING_PREF);
}
}