mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-06 08:51:15 -05:00
Settings: framework sliders, colour wells, buttons and template rows; tests follow framework focus and key rules
This commit is contained in:
@@ -21,6 +21,7 @@ use crate::theme::Tokens;
|
||||
use crate::widgets::register;
|
||||
|
||||
mod appearance;
|
||||
mod controls;
|
||||
mod display;
|
||||
mod general;
|
||||
mod import;
|
||||
|
||||
@@ -424,7 +424,11 @@ fn appearance_sdk_settings_callback_pointer_and_keyboard_use_existing_native_sco
|
||||
fn native_journey(host: Host) {
|
||||
let mut f = Fixture::new(host);
|
||||
f.pick(ThemeKind::Paper);
|
||||
f.tab_to(&Fixture::radio(ThemeKind::Silver));
|
||||
// A family is one roving stop: Tab acquires its selected radio, an arrow moves to the
|
||||
// neighbouring member and Space selects it.
|
||||
f.tab_to(&Fixture::radio(ThemeKind::Paper));
|
||||
f.key(Key::ArrowUp);
|
||||
assert!(f.focused(&Fixture::radio(ThemeKind::Silver)), "arrow acquires the neighbouring family member; trace={:#?}", f.trace);
|
||||
let mut wanted = f.state();
|
||||
wanted["settings"]["lightTheme"] = json!("silver");
|
||||
f.key(Key::Space);
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
//! The framework controls the Settings pages share besides checkboxes, choices and text fields
|
||||
//! ([`super::widgets`]): a push button, a slider with its number field, and a colour well that
|
||||
//! opens a small colour editor.
|
||||
//!
|
||||
//! Every control is a framework component, so Tab and Shift+Tab reach it like any other stop of the
|
||||
//! page. Each is addressable by the automation name its caller gives it (`button:{name}`,
|
||||
//! `slider:{name}` / `sliderValue:{name}`, `button:{name}` for a colour well) and does nothing while
|
||||
//! the framework is only measuring the page.
|
||||
|
||||
use craft::behavior::{EditEvent, Mixed};
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, Sizing};
|
||||
use craft::ui::form::{SliderField, SliderFieldLayout};
|
||||
use craft::ui::popover::Popover;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::value_drag::SliderScale;
|
||||
use egui::{Color32, Sense, vec2};
|
||||
|
||||
/// Whether this pass acts: never a sizing pass or the framework's measuring pass.
|
||||
pub(crate) fn live(ui: &egui::Ui) -> bool {
|
||||
!ui.is_sizing_pass() && !craft::ui::runtime::measure::active(ui.ctx())
|
||||
}
|
||||
|
||||
/// The identity a control called `name` keeps its framework state under.
|
||||
pub(crate) fn owner(name: &str) -> egui::Id {
|
||||
egui::Id::new(("settings-control", name))
|
||||
}
|
||||
|
||||
/// A push button (`button:{name}`); true when it was activated by the pointer, the keyboard or
|
||||
/// assistive technology. A disabled button is no focus stop and never activates.
|
||||
pub(crate) fn button(ui: &mut egui::Ui, name: &str, label: &str, enabled: bool) -> bool {
|
||||
let real = live(ui);
|
||||
let shown = Button::new(crate::i18n::tr(label).to_owned()).id_salt(("settings-button", name)).enabled(enabled).show(ui);
|
||||
if real {
|
||||
crate::widgets::register_response(format!("button:{name}"), shown.response.rect, &shown.response);
|
||||
}
|
||||
real && enabled && ui.is_enabled() && shown.clicked()
|
||||
}
|
||||
|
||||
/// How a slider reads: its caption (the accessible name; the row shows the visible one), its span
|
||||
/// and its unit in the numbers the person sees, the least change one step makes, and whether the
|
||||
/// track is logarithmic.
|
||||
pub(crate) struct Shape<'a> {
|
||||
pub label: &'a str,
|
||||
pub lo: f64,
|
||||
pub hi: f64,
|
||||
pub unit: &'a str,
|
||||
pub step: f64,
|
||||
pub log: bool,
|
||||
}
|
||||
|
||||
/// What a slider asks its owner to do, in the numbers it shows.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) enum Step {
|
||||
/// Show `value` now (a drag in progress, or an abandoned gesture's value going back) without saving it.
|
||||
Preview(f64),
|
||||
/// The change is done: save `value`.
|
||||
Save(f64),
|
||||
}
|
||||
|
||||
/// A slider with its number field in one line (`slider:{name}`, `sliderValue:{name}`), over `value`.
|
||||
/// A drag previews as it goes and saves when let go; a typed value, a key or a click on the track
|
||||
/// saves at once; Escape in a drag gives the value back.
|
||||
pub(crate) fn slider(ui: &mut egui::Ui, owner: egui::Id, name: &str, shape: &Shape<'_>, value: f64) -> Vec<Step> {
|
||||
let real = live(ui);
|
||||
let id = owner.with(("slider", name));
|
||||
let (out, record) = craft::ui::runtime::inspect::record(ui, id.with("inspect"), |ui| {
|
||||
let mut field = SliderField::new(crate::i18n::tr(shape.label).to_owned(), Bind::given(value), shape.lo..=shape.hi)
|
||||
.id(id)
|
||||
.layout(SliderFieldLayout::Inline)
|
||||
.field_sizing(Sizing::Content)
|
||||
.step(shape.step)
|
||||
.sizing(Sizing::FillWidth);
|
||||
if !shape.unit.is_empty() {
|
||||
field = field.unit(shape.unit.to_owned());
|
||||
}
|
||||
if shape.log {
|
||||
field = field.scale(SliderScale::Log);
|
||||
}
|
||||
field.show(ui)
|
||||
});
|
||||
let mut steps = Vec::new();
|
||||
if !real {
|
||||
return steps;
|
||||
}
|
||||
if let Some(record) = record {
|
||||
for (index, element) in record.elements.iter().enumerate() {
|
||||
let Some(facts) = &element.facts else { continue };
|
||||
let prefix = match facts.role.as_str() {
|
||||
"Slider" => "slider",
|
||||
"SpinButton" => "sliderValue",
|
||||
_ => continue,
|
||||
};
|
||||
// A composite child may have an SDK arena response rather than an egui read_response.
|
||||
// Use that recorded child's real owner and stop bounds; this registers an alias only,
|
||||
// never another interactive widget or a guessed target.
|
||||
let mut response = ui.ctx().read_response(element.id).unwrap_or_else(|| {
|
||||
let mut response = out.response.clone();
|
||||
response.id = element.id;
|
||||
response.rect = record.stop_rect(index).unwrap_or(element.rect);
|
||||
response.interact_rect = response.rect.intersect(ui.clip_rect());
|
||||
response
|
||||
});
|
||||
response.interact_rect = response.interact_rect.intersect(ui.clip_rect());
|
||||
crate::widgets::register_response(format!("{prefix}:{name}"), response.rect, &response);
|
||||
}
|
||||
}
|
||||
if !ui.is_enabled() {
|
||||
return steps;
|
||||
}
|
||||
for event in &out.events {
|
||||
match event {
|
||||
EditEvent::Update { value, .. } => steps.push(Step::Preview(*value)),
|
||||
EditEvent::Commit { before: Mixed::Same(before), after, .. } => {
|
||||
steps.push(Step::Preview(*before));
|
||||
if after != before {
|
||||
steps.push(Step::Save(*after));
|
||||
}
|
||||
}
|
||||
EditEvent::Set { before, after, .. } => {
|
||||
if !matches!(before, Mixed::Same(value) if value == after) {
|
||||
steps.push(Step::Save(*after));
|
||||
}
|
||||
}
|
||||
EditEvent::Cancel { before: Some(Mixed::Same(before)), .. } => steps.push(Step::Preview(*before)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
steps
|
||||
}
|
||||
|
||||
/// `#rrggbb` (or `rrggbb`, `#rgb`) as a colour.
|
||||
pub(crate) fn parse_hex(text: &str) -> Option<[u8; 3]> {
|
||||
let digits = text.trim().trim_start_matches('#');
|
||||
let value = |hex: &str| u8::from_str_radix(hex, 16).ok();
|
||||
match digits.len() {
|
||||
6 if digits.is_ascii() => Some([value(&digits[0..2])?, value(&digits[2..4])?, value(&digits[4..6])?]),
|
||||
3 if digits.is_ascii() => Some([value(&digits[0..1])? * 17, value(&digits[1..2])? * 17, value(&digits[2..3])? * 17]),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A colour well (`button:{name}`): a button showing the colour that opens a small editor of red, green
|
||||
/// and blue sliders and a hex field. Returns the colour once an edit is done (a slider let go, a hex value
|
||||
/// entered); a drag shows its colour in the well meanwhile and saves nothing.
|
||||
pub(crate) fn colour(ui: &mut egui::Ui, owner: egui::Id, name: &str, label: &str, value: [u8; 3]) -> Option<[u8; 3]> {
|
||||
let real = live(ui);
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(44.0, 24.0), Sense::hover());
|
||||
if !real {
|
||||
return None;
|
||||
}
|
||||
let words = crate::i18n::tr(label).to_owned();
|
||||
let draft_key = owner.with("colour-draft");
|
||||
let open_key = owner.with("colour-open");
|
||||
let stamp_key = open_key.with("pass");
|
||||
let pass = ui.ctx().cumulative_pass_nr();
|
||||
let (kept, previous) = ui.data(|d| (d.get_temp::<bool>(open_key).unwrap_or(false), d.get_temp::<u64>(stamp_key)));
|
||||
// (an editor left open by a page that went away is not open when the page comes back)
|
||||
let mut open = kept && previous.is_some_and(|last| last == pass || last.checked_add(1) == Some(pass));
|
||||
let mut rgb: [u8; 3] = ui.data(|d| d.get_temp(draft_key)).unwrap_or(value);
|
||||
|
||||
let chip = Button::new(words.clone()).id(owner.with("chip")).painted(Label::Empty).show_at(ui, rect);
|
||||
crate::widgets::register_response(format!("button:{name}"), rect, &chip.response);
|
||||
let face = rect.shrink2(vec2(7.0, 5.0));
|
||||
ui.painter().rect_filled(face, 3.0, Color32::from_rgb(rgb[0], rgb[1], rgb[2]));
|
||||
ui.painter().rect_stroke(face, 3.0, egui::Stroke::new(1.0, Color32::from_gray(128)), egui::StrokeKind::Inside);
|
||||
if ui.is_enabled() && chip.clicked() {
|
||||
open = !open;
|
||||
}
|
||||
|
||||
let mut saved = false;
|
||||
let _editor = Popover::new(words, Bind::bound(&mut open)).id_salt(("settings-colour-editor", name)).opened_by(&chip.response).show(ui, |ui, _| {
|
||||
ui.set_min_width(240.0);
|
||||
for (i, channel) in ["Red", "Green", "Blue"].into_iter().enumerate() {
|
||||
let shape = Shape { label: channel, lo: 0.0, hi: 255.0, unit: "", step: 1.0, log: false };
|
||||
let steps = ui
|
||||
.horizontal(|ui| {
|
||||
ui.add_sized(vec2(48.0, 24.0), egui::Label::new(crate::i18n::tr(channel)));
|
||||
slider(ui, owner, &format!("{name}{channel}"), &shape, f64::from(rgb[i]))
|
||||
})
|
||||
.inner;
|
||||
for step in steps {
|
||||
let (Step::Preview(v) | Step::Save(v)) = step;
|
||||
rgb[i] = v.round().clamp(0.0, 255.0) as u8;
|
||||
saved |= matches!(step, Step::Save(_));
|
||||
}
|
||||
}
|
||||
if let Some(typed) = hex_field(ui, owner, name, rgb) {
|
||||
rgb = typed;
|
||||
saved = true;
|
||||
}
|
||||
});
|
||||
let editing = open;
|
||||
ui.data_mut(|d| {
|
||||
d.insert_temp(open_key, open);
|
||||
d.insert_temp(stamp_key, pass);
|
||||
if editing && !saved && rgb != value {
|
||||
d.insert_temp(draft_key, rgb);
|
||||
} else {
|
||||
d.remove::<[u8; 3]>(draft_key);
|
||||
}
|
||||
});
|
||||
(saved && ui.is_enabled() && rgb != value).then_some(rgb)
|
||||
}
|
||||
|
||||
/// The hex text of a colour well's editor (`field:{name}Hex`): the colour typed in, once Return or leaving the
|
||||
/// field enters it.
|
||||
fn hex_field(ui: &mut egui::Ui, owner: egui::Id, name: &str, rgb: [u8; 3]) -> Option<[u8; 3]> {
|
||||
use craft::ui::text::TextField;
|
||||
let key = owner.with("colour-hex");
|
||||
let mut text: String = ui.data(|d| d.get_temp(key)).unwrap_or_else(|| format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2]));
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(96.0, 24.0), Sense::hover());
|
||||
if !live(ui) {
|
||||
return None;
|
||||
}
|
||||
let out = TextField::new(crate::i18n::tr("Hex"), Bind::bound(&mut text)).id(key.with("field")).submits().show_at(ui, rect);
|
||||
crate::widgets::register_response(format!("field:{name}Hex"), out.response.rect, &out.response);
|
||||
// (what is typed is kept while the field has the keyboard; otherwise it shows the colour)
|
||||
let committed = out.events.committed().cloned();
|
||||
if out.response.has_focus() && committed.is_none() {
|
||||
ui.data_mut(|d| d.insert_temp(key, text));
|
||||
} else {
|
||||
ui.data_mut(|d| d.remove::<String>(key));
|
||||
}
|
||||
committed.as_deref().and_then(parse_hex).filter(|typed| *typed != rgb)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::parse_hex;
|
||||
|
||||
#[test]
|
||||
fn hex_colours_read_with_or_without_the_hash_and_in_short_form() {
|
||||
assert_eq!(parse_hex("#203040"), Some([0x20, 0x30, 0x40]));
|
||||
assert_eq!(parse_hex("ff8000"), Some([0xff, 0x80, 0x00]));
|
||||
assert_eq!(parse_hex(" #f80 "), Some([0xff, 0x88, 0x00]));
|
||||
assert_eq!(parse_hex("#12345"), None);
|
||||
assert_eq!(parse_hex("#gg0000"), None);
|
||||
assert_eq!(parse_hex("#é0000"), None);
|
||||
assert_eq!(parse_hex(""), None);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::appearance::appearance;
|
||||
use super::widgets::{check, choices, heading, hint, path_label, row};
|
||||
use super::{GridBadges, LightcraftApp, RichText, Tokens, Value, json, register};
|
||||
use super::{GridBadges, LightcraftApp, RichText, Tokens, Value, json};
|
||||
|
||||
// ---------------------------------------------------------------------------------- Interface
|
||||
|
||||
@@ -237,17 +237,28 @@ mod loupe_view_options_flow_tests;
|
||||
|
||||
/// A playback duration slider (`slider:{id}`). While it is dragged the value changes in memory
|
||||
/// (the slideshow reads it); letting go saves it through `slideshow.playback`.
|
||||
pub(super) fn duration_slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, key: &str, value: f64, range: std::ops::RangeInclusive<f64>) {
|
||||
let mut v = value;
|
||||
let r = ui.add(egui::Slider::new(&mut v, range).logarithmic(key == "slideDuration").suffix(" s").max_decimals(1));
|
||||
register(ui, format!("slider:{id}"), r.rect);
|
||||
if r.changed()
|
||||
&& let Ok(next) = app.session.slideshow.merged(&json!({ key: v }))
|
||||
{
|
||||
app.session.slideshow = next;
|
||||
}
|
||||
if r.drag_stopped() || (r.changed() && !r.dragged()) {
|
||||
let _ = app.run("slideshow.playback", json!({ key: v }));
|
||||
pub(super) fn duration_slider(
|
||||
app: &mut LightcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
id: &str,
|
||||
label: &str,
|
||||
key: &str,
|
||||
value: f64,
|
||||
range: std::ops::RangeInclusive<f64>,
|
||||
) {
|
||||
use super::controls::{self, Shape, Step};
|
||||
let shape = Shape { label, lo: *range.start(), hi: *range.end(), unit: "s", step: 0.1, log: key == "slideDuration" };
|
||||
for step in controls::slider(ui, controls::owner(id), id, &shape, value) {
|
||||
match step {
|
||||
Step::Preview(v) => {
|
||||
if let Ok(next) = app.session.slideshow.merged(&json!({ key: v })) {
|
||||
app.session.slideshow = next;
|
||||
}
|
||||
}
|
||||
Step::Save(v) => {
|
||||
let _ = app.run("slideshow.playback", json!({ key: v }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::widgets::{check, choices, field, heading, hint, path_label, row};
|
||||
use super::{LightcraftApp, RichText, StartupView, Tokens, json, register};
|
||||
use super::{LightcraftApp, RichText, StartupView, Tokens, json};
|
||||
|
||||
// ------------------------------------------------------------------------------------- General
|
||||
|
||||
@@ -168,9 +168,7 @@ fn lens_profiles(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
};
|
||||
row(ui, t, crate::i18n::tr("Lens database"), |ui| {
|
||||
ui.label(RichText::new(status).color(t.text));
|
||||
let r = ui.add_enabled(!own && !running && !installed, egui::Button::new(crate::i18n::tr("Download Lens Database")));
|
||||
register(ui, "button:settingsLensDatabase", r.rect);
|
||||
if r.clicked()
|
||||
if super::controls::button(ui, "settingsLensDatabase", "Download Lens Database", !own && !running && !installed)
|
||||
&& let Err(e) = crate::lens_db::download_default(app)
|
||||
{
|
||||
app.toast(ui.ctx(), e);
|
||||
|
||||
@@ -244,18 +244,13 @@ fn smart_previews(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
let mut result = None;
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(LABEL_W);
|
||||
if app.services.pick_folder.is_some() {
|
||||
let r = ui.button(crate::i18n::tr("Choose Folder…"));
|
||||
register(ui, "button:settingsSmartChoose", r.rect);
|
||||
if r.clicked()
|
||||
&& let Some(dir) = app.services.pick_folder.as_mut().and_then(|f| f())
|
||||
{
|
||||
result = Some(app.run("library.smartPreviewsLocation", json!({"path": dir, "existing": existing})));
|
||||
}
|
||||
if app.services.pick_folder.is_some()
|
||||
&& super::controls::button(ui, "settingsSmartChoose", "Choose Folder…", true)
|
||||
&& let Some(dir) = app.services.pick_folder.as_mut().and_then(|f| f())
|
||||
{
|
||||
result = Some(app.run("library.smartPreviewsLocation", json!({"path": dir, "existing": existing})));
|
||||
}
|
||||
let r = ui.add_enabled(custom, egui::Button::new(crate::i18n::tr("Use Library Folder")));
|
||||
register(ui, "button:settingsSmartReset", r.rect);
|
||||
if r.clicked() {
|
||||
if super::controls::button(ui, "settingsSmartReset", "Use Library Folder", custom) {
|
||||
result = Some(app.run("library.smartPreviewsLocation", json!({"reset": true, "existing": existing})));
|
||||
}
|
||||
});
|
||||
@@ -303,8 +298,6 @@ mod tests {
|
||||
fn clear_preview_cache_button(app: &mut LightcraftApp, ui: &mut egui::Ui) {
|
||||
use craft::ui::contract::{Props as _, Show as _};
|
||||
let label = crate::i18n::tr("Clear Cache");
|
||||
// Keep Settings a single native keyboard traversal domain. A lone SDK stop would
|
||||
// consume Tab without reaching any of the size buttons that precede this action.
|
||||
let (response, clicked) = {
|
||||
let out = craft::ui::buttons::Button::new(label).id_salt("settingsClearCache").show(ui);
|
||||
let clicked = out.clicked();
|
||||
|
||||
@@ -39,33 +39,30 @@ fn set(app: &mut LightcraftApp, p: Value) {
|
||||
}
|
||||
|
||||
/// A layout slider (`slider:{id}`): `key`'s value, 0–`max` (percent) or −180–180° (degrees).
|
||||
fn slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, key: &str, value: f64, max: f64, unit: Unit) {
|
||||
let (mut v, range, suffix) = match unit {
|
||||
Unit::Percent => (value * 100.0, 0.0..=max * 100.0, " %"),
|
||||
Unit::Degrees => (value, -180.0..=180.0, "°"),
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, label: &str, key: &str, value: f64, max: f64, unit: Unit) {
|
||||
use super::controls::{self, Shape, Step};
|
||||
let (k, lo, hi, suffix) = match unit {
|
||||
Unit::Percent => (100.0, 0.0, max * 100.0, "%"),
|
||||
Unit::Degrees => (1.0, -180.0, 180.0, "°"),
|
||||
};
|
||||
let r = ui.add(egui::Slider::new(&mut v, range).suffix(suffix).max_decimals(1));
|
||||
register(ui, format!("slider:{id}"), r.rect);
|
||||
let value = match unit {
|
||||
Unit::Percent => v / 100.0,
|
||||
Unit::Degrees => v,
|
||||
};
|
||||
if r.changed()
|
||||
&& let Ok(next) = app.session.slide_layout.merged(&json!({ key: value }))
|
||||
{
|
||||
app.session.slide_layout = next;
|
||||
}
|
||||
if r.drag_stopped() || (r.changed() && !r.dragged()) {
|
||||
set(app, json!({ key: value }));
|
||||
let shape = Shape { label, lo, hi, unit: suffix, step: 0.1, log: false };
|
||||
for step in controls::slider(ui, controls::owner(id), id, &shape, value * k) {
|
||||
match step {
|
||||
Step::Preview(v) => {
|
||||
if let Ok(next) = app.session.slide_layout.merged(&json!({ key: v / k })) {
|
||||
app.session.slide_layout = next;
|
||||
}
|
||||
}
|
||||
Step::Save(v) => set(app, json!({ key: v / k })),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A colour button (`button:{id}`) for `key`.
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, key: &str, value: [u8; 3]) {
|
||||
let mut c = value;
|
||||
let r = egui::color_picker::color_edit_button_srgb(ui, &mut c);
|
||||
register(ui, format!("button:{id}"), r.rect);
|
||||
if r.changed() {
|
||||
/// A colour well (`button:{id}`) for `key`.
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, label: &str, key: &str, value: [u8; 3]) {
|
||||
use super::controls;
|
||||
if let Some(c) = controls::colour(ui, controls::owner(id), id, label, value) {
|
||||
set(app, json!({ key: c }));
|
||||
}
|
||||
}
|
||||
@@ -86,7 +83,7 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
heading(ui, t, "Layout");
|
||||
let linked = toggle(app, ui, "slideshowLinkMargins", "linkMargins", s.link_margins, "Link all margins");
|
||||
if linked {
|
||||
row(ui, t, "Margins", |ui| slider(app, ui, "slideshowMargins", "marginLeft", s.margin_left, MARGIN_MAX, Unit::Percent));
|
||||
row(ui, t, "Margins", |ui| slider(app, ui, "slideshowMargins", "Margins", "marginLeft", s.margin_left, MARGIN_MAX, Unit::Percent));
|
||||
} else {
|
||||
for (id, key, label, v) in [
|
||||
("slideshowMarginLeft", "marginLeft", "Left", s.margin_left),
|
||||
@@ -94,7 +91,7 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
("slideshowMarginTop", "marginTop", "Top", s.margin_top),
|
||||
("slideshowMarginBottom", "marginBottom", "Bottom", s.margin_bottom),
|
||||
] {
|
||||
row(ui, t, label, |ui| slider(app, ui, id, key, v, MARGIN_MAX, Unit::Percent));
|
||||
row(ui, t, label, |ui| slider(app, ui, id, label, key, v, MARGIN_MAX, Unit::Percent));
|
||||
}
|
||||
}
|
||||
hint(ui, t, "Margins are a share of the slide's shorter side, so slides look the same on any screen.");
|
||||
@@ -111,23 +108,27 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
heading(ui, t, "Options");
|
||||
toggle(app, ui, "slideshowZoomToFill", "zoomToFill", s.zoom_to_fill, "Zoom to fill frame");
|
||||
if toggle(app, ui, "slideshowStroke", "strokeBorder", s.stroke_border, "Stroke border") {
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowStrokeColor", "strokeColor", s.stroke_color));
|
||||
row(ui, t, "Width", |ui| slider(app, ui, "slideshowStrokeWidth", "strokeWidth", s.stroke_width, STROKE_MAX, Unit::Percent));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowStrokeColor", "Colour", "strokeColor", s.stroke_color));
|
||||
row(ui, t, "Width", |ui| slider(app, ui, "slideshowStrokeWidth", "Width", "strokeWidth", s.stroke_width, STROKE_MAX, Unit::Percent));
|
||||
}
|
||||
if toggle(app, ui, "slideshowShadow", "castShadow", s.cast_shadow, "Cast shadow") {
|
||||
row(ui, t, "Opacity", |ui| slider(app, ui, "slideshowShadowOpacity", "shadowOpacity", s.shadow_opacity, 1.0, Unit::Percent));
|
||||
row(ui, t, "Offset", |ui| slider(app, ui, "slideshowShadowOffset", "shadowOffset", s.shadow_offset, SHADOW_OFFSET_MAX, Unit::Percent));
|
||||
row(ui, t, "Radius", |ui| slider(app, ui, "slideshowShadowRadius", "shadowRadius", s.shadow_radius, SHADOW_RADIUS_MAX, Unit::Percent));
|
||||
row(ui, t, "Angle", |ui| slider(app, ui, "slideshowShadowAngle", "shadowAngle", s.shadow_angle, 180.0, Unit::Degrees));
|
||||
row(ui, t, "Opacity", |ui| slider(app, ui, "slideshowShadowOpacity", "Opacity", "shadowOpacity", s.shadow_opacity, 1.0, Unit::Percent));
|
||||
row(ui, t, "Offset", |ui| {
|
||||
slider(app, ui, "slideshowShadowOffset", "Offset", "shadowOffset", s.shadow_offset, SHADOW_OFFSET_MAX, Unit::Percent)
|
||||
});
|
||||
row(ui, t, "Radius", |ui| {
|
||||
slider(app, ui, "slideshowShadowRadius", "Radius", "shadowRadius", s.shadow_radius, SHADOW_RADIUS_MAX, Unit::Percent)
|
||||
});
|
||||
row(ui, t, "Angle", |ui| slider(app, ui, "slideshowShadowAngle", "Angle", "shadowAngle", s.shadow_angle, 180.0, Unit::Degrees));
|
||||
}
|
||||
|
||||
ui.add_space(6.0);
|
||||
heading(ui, t, "Backdrop");
|
||||
row(ui, t, "Background colour", |ui| colour(app, ui, "slideshowBackdropColor", "backdropColor", s.backdrop_color));
|
||||
row(ui, t, "Background colour", |ui| colour(app, ui, "slideshowBackdropColor", "Background colour", "backdropColor", s.backdrop_color));
|
||||
if toggle(app, ui, "slideshowWash", "colorWash", s.color_wash, "Colour wash") {
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowWashColor", "washColor", s.wash_color));
|
||||
row(ui, t, "Opacity", |ui| slider(app, ui, "slideshowWashOpacity", "washOpacity", s.wash_opacity, 1.0, Unit::Percent));
|
||||
row(ui, t, "Angle", |ui| slider(app, ui, "slideshowWashAngle", "washAngle", s.wash_angle, 180.0, Unit::Degrees));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowWashColor", "Colour", "washColor", s.wash_color));
|
||||
row(ui, t, "Opacity", |ui| slider(app, ui, "slideshowWashOpacity", "Opacity", "washOpacity", s.wash_opacity, 1.0, Unit::Percent));
|
||||
row(ui, t, "Angle", |ui| slider(app, ui, "slideshowWashAngle", "Angle", "washAngle", s.wash_angle, 180.0, Unit::Degrees));
|
||||
}
|
||||
background_photo_controls(app, ui, t, &s);
|
||||
reset_layout_button(app, ui);
|
||||
@@ -142,7 +143,6 @@ fn background_photo_controls(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tok
|
||||
let on = s.background_image.is_some();
|
||||
let enabled = on || active.is_some();
|
||||
let interactive = !ui.is_sizing_pass() && !craft::ui::runtime::measure::active(ui.ctx());
|
||||
// Settings remains a native subtree until mixed SDK/native traversal is supported.
|
||||
let next = {
|
||||
let out = Checkbox::new(Bind::given(on))
|
||||
.id_salt(("settings-check", "settings.slideshowBackgroundImage"))
|
||||
@@ -174,7 +174,9 @@ fn background_photo_controls(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tok
|
||||
set(app, json!({"backgroundImage": a.0}));
|
||||
}
|
||||
});
|
||||
row(ui, t, "Opacity", |ui| slider(app, ui, "slideshowBackgroundOpacity", "backgroundOpacity", s.background_opacity, 1.0, Unit::Percent));
|
||||
row(ui, t, "Opacity", |ui| {
|
||||
slider(app, ui, "slideshowBackgroundOpacity", "Opacity", "backgroundOpacity", s.background_opacity, 1.0, Unit::Percent)
|
||||
});
|
||||
} else {
|
||||
hint(ui, t, "Select a photo, then turn this on to fill the slide behind every photo with it.");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::LightcraftApp;
|
||||
use crate::panels::settings::{check, choices, heading, hint, row};
|
||||
use crate::text_field::TextField;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets::register;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Unit {
|
||||
@@ -38,31 +37,25 @@ struct Range {
|
||||
}
|
||||
|
||||
/// A slider (`slider:{id}`) over `range`; `wrap(value)` makes the `slideshow.overlays` request.
|
||||
fn slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, value: f64, range: Range, wrap: &dyn Fn(f64) -> Value) {
|
||||
fn slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, label: &str, value: f64, range: Range, wrap: &dyn Fn(f64) -> Value) {
|
||||
use super::controls::{self, Shape, Step};
|
||||
let (k, suffix) = match range.unit {
|
||||
Unit::Percent => (100.0, " %"),
|
||||
Unit::Percent => (100.0, "%"),
|
||||
Unit::Degrees => (1.0, "°"),
|
||||
};
|
||||
let mut v = value * k;
|
||||
let r = ui.add(egui::Slider::new(&mut v, range.lo * k..=range.hi * k).suffix(suffix).max_decimals(1));
|
||||
register(ui, format!("slider:{id}"), r.rect);
|
||||
let p = wrap(v / k);
|
||||
if r.changed()
|
||||
&& let Ok(next) = app.session.slide_overlays.merged(&p)
|
||||
{
|
||||
app.session.slide_overlays = next;
|
||||
}
|
||||
if r.drag_stopped() || (r.changed() && !r.dragged()) {
|
||||
set(app, p);
|
||||
let shape = Shape { label, lo: range.lo * k, hi: range.hi * k, unit: suffix, step: 0.1, log: false };
|
||||
for step in controls::slider(ui, controls::owner(id), id, &shape, value * k) {
|
||||
match step {
|
||||
Step::Preview(v) => text_row_preview(app, &wrap(v / k)),
|
||||
Step::Save(v) => set(app, wrap(v / k)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A colour button (`button:{id}`).
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, value: [u8; 3], wrap: &dyn Fn([u8; 3]) -> Value) {
|
||||
let mut c = value;
|
||||
let r = egui::color_picker::color_edit_button_srgb(ui, &mut c);
|
||||
register(ui, format!("button:{id}"), r.rect);
|
||||
if r.changed() {
|
||||
/// A colour well (`button:{id}`).
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, label: &str, value: [u8; 3], wrap: &dyn Fn([u8; 3]) -> Value) {
|
||||
use super::controls;
|
||||
if let Some(c) = controls::colour(ui, controls::owner(id), id, label, value) {
|
||||
set(app, wrap(c));
|
||||
}
|
||||
}
|
||||
@@ -132,14 +125,26 @@ fn placement(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, id: &str, p
|
||||
});
|
||||
}
|
||||
row(ui, t, "Offset X", |ui| {
|
||||
slider(app, ui, &format!("{id}OffsetX"), p.offset_x, Range { lo: -OFFSET_MAX / 2.0, hi: OFFSET_MAX / 2.0, unit: Unit::Percent }, &|v| {
|
||||
wrap(json!({"offsetX": v}))
|
||||
})
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
&format!("{id}OffsetX"),
|
||||
"Offset X",
|
||||
p.offset_x,
|
||||
Range { lo: -OFFSET_MAX / 2.0, hi: OFFSET_MAX / 2.0, unit: Unit::Percent },
|
||||
&|v| wrap(json!({"offsetX": v})),
|
||||
)
|
||||
});
|
||||
row(ui, t, "Offset Y", |ui| {
|
||||
slider(app, ui, &format!("{id}OffsetY"), p.offset_y, Range { lo: -OFFSET_MAX / 2.0, hi: OFFSET_MAX / 2.0, unit: Unit::Percent }, &|v| {
|
||||
wrap(json!({"offsetY": v}))
|
||||
})
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
&format!("{id}OffsetY"),
|
||||
"Offset Y",
|
||||
p.offset_y,
|
||||
Range { lo: -OFFSET_MAX / 2.0, hi: OFFSET_MAX / 2.0, unit: Unit::Percent },
|
||||
&|v| wrap(json!({"offsetY": v})),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -180,13 +185,29 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
});
|
||||
} else {
|
||||
row(ui, t, "Text", |ui| text(app, ui, "slideshowPlateText", &p.text, "Your name or studio", &|v| plate(json!({"text": v}))));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowPlateColor", p.color, &|c| plate(json!({"color": c}))));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowPlateColor", "Colour", p.color, &|c| plate(json!({"color": c}))));
|
||||
}
|
||||
row(ui, t, "Size", |ui| {
|
||||
slider(app, ui, "slideshowPlateSize", p.size, Range { lo: 0.01, hi: PLATE_SIZE_MAX, unit: Unit::Percent }, &|v| plate(json!({"size": v})))
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
"slideshowPlateSize",
|
||||
"Size",
|
||||
p.size,
|
||||
Range { lo: 0.01, hi: PLATE_SIZE_MAX, unit: Unit::Percent },
|
||||
&|v| plate(json!({"size": v})),
|
||||
)
|
||||
});
|
||||
row(ui, t, "Opacity", |ui| {
|
||||
slider(app, ui, "slideshowPlateOpacity", p.opacity, Range { lo: 0.0, hi: 1.0, unit: Unit::Percent }, &|v| plate(json!({"opacity": v})))
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
"slideshowPlateOpacity",
|
||||
"Opacity",
|
||||
p.opacity,
|
||||
Range { lo: 0.0, hi: 1.0, unit: Unit::Percent },
|
||||
&|v| plate(json!({"opacity": v})),
|
||||
)
|
||||
});
|
||||
placement(app, ui, t, "slideshowPlate", &p.place, true, &plate);
|
||||
toggle(app, ui, "slideshowPlateBehind", p.behind, "Render behind image", &|v| plate(json!({"behind": v})));
|
||||
@@ -197,9 +218,17 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
let r = s.rating_stars.clone();
|
||||
let stars = |v: Value| json!({ "ratingStars": v });
|
||||
if toggle(app, ui, "slideshowStars", r.enabled, "Rating stars", &|v| stars(json!({"enabled": v}))) {
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowStarsColor", r.color, &|c| stars(json!({"color": c}))));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, "slideshowStarsColor", "Colour", r.color, &|c| stars(json!({"color": c}))));
|
||||
row(ui, t, "Size", |ui| {
|
||||
slider(app, ui, "slideshowStarsSize", r.size, Range { lo: 0.01, hi: STAR_SIZE_MAX, unit: Unit::Percent }, &|v| stars(json!({"size": v})))
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
"slideshowStarsSize",
|
||||
"Size",
|
||||
r.size,
|
||||
Range { lo: 0.01, hi: STAR_SIZE_MAX, unit: Unit::Percent },
|
||||
&|v| stars(json!({"size": v})),
|
||||
)
|
||||
});
|
||||
placement(app, ui, t, "slideshowStars", &r.place, true, &stars);
|
||||
}
|
||||
@@ -220,10 +249,18 @@ pub fn sections(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
if toggle(app, ui, "slideshowWatermark", s.show_watermark, "Watermark", &|v| json!({"showWatermark": v})) {
|
||||
row(ui, t, "Text", |ui| text(app, ui, "slideshowWatermarkText", &w.text, "© Your Name", &|v| wm(json!({"text": v}))));
|
||||
row(ui, t, "Size", |ui| {
|
||||
slider(app, ui, "slideshowWatermarkSize", w.size as f64, Range { lo: 0.01, hi: 0.15, unit: Unit::Percent }, &|v| wm(json!({"size": v})))
|
||||
slider(
|
||||
app,
|
||||
ui,
|
||||
"slideshowWatermarkSize",
|
||||
"Size",
|
||||
w.size as f64,
|
||||
Range { lo: 0.01, hi: 0.15, unit: Unit::Percent },
|
||||
&|v| wm(json!({"size": v})),
|
||||
)
|
||||
});
|
||||
row(ui, t, "Opacity", |ui| {
|
||||
slider(app, ui, "slideshowWatermarkOpacity", w.opacity as f64, Range { lo: 0.05, hi: 1.0, unit: Unit::Percent }, &|v| {
|
||||
slider(app, ui, "slideshowWatermarkOpacity", "Opacity", w.opacity as f64, Range { lo: 0.05, hi: 1.0, unit: Unit::Percent }, &|v| {
|
||||
wm(json!({"opacity": v}))
|
||||
})
|
||||
});
|
||||
@@ -351,66 +388,18 @@ fn text_row_slider(
|
||||
wrap: &dyn Fn(Value) -> Value,
|
||||
key: &str,
|
||||
) {
|
||||
use craft::behavior::{EditEvent, Mixed};
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, Sizing};
|
||||
use craft::ui::form::{SliderField, SliderFieldLayout};
|
||||
let real = real_pass(ui);
|
||||
use super::controls::{self, Shape, Step};
|
||||
let (k, suffix) = match range.unit {
|
||||
Unit::Percent => (100.0, "%"),
|
||||
Unit::Degrees => (1.0, "°"),
|
||||
};
|
||||
let shape = Shape { label, lo: range.lo * k, hi: range.hi * k, unit: suffix, step: 0.1, log: false };
|
||||
// (the preview and the saved value are what `key` of this text overlay becomes)
|
||||
let patch = |value: f64| wrap(json!({key: value / k}));
|
||||
let (out, record) = craft::ui::runtime::inspect::record(ui, owner.with((key, "inspect")), |ui| {
|
||||
SliderField::new(crate::i18n::tr(label).to_owned(), Bind::given(value * k), range.lo * k..=range.hi * k)
|
||||
.id(owner.with(key))
|
||||
.layout(SliderFieldLayout::Inline)
|
||||
.field_sizing(Sizing::Content)
|
||||
.unit(suffix)
|
||||
.step(0.1)
|
||||
.sizing(Sizing::FillWidth)
|
||||
.show(ui)
|
||||
});
|
||||
if !real {
|
||||
return;
|
||||
}
|
||||
if let Some(record) = record {
|
||||
for (index, element) in record.elements.iter().enumerate() {
|
||||
let Some(facts) = &element.facts else { continue };
|
||||
let prefix = match facts.role.as_str() {
|
||||
"Slider" => "slider",
|
||||
"SpinButton" => "sliderValue",
|
||||
_ => continue,
|
||||
};
|
||||
// A composite child may have an SDK arena response rather than an egui read_response.
|
||||
// Use that recorded child's real owner and stop bounds, as KeywordSet's footer does;
|
||||
// this registers an alias only, never another interactive widget or a guessed target.
|
||||
let mut response = ui.ctx().read_response(element.id).unwrap_or_else(|| {
|
||||
let mut response = out.response.clone();
|
||||
response.id = element.id;
|
||||
response.rect = record.stop_rect(index).unwrap_or(element.rect);
|
||||
response.interact_rect = response.rect.intersect(ui.clip_rect());
|
||||
response
|
||||
});
|
||||
response.interact_rect = response.interact_rect.intersect(ui.clip_rect());
|
||||
crate::widgets::register_response(format!("{prefix}:{name}"), response.rect, &response);
|
||||
}
|
||||
}
|
||||
for event in &out.events {
|
||||
match event {
|
||||
EditEvent::Update { value, .. } if ui.is_enabled() => text_row_preview(app, &patch(*value)),
|
||||
EditEvent::Commit { before: Mixed::Same(before), after, .. } if ui.is_enabled() => {
|
||||
text_row_preview(app, &patch(*before));
|
||||
if after != before {
|
||||
set(app, patch(*after));
|
||||
}
|
||||
}
|
||||
EditEvent::Set { before, after, .. } if ui.is_enabled() => {
|
||||
if !matches!(before, Mixed::Same(value) if value == after) {
|
||||
set(app, patch(*after));
|
||||
}
|
||||
}
|
||||
EditEvent::Cancel { before: Some(Mixed::Same(before)), .. } => text_row_preview(app, &patch(*before)),
|
||||
_ => {}
|
||||
for step in controls::slider(ui, owner, name, &shape, value * k) {
|
||||
match step {
|
||||
Step::Preview(v) => text_row_preview(app, &patch(v)),
|
||||
Step::Save(v) => set(app, patch(v)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -522,16 +511,9 @@ fn text_overlays(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) -> bool
|
||||
text_row_slider(app, ui, owner, &format!("{name}{suffix}"), label, value, Range { lo, hi, unit: Unit::Percent }, &wrap, key)
|
||||
});
|
||||
}
|
||||
// Keep the existing platform-neutral egui colour picker; only accepted real changes
|
||||
// enter the existing validated command. It is not a new SDK colour-dialog provider.
|
||||
row(ui, t, "Colour", |ui| {
|
||||
let mut color = o.color;
|
||||
let response = ui.add_enabled_ui(real, |ui| egui::color_picker::color_edit_button_srgb(ui, &mut color)).inner;
|
||||
if real {
|
||||
crate::widgets::register_response(format!("button:{name}Color"), response.rect, &response);
|
||||
if ui.is_enabled() && response.changed() {
|
||||
set(app, wrap(json!({"color": color})));
|
||||
}
|
||||
if let Some(color) = super::controls::colour(ui, owner.with("colour"), &format!("{name}Color"), "Colour", o.color) {
|
||||
set(app, wrap(json!({"color": color})));
|
||||
}
|
||||
});
|
||||
row(ui, t, "Opacity", |ui| {
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
//! update it with the current settings, rename, export or delete it; a built-in to export it.
|
||||
//! Every action goes through a `slideshow.templates.*` command.
|
||||
|
||||
use craft::theme::Variant;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::runtime::env::Label;
|
||||
use egui::{RichText, Sense, Stroke, vec2};
|
||||
use lightcraft_engine::slide_template::{PREVIOUS, SlideLook, Template};
|
||||
use serde_json::json;
|
||||
@@ -17,7 +23,7 @@ use crate::LightcraftApp;
|
||||
use crate::panels::settings::{heading, hint};
|
||||
use crate::text_field::TextField;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets::{register, register_response};
|
||||
use crate::widgets::register_response;
|
||||
|
||||
/// The user templates list is at most this tall (it scrolls past it).
|
||||
const USER_LIST_H: f32 = 180.0;
|
||||
@@ -35,6 +41,19 @@ fn set_hovered(ctx: &egui::Context, id: Option<String>) {
|
||||
ctx.data_mut(|d| d.insert_temp(hovered_key(), id));
|
||||
}
|
||||
|
||||
fn menu_target_key() -> egui::Id {
|
||||
egui::Id::unique("settingsSlideshowTemplateMenuTarget")
|
||||
}
|
||||
|
||||
/// The template whose menu is open (its row keeps its preview while the pointer is in the menu).
|
||||
fn menu_target(ctx: &egui::Context) -> Option<String> {
|
||||
ctx.data(|d| d.get_temp::<Option<String>>(menu_target_key())).flatten()
|
||||
}
|
||||
|
||||
fn set_menu_target(ctx: &egui::Context, id: Option<String>) {
|
||||
ctx.data_mut(|d| d.insert_temp(menu_target_key(), id));
|
||||
}
|
||||
|
||||
/// What a row is doing: being renamed (with the text so far), or waiting for a delete to be confirmed.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Pending {
|
||||
@@ -94,83 +113,121 @@ fn apply(app: &mut LightcraftApp, ctx: &egui::Context, id: &str, name: &str) {
|
||||
fn template_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, tpl: &Template, current: bool, hovered: &mut Option<String>) {
|
||||
let ctx = ui.ctx().clone();
|
||||
let name = shown_name(tpl);
|
||||
if let Some(Pending::Rename(id, mut text)) = pending(&ctx).filter(|p| matches!(p, Pending::Rename(id, _) if *id == tpl.id)) {
|
||||
let r = TextField::singleline("field:slideshowTemplateRename", &mut text)
|
||||
.width(ui.available_width().clamp(80.0, 260.0))
|
||||
.select_on_focus(true)
|
||||
.show(ui);
|
||||
if !r.editing && r.ending.is_none() {
|
||||
crate::text_field::focus_id(&ctx, r.response.id);
|
||||
}
|
||||
if r.committed() {
|
||||
set_pending(&ctx, None);
|
||||
if text.trim() != tpl.name {
|
||||
act(app, &ctx, "slideshow.templates.rename", json!({"id": id, "name": text}), |_| String::new());
|
||||
}
|
||||
} else if r.cancelled() {
|
||||
set_pending(&ctx, None);
|
||||
} else {
|
||||
set_pending(&ctx, Some(Pending::Rename(id, text)));
|
||||
}
|
||||
return;
|
||||
if let Some(Pending::Rename(id, text)) = pending(&ctx).filter(|p| matches!(p, Pending::Rename(id, _) if *id == tpl.id)) {
|
||||
rename_row(app, ui, &ctx, tpl, id, text);
|
||||
} else if pending(&ctx) == Some(Pending::Delete(tpl.id.clone())) {
|
||||
delete_row(app, ui, t, &ctx, tpl, &name);
|
||||
} else {
|
||||
plain_row(app, ui, t, &ctx, tpl, &name, current, hovered);
|
||||
}
|
||||
if pending(&ctx) == Some(Pending::Delete(tpl.id.clone())) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(crate::i18n::tr_format!("Delete “{name}”?", name = name)).color(t.caution));
|
||||
if crate::widgets::text_button(ui, "slideshowTemplateDeleteConfirm", "Delete", false).clicked() {
|
||||
set_pending(&ctx, None);
|
||||
act(app, &ctx, "slideshow.templates.delete", json!({"id": tpl.id}), |_| String::new());
|
||||
}
|
||||
if crate::widgets::text_button(ui, "slideshowTemplateDeleteCancel", "Cancel", false).clicked() {
|
||||
set_pending(&ctx, None);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
let w = ui.available_width();
|
||||
let (rect, resp) = ui.allocate_exact_size(vec2(w, 22.0), Sense::click());
|
||||
register_response(format!("template:{}", tpl.id), rect, &resp);
|
||||
if resp.hovered() || resp.context_menu_opened() {
|
||||
*hovered = Some(tpl.id.clone());
|
||||
}
|
||||
let p = ui.painter();
|
||||
if resp.hovered() {
|
||||
p.rect_filled(rect, 3.0, t.hover);
|
||||
}
|
||||
if current {
|
||||
p.rect_stroke(rect.shrink(0.5), 3.0, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
|
||||
}
|
||||
let colour = if current { t.text } else { t.text_label };
|
||||
p.text(rect.left_center() + vec2(8.0, 0.0), egui::Align2::LEFT_CENTER, &name, t.font(12.0), colour);
|
||||
if resp.clicked() {
|
||||
apply(app, &ctx, &tpl.id, &name);
|
||||
}
|
||||
crate::widgets::context_menu(&resp, |ui| menu(app, ui, tpl, &name));
|
||||
}
|
||||
|
||||
/// A menu entry registered as `button:{id}`.
|
||||
/// The row of a template being renamed: its name in a text field.
|
||||
fn rename_row(app: &mut LightcraftApp, ui: &mut egui::Ui, ctx: &egui::Context, tpl: &Template, id: String, mut text: String) {
|
||||
let r = TextField::singleline("field:slideshowTemplateRename", &mut text)
|
||||
.width(ui.available_width().clamp(80.0, 260.0))
|
||||
.select_on_focus(true)
|
||||
.show(ui);
|
||||
if !r.editing && r.ending.is_none() {
|
||||
crate::text_field::focus_id(ctx, r.response.id);
|
||||
}
|
||||
if r.committed() {
|
||||
set_pending(ctx, None);
|
||||
if text.trim() != tpl.name {
|
||||
act(app, ctx, "slideshow.templates.rename", json!({"id": id, "name": text}), |_| String::new());
|
||||
}
|
||||
} else if r.cancelled() {
|
||||
set_pending(ctx, None);
|
||||
} else {
|
||||
set_pending(ctx, Some(Pending::Rename(id, text)));
|
||||
}
|
||||
}
|
||||
|
||||
/// The row of a template whose delete waits to be confirmed.
|
||||
fn delete_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, ctx: &egui::Context, tpl: &Template, name: &str) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(crate::i18n::tr_format!("Delete “{name}”?", name = name)).color(t.caution));
|
||||
if crate::widgets::text_button(ui, "slideshowTemplateDeleteConfirm", "Delete", false).clicked() {
|
||||
set_pending(ctx, None);
|
||||
act(app, ctx, "slideshow.templates.delete", json!({"id": tpl.id}), |_| String::new());
|
||||
}
|
||||
if crate::widgets::text_button(ui, "slideshowTemplateDeleteCancel", "Cancel", false).clicked() {
|
||||
set_pending(ctx, None);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A template's ordinary row: a framework button painted with its name, a Tab stop that acts on Enter and
|
||||
/// Space, with a menu that opens on a right-click or the menu key.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn plain_row(
|
||||
app: &mut LightcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
t: &Tokens,
|
||||
ctx: &egui::Context,
|
||||
tpl: &Template,
|
||||
name: &str,
|
||||
current: bool,
|
||||
hovered: &mut Option<String>,
|
||||
) {
|
||||
let w = ui.available_width();
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(w, 22.0), Sense::hover());
|
||||
if !super::controls::live(ui) {
|
||||
return;
|
||||
}
|
||||
let face = Button::new(name.replace('&', "&&"))
|
||||
.id_salt(("settings-template", tpl.id.as_str()))
|
||||
.painted(Label::Empty)
|
||||
.variant(Variant::GHOST)
|
||||
.show_at(ui, rect);
|
||||
let resp = face.response.clone();
|
||||
register_response(format!("template:{}", tpl.id), rect, &resp);
|
||||
if resp.hovered() || menu_target(ctx).as_deref() == Some(tpl.id.as_str()) {
|
||||
*hovered = Some(tpl.id.clone());
|
||||
}
|
||||
if resp.secondary_clicked() {
|
||||
set_menu_target(ctx, Some(tpl.id.clone()));
|
||||
}
|
||||
let painter = ui.painter();
|
||||
if current {
|
||||
painter.rect_stroke(rect.shrink(0.5), 3.0, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
|
||||
}
|
||||
let colour = if current { t.text } else { t.text_label };
|
||||
painter.text(rect.left_center() + vec2(8.0, 0.0), egui::Align2::LEFT_CENTER, name, t.font(12.0), colour);
|
||||
if ui.is_enabled() && face.clicked() {
|
||||
apply(app, ctx, &tpl.id, name);
|
||||
}
|
||||
let shown = Menu::context(crate::i18n::tr("Slideshow template"), &resp)
|
||||
.id_salt(("settings-template-menu", tpl.id.as_str()))
|
||||
.show(ui, |ui, _| menu(app, ui, tpl, name));
|
||||
if shown.output.closed.is_some() && menu_target(ctx).as_deref() == Some(tpl.id.as_str()) {
|
||||
set_menu_target(ctx, None);
|
||||
}
|
||||
}
|
||||
|
||||
/// A menu entry registered as `button:{id}`; true when it ran (which closes the menu).
|
||||
fn item(ui: &mut egui::Ui, id: &str, label: &str, enabled: bool) -> bool {
|
||||
let r = ui.add_enabled(enabled, egui::Button::new(crate::i18n::tr(label)));
|
||||
register(ui, format!("button:{id}"), r.rect);
|
||||
r.clicked()
|
||||
let shown = MenuItem::new(crate::i18n::tr(label).to_owned()).id_salt(("settings-template-item", id)).enabled(enabled).show(ui);
|
||||
if !super::controls::live(ui) {
|
||||
return false;
|
||||
}
|
||||
register_response(format!("button:{id}"), shown.response.rect, &shown.response);
|
||||
enabled && ui.is_enabled() && shown.ran
|
||||
}
|
||||
|
||||
fn menu(app: &mut LightcraftApp, ui: &mut egui::Ui, tpl: &Template, name: &str) {
|
||||
let ctx = ui.ctx().clone();
|
||||
if item(ui, "slideshowTemplateApply", "Apply", true) {
|
||||
apply(app, &ctx, &tpl.id, name);
|
||||
ui.close();
|
||||
}
|
||||
let user = !tpl.builtin && tpl.id != PREVIOUS;
|
||||
if user {
|
||||
if item(ui, "slideshowTemplateUpdate", "Update with Current Settings", true) {
|
||||
let n = name.to_string();
|
||||
act(app, &ctx, "slideshow.templates.update", json!({"id": tpl.id}), |_| crate::i18n::tr_format!("Updated {name}", name = n));
|
||||
ui.close();
|
||||
}
|
||||
if item(ui, "slideshowTemplateRename", "Rename…", true) {
|
||||
set_pending(&ctx, Some(Pending::Rename(tpl.id.clone(), tpl.name.clone())));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
if tpl.id != PREVIOUS && item(ui, "slideshowTemplateExport", "Export…", app.services.save_slideshow_template.is_some()) {
|
||||
@@ -180,13 +237,11 @@ fn menu(app: &mut LightcraftApp, ui: &mut egui::Ui, tpl: &Template, name: &str)
|
||||
crate::i18n::tr_format!("Exported to {path}", path = r["path"].as_str().unwrap_or_default())
|
||||
});
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
if user {
|
||||
ui.separator();
|
||||
Divider::horizontal().show(ui);
|
||||
if item(ui, "slideshowTemplateDelete", "Delete", true) {
|
||||
set_pending(&ctx, Some(Pending::Delete(tpl.id.clone())));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Actual native Titles-section coverage plus SDK-only enable/content/editor leaf coverage.
|
||||
//! SDK leaves intentionally exclude the native colour picker and sliders: this is not shipped
|
||||
//! Settings mixed traversal, desktop playback, or preview/render acceptance.
|
||||
//! The whole Titles section plus the enable/content/editor leaves on their own.
|
||||
//! Every control is a framework control, so keyboard traversal is one focus chain; this is not
|
||||
//! desktop playback or preview/render acceptance.
|
||||
use super::*;
|
||||
use crate::headless::HeadlessView;
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Rect};
|
||||
@@ -225,13 +225,10 @@ impl Fixture {
|
||||
self.frame(vec![Event::PointerGone]);
|
||||
for _ in 0..64 {
|
||||
let hit = self.hits.iter().find(|(name, _)| name == id).unwrap().1;
|
||||
let native_focus = self.ctx.memory(|m| m.focused()).and_then(|id| self.ctx.read_response(id));
|
||||
// The whole section is framework controls now (the colour wells and sliders too), so
|
||||
// both presentations walk one focus chain.
|
||||
let sdk_focus = craft::ui::runtime::focus::focused_rec(&self.ctx);
|
||||
let reached = match self.presentation {
|
||||
Presentation::NativeSections => native_focus.is_some_and(|r| r.rect == self.rect(id)),
|
||||
Presentation::SdkWorkflow => sdk_focus.is_some_and(|r| r.stop.id == hit.id),
|
||||
};
|
||||
if reached {
|
||||
if sdk_focus.is_some_and(|r| r.stop.id == hit.id) {
|
||||
return;
|
||||
}
|
||||
self.key(Key::Tab);
|
||||
|
||||
@@ -15,7 +15,6 @@ use serde_json::{Value, json};
|
||||
use crate::LightcraftApp;
|
||||
use crate::panels::settings::{check, choices, heading, hint, row};
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets::register;
|
||||
|
||||
/// Where the preview's choice lives (egui memory): `None` = the photo's slide.
|
||||
fn preview_key() -> egui::Id {
|
||||
@@ -54,6 +53,7 @@ fn slider(
|
||||
app: &mut LightcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
id: &str,
|
||||
label: &str,
|
||||
t: Title,
|
||||
key: &str,
|
||||
value: f64,
|
||||
@@ -61,27 +61,27 @@ fn slider(
|
||||
k: f64,
|
||||
suffix: &str,
|
||||
) {
|
||||
let mut v = value * k;
|
||||
let r = ui.add(egui::Slider::new(&mut v, (range.start() * k)..=(range.end() * k)).suffix(suffix).max_decimals(1));
|
||||
register(ui, format!("slider:{id}"), r.rect);
|
||||
let p = json!({ t.id(): { key: v / k } });
|
||||
if r.changed() {
|
||||
if let Ok(next) = app.session.slide_titles.merged(&p) {
|
||||
app.session.slide_titles = next;
|
||||
use super::controls::{self, Shape, Step};
|
||||
let shape = Shape { label, lo: range.start() * k, hi: range.end() * k, unit: suffix.trim(), step: 0.1, log: false };
|
||||
for step in controls::slider(ui, controls::owner(id), id, &shape, value * k) {
|
||||
match step {
|
||||
Step::Preview(v) => {
|
||||
if let Ok(next) = app.session.slide_titles.merged(&json!({ t.id(): { key: v / k } })) {
|
||||
app.session.slide_titles = next;
|
||||
}
|
||||
set_preview_shows(ui.ctx(), Some(t));
|
||||
}
|
||||
Step::Save(v) => {
|
||||
let _ = app.run("slideshow.titles", json!({ t.id(): { key: v / k } }));
|
||||
}
|
||||
}
|
||||
set_preview_shows(ui.ctx(), Some(t));
|
||||
}
|
||||
if r.drag_stopped() || (r.changed() && !r.dragged()) {
|
||||
let _ = app.run("slideshow.titles", p);
|
||||
}
|
||||
}
|
||||
|
||||
/// A colour button (`button:{id}`) for `key` of screen `t`.
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, t: Title, key: &str, value: [u8; 3]) {
|
||||
let mut c = value;
|
||||
let r = egui::color_picker::color_edit_button_srgb(ui, &mut c);
|
||||
register(ui, format!("button:{id}"), r.rect);
|
||||
if r.changed() {
|
||||
/// A colour well (`button:{id}`) for `key` of screen `t`.
|
||||
fn colour(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, label: &str, t: Title, key: &str, value: [u8; 3]) {
|
||||
use super::controls;
|
||||
if let Some(c) = controls::colour(ui, controls::owner(id), id, label, value) {
|
||||
set(app, ui.ctx(), t, key, json!(c));
|
||||
}
|
||||
}
|
||||
@@ -179,19 +179,19 @@ fn screen(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, title: Title,
|
||||
if !screen_enable(app, ui, title, s, name, label) {
|
||||
return;
|
||||
}
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, &format!("{name}Color"), title, "color", s.color));
|
||||
row(ui, t, "Colour", |ui| colour(app, ui, &format!("{name}Color"), "Colour", title, "color", s.color));
|
||||
screen_content(app, ui, t, title, s, name, content_id);
|
||||
if s.content == TitleContent::None {
|
||||
return;
|
||||
}
|
||||
row(ui, t, "Scale", |ui| slider(app, ui, &format!("{name}Scale"), title, "scale", s.scale, SIZE_MIN..=PLATE_SIZE_MAX, 100.0, " %"));
|
||||
row(ui, t, "Scale", |ui| slider(app, ui, &format!("{name}Scale"), "Scale", title, "scale", s.scale, SIZE_MIN..=PLATE_SIZE_MAX, 100.0, "%"));
|
||||
ui.horizontal(|ui| {
|
||||
let mut over = s.override_color;
|
||||
if check(ui, &format!("settings.{name}Override"), &mut over, "Override colour") && title_input(ui) {
|
||||
set(app, ui.ctx(), title, "overrideColor", json!(over));
|
||||
}
|
||||
if over {
|
||||
colour(app, ui, &format!("{name}TextColor"), title, "textColor", s.text_color);
|
||||
colour(app, ui, &format!("{name}TextColor"), "Text colour", title, "textColor", s.text_color);
|
||||
}
|
||||
});
|
||||
let mut own = s.duration.is_some();
|
||||
@@ -200,7 +200,7 @@ fn screen(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, title: Title,
|
||||
set(app, ui.ctx(), title, "duration", d);
|
||||
}
|
||||
if let Some(d) = s.duration {
|
||||
row(ui, t, "Duration", |ui| slider(app, ui, &format!("{name}Duration"), title, "duration", d, SLIDE_MIN..=SLIDE_MAX, 1.0, " s"));
|
||||
row(ui, t, "Duration", |ui| slider(app, ui, &format!("{name}Duration"), "Duration", title, "duration", d, SLIDE_MIN..=SLIDE_MAX, 1.0, "s"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::display::duration_slider;
|
||||
use super::widgets::{check, choices, heading, hint, row};
|
||||
use super::{LightcraftApp, Tokens, Value, json, register};
|
||||
use super::{LightcraftApp, Tokens, Value, json};
|
||||
|
||||
/// The Slideshow tab: the slide preview, then the settings, in one column the width of the page
|
||||
/// (the page scrolls; a column beside the preview would be wider than the window). Without
|
||||
@@ -75,10 +75,10 @@ fn playback_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
}
|
||||
hint(ui, t, crate::i18n::tr("A manual slideshow shows each slide until → or ← changes it. Exports still use the slide duration."));
|
||||
row(ui, t, crate::i18n::tr("Slide duration"), |ui| {
|
||||
duration_slider(app, ui, "slideshowSlide", "slideDuration", s.slide_duration, SLIDE_MIN..=SLIDE_MAX)
|
||||
duration_slider(app, ui, "slideshowSlide", "Slide duration", "slideDuration", s.slide_duration, SLIDE_MIN..=SLIDE_MAX)
|
||||
});
|
||||
row(ui, t, crate::i18n::tr("Fade duration"), |ui| {
|
||||
duration_slider(app, ui, "slideshowFade", "fadeDuration", s.fade_duration, 0.0..=FADE_MAX.min(s.slide_duration))
|
||||
duration_slider(app, ui, "slideshowFade", "Fade duration", "fadeDuration", s.fade_duration, 0.0..=FADE_MAX.min(s.slide_duration))
|
||||
});
|
||||
hint(ui, t, crate::i18n::tr("A slide stays up for its duration, its fade in included. A fade of 0 cuts."));
|
||||
row(ui, t, crate::i18n::tr("Fade"), |ui| {
|
||||
@@ -106,13 +106,10 @@ fn playback_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
let _ = app.run("slideshow.playback", json!({"fadeColor": c}));
|
||||
}
|
||||
if f == Fade::Color
|
||||
&& let Some(mut c) = s.fade_color
|
||||
&& let Some(c) = s.fade_color
|
||||
&& let Some(c) = super::controls::colour(ui, super::controls::owner("slideshowFadeColor"), "slideshowFadeColor", "Fade colour", c)
|
||||
{
|
||||
let r = egui::color_picker::color_edit_button_srgb(ui, &mut c);
|
||||
register(ui, "button:slideshowFadeColor", r.rect);
|
||||
if r.changed() {
|
||||
let _ = app.run("slideshow.playback", json!({"fadeColor": c}));
|
||||
}
|
||||
let _ = app.run("slideshow.playback", json!({"fadeColor": c}));
|
||||
}
|
||||
});
|
||||
let mut v = s.random_order;
|
||||
|
||||
@@ -175,11 +175,10 @@ impl Fixture {
|
||||
fn tab_to(&mut self, id: &str) {
|
||||
self.frame(vec![Event::PointerGone]);
|
||||
for _ in 0..32 {
|
||||
let rect = self.rect(id);
|
||||
let native_focus = self.ctx.memory(|m| m.focused()).and_then(|id| self.ctx.read_response(id));
|
||||
// Every control of the page is a framework stop now, so one focus owner answers for both runs.
|
||||
let sdk_focus = craft::ui::runtime::focus::focused_rec(&self.ctx);
|
||||
let hit = self.hits.iter().find(|(name, _)| name == id).unwrap().1;
|
||||
if (self.native && native_focus.is_some_and(|r| r.rect == rect)) || (!self.native && sdk_focus.is_some_and(|r| r.stop.id == hit.id)) {
|
||||
if sdk_focus.is_some_and(|r| r.stop.id == hit.id) {
|
||||
return;
|
||||
}
|
||||
self.key(Key::Tab);
|
||||
@@ -383,12 +382,23 @@ fn slideshow_background_pointer_release_outside_cancels_without_changing_prefere
|
||||
f.click(BACKGROUND);
|
||||
f.select(Some(f.ids[1]));
|
||||
let before = f.state();
|
||||
let journal = f.app.session.journal.len();
|
||||
let unrelated = f.layout_without_background();
|
||||
let at = f.rect(id).center();
|
||||
f.frame(vec![Event::PointerMoved(at)]);
|
||||
f.pointer(at, true);
|
||||
f.pointer(egui::pos2(990.0, 790.0), false);
|
||||
f.frame(vec![]);
|
||||
assert_eq!(f.state(), before);
|
||||
if id == BACKGROUND {
|
||||
// The framework checkbox carries a sweep: a press that is dragged off it has set the value
|
||||
// the sweep brings (here off), once, and releasing elsewhere adds nothing to that.
|
||||
assert!(f.app.session.slide_layout.background_image.is_none());
|
||||
f.assert_command(journal, json!({"backgroundImage": null}));
|
||||
assert_eq!(f.document(), before["document"]);
|
||||
assert_eq!(f.layout_without_background(), unrelated);
|
||||
} else {
|
||||
assert_eq!(f.state(), before);
|
||||
}
|
||||
f.idle_is_inert();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,12 +275,8 @@ pub fn settings_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
.unwrap_or_default();
|
||||
heading(ui, t, "Your own model (optional)");
|
||||
let installing = downloads.iter().any(|d| d["id"] == "local-install" && d["state"].as_str() == Some("installing"));
|
||||
let r = crate::button::Button::new("Install from file…")
|
||||
.enabled(runtime && app.services.pick_denoise_model.is_some())
|
||||
.busy(installing)
|
||||
.widget("denoise:installFile")
|
||||
.show(ui);
|
||||
if r.clicked()
|
||||
let can_install = runtime && app.services.pick_denoise_model.is_some();
|
||||
if install_button(ui, can_install, installing)
|
||||
&& let Some(path) = app.services.pick_denoise_model.as_mut().and_then(|f| f().into_iter().next())
|
||||
{
|
||||
match app.session.execute("denoise.models.inspect", &json!({"path": path})) {
|
||||
@@ -524,6 +520,47 @@ fn device_line(d: &Value, run_on: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// A model row's button: a framework button that keeps its activation through the tooltip chain.
|
||||
struct ModelButton {
|
||||
response: egui::Response,
|
||||
activated: bool,
|
||||
}
|
||||
|
||||
impl ModelButton {
|
||||
fn clicked(&self) -> bool {
|
||||
self.activated
|
||||
}
|
||||
|
||||
fn on_hover_text(mut self, text: impl Into<egui::WidgetText>) -> Self {
|
||||
self.response = self.response.on_hover_text(text);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A button of a model row (`widget` names it for the control channel), never acting while the framework only measures.
|
||||
fn model_button(ui: &mut egui::Ui, widget: &str, label: &str) -> ModelButton {
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Props as _, Show as _};
|
||||
let real = !ui.is_sizing_pass() && !craft::ui::runtime::measure::active(ui.ctx());
|
||||
let shown = Button::new(tr(label).to_owned()).id_salt(("denoise-model", widget)).show(ui);
|
||||
if real {
|
||||
crate::widgets::register_response(widget.to_owned(), shown.response.rect, &shown.response);
|
||||
}
|
||||
ModelButton { activated: real && ui.is_enabled() && shown.clicked(), response: shown.response }
|
||||
}
|
||||
|
||||
/// Install from file… (`denoise:installFile`): busy while an installation runs, disabled without a model chooser.
|
||||
fn install_button(ui: &mut egui::Ui, enabled: bool, installing: bool) -> bool {
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::{Props as _, Show as _};
|
||||
let real = !ui.is_sizing_pass() && !craft::ui::runtime::measure::active(ui.ctx());
|
||||
let shown = Button::new(tr("Install from file…").to_owned()).id_salt("denoise:installFile").enabled(enabled).loading(installing).show(ui);
|
||||
if real {
|
||||
crate::widgets::register_response("denoise:installFile", shown.response.rect, &shown.response);
|
||||
}
|
||||
real && enabled && ui.is_enabled() && shown.clicked()
|
||||
}
|
||||
|
||||
fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value, dl: Option<&Value>, can_run: bool) {
|
||||
let id = m["id"].as_str().unwrap_or("").to_string();
|
||||
let (installed, selected) = (m["installed"].as_bool() == Some(true), m["selected"].as_bool() == Some(true));
|
||||
@@ -587,22 +624,19 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if installed {
|
||||
let r = ui.button(tr("Remove"));
|
||||
register(ui, format!("denoise:remove:{id}"), r.rect);
|
||||
let r = model_button(ui, &format!("denoise:remove:{id}"), "Remove");
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.models.remove", json!({"id": id}));
|
||||
app.caches.denoise.epoch += 1;
|
||||
}
|
||||
if selected {
|
||||
let r = ui.button(tr("Stop using"));
|
||||
register(ui, format!("denoise:off:{id}"), r.rect);
|
||||
let r = model_button(ui, &format!("denoise:off:{id}"), "Stop using");
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.models.select", json!({"id": null}));
|
||||
app.caches.denoise.epoch += 1;
|
||||
}
|
||||
} else {
|
||||
let r = ui.button(tr("Use"));
|
||||
register(ui, format!("denoise:use:{id}"), r.rect);
|
||||
let r = model_button(ui, &format!("denoise:use:{id}"), "Use");
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.models.select", json!({"id": id}));
|
||||
app.caches.denoise.epoch += 1;
|
||||
@@ -611,8 +645,7 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
|
||||
} else {
|
||||
match dl_state {
|
||||
Some("running") => {
|
||||
let r = ui.button(tr("Cancel"));
|
||||
register(ui, format!("denoise:cancelDownload:{id}"), r.rect);
|
||||
let r = model_button(ui, &format!("denoise:cancelDownload:{id}"), "Cancel");
|
||||
if r.clicked() {
|
||||
let _ = app.run("denoise.models.downloadCancel", json!({"id": id}));
|
||||
app.caches.denoise.dl_watch.retain(|w| w != &id);
|
||||
@@ -622,10 +655,8 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
|
||||
Some("done" | "installing") => {}
|
||||
_ => {
|
||||
if let Some(url) = m["source"].as_str() {
|
||||
let r = ui
|
||||
.button(tr("Open page"))
|
||||
let r = model_button(ui, &format!("denoise:get:{id}"), "Open page")
|
||||
.on_hover_text(tr("Opens the model's own page in your browser, to read about it or get the file yourself."));
|
||||
register(ui, format!("denoise:get:{id}"), r.rect);
|
||||
if r.clicked() {
|
||||
open_page(app, url);
|
||||
}
|
||||
@@ -637,8 +668,7 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
|
||||
mb(m["sizeBytes"].as_u64()),
|
||||
host = host
|
||||
);
|
||||
let r = ui.button(tr(label)).on_hover_text(tip);
|
||||
register(ui, format!("denoise:download:{id}"), r.rect);
|
||||
let r = model_button(ui, &format!("denoise:download:{id}"), label).on_hover_text(tip);
|
||||
if r.clicked() {
|
||||
open_download_dialog(app, m);
|
||||
}
|
||||
|
||||
@@ -527,22 +527,12 @@ fn denoise_native_settings_natural_keyboard_acquires_intended_fifty_gb_row_and_c
|
||||
assert_eq!(r.settings()["cacheGb"], 20);
|
||||
assert_eq!(r.docs(), docs);
|
||||
assert_eq!(r.owned.cache(), cache);
|
||||
// Native ComboBox ArrowDown acquires first row5, not a selected20GB lead.
|
||||
// Walk the actual native rows5 ->10 ->20 ->50 before pressing Enter.
|
||||
for intended in ["5 GB", "10 GB", "20 GB", "50 GB"] {
|
||||
r.key(Key::ArrowDown, false);
|
||||
let focused = r.ctx.memory(|m| m.focused()).expect("natural native row focus");
|
||||
let response = r.ctx.read_response(focused).expect("real native row response");
|
||||
assert!(response.enabled() && response.sense.senses_click());
|
||||
assert!(
|
||||
r.nodes.iter().any(|node| node.name.as_deref() == Some(intended)
|
||||
&& node.rect.is_some_and(|rect| rect == response.rect || rect == response.interact_rect)),
|
||||
"natural focus must acquire intended native row {intended}"
|
||||
);
|
||||
assert_eq!(r.settings()["cacheGb"], 20, "native row traversal only focuses, never commits");
|
||||
assert_eq!(r.docs(), docs);
|
||||
assert_eq!(r.owned.cache(), cache);
|
||||
}
|
||||
// The framework list opens on the current 20 GB row: one ArrowDown reaches 50 GB, and only
|
||||
// Enter commits it.
|
||||
r.key(Key::ArrowDown, false);
|
||||
assert_eq!(r.settings()["cacheGb"], 20, "row traversal only highlights, never commits");
|
||||
assert_eq!(r.docs(), docs);
|
||||
assert_eq!(r.owned.cache(), cache);
|
||||
r.key(Key::Enter, false);
|
||||
assert_eq!(r.settings()["cacheGb"], 50);
|
||||
r.tab_to(CLEAR, false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Native/candidate characterization of Settings Tab ownership boundaries.
|
||||
//! Characterization of Settings Tab ownership boundaries (every Settings control is a framework control).
|
||||
use crate::headless::Headless;
|
||||
use crate::state::Dialog;
|
||||
use crate::{LightcraftApp, Services};
|
||||
@@ -44,25 +44,27 @@ fn raw_tab(shift: bool, pressed: bool) -> egui::Event {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_raw_batch_of_tab_presses_and_releases_matches_the_native_last_direction() {
|
||||
fn a_raw_batch_of_tab_presses_and_releases_moves_once_per_press_in_its_own_direction() {
|
||||
let mut h = demo();
|
||||
ask(&mut h, "ui.clickWidget", json!({"id":"field:settings.copyright"}));
|
||||
assert_eq!(focused(&h).as_deref(), Some("field:settings.copyright"));
|
||||
// The framework moves the focus once for each Tab press of a batch: two forward presses walk two stops.
|
||||
h.events.extend([raw_tab(false, true), raw_tab(false, false), raw_tab(false, true), raw_tab(false, false)]);
|
||||
h.step();
|
||||
steps(&mut h);
|
||||
eprintln!("SETTINGS_RAW_TWO_FORWARD={:?}", focused(&h));
|
||||
assert_eq!(focused(&h).as_deref(), Some("field:settings.creator"));
|
||||
assert_eq!(focused(&h).as_deref(), Some("check:settings.autoWriteXmp"));
|
||||
// A forward press then a reverse one walks a stop on and back to where it was.
|
||||
h.events.extend([raw_tab(false, true), raw_tab(false, false), raw_tab(true, true), raw_tab(true, false)]);
|
||||
h.step();
|
||||
steps(&mut h);
|
||||
eprintln!("SETTINGS_RAW_FORWARD_THEN_REVERSE={:?}", focused(&h));
|
||||
assert_eq!(focused(&h).as_deref(), Some("field:settings.copyright"));
|
||||
assert_eq!(focused(&h).as_deref(), Some("check:settings.autoWriteXmp"));
|
||||
// A release by itself is not a focus movement.
|
||||
h.events.push(raw_tab(false, false));
|
||||
h.step();
|
||||
steps(&mut h);
|
||||
assert_eq!(focused(&h).as_deref(), Some("field:settings.copyright"));
|
||||
assert_eq!(focused(&h).as_deref(), Some("check:settings.autoWriteXmp"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -82,17 +84,23 @@ fn modified_tab_leaves_a_real_text_draft_with_its_owner() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_open_native_preset_combo_keeps_tab_and_escape_out_of_the_settings_page() {
|
||||
fn an_open_preset_combo_closes_on_tab_and_escape_stays_out_of_the_settings_page() {
|
||||
let mut h = demo();
|
||||
let before = h.app.session.import_defaults.clone();
|
||||
ask(&mut h, "ui.clickWidget", json!({"id":"combo:settingsRawPreset"}));
|
||||
assert!(popup_open(&h));
|
||||
// The framework list closes when Tab leaves it, choosing nothing, and the focus moves on.
|
||||
ask(&mut h, "ui.key", json!({"key":"Tab"}));
|
||||
eprintln!("SETTINGS_COMBO_TAB_FOCUS={:?} popup={}", focused(&h), popup_open(&h));
|
||||
assert!(popup_open(&h));
|
||||
assert!(!popup_open(&h));
|
||||
assert_eq!(h.app.session.import_defaults, before);
|
||||
assert_eq!(h.app.ui.dialog, Some(Dialog::Settings { tab: "import".into() }));
|
||||
// Escape closes an open list and does not reach the page: Settings stays.
|
||||
ask(&mut h, "ui.clickWidget", json!({"id":"combo:settingsRawPreset"}));
|
||||
assert!(popup_open(&h));
|
||||
ask(&mut h, "ui.key", json!({"key":"Escape"}));
|
||||
assert!(!popup_open(&h));
|
||||
assert_eq!(h.app.session.import_defaults, before);
|
||||
assert_eq!(h.app.ui.dialog, Some(Dialog::Settings { tab: "import".into() }));
|
||||
}
|
||||
|
||||
@@ -179,8 +187,9 @@ fn coalesced_tab_then_enter_activates_the_new_real_sidecar_choice() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coalesced_tab_then_text_preserves_native_departing_field_order() {
|
||||
fn coalesced_tab_then_text_goes_to_the_field_the_tab_moved_to() {
|
||||
let mut h = demo();
|
||||
let copyright = h.app.session.import_defaults.copyright.clone();
|
||||
ask(&mut h, "ui.clickWidget", json!({"id":"field:settings.copyright"}));
|
||||
h.events.extend([raw_tab(false, true), raw_tab(false, false), egui::Event::Text("Coalesced Creator Draft".into())]);
|
||||
h.step();
|
||||
@@ -193,10 +202,10 @@ fn coalesced_tab_then_text_preserves_native_departing_field_order() {
|
||||
);
|
||||
assert_eq!(focused(&h).as_deref(), Some("field:settings.creator"));
|
||||
ask(&mut h, "ui.key", json!({"key":"Enter"}));
|
||||
// Native TextEdit handles this pass's text on the departing field before Away commits.
|
||||
// Focus has moved to Creator, but the text must not be silently rerouted there.
|
||||
assert_eq!(h.app.session.import_defaults.creator, "");
|
||||
assert_eq!(h.app.session.import_defaults.copyright, "Coalesced Creator Draft");
|
||||
// The framework moves the focus first, so the text that arrived with the Tab belongs to the
|
||||
// field that has the keyboard now, Creator; Copyright is left as it was.
|
||||
assert_eq!(h.app.session.import_defaults.creator, "Coalesced Creator Draft");
|
||||
assert_eq!(h.app.session.import_defaults.copyright, copyright);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user