DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #144: Character Style Options dialog; style.character.edit renames everywhere, validates Based On, null unsets; New Character Style opens the dialog
aionggf4f0896f85a4
diff --cc crates/ui-egui/src/dialogs.rsindex 5e66181af,98e642b53..756662eff--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@@ -1744,14 -1763,30 +1793,30 @@@ fn regex_ok(p: &str) -> Result<(), ()>fn paragraph_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {let name = d.s("name");+ let new = d.b("new");- let Some(st) = app.session.active() else { return };- let style = match st.doc.styles.para(&name) {+ let Some(doc) = app.session.active().map(|s| s.doc.clone()) else { return };- let Some(style) = doc.styles.para(&name).cloned() else {- ui.label(format!("No style named {name}"));- return;++ let style = match doc.styles.para(&name) {+ _ if new => designcraft_doc::ParagraphStyle {+ name: String::new(),+ based_on: None,+ next_style: None,+ para: Default::default(),+ chars: Default::default(),+ shortcut: String::new(),+ },+ Some(s) => s.clone(),+ None => {+ ui.label(format!("No style named {name}"));+ return;+ }};- let names: Vec<String> = doc.styles.paragraph.iter().map(|p| p.name.clone()).filter(|n| *n != name).collect();- let (pp, cp) = doc.styles.resolve_para_style(&name);+ if new && !d.fields.contains_key("rename") {- d.fields.insert("rename".into(), json!(next_style_name(&st.doc.styles, true)));++ d.fields.insert("rename".into(), json!(next_style_name(&doc.styles, true)));+ }- let names: Vec<String> = st.doc.styles.paragraph.iter().map(|p| p.name.clone()).filter(|n| new || *n != name).collect();++ let names: Vec<String> = doc.styles.paragraph.iter().map(|p| p.name.clone()).filter(|n| new || *n != name).collect();+ // A new style shows what it would inherit from its Based On.- let (pp, cp) = st.doc.styles.resolve_para_style(if new { d.fields.get("basedOn").and_then(Value::as_str).unwrap_or("") } else { &name });- let units = st.doc.settings.horizontal_units;++ let (pp, cp) = doc.styles.resolve_para_style(if new { d.fields.get("basedOn").and_then(Value::as_str).unwrap_or("") } else { &name });+ let units = doc.settings.horizontal_units;let pv = serde_json::to_value(&pp).unwrap_or_default();let cv = serde_json::to_value(&cp).unwrap_or_default();let cur = |d: &Dialog, k: &str, base: &Value| d.fields.get(k).cloned().unwrap_or_else(|| base.clone());@@@ -2133,22 -2129,7 +2159,7 @@@ui.end_row();});}- "color" => {- let cur_fill = cur(d, "c.fill", &cv["fill"]).as_str().unwrap_or("").to_string();- let swatches: Vec<String> = doc.swatches.iter().map(|s| s.name.clone()).collect();- egui::ScrollArea::vertical().max_height(260.0).show(ui, |ui| {- for sw in swatches {- let (c, g) = crate::widgets::swatch_colors(&doc, &sw, 1.0);- ui.horizontal(|ui| {- let (r, _) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::hover());- crate::widgets::paint_chip(ui.painter(), r, c, g);- if ui.selectable_label(sw == cur_fill, &sw).clicked() {- d.fields.insert("c.fill".into(), json!(sw));- }- });- }- });- }- "color" => character_color(&app.ui.language, ui, d, &CharFields { base: &cv, sparse: false }, &st.doc),++ "color" => character_color(&app.ui.language, ui, d, &CharFields { base: &cv, sparse: false }, &doc),_ => {egui::Grid::new("psg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Style Name:"));@@@ -2197,6 -2178,482 +2208,483 @@@});}+ /// The section list on the left of the style options dialogs.+ fn section_list(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, sections: &[(&str, &str)]) {+ ui.vertical(|ui| {+ ui.set_width(170.0);+ for (id, label) in sections {+ if ui.selectable_label(d.s("section") == *id, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).clicked() {+ d.fields.insert("section".into(), json!(id));+ }+ }+ });+ }++ /// "Paragraph Style n" / "Character Style n": the first name no style has.+ fn next_style_name(styles: &designcraft_doc::Styles, para: bool) -> String {+ let (base, count) = if para { ("Paragraph Style", styles.paragraph.len()) } else { ("Character Style", styles.character.len()) };+ let taken = |n: &str| if para { styles.para(n).is_some() } else { styles.char_style(n).is_some() };+ // Among count + 1 numbers at least one is free.+ (1..=count + 1).map(|i| format!("{base} {i}")).find(|n| !taken(n)).unwrap_or_else(|| format!("{base} {}", count + 1))+ }++ /// Paragraph or Character Style Options for an existing style (a double-click on it in the styles+ /// panel, or Edit in its menu). [None] and [No Paragraph Style] have no options.+ pub fn open_style_options(app: &mut DesignApp, para: bool, name: &str) {+ if name == if para { designcraft_doc::NO_PARA_STYLE } else { designcraft_doc::NO_CHAR_STYLE } {+ return;+ }+ let id = if para { "paragraphStyleOptions" } else { "characterStyleOptions" };+ app.ui.dialog = Some(Dialog::new(id, json!({"name": name})));+ }++ /// New Paragraph Style… / New Character Style…: the style options for a style made on OK, named+ /// with the next free "Paragraph Style n" / "Character Style n".+ pub fn open_new_style(app: &mut DesignApp, para: bool) {+ let Some(st) = app.session.active() else { return };+ let name = next_style_name(&st.doc.styles, para);+ let id = if para { "paragraphStyleOptions" } else { "characterStyleOptions" };+ app.ui.dialog = Some(Dialog::new(id, json!({"new": true, "rename": name})));+ }++ /// Character Style Options: General, then the character sections it shares with Paragraph Style+ /// Options. A character style sets only some attributes: the fields show those it and its Based+ /// On set and leave the rest blank. Edits are `c.<attr>` fields (`null` = no longer set), applied+ /// on OK; `new` makes the style instead of editing `name`.+ fn character_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {+ let name = d.s("name");+ let new = d.b("new");+ let Some(doc) = app.session.active().map(|st| st.doc.clone()) else { return };+ let styles = &doc.styles;+ let style = match styles.char_style(&name) {+ _ if new => designcraft_doc::CharacterStyle { name: String::new(), based_on: None, chars: Default::default(), shortcut: String::new() },+ Some(s) if name != designcraft_doc::NO_CHAR_STYLE => s.clone(),+ _ => {+ crate::rtl::label(ui, format!("No style named {name}"));+ return;+ }+ };+ if !d.fields.contains_key("rename") {+ d.fields.insert("rename".into(), json!(if new { next_style_name(styles, false) } else { name.clone() }));+ }+ let based = d+ .fields+ .get("basedOn")+ .and_then(Value::as_str)+ .map(str::to_string)+ .or(style.based_on.clone())+ .unwrap_or_else(|| designcraft_doc::NO_CHAR_STYLE.into());+ // The fields show the style's own attributes over those its Based On gives it.+ let mut shown = styles.char_style_attrs(&based);+ shown.merge(&style.chars);+ let base = serde_json::to_value(&shown).unwrap_or_default();+ let cf = CharFields { base: &base, sparse: true };+ let lang = app.ui.language.clone();+ ui.set_min_width(560.0);+ ui.horizontal_top(|ui| {+ // A fixed height: the separator would otherwise stretch the dialog to the window.+ ui.set_min_height(380.0);+ ui.set_max_height(380.0);+ section_list(+ &lang,+ ui,+ d,+ &[+ ("general", "General"),+ ("chars", "Basic Character Formats"),+ ("advanced", "Advanced Character Formats"),+ ("color", "Character Color"),+ ("openType", "OpenType Features"),+ ("underline", "Underline Options"),+ ("strikethrough", "Strikethrough Options"),+ ],+ );+ ui.separator();+ ui.vertical(|ui| match d.s("section").as_str() {+ "chars" => basic_character_formats(app, ui, d, &cf),+ "advanced" => advanced_character_formats(&lang, ui, d, &cf),+ "color" => character_color(&lang, ui, d, &cf, &doc),+ "openType" => open_type_features(&lang, ui, d, &cf),+ "underline" => line_options(&lang, ui, d, &cf, &doc, "underline"),+ "strikethrough" => line_options(&lang, ui, d, &cf, &doc, "strikethrough"),+ _ => {+ egui::Grid::new("csg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(&lang, "Style Name:"));+ text_field(ui, d, "rename", 220.0);+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(&lang, "Based On:"));+ egui::ComboBox::from_id_salt("csbased")+ .selected_text(crate::rtl::widget(ui, crate::i18n::style_name(&lang, &based)))+ .width(220.0)+ .show_ui(ui, |ui| {+ // Not itself, nor a style based on it.+ for s in styles.character.iter().filter(|s| new || !styles.char_based_on_cycles(&name, &s.name)) {+ if ui.selectable_label(s.name == based, crate::rtl::widget(ui, crate::i18n::style_name(&lang, &s.name))).clicked() {+ d.fields.insert("basedOn".into(), json!(s.name));+ }+ }+ });+ ui.end_row();+ });+ let status = d.s("status");+ if !status.is_empty() {+ crate::rtl::label(ui, egui::RichText::new(status).color(crate::theme::Tokens::get(ui.ctx()).text_strong));+ }+ ui.add_space(8.0);+ crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&lang, "Style Settings:")).font(semibold(12.0)));+ // What OK would leave the style setting, after its Based On.+ let mut own = serde_json::to_value(&style.chars).unwrap_or_default();+ if let Some(o) = own.as_object_mut() {+ for (k, v) in d.fields.iter().filter_map(|(k, v)| Some((k.strip_prefix("c.")?, v))) {+ if v.is_null() {+ o.remove(k);+ } else {+ o.insert(k.to_string(), v.clone());+ }+ }+ }+ let mut parts = vec![crate::i18n::style_name(&lang, &based).to_string()];+ parts.extend(own.as_object().into_iter().flatten().map(|(k, v)| format!("{}: {}", setting_label(&lang, k), setting_text(v))));+ ui.add(egui::Label::new(egui::RichText::new(parts.join(" + ")).color(crate::theme::Tokens::get(ui.ctx()).text_dim)).wrap());+ }+ });+ });+ }++ /// An attribute's name as Style Settings shows it: the field's label where the name reads poorly.+ fn setting_label(lang: &str, key: &str) -> String {+ match key {+ "hScale" => crate::i18n::tr(lang, "Horizontal Scale:").trim_end_matches([':', ':']).to_string(),+ "vScale" => crate::i18n::tr(lang, "Vertical Scale:").trim_end_matches([':', ':']).to_string(),+ "capitalization" => crate::i18n::tr(lang, "Case:").trim_end_matches([':', ':']).to_string(),+ "otfFeatures" => crate::i18n::tr(lang, "OpenType Features").to_string(),+ _ => crate::i18n::tr(lang, &humanize(key)).to_string(),+ }+ }++ /// An attribute value as Style Settings shows it.+ fn setting_text(v: &Value) -> String {+ match v {+ Value::String(s) => s.clone(),+ Value::Number(n) => n.as_f64().map_or_else(|| n.to_string(), |x| format!("{}", (x * 1000.0).round() / 1000.0)),+ Value::Bool(b) => if *b { "on" } else { "off" }.into(),+ Value::Array(a) => a.iter().map(setting_text).collect::<Vec<_>>().join(", "),+ Value::Object(o) => o.get("value").or_else(|| o.get("kind")).map(setting_text).unwrap_or_default(),+ Value::Null => String::new(),+ }+ }++ /// Where the character sections of the style options dialogs get the values they show: `base`+ /// holds them by attribute name (resolved values for a paragraph style; for a character style the+ /// attributes it sets, the others absent). `sparse` (a character style) lets a field be blank:+ /// emptying it, or picking the blank entry, unsets the attribute.+ struct CharFields<'a> {+ base: &'a Value,+ sparse: bool,+ }++ impl CharFields<'_> {+ /// The value shown for attribute `key`: the dialog's edit, else the base value.+ fn get(&self, d: &Dialog, key: &str) -> Value {+ d.fields.get(&format!("c.{key}")).cloned().unwrap_or_else(|| self.base.get(key).cloned().unwrap_or(Value::Null))+ }+ fn set(&self, d: &mut Dialog, key: &str, v: Value) {+ d.fields.insert(format!("c.{key}"), v);+ }+ }++ /// A number attribute shown multiplied by `scale` (100 for a fraction shown as a percentage).+ fn char_number(ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, suffix: &str, scale: f64, range: (f64, f64)) {+ let v = cf.get(d, key).as_f64().map(|x| x * scale);+ let field = crate::widgets::NumField::number(key, v, suffix, 2).width(80.0).range(range.0, range.1);+ let edit = if cf.sparse { field.show_or_clear(ui) } else { field.show(ui).map(Some) };+ if let Some(n) = edit {+ cf.set(d, key, n.map_or(Value::Null, |n| json!(n / scale)));+ }+ }++ /// An attribute chosen from `opts` (value, label); a character style also has a blank entry.+ fn char_choice(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, opts: &[(Value, &str)]) {+ let cur = cf.get(d, key);+ let shown = opts.iter().find(|o| o.0 == cur).map_or("", |o| crate::i18n::tr(lang, o.1));+ egui::ComboBox::from_id_salt(("cs", key)).selected_text(crate::rtl::widget(ui, shown)).width(200.0).show_ui(ui, |ui| {+ if cf.sparse && ui.selectable_label(cur.is_null(), " ").clicked() {+ cf.set(d, key, Value::Null);+ }+ for (v, label) in opts {+ if ui.selectable_label(*v == cur, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).clicked() {+ cf.set(d, key, v.clone());+ }+ }+ });+ }++ /// An on/off attribute; for a character style a third, mixed state leaves it unset (clicks go+ /// unset → on → off → unset).+ fn char_check(ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, label: &str) {+ let cur = cf.get(d, key);+ let mut on = cur.as_bool().unwrap_or(false);+ let unset = cf.sparse && cur.is_null();+ if ui.add(egui::Checkbox::new(&mut on, crate::rtl::widget(ui, label)).indeterminate(unset)).clicked() {+ let next = match cur.as_bool() {+ _ if !cf.sparse => json!(on),+ None => json!(true),+ Some(true) => json!(false),+ Some(false) => Value::Null,+ };+ cf.set(d, key, next);+ }+ }++ /// A swatch attribute from a menu; `text_color` names the "" entry (the text's own colour).+ fn char_swatch(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, doc: &designcraft_doc::Document, key: &str, text_color: Option<&str>) {+ let mut opts: Vec<(Value, &str)> = text_color.map(|l| (json!(""), l)).into_iter().collect();+ opts.extend(doc.swatches.iter().map(|w| (json!(w.name), w.name.as_str())));+ char_choice(lang, ui, d, cf, key, &opts);+ }++ /// Basic Character Formats: font, size, leading, kerning, tracking, case, position and the+ /// underline, strikethrough, ligatures and no-break switches.-fn basic_character_formats(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {- let lang = app.ui.language.as_str();++fn basic_character_formats(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {++ let lang = app.ui.language.clone();++ let lang = lang.as_str();+ let fonts = crate::panels::fonts(app);- let menu = crate::panels::font_menu(app);+ egui::Grid::new("psc").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Font Family:"));+ let fam = cf.get(d, "fontFamily").as_str().unwrap_or("").to_string();- egui::ComboBox::from_id_salt("psfam").selected_text(crate::panels::font_label(app, &menu, &fam)).width(200.0).show_ui(ui, |ui| {- if cf.sparse && ui.selectable_label(fam.is_empty(), " ").clicked() {- cf.set(d, "fontFamily", Value::Null);- }- if let Some(f) = crate::panels::font_menu_rows(app, ui, &menu, &fam) {++ ui.horizontal(|ui| {++ if let Some(f) = crate::panels::font_combo(app, ui, "psfam", &fam, 200.0) {+ cf.set(d, "fontFamily", json!(f));+ }++ // A style may leave the family unset.++ if cf.sparse && !fam.is_empty() && ui.small_button("×").on_hover_text(crate::i18n::tr(lang, "Clear")).clicked() {++ cf.set(d, "fontFamily", Value::Null);++ }+ });+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Font Style:"));+ let sty = cf.get(d, "fontStyle").as_str().unwrap_or("").to_string();+ if cf.sparse && fam.is_empty() {+ // No family to list styles of: type the style ("Italic" in whatever font the text has).+ let mut s = sty.clone();+ if ui.add(egui::TextEdit::singleline(&mut s).desired_width(200.0)).changed() {+ cf.set(d, "fontStyle", if s.trim().is_empty() { Value::Null } else { json!(s) });+ }+ } else {+ egui::ComboBox::from_id_salt("pssty").selected_text(&sty).width(200.0).show_ui(ui, |ui| {+ if cf.sparse && ui.selectable_label(sty.is_empty(), " ").clicked() {+ cf.set(d, "fontStyle", Value::Null);+ }+ for s in fonts.styles(&fam) {+ if ui.selectable_label(s == sty, &s).clicked() {+ cf.set(d, "fontStyle", json!(s));+ }+ }+ });+ }+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Size:"));+ char_number(ui, d, cf, "size", " pt", 1.0, (0.1, 1296.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Leading:"));+ let lv = match cf.get(d, "leading") {+ v if v["kind"] == "points" => v["value"].as_f64(),+ _ => None,+ };+ let field = crate::widgets::NumField::number("pslead", lv, " pt", 2).width(80.0).range(0.0, 5000.0);+ let edit = if cf.sparse { field.show_or_clear(ui) } else { field.show(ui).map(Some) };+ if let Some(n) = edit {+ cf.set(d, "leading", n.map_or(Value::Null, |n| json!({"kind": "points", "value": n})));+ }+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Kerning:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "kerning",+ &[(json!({"kind": "metrics"}), "Metrics"), (json!({"kind": "optical"}), "Optical"), (json!({"kind": "none"}), "0")],+ );+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Tracking:"));+ char_number(ui, d, cf, "tracking", "", 1.0, (-1000.0, 10000.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Case:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "capitalization",+ &[+ (json!("normal"), "Normal"),+ (json!("allCaps"), "All Caps"),+ (json!("smallCaps"), "Small Caps"),+ (json!("openTypeAllSmallCaps"), "OpenType All Small Caps"),+ ],+ );+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Position:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "position",+ &[+ (json!("normal"), "Normal"),+ (json!("superscript"), "Superscript"),+ (json!("subscript"), "Subscript"),+ (json!("otSuperscript"), "OpenType Superscript"),+ (json!("otSubscript"), "OpenType Subscript"),+ (json!("otNumerator"), "OpenType Numerator"),+ (json!("otDenominator"), "OpenType Denominator"),+ ],+ );+ ui.end_row();+ });+ ui.add_space(4.0);+ egui::Grid::new("pscb").num_columns(2).spacing([16.0, 4.0]).show(ui, |ui| {+ char_check(ui, d, cf, "underline", crate::i18n::tr(lang, "Underline"));+ char_check(ui, d, cf, "ligatures", crate::i18n::tr(lang, "Ligatures"));+ ui.end_row();+ char_check(ui, d, cf, "strikethrough", crate::i18n::tr(lang, "Strikethrough"));+ char_check(ui, d, cf, "noBreak", crate::i18n::tr(lang, "No Break"));+ ui.end_row();+ });+ }++ /// Advanced Character Formats: scaling, baseline shift, skew and language.+ fn advanced_character_formats(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ egui::Grid::new("csa").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Horizontal Scale:"));+ char_number(ui, d, cf, "hScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Vertical Scale:"));+ char_number(ui, d, cf, "vScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Baseline Shift:"));+ char_number(ui, d, cf, "baselineShift", " pt", 1.0, (-5000.0, 5000.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Skew:"));+ char_number(ui, d, cf, "skew", "°", 1.0, (-85.0, 85.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Language:"));+ let opts: Vec<(Value, &str)> = crate::panels::properties::LANGUAGES.iter().map(|l| (json!(l), *l)).collect();+ char_choice(lang, ui, d, cf, "language", &opts);+ ui.end_row();+ });+ }++ /// Character Color: the fill or stroke swatch, its tint and the stroke weight.+ fn character_color(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, doc: &designcraft_doc::Document) {+ let stroke = d.s("colorTarget") == "stroke";+ ui.horizontal(|ui| {+ for (target, label) in [("fill", "Fill"), ("stroke", "Stroke")] {+ if ui.selectable_label((target == "stroke") == stroke, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).clicked() {+ d.fields.insert("colorTarget".into(), json!(target));+ }+ }+ });+ let key = if stroke { "stroke" } else { "fill" };+ let cur = cf.get(d, key).as_str().unwrap_or("").to_string();+ egui::ScrollArea::vertical().id_salt(("cscolor", key)).max_height(220.0).show(ui, |ui| {+ for sw in &doc.swatches {+ let (c, g) = crate::widgets::swatch_colors(doc, &sw.name, 1.0);+ ui.horizontal(|ui| {+ let (r, _) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::hover());+ crate::widgets::paint_chip(ui.painter(), r, c, g);+ if ui.selectable_label(sw.name == cur, &sw.name).clicked() {+ // A character style's chosen swatch, clicked again, is no longer set.+ cf.set(d, key, if cf.sparse && sw.name == cur { Value::Null } else { json!(sw.name) });+ }+ });+ }+ });+ egui::Grid::new("cscg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Tint:"));+ char_number(ui, d, cf, if stroke { "strokeTint" } else { "fillTint" }, "%", 100.0, (0.0, 100.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Weight:"));+ char_number(ui, d, cf, "strokeWeight", " pt", 1.0, (0.0, 800.0));+ ui.end_row();+ });+ }++ /// OpenType Features: the feature switches, figure style and stylistic sets (one `otfFeatures`+ /// list: changing any feature sets the whole list).+ fn open_type_features(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ use designcraft_doc::otf;+ let mut list: Vec<String> =+ cf.get(d, "otfFeatures").as_array().map(|a| a.iter().filter_map(|v| v.as_str().map(str::to_string)).collect()).unwrap_or_default();+ let mut changed = false;+ egui::Grid::new("csot").num_columns(2).spacing([16.0, 4.0]).show(ui, |ui| {+ for (i, (tag, label, _)) in otf::TOGGLES.iter().enumerate() {+ let mut on = otf::is_on(&list, tag);+ if ui.checkbox(&mut on, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).changed() {+ otf::set(&mut list, tag, on);+ changed = true;+ }+ if i % 2 == 1 {+ ui.end_row();+ }+ }+ });+ ui.add_space(6.0);+ ui.horizontal(|ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Figure Style:"));+ let fig = otf::figures(&list);+ let shown = otf::FIGURES.iter().find(|f| f.0 == fig).map_or("", |f| f.1);+ egui::ComboBox::from_id_salt("csfig").selected_text(crate::rtl::widget(ui, crate::i18n::tr(lang, shown))).width(180.0).show_ui(ui, |ui| {+ for (id, label, ..) in otf::FIGURES {+ if ui.selectable_label(fig == *id, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).clicked() && otf::set_figures(&mut list, id)+ {+ changed = true;+ }+ }+ });+ });+ ui.add_space(4.0);+ crate::rtl::label(ui, crate::i18n::tr(lang, "Stylistic Sets"));+ let mask = otf::stylistic_sets(&list);+ egui::Grid::new("csss").num_columns(10).spacing([2.0, 2.0]).show(ui, |ui| {+ for n in 1..=20u32 {+ let bit = 1u32 << (n - 1);+ if ui.add_sized([28.0, 20.0], egui::Button::selectable(mask & bit != 0, format!("{n}"))).clicked() {+ otf::set_stylistic_sets(&mut list, mask ^ bit);+ changed = true;+ }+ if n % 10 == 0 {+ ui.end_row();+ }+ }+ });+ if changed {+ cf.set(d, "otfFeatures", json!(list));+ }+ }++ /// Underline Options / Strikethrough Options (`key` is `underline` or `strikethrough`).+ fn line_options(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, doc: &designcraft_doc::Document, key: &str) {+ char_check(ui, d, cf, key, crate::i18n::tr(lang, if key == "underline" { "Underline On" } else { "Strikethrough On" }));+ ui.add_space(4.0);+ egui::Grid::new(("csline", key)).num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {+ crate::rtl::label(ui, crate::i18n::tr(lang, "Weight:"));+ char_number(ui, d, cf, &format!("{key}Weight"), " pt", 1.0, (0.0, 800.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Offset:"));+ char_number(ui, d, cf, &format!("{key}Offset"), " pt", 1.0, (-800.0, 800.0));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Color:"));+ char_swatch(lang, ui, d, cf, doc, &format!("{key}Color"), Some("(Text Color)"));+ ui.end_row();+ crate::rtl::label(ui, crate::i18n::tr(lang, "Tint:"));+ char_number(ui, d, cf, &format!("{key}Tint"), "%", 100.0, (0.0, 100.0));+ ui.end_row();+ });+ }+fn combo(ui: &mut egui::Ui, d: &mut Dialog, key: &str, opts: &[(&str, &str)]) {let cur = d.s(key);let shown = opts.iter().find(|o| o.0 == cur).map_or(cur.as_str(), |o| o.1).to_string();