* claim: #8876 * claim: #8876 * Theme options: persist per-theme values and expose preferences contracts * Restore selected theme mode after stopping a followed theme * claim: #8876 * Preferences: render theme options and apply readable panel opacity * Use floating-point scale expectation in theme preferences scenario * Keep panel opacity colour construction inside theme tokens * Complete theme options translations in Arabic Hebrew and Vietnamese * Let standalone theme sliders fill their option cells
This commit is contained in:
@@ -70,6 +70,7 @@ pub mod sketch_constraints;
|
||||
pub mod sketch_create;
|
||||
pub mod sketch_equation;
|
||||
pub mod surface_analysis;
|
||||
pub mod ui_prefs;
|
||||
pub mod view_navigation;
|
||||
|
||||
pub use check::{Contract, Issue, ParamCheck, TypedContract, input_schema_for, issues, output_schema_for, run_checked, run_checked_as};
|
||||
|
||||
@@ -378,6 +378,93 @@ fn a_level_is_read_back_from_its_name() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ui_prefs_theme_options_input_schema_covers_updates_and_resets() {
|
||||
use super::ui_prefs::PrefsParams;
|
||||
let schema = input_schema_for::<PrefsParams>();
|
||||
let schema = schema.as_value();
|
||||
assert!(schema["properties"]["theme_options"].is_object());
|
||||
for value in [
|
||||
json!({}),
|
||||
json!({"theme_options":{}}),
|
||||
json!({"theme_options":{"a":{}}}),
|
||||
json!({"theme_options":{"a":{"enabled":true,"amount":3.5,"style":"cool","reset":null}},"theme":"a"}),
|
||||
] {
|
||||
assert!(serde_json::from_value::<PrefsParams>(value.clone()).is_ok(), "{value}");
|
||||
assert!(conforms(schema, schema, &value), "{value}");
|
||||
}
|
||||
for value in [
|
||||
json!({"theme_options":null}),
|
||||
json!({"theme_options":[]}),
|
||||
json!({"theme_options":{"a":true}}),
|
||||
json!({"theme_options":{"a":{"enabled":{}}}}),
|
||||
json!({"theme_options":{"a":{"amount":[]}}}),
|
||||
] {
|
||||
assert!(serde_json::from_value::<PrefsParams>(value.clone()).is_err(), "{value}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ui_prefs_theme_options_output_schema_matches_serialized_reply() {
|
||||
use super::ui_prefs::*;
|
||||
let options = ThemeOptionsReply {
|
||||
theme_option_defs: vec![
|
||||
ThemeOptionDef {
|
||||
id: "enabled".into(),
|
||||
kind: ThemeOptionKind::Bool { default: false },
|
||||
label: "Enabled".into(),
|
||||
help: String::new(),
|
||||
parent: None,
|
||||
advanced: false,
|
||||
section: None,
|
||||
standard: false,
|
||||
available: true,
|
||||
reason: None,
|
||||
},
|
||||
ThemeOptionDef {
|
||||
id: "blur".into(),
|
||||
kind: ThemeOptionKind::Range { default: 0.0, min: 0.0, max: 100.0, step: 1.0, unit: Some("px".into()) },
|
||||
label: "blur".into(),
|
||||
help: String::new(),
|
||||
parent: None,
|
||||
advanced: false,
|
||||
section: None,
|
||||
standard: true,
|
||||
available: false,
|
||||
reason: Some("not implemented".into()),
|
||||
},
|
||||
ThemeOptionDef {
|
||||
id: "style".into(),
|
||||
kind: ThemeOptionKind::Choice { default: "warm".into(), values: vec![ThemeChoice { id: "warm".into(), label: "Warm".into() }] },
|
||||
label: "Style".into(),
|
||||
help: String::new(),
|
||||
parent: Some("enabled".into()),
|
||||
advanced: true,
|
||||
section: Some("Details".into()),
|
||||
standard: false,
|
||||
available: true,
|
||||
reason: None,
|
||||
},
|
||||
],
|
||||
theme_option_values: [
|
||||
("enabled".into(), ThemeOptionValue::Bool(true)),
|
||||
("blur".into(), ThemeOptionValue::Num(0.0)),
|
||||
("style".into(), ThemeOptionValue::Choice("warm".into())),
|
||||
]
|
||||
.into(),
|
||||
theme_option_notices: vec![ThemeOptionNotice { id: "removed".into(), kind: ThemeOptionNoticeKind::UnknownOption }],
|
||||
};
|
||||
let reply = PrefsReply { options, settings: [("theme".into(), json!("a")), ("theme_options".into(), json!({"a":{"enabled":true}}))].into() };
|
||||
let value = serde_json::to_value(&reply).unwrap();
|
||||
let schema = output_schema_for::<PrefsReply>();
|
||||
let schema = schema.as_value();
|
||||
for field in ["theme_option_defs", "theme_option_values", "theme_option_notices"] {
|
||||
assert!(schema["properties"][field].is_object(), "{schema}");
|
||||
}
|
||||
assert!(conforms(schema, schema, &value), "{schema}\n{value}");
|
||||
assert_eq!(serde_json::to_value(serde_json::from_value::<PrefsReply>(value.clone()).unwrap()).unwrap(), value);
|
||||
}
|
||||
|
||||
/// Whether `v` conforms to `node` of the schema `root`, for the keywords these schemas use
|
||||
/// apart from `pattern`: `type`, `properties`, `required`, `additionalProperties: false`,
|
||||
/// `items`, `minItems`, `maxItems`, `uniqueItems`, `enum`, `minLength`, `maxLength`, `minimum`,
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
//! Theme-option contracts for the UI-owned `ui.prefs` control method.
|
||||
//! Other preferences remain owned and validated by the UI preference table.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum ThemeOptionValue {
|
||||
Bool(bool),
|
||||
Choice(String),
|
||||
Num(f32),
|
||||
}
|
||||
|
||||
/// Null resets one option; an empty inner map resets that theme.
|
||||
pub type ThemeOptionsUpdate = BTreeMap<String, BTreeMap<String, Option<ThemeOptionValue>>>;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct PrefsParams {
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub theme_options: ThemeOptionsUpdate,
|
||||
#[serde(flatten)]
|
||||
pub settings: BTreeMap<String, Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct ThemeChoice {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
#[serde(tag = "type", rename_all = "lowercase")]
|
||||
pub enum ThemeOptionKind {
|
||||
Bool { default: bool },
|
||||
Choice { default: String, values: Vec<ThemeChoice> },
|
||||
Range { default: f32, min: f32, max: f32, step: f32, unit: Option<String> },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct ThemeOptionDef {
|
||||
pub id: String,
|
||||
#[serde(flatten)]
|
||||
pub kind: ThemeOptionKind,
|
||||
pub label: String,
|
||||
pub help: String,
|
||||
pub parent: Option<String>,
|
||||
pub advanced: bool,
|
||||
pub section: Option<String>,
|
||||
pub standard: bool,
|
||||
pub available: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ThemeOptionNoticeKind {
|
||||
UnknownOption,
|
||||
WrongType,
|
||||
UnknownChoice,
|
||||
NonFinite,
|
||||
OutOfRange,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct ThemeOptionNotice {
|
||||
pub id: String,
|
||||
pub kind: ThemeOptionNoticeKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct ThemeOptionsReply {
|
||||
pub theme_option_defs: Vec<ThemeOptionDef>,
|
||||
pub theme_option_values: BTreeMap<String, ThemeOptionValue>,
|
||||
pub theme_option_notices: Vec<ThemeOptionNotice>,
|
||||
}
|
||||
|
||||
/// Complete control reply: other preferences and dialog state share the outer object.
|
||||
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct PrefsReply {
|
||||
#[serde(flatten)]
|
||||
pub options: ThemeOptionsReply,
|
||||
#[serde(flatten)]
|
||||
pub settings: BTreeMap<String, Value>,
|
||||
}
|
||||
Reference in New Issue
Block a user