diff --git a/fonts/NotoSansTC-Bold.otf b/fonts/NotoSansTC-Bold.otf new file mode 100644 index 0000000..3a3f5ed Binary files /dev/null and b/fonts/NotoSansTC-Bold.otf differ diff --git a/src/app.rs b/src/app.rs index 56a9193..84cde74 100644 --- a/src/app.rs +++ b/src/app.rs @@ -146,6 +146,8 @@ pub struct App { save_now: bool, /// 設定 › 一般 › 文件索引: the path being typed for a new folder. doc_new: String, + /// The folder typed in 設定 › 一般 wasn't found. + doc_new_bad: bool, /// Turns that AnyBot stopping cut off, found at start (see resume_interrupted). interrupted: Vec, last_tick: Instant, @@ -351,6 +353,7 @@ impl App { delivered: vec![], save_now: false, doc_new: String::new(), + doc_new_bad: false, interrupted, last_tick: Instant::now(), show_routines: None, @@ -2522,7 +2525,7 @@ impl App { } let right_w = bar.right() - right.min_rect().left(); // Left: the bot's name, plain; a press opens the conversation's details. - let font = egui::FontId::proportional(FONT_XL); + let font = egui::FontId::new(FONT_XL, crate::bold()); let name = sidebar_ui::shorten_width(ui, &bot.name, (bar.width() - right_w - 48.0).max(60.0), FONT_XL); let galley = ui.painter().layout_no_wrap(name, font, p.text); let rect = egui::Rect::from_min_size(egui::pos2(bar.left() + 14.0, bar.center().y - 18.0), vec2(galley.size().x + 20.0, 36.0)); @@ -2551,7 +2554,7 @@ impl App { self.live_face(ui, bot.id, face, true); ui.vertical(|ui| { ui.add_space(22.0); - ui.label(RichText::new(t("嗨,我是 {name}").replace("{name}", &bot.name)).size(28.0).strong().color(p.text)); + ui.label(RichText::new(t("嗨,我是 {name}").replace("{name}", &bot.name)).size(28.0).strong().family(crate::bold()).color(p.text)); let about = if bot.description.is_empty() { t("想做什麼?直接說,或從下面挑一個開始。") } else { bot.description.clone() }; ui.add(egui::Label::new(RichText::new(about).size(FONT_LG).color(p.text2)).wrap()); }); @@ -2611,7 +2614,7 @@ impl App { ApprovalKind::Action | ApprovalKind::Handoff => None, }; let mut answer = None; - ui.label(RichText::new(title).strong().size(if big { 17.0 } else { 14.0 })); + ui.label(RichText::new(title).strong().family(crate::bold()).size(if big { 17.0 } else { 14.0 })); ui.add_space(2.0); let (head, detail) = reason.split_once(':').unwrap_or(("", reason.as_str())); match note { @@ -2630,7 +2633,7 @@ impl App { ui.horizontal(|ui| { let once = if kind == ApprovalKind::Action { "允許" } else { "允許這一次" }; ui.spacing_mut().button_padding = vec2(14.0, 7.0); - if ui.add(egui::Button::new(RichText::new(once).strong().color(p.on_primary)).fill(p.primary).corner_radius(12).min_size(vec2(0.0, if big { 34.0 } else { 0.0 }))).clicked() { + if ui.add(egui::Button::new(RichText::new(once).strong().family(crate::bold()).color(p.on_primary)).fill(p.primary).corner_radius(12).min_size(vec2(0.0, if big { 34.0 } else { 0.0 }))).clicked() { answer = Some(ApprovalAnswer::Once); } let always = match kind { @@ -2723,7 +2726,7 @@ impl App { let mut at = ui.new_child(egui::UiBuilder::new().max_rect(egui::Rect::from_min_max(egui::pos2(face.right() + 10.0, row.top()), row.right_bottom())).layout(Layout::left_to_right(Align::Center))); let words = sidebar_ui::shorten_width(&at, &words, at.available_width() - 8.0, 13.5); if waiting { - at.label(RichText::new(words).size(13.5).strong().color(col)); + at.label(RichText::new(words).size(13.5).strong().family(crate::bold()).color(col)); } else { chat_ui::shimmer(&mut at, &words, col.gamma_multiply(0.75), col, 13.5); } @@ -2758,7 +2761,7 @@ impl App { ui.label(RichText::new(sidebar_ui::shorten_width(ui, &format!("· {computer}"), (ui.available_width() - 4.0).max(40.0), FONT_XS)).size(FONT_XS).color(p.text3)); }); ui.add_space(2.0); - ui.label(RichText::new(t("需要處理")).strong().size(15.0)); + ui.label(RichText::new(t("需要處理")).strong().family(crate::bold()).size(15.0)); ui.add(egui::Label::new(RichText::new(&instruction).size(13.5).color(p.text2)).wrap()); ui.add_space(8.0); // The screen, 16:10, with 「接管」 on it. @@ -3170,7 +3173,7 @@ impl App { for name in crate::botbrowser::choices() { ui.horizontal(|ui| { let mut on = name == current; - if ui.radio_value(&mut on, true, RichText::new(&name).strong()).clicked() && name != current { + if ui.radio_value(&mut on, true, RichText::new(&name).strong().family(crate::bold())).clicked() && name != current { let _ = crate::botbrowser::set_current(&name); } if name == current { @@ -3270,7 +3273,7 @@ impl App { for r in &bot.routines { setting_card(ui, p, |ui| { ui.horizontal(|ui| { - ui.label(RichText::new(&r.title).strong().size(FONT_LG)); + ui.label(RichText::new(&r.title).strong().family(crate::bold()).size(FONT_LG)); if r.paused { ui.label(RichText::new(t("已暫停")).size(11.5).color(p.text3)); } @@ -3675,14 +3678,19 @@ impl App { ui.spacing_mut().item_spacing.y = 2.0; use crate::icons::Icon; for (tab, name, icon) in [(SettingsTab::General, "一般", Icon::Gear), (SettingsTab::Providers, "模型", Icon::Sparkle), (SettingsTab::Channels, "整合", Icon::Chat), (SettingsTab::Computers, "電腦", Icon::Monitor), (SettingsTab::Review, "權限", Icon::Shield), (SettingsTab::Vault, "保險庫", Icon::Vault), (SettingsTab::Voice, "語音", Icon::Mic), (SettingsTab::Updates, "更新", Icon::CloudDownload)] { - let (rect, r) = ui.allocate_exact_size(vec2(ui.available_width(), 32.0), egui::Sense::click()); + let (rect, r) = ui.allocate_exact_size(vec2(ui.available_width(), 38.0), egui::Sense::click()); let on = self.settings_tab == tab || (tab == SettingsTab::General && self.settings_tab == SettingsTab::Remote); if on || r.hovered() { - ui.painter().rect_filled(rect, 8, if on { p.active } else { p.hover }); + ui.painter().rect_filled(rect, 10, if on { p.primary } else { p.hover }); } - let col = if on { p.text } else { p.text2 }; + let col = if on { p.on_primary } else { p.text }; crate::icons::paint(ui.painter(), egui::Rect::from_center_size(rect.left_center() + vec2(18.0, 0.0), vec2(16.0, 16.0)), icon, col); - ui.painter().text(rect.left_center() + vec2(34.0, 0.0), egui::Align2::LEFT_CENTER, t(name), egui::FontId::proportional(FONT_BASE), col); + let font = if on { egui::FontId::new(FONT_BASE, crate::bold()) } else { egui::FontId::proportional(FONT_BASE) }; + ui.painter().text(rect.left_center() + vec2(36.0, 0.0), egui::Align2::LEFT_CENTER, t(name), font, col); + // 更新: a newer build is waiting (the yellow that means 「需要你」). + if tab == SettingsTab::Updates && self.newer_build.is_some() && rect.width() > 110.0 { + ui.painter().circle_filled(rect.right_center() - vec2(14.0, 0.0), 5.0, p.attention); + } if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { self.settings_tab = tab; } @@ -3695,23 +3703,63 @@ impl App { ui.spacing_mut().item_spacing = vec2(8.0, 6.0); dialog_body(ui, ("settings-page", self.settings_tab as u8), page_h, |ui| match self.settings_tab { SettingsTab::General => { - section(ui, "帳戶", p); - let acct = if self.state.remote.host_token.is_empty() { t("尚未登入帳號 · 手機、帳號、團隊、備份") } else { format!("{} · {}", self.state.remote.relay_user, self.state.remote.relay_url) }; - setting_row(ui, p, "帳戶", &acct, |ui| { - if ui.add(secondary_button("管理")).clicked() { - self.settings_tab = SettingsTab::Remote; - } + // One thing a row, in plain words; what needs explaining is behind the ?. + section(ui, "外觀", p); + rows_card(ui, p, |ui| { + card_row(ui, p, "主題", "", "", |ui| { + if let Some(th) = segmented(ui, p, self.state.theme, &[(Theme::Light, "淺色"), (Theme::Dark, "深色"), (Theme::System, "跟著系統")]) { + self.state.theme = th; + theme_changed = true; + } + }); + card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| { + if let Some(a) = segmented(ui, p, self.state.accent, &[(Accent::BotColor, "跟著 Bot"), (Accent::Black, "只用黑色")]) { + self.state.accent = a; + self.dirty = true; + } + }); + card_row(ui, p, "字型", "", "思源黑體有粗體;粉圓體和系統字型只有一種粗細。", |ui| { + let cur = crate::font_choice(); + if let Some(v) = segmented(ui, p, cur.as_str(), &[("noto", "思源黑體"), ("system", "系統字型"), ("huninn", "粉圓體")]) { + if let Some(d) = State::path().parent() { + let _ = std::fs::create_dir_all(d); + let _ = std::fs::write(d.join("font.txt"), v); + } + crate::load_fonts(ctx); + } + }); + let other_menu = !matches!(crate::i18n::lang().as_str(), "zh-TW" | "zh-CN" | "en" | "ja"); + card_row(ui, p, "語言", if other_menu { "選單用英文顯示,Bot 用你選的語言回答" } else { "" }, "AnyBot 的選單和 Bot 回答用的語言", |ui| { + let cur = self.state.language.clone(); + let shown = if cur == "auto" { format!("{}({})", t("自動偵測"), crate::i18n::endonym(&crate::i18n::system())) } else { crate::i18n::endonym(&cur).to_string() }; + egui::ComboBox::from_id_salt("language").selected_text(shown).height(360.0).show_ui(ui, |ui| { + let mut pick = |ui: &mut egui::Ui, v: &str, label: String| { + if ui.selectable_label(cur == v, label).clicked() { + self.state.language = v.to_string(); + crate::i18n::set(v); + self.dirty = true; + } + }; + pick(ui, "auto", t("自動偵測")); + let mut rows: Vec<_> = crate::i18n::LANGS.to_vec(); + rows.sort_by(|a, b| a.1.cmp(b.1)); + for (tag, endo, eng) in rows { + pick(ui, tag, if endo == eng { endo.to_string() } else { format!("{endo} · {eng}") }); + } + }); + }); }); section(ui, "記憶與文件", p); - // 語意搜尋: 本機模型 (default) / Ollama / 關閉; the line under it says how it is now. - let choice = match self.state.embed_model.trim() { - "" | "local" => "local", - "off" => "off", - _ => "ollama", - }; - setting_row(ui, p, "語意搜尋", &crate::embed::status(), |ui| { - for (k, label) in [("off", "關閉"), ("ollama", "Ollama"), ("local", "本機模型")] { - if ui.add(egui::Button::new(RichText::new(t(label)).size(FONT_SM).color(if choice == k { p.text } else { p.text2 })).fill(if choice == k { p.active } else { Color32::TRANSPARENT }).corner_radius(8)).clicked() && choice != k { + rows_card(ui, p, |ui| { + // 用意思找記憶 (語意搜尋): 本機模型 (default) / Ollama / 關閉; how it is now is behind the ?. + let choice = match self.state.embed_model.trim() { + "" | "local" => "local", + "off" => "off", + _ => "ollama", + }; + let help = format!("{}\n\n{}", crate::embed::status(), t("本機模型:minishlab/potion-multilingual-128M,第一次下載約 530 MB、存成 130 MB,在這台電腦上算,什麼都不上傳。大腦會載入;這台當螢幕時,設了資料夾才載入。換了以後所有向量會重算。")); + card_row(ui, p, "用意思找記憶", "在這台電腦上算,不會上傳", &help, |ui| { + if let Some(k) = segmented(ui, p, choice, &[("local", "本機模型"), ("ollama", "Ollama"), ("off", "關閉")]) { self.state.embed_model = match k { "local" => String::new(), other => other.to_string(), @@ -3719,125 +3767,102 @@ impl App { crate::embed::configure(&crate::embed::ollama_base(&self.state.provider(crate::providers::ProviderKind::Ollama).base_url), &self.state.embed_model); self.dirty = true; } - } - }); - hint(ui, "本機模型:minishlab/potion-multilingual-128M,第一次下載約 530 MB、存成 130 MB,在這台電腦上算,什麼都不上傳。大腦會載入;這台當螢幕時,設了文件索引資料夾才載入。換了以後所有向量會重算。", p); - ui.ctx().request_repaint_after(std::time::Duration::from_secs(1)); - let shown = doc_folders().join(" · "); - setting_row(ui, p, "文件索引", &format!("Bot 在這些資料夾的文字檔(md/txt/csv/程式碼)裡找答案,全程只在本機:{shown}"), |_ui| {}); - ui.horizontal(|ui| { + }); + ui.ctx().request_repaint_after(std::time::Duration::from_secs(1)); + let n = self.state.doc_folders.len(); + let count = if n == 0 { t("還沒有") } else { t("{n} 個").replace("{n}", &n.to_string()) }; + card_row(ui, p, "Bot 可以翻的資料夾", "", "Bot 在這些資料夾的文字檔(md、txt、csv、程式碼)裡找答案,全程只在這台電腦上。", |ui| { + ui.label(RichText::new(count).size(FONT_BASE).color(p.text2)); + }); for f in self.state.doc_folders.clone() { - if ui.add(secondary_button(&format!("移除 {f}"))).clicked() { - self.state.doc_folders.retain(|x| x != &f); - set_doc_folders(self.state.doc_folders.clone()); - self.dirty = true; - } + ui.horizontal(|ui| { + ui.set_min_height(34.0); + ui.spacing_mut().item_spacing.x = 8.0; + ui.with_layout(Layout::right_to_left(Align::Center), |ui| { + if small_button(ui, "移除", p).clicked() { + self.state.doc_folders.retain(|x| x != &f); + set_doc_folders(self.state.doc_folders.clone()); + self.dirty = true; + } + ui.with_layout(Layout::left_to_right(Align::Center), |ui| { + ui.add(egui::Label::new(RichText::new(&f).size(FONT_SM).color(p.text2)).truncate()); + }); + }); + }); } - }); - ui.horizontal(|ui| { - ui.add_sized([280.0, 24.0], egui::TextEdit::singleline(&mut self.doc_new).hint_text("資料夾路徑,例如 ~/筆記")); - if ui.add(secondary_button("新增資料夾")).clicked() { - let mut f = self.doc_new.trim().to_string(); - if f.starts_with("~/") { - if let Ok(h) = std::env::var("HOME") { - f = format!("{h}/{}", &f[2..]); + ui.horizontal(|ui| { + ui.set_min_height(44.0); + ui.spacing_mut().item_spacing.x = 8.0; + ui.add_sized([280.0, 26.0], egui::TextEdit::singleline(&mut self.doc_new).hint_text(t("資料夾路徑,例如 ~/筆記"))); + if ui.add(secondary_button("加入資料夾")).clicked() { + let mut f = self.doc_new.trim().to_string(); + if f.starts_with("~/") { + if let Ok(h) = std::env::var("HOME") { + f = format!("{h}/{}", &f[2..]); + } } - } - if f.is_empty() { - } else if std::path::Path::new(&f).is_dir() && !self.state.doc_folders.contains(&f) { - self.state.doc_folders.push(f); - set_doc_folders(self.state.doc_folders.clone()); - self.dirty = true; - self.doc_new.clear(); - } else { - ui.label(RichText::new("這個資料夾不存在").size(FONT_SM).color(p.text2)); - } - } - }); - section(ui, "外觀", p); - setting_row(ui, p, "主題", "為 AnyBot 選擇淺色或深色外觀", |ui| { - for (th, n) in [(Theme::System, "跟隨系統"), (Theme::Dark, "深色"), (Theme::Light, "淺色")] { - if ui.selectable_value(&mut self.state.theme, th, t(n)).clicked() { - theme_changed = true; - } - } - }); - setting_row(ui, p, "強調色", "用 Bot 的顏色為 1:1 Bot 訊息和卡片上色,或保持黑色", |ui| { - for (a, n) in [(Accent::Black, "黑色"), (Accent::BotColor, "Bot 顏色")] { - if ui.selectable_value(&mut self.state.accent, a, t(n)).clicked() { - self.dirty = true; - } - } - }); - setting_row(ui, p, "字型", "AnyBot 畫面使用的字型", |ui| { - let cur = crate::font_choice(); - for (v, n) in [("noto", "思源黑體"), ("system", "系統字型"), ("huninn", "粉圓體")] { - if ui.selectable_label(cur == v, t(n)).clicked() && cur != v { - if let Some(d) = State::path().parent() { - let _ = std::fs::create_dir_all(d); - let _ = std::fs::write(d.join("font.txt"), v); - } - crate::load_fonts(ctx); - } - } - }); - setting_row(ui, p, "語言", "選擇 AnyBot 選單和 Bot 回答使用的語言", |ui| { - let cur = self.state.language.clone(); - let shown = if cur == "auto" { format!("{}({})", t("自動偵測"), crate::i18n::endonym(&crate::i18n::system())) } else { crate::i18n::endonym(&cur).to_string() }; - egui::ComboBox::from_id_salt("language").selected_text(shown).height(360.0).show_ui(ui, |ui| { - let mut pick = |ui: &mut egui::Ui, v: &str, label: String| { - if ui.selectable_label(cur == v, label).clicked() { - self.state.language = v.to_string(); - crate::i18n::set(v); + if f.is_empty() { + } else if std::path::Path::new(&f).is_dir() && !self.state.doc_folders.contains(&f) { + self.state.doc_folders.push(f); + set_doc_folders(self.state.doc_folders.clone()); self.dirty = true; + self.doc_new.clear(); + } else { + self.doc_new_bad = true; } - }; - pick(ui, "auto", t("自動偵測")); - let mut rows: Vec<_> = crate::i18n::LANGS.to_vec(); - rows.sort_by(|a, b| a.1.cmp(b.1)); - for (tag, endo, eng) in rows { - pick(ui, tag, if endo == eng { endo.to_string() } else { format!("{endo} · {eng}") }); + } + if self.doc_new_bad && !self.doc_new.trim().is_empty() { + ui.label(RichText::new(t("找不到這個資料夾")).size(FONT_SM).color(p.danger)); + } else { + self.doc_new_bad = false; } }); }); - if !matches!(crate::i18n::lang().as_str(), "zh-TW" | "zh-CN" | "en" | "ja") { - hint(ui, "選單會用英文顯示;Bot 會用你選的語言回答。", p); - } section(ui, "通知", p); - setting_row(ui, p, "通知", "Bot 完成任務或等你處理時通知你", |ui| { - if ui.add(egui::Checkbox::without_text(&mut self.state.notify)).changed() { - self.dirty = true; - } - }); - hint(ui, "視窗不在最前面,或 90 秒沒有動鍵盤滑鼠,就會通知。登入帳號後也會推播到手機。", p); - setting_row(ui, p, "需要你時發出提示音", "Bot 要你允許某件事、或要你親自處理一個步驟時,響一聲(就算你正在看 AnyBot)", |ui| { - let before = self.state.alert_sound; - if ui.add(egui::Checkbox::without_text(&mut self.state.alert_sound)).changed() { - self.dirty = true; - // Turned on: let the person hear what it sounds like. - if !before { - crate::voice::chime(); + rows_card(ui, p, |ui| { + card_row(ui, p, "Bot 做完或等你時通知", "", "視窗不在最前面,或 90 秒沒有動鍵盤滑鼠,就會通知。登入帳號後也會推播到手機。", |ui| { + if ui.add(computers_ui::toggle(&mut self.state.notify)).changed() { + self.dirty = true; } - } + }); + card_row(ui, p, "需要你時響一聲", "", "Bot 要你允許某件事、或要你親自處理一個步驟時,響一聲(就算你正在看 AnyBot)。", |ui| { + let before = self.state.alert_sound; + if ui.add(computers_ui::toggle(&mut self.state.alert_sound)).changed() { + self.dirty = true; + // Turned on: let the person hear what it sounds like. + if !before { + crate::voice::chime(); + } + } + }); }); section(ui, "Bot", p); - setting_row(ui, p, "時區", "設定 Bot 用於排程和提醒的時區", |ui| { - if ui.add(egui::TextEdit::singleline(&mut self.state.timezone).desired_width(150.0)).changed() { - self.dirty = true; - } - if ui.add(secondary_button("用這台電腦的")).clicked() { - self.state.timezone = crate::routines::local_timezone(); - self.dirty = true; - } + rows_card(ui, p, |ui| { + let bad = self.state.timezone.parse::().is_err(); + card_row(ui, p, "時區", if bad { "看不懂這個時區,請用像 Asia/Taipei 這樣的名稱" } else { "" }, "Bot 排例行任務和提醒時用的時區", |ui| { + if ui.add(secondary_button("用這台電腦的")).clicked() { + self.state.timezone = crate::routines::local_timezone(); + self.dirty = true; + } + if ui.add(egui::TextEdit::singleline(&mut self.state.timezone).desired_width(150.0)).changed() { + self.dirty = true; + } + }); }); - if self.state.timezone.parse::().is_err() { - ui.label(RichText::new(t("看不懂這個時區,請用像 Asia/Taipei 這樣的名稱")).size(11.5).color(p.danger)); - } - section(ui, "系統", p); - setting_row(ui, p, "資料", "聊天記錄和金鑰只存在這台電腦上", |ui| { - if ui.add(secondary_button(if cfg!(target_os = "macos") { "在 Finder 中顯示" } else { "打開所在資料夾" })).clicked() { - crate::preview::reveal(&State::path()); - } + section(ui, "帳戶", p); + rows_card(ui, p, |ui| { + let signed_in = !self.state.remote.host_token.is_empty(); + let (who, sub) = if signed_in { (self.state.remote.relay_user.clone(), self.state.remote.relay_url.clone()) } else { (t("還沒登入"), t("登入後可以用手機、團隊和備份")) }; + card_row(ui, p, &who, &sub, "", |ui| { + if ui.add(secondary_button(if signed_in { "管理帳戶" } else { "登入" })).clicked() { + self.settings_tab = SettingsTab::Remote; + } + }); + card_row(ui, p, "資料放在哪", "聊天記錄和金鑰只存在這台電腦上", "", |ui| { + if ui.add(secondary_button(if cfg!(target_os = "macos") { "在 Finder 中顯示" } else { "打開資料夾" })).clicked() { + crate::preview::reveal(&State::path()); + } + }); }); } SettingsTab::Updates => { @@ -3980,7 +4005,7 @@ impl App { ui.vertical(|ui| { let k = self.settings_provider; let w = ui.available_width(); - ui.label(RichText::new(k.label()).strong().size(FONT_XL)); + ui.label(RichText::new(k.label()).strong().family(crate::bold()).size(FONT_XL)); hint(ui, k.key_help(), p); ui.add_space(6.0); let ps = self.state.provider_mut(k); @@ -4793,7 +4818,7 @@ fn card(ui: &mut egui::Ui, args: &str, p: Palette) { crate::icons::paint(ui.painter(), r, icon, p.text2); ui.vertical(|ui| { ui.spacing_mut().item_spacing.y = 1.0; - ui.label(RichText::new(v["title"].as_str().unwrap_or("")).strong().size(FONT_LG)); + ui.label(RichText::new(v["title"].as_str().unwrap_or("")).strong().family(crate::bold()).size(FONT_LG)); if let Some(st) = v["subtitle"].as_str().filter(|x| !x.is_empty()) { ui.label(RichText::new(st).size(FONT_XS).color(p.text3)); } @@ -5050,9 +5075,9 @@ fn pill_icon(ui: &mut egui::Ui, icon: crate::icons::Icon, p: Palette) -> egui::R /// A group heading inside a settings page (like the original's section titles). fn section(ui: &mut egui::Ui, title: &str, p: Palette) { - ui.add_space(14.0); - ui.label(RichText::new(t(title)).size(FONT_SM).strong().color(p.text3)); - ui.add_space(2.0); + ui.add_space(16.0); + ui.label(RichText::new(t(title)).size(FONT_LG).family(crate::bold()).color(p.text)); + ui.add_space(4.0); } /// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no @@ -5092,8 +5117,75 @@ fn help_mark(ui: &mut egui::Ui, text: &str, p: Palette) { } /// One setting: its name (with「?」for the explanation) on the left, its control on the right. +/// The quiet fill of a settings card. +fn card_fill(p: Palette) -> Color32 { + if p.pane.r() < 128 { Color32::from_rgb(0x1e, 0x1e, 0x1e) } else { Color32::from_rgb(0xf5, 0xf5, 0xf3) } +} + +/// A group of settings: one quiet card, its rows (`card_row`) divided by hairlines. +fn rows_card(ui: &mut egui::Ui, p: Palette, rows: impl FnOnce(&mut egui::Ui)) { + Frame::new().fill(card_fill(p)).corner_radius(16).inner_margin(Margin::symmetric(16, 2)).show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.spacing_mut().item_spacing.y = 0.0; + rows(ui); + }); +} + +/// One setting in a card: its name (and at most one small line under it) on the left, its +/// control on the right; anything longer is behind the ? (`help`). +fn card_row(ui: &mut egui::Ui, p: Palette, label: &str, sub: &str, help: &str, control: impl FnOnce(&mut egui::Ui)) { + let top = ui.cursor().top(); + if top > ui.max_rect().top() + 1.0 { + ui.painter().hline(ui.max_rect().x_range(), top, Stroke::new(1.0, p.border)); + } + let h = if sub.is_empty() { 52.0 } else { 62.0 }; + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), h), egui::Sense::hover()); + // The control first, from the right edge; the words get the room that is left. + let mut right = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(Layout::right_to_left(Align::Center))); + right.spacing_mut().item_spacing.x = 8.0; + control(&mut right); + let words = egui::Rect::from_min_max(rect.min, egui::pos2((right.min_rect().left() - 12.0).max(rect.left() + 80.0), rect.bottom())); + if sub.is_empty() { + let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::left_to_right(Align::Center))); + left.spacing_mut().item_spacing.x = 4.0; + left.add(egui::Label::new(RichText::new(t(label)).size(FONT_LG).color(p.text)).truncate()); + help_mark(&mut left, help, p); + } else { + let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::top_down(Align::Min))); + left.spacing_mut().item_spacing = vec2(4.0, 1.0); + left.add_space((h - 42.0) / 2.0); + left.horizontal(|ui| { + ui.add(egui::Label::new(RichText::new(t(label)).size(FONT_LG).color(p.text)).truncate()); + help_mark(ui, help, p); + }); + left.add(egui::Label::new(RichText::new(t(sub)).size(12.5).color(p.text2)).truncate()); + } +} + +/// A choice among a few: the one chosen is the raised, bold one. Returns a new choice. +fn segmented(ui: &mut egui::Ui, p: Palette, cur: T, options: &[(T, &str)]) -> Option { + let mut picked = None; + Frame::new().fill(p.active).corner_radius(10).inner_margin(Margin::same(3)).show(ui, |ui| { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 2.0; + // (In a row laid out from the right, the first choice is still the left one.) + let reversed = ui.layout().prefer_right_to_left(); + let order: Vec<&(T, &str)> = if reversed { options.iter().rev().collect() } else { options.iter().collect() }; + for (v, label) in order { + let on = *v == cur; + let text = RichText::new(t(label)).size(FONT_SM).color(if on { p.text } else { p.text2 }); + let text = if on { text.family(crate::bold()) } else { text }; + if ui.add(egui::Button::new(text).fill(if on { p.elevated } else { Color32::TRANSPARENT }).stroke(Stroke::NONE).corner_radius(8).min_size(vec2(0.0, 26.0))).clicked() && !on { + picked = Some(*v); + } + } + }); + }); + picked +} + fn setting_row(ui: &mut egui::Ui, p: Palette, label: &str, desc: &str, control: impl FnOnce(&mut egui::Ui)) { - Frame::new().fill(p.elevated).corner_radius(10).inner_margin(Margin::symmetric(14, 10)).show(ui, |ui| { + Frame::new().fill(card_fill(p)).corner_radius(14).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal(|ui| { let w = (ui.available_width() * 0.5).max(180.0); @@ -5113,7 +5205,7 @@ fn setting_row(ui: &mut egui::Ui, p: Palette, label: &str, desc: &str, control: fn setting_title(ui: &mut egui::Ui, title: &str, desc: &str, p: Palette) { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 4.0; - ui.label(RichText::new(t(title)).strong().size(FONT_BASE)); + ui.label(RichText::new(t(title)).strong().family(crate::bold()).size(FONT_BASE)); help_mark(ui, desc, p); }); ui.add_space(4.0); @@ -5127,9 +5219,8 @@ fn hint(ui: &mut egui::Ui, text: impl Into, p: Palette) { /// A rounded group of related settings, like a macOS settings card. fn setting_card(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R { let r = Frame::new() - .fill(p.hover.gamma_multiply(0.6)) - .stroke(Stroke::new(1.0, p.border.gamma_multiply(0.6))) - .corner_radius(12) + .fill(card_fill(p)) + .corner_radius(16) .inner_margin(Margin::symmetric(16, 14)) .show(ui, |ui| { ui.set_width(ui.available_width()); @@ -5155,7 +5246,7 @@ fn field_label(ui: &mut egui::Ui, text: &str, p: Palette) { } fn primary_button(text: &str, p: Palette) -> egui::Button<'static> { - egui::Button::new(RichText::new(t(text)).color(p.on_primary).strong()).fill(p.primary).corner_radius(8).min_size(vec2(72.0, 30.0)) + egui::Button::new(RichText::new(t(text)).color(p.on_primary).strong().family(crate::bold())).fill(p.primary).corner_radius(8).min_size(vec2(72.0, 30.0)) } fn secondary_button(text: &str) -> egui::Button<'static> { @@ -5163,7 +5254,7 @@ fn secondary_button(text: &str) -> egui::Button<'static> { } fn danger_button(text: &str, p: Palette) -> egui::Button<'static> { - egui::Button::new(RichText::new(t(text)).color(Color32::WHITE).strong()).fill(p.danger).corner_radius(8).min_size(vec2(72.0, 30.0)) + egui::Button::new(RichText::new(t(text)).color(Color32::WHITE).strong().family(crate::bold())).fill(p.danger).corner_radius(8).min_size(vec2(72.0, 30.0)) } /// Tallest a dialog may be: the window minus a margin above and below. @@ -5193,7 +5284,7 @@ fn dialog(ctx: &egui::Context, id: &str, title: &str, width: f32, outside_closes Frame::new().inner_margin(Margin { left: 20, right: 12, top: 12, bottom: 12 }).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal(|ui| { - ui.label(RichText::new(t(title)).strong().size(FONT_XL)); + ui.label(RichText::new(t(title)).strong().family(crate::bold()).size(FONT_XL)); ui.add_space((ui.available_width() - 28.0).max(0.0)); // Drawn, not a glyph: not every Chinese font has "✕". let (rect, r) = ui.allocate_exact_size(vec2(28.0, 28.0), egui::Sense::click()); diff --git a/src/app/channels_ui.rs b/src/app/channels_ui.rs index 4aa5a56..3bd5711 100644 --- a/src/app/channels_ui.rs +++ b/src/app/channels_ui.rs @@ -191,7 +191,7 @@ impl App { setting_card(ui, p, |ui| { ui.horizontal(|ui| { ui.label(RichText::new(c.kind.label()).size(FONT_XS).color(p.text2)); - ui.label(RichText::new(&c.name).strong().size(FONT_BASE)); + ui.label(RichText::new(&c.name).strong().family(crate::bold()).size(FONT_BASE)); let st = statuses.get(&c.id); let (col, text) = match st { _ if !c.enabled => (p.text3, "已暫停".to_string()), @@ -389,7 +389,7 @@ impl App { ui.checkbox(&mut s.enabled, t("開啟")); }, |ui| { - ui.label(RichText::new(&name).strong().size(FONT_BASE)); + ui.label(RichText::new(&name).strong().family(crate::bold()).size(FONT_BASE)); let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover()); ui.painter().circle_filled(r.center(), 4.0, col); ui.add(egui::Label::new(RichText::new(&text).size(11.5).color(p.text3)).truncate()).on_hover_text(&text); @@ -447,7 +447,7 @@ impl App { } }, |ui| { - ui.label(RichText::new(&name).strong().size(FONT_SM).color(name_col)).on_hover_text(&description); + ui.label(RichText::new(&name).strong().family(crate::bold()).size(FONT_SM).color(name_col)).on_hover_text(&description); if files > 0 { ui.label(RichText::new(format!("{files} 檔")).size(11.0).color(p.accent)); } @@ -513,7 +513,7 @@ impl App { } }, |ui| { - ui.label(RichText::new(b.slug).strong().size(FONT_SM)); + ui.label(RichText::new(b.slug).strong().family(crate::bold()).size(FONT_SM)); let about = format!("{} — {}", b.title, b.summary); ui.add(egui::Label::new(RichText::new(&about).size(FONT_XS).color(p.text3)).truncate()).on_hover_text(&about); }, @@ -549,7 +549,7 @@ impl App { } }, |ui| { - ui.label(RichText::new(r.name).strong().size(FONT_SM)); + ui.label(RichText::new(r.name).strong().family(crate::bold()).size(FONT_SM)); ui.add(egui::Label::new(RichText::new(r.summary).size(FONT_XS).color(p.text3)).truncate()).on_hover_text(r.summary); }, ); @@ -601,7 +601,7 @@ impl App { } }, |ui| { - ui.label(RichText::new(name).strong().size(FONT_SM)); + ui.label(RichText::new(name).strong().family(crate::bold()).size(FONT_SM)); ui.add(egui::Label::new(RichText::new(desc).size(FONT_XS).color(p.text3)).truncate()).on_hover_text(desc); }, ); @@ -722,7 +722,7 @@ impl App { } }, |ui| { - ui.label(RichText::new(title).strong().size(FONT_SM)); + ui.label(RichText::new(title).strong().family(crate::bold()).size(FONT_SM)); if e["header"].is_object() { ui.label(RichText::new(t("要金鑰")).size(11.0).color(p.accent)); } diff --git a/src/app/chat_ui.rs b/src/app/chat_ui.rs index 03d0f64..8e66a2e 100644 --- a/src/app/chat_ui.rs +++ b/src/app/chat_ui.rs @@ -933,7 +933,7 @@ impl App { } let mut row = ui.new_child(egui::UiBuilder::new().max_rect(rect.shrink2(vec2(10.0, 0.0))).layout(Layout::left_to_right(Align::Center))); // Not selectable: a selectable label takes the click the row is waiting for. - row.add(egui::Label::new(RichText::new(format!("/{name}")).strong().size(FONT_SM).color(p.text)).selectable(false)); + row.add(egui::Label::new(RichText::new(format!("/{name}")).strong().family(crate::bold()).size(FONT_SM).color(p.text)).selectable(false)); row.add(egui::Label::new(RichText::new(about).size(FONT_XS).color(p.text3)).truncate().selectable(false)); if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { picked = Some(i); diff --git a/src/app/computers_ui.rs b/src/app/computers_ui.rs index f8cd93f..416225a 100644 --- a/src/app/computers_ui.rs +++ b/src/app/computers_ui.rs @@ -1071,13 +1071,13 @@ impl App { let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover()); ui.painter().circle_filled(r.center(), 4.5, if held { p.text3 } else { Color32::from_rgb(0xfc, 0x2c, 0x3e) }); let text = if held { "你正在操作,Bot 已暫停".to_string() } else { format!("{who} 正在操作你的電腦") }; - ui.label(RichText::new(text).size(FONT_SM).strong()); + ui.label(RichText::new(text).size(FONT_SM).strong().family(crate::bold())); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { if !held && ui.add(egui::Button::new(RichText::new(t("停止")).size(FONT_XS)).corner_radius(14)).clicked() { stop_bot = Some(who.clone()); } let label = if held { "交還給 Bot" } else { "取得控制權" }; - if ui.add(egui::Button::new(RichText::new(label).size(FONT_XS).strong().color(p.on_primary)).fill(p.primary).corner_radius(14)).clicked() { + if ui.add(egui::Button::new(RichText::new(label).size(FONT_XS).strong().family(crate::bold()).color(p.on_primary)).fill(p.primary).corner_radius(14)).clicked() { toggle = true; } }); @@ -1154,7 +1154,7 @@ impl App { Frame::new().fill(p.elevated).corner_radius(10).inner_margin(Margin::symmetric(12, 8)).show(ui, |ui| { ui.set_width(ui.available_width()); ui.horizontal(|ui| { - ui.label(RichText::new(&d.name).strong().size(FONT_SM)); + ui.label(RichText::new(&d.name).strong().family(crate::bold()).size(FONT_SM)); ui.label(RichText::new(format!("{} · {} 個步驟", d.created, d.steps.len())).size(11.5).color(p.text3)); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { if ui.add(egui::Button::new(RichText::new(t("刪除")).size(12.0).color(p.text3)).frame(false)).clicked() { @@ -1213,12 +1213,12 @@ impl App { let t = ui.input(|i| i.time) as f32; ui.painter().circle_filled(r.center(), 4.5, Color32::from_rgb(0xfc, 0x2c, 0x3e).gamma_multiply(0.6 + 0.4 * (t * 3.0).sin().abs())); let secs = since.elapsed().as_secs(); - ui.label(RichText::new(format!("{who} 正在觀看並學習 {:02}:{:02}", secs / 60, secs % 60)).size(FONT_SM).strong()); + ui.label(RichText::new(format!("{who} 正在觀看並學習 {:02}:{:02}", secs / 60, secs % 60)).size(FONT_SM).strong().family(crate::bold())); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { if ui.add(egui::Button::new(RichText::new(crate::i18n::t("取消")).size(FONT_XS)).corner_radius(14)).clicked() { cancel = true; } - if ui.add(egui::Button::new(RichText::new(crate::i18n::t("完成")).size(FONT_XS).strong().color(p.on_primary)).fill(p.primary).corner_radius(14)).clicked() { + if ui.add(egui::Button::new(RichText::new(crate::i18n::t("完成")).size(FONT_XS).strong().family(crate::bold()).color(p.on_primary)).fill(p.primary).corner_radius(14)).clicked() { finish = true; } }); @@ -1248,7 +1248,7 @@ impl App { } /// An on/off switch (the original's toggle, size md). -fn toggle(on: &mut bool) -> impl egui::Widget + '_ { +pub(super) fn toggle(on: &mut bool) -> impl egui::Widget + '_ { move |ui: &mut egui::Ui| -> egui::Response { let size = vec2(36.0, 20.0); let (rect, mut r) = ui.allocate_exact_size(size, egui::Sense::click()); diff --git a/src/app/files_ui.rs b/src/app/files_ui.rs index f95828b..f1d50b8 100644 --- a/src/app/files_ui.rs +++ b/src/app/files_ui.rs @@ -222,7 +222,7 @@ impl App { ui.horizontal(|ui| { ui.vertical(|ui| { ui.spacing_mut().item_spacing.y = 2.0; - ui.add(egui::Label::new(RichText::new(&fv.name).size(14.0).strong().color(p.text)).truncate()); + ui.add(egui::Label::new(RichText::new(&fv.name).size(14.0).strong().family(crate::bold()).color(p.text)).truncate()); let sub = match &fv.preview { Preview::Table(s) => format!("{} {}", s.get(fv.sheet).map(|x| x.1.len().saturating_sub(1)).unwrap_or(0), t("列")), Preview::Pdf => match fv.job.as_ref().map(|j| j.lock().unwrap().total) { diff --git a/src/app/markdown_ui.rs b/src/app/markdown_ui.rs index b4cd479..5320e66 100644 --- a/src/app/markdown_ui.rs +++ b/src/app/markdown_ui.rs @@ -534,6 +534,10 @@ impl App { strikes.push(chars..chars + n); } chars += n; + // A font with a real bold weight sets bold words and headings in it. + if (heading || s.bold) && !s.code && crate::has_bold() { + fmt.font_id.family = crate::bold(); + } let mut twin = fmt.clone(); if !(heading || s.bold) { twin.color = Color32::TRANSPARENT; @@ -546,7 +550,7 @@ impl App { } job.wrap.max_width = ui.available_width(); bold_job.wrap.max_width = job.wrap.max_width; - let any_bold = heading || spans.iter().any(|s| s.bold); + let any_bold = !crate::has_bold() && (heading || spans.iter().any(|s| s.bold)); let galley = ui.fonts_mut(|f| f.layout_job(job.clone())); let label = egui::Label::new(job).sense(if ranges.is_empty() { egui::Sense::hover() } else { egui::Sense::click() }); let resp = ui.add(label); @@ -613,7 +617,7 @@ impl App { ui.add(egui::Label::new(RichText::new(label).size(12.0).color(p.text2)).wrap()); // A long value (a phrase, not a number) a size smaller, so it doesn't fill the tile. let size = if value.chars().count() > 10 { 15.0 } else { 20.0 }; - ui.add(egui::Label::new(RichText::new(value).size(size).strong().color(p.text)).wrap()); + ui.add(egui::Label::new(RichText::new(value).size(size).strong().family(crate::bold()).color(p.text)).wrap()); if !note.is_empty() { ui.add(egui::Label::new(RichText::new(note).size(11.5).color(p.text3)).wrap()); } @@ -642,7 +646,7 @@ impl App { }; let mut t = RichText::new(name).size(TRANSCRIPT_FONT).color(c); if *st == crate::pages::Step::Now { - t = t.strong(); + t = t.strong().family(crate::bold()); } ui.add(egui::Label::new(t).wrap()); if !note.is_empty() { @@ -689,7 +693,7 @@ impl App { Frame::new().fill(edge.gamma_multiply(0.10)).corner_radius(8).inner_margin(Margin { left: 16, right: 12, top: 10, bottom: 10 }).show(ui, |ui| { ui.set_width(ui.available_width()); ui.spacing_mut().item_spacing.y = 0.0; - ui.label(RichText::new(title).size(12.5).strong().color(edge)); + ui.label(RichText::new(title).size(12.5).strong().family(crate::bold()).color(edge)); ui.add_space(4.0); for (i, b) in inner.iter().enumerate() { if i > 0 { diff --git a/src/app/memory_ui.rs b/src/app/memory_ui.rs index df1b9b4..2382cd5 100644 --- a/src/app/memory_ui.rs +++ b/src/app/memory_ui.rs @@ -399,7 +399,7 @@ impl App { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 4.0; ui.label(RichText::new(t(label)).size(FONT_SM).color(p.text3)); - ui.label(RichText::new(v.to_string()).size(FONT_SM).strong().color(p.text)); + ui.label(RichText::new(v.to_string()).size(FONT_SM).strong().family(crate::bold()).color(p.text)); }); } }); diff --git a/src/app/mirror_ui.rs b/src/app/mirror_ui.rs index e3ea6de..d7dcda4 100644 --- a/src/app/mirror_ui.rs +++ b/src/app/mirror_ui.rs @@ -1360,7 +1360,7 @@ impl App { ui.set_max_width(TRANSCRIPT_MAX_WIDTH.min(ui.available_width() - 48.0)); Frame::new().fill(if connecting { p.hover } else { p.danger.gamma_multiply(0.08) }).corner_radius(8).inner_margin(Margin::symmetric(12, 8)).show(ui, |ui| { ui.vertical(|ui| { - ui.label(RichText::new(title).size(FONT_SM).strong().color(p.text)); + ui.label(RichText::new(title).size(FONT_SM).strong().family(crate::bold()).color(p.text)); for line in [reason, tail] { if !line.is_empty() { ui.add(egui::Label::new(RichText::new(line).size(FONT_SM).color(p.text2)).wrap()); diff --git a/src/app/pages_ui.rs b/src/app/pages_ui.rs index aeb932d..fea2e3b 100644 --- a/src/app/pages_ui.rs +++ b/src/app/pages_ui.rs @@ -23,7 +23,7 @@ impl App { // The page's beginning: the title, then a few lines fading out. Frame::new().inner_margin(Margin { left: 18, right: 18, top: 16, bottom: 12 }).show(ui, |ui| { ui.set_width(ui.available_width()); - ui.add(egui::Label::new(RichText::new(&page.title).size(17.0).strong().color(p.text)).wrap()); + ui.add(egui::Label::new(RichText::new(&page.title).size(17.0).strong().family(crate::bold()).color(p.text)).wrap()); ui.add_space(8.0); let lines = crate::pages::preview(&page, 4); let n = lines.len().max(1) as f32; @@ -88,7 +88,7 @@ impl App { let close = dialog(ctx, "page-view", "頁面", w, true, p, |ui| { dialog_body(ui, ("page-body", id), h, |ui| { ui.spacing_mut().item_spacing.y = 0.0; - ui.add(egui::Label::new(RichText::new(&shown.title).size(26.0).strong().color(p.text)).wrap()); + ui.add(egui::Label::new(RichText::new(&shown.title).size(26.0).strong().family(crate::bold()).color(p.text)).wrap()); ui.add_space(6.0); let mut meta = format!("{} · {} {}", bot_name, t("更新於"), crate::pages::when(shown.updated)); if cur.revision > 1 || old { diff --git a/src/app/panel_ui.rs b/src/app/panel_ui.rs index f7777f8..c7a90aa 100644 --- a/src/app/panel_ui.rs +++ b/src/app/panel_ui.rs @@ -66,7 +66,7 @@ impl App { self.edit_bot = Some((bot.clone(), false)); } ui.add_space(14.0); - ui.add(egui::Label::new(RichText::new(&bot.name).size(19.0).strong().color(p.text)).truncate()); + ui.add(egui::Label::new(RichText::new(&bot.name).size(19.0).strong().family(crate::bold()).color(p.text)).truncate()); if !bot.description.is_empty() { ui.add_space(3.0); ui.add(egui::Label::new(RichText::new(&bot.description).size(12.0).color(p.text3)).truncate()); diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs index b3a1dfa..375fc6e 100644 --- a/src/app/remote_ui.rs +++ b/src/app/remote_ui.rs @@ -182,7 +182,7 @@ impl App { ui.add_space(6.0); ui.separator(); ui.horizontal(|ui| { - ui.label(RichText::new(t("加一台電腦")).size(13.5).strong()); + ui.label(RichText::new(t("加一台電腦")).size(13.5).strong().family(crate::bold())); help_mark(ui, "讓另一台電腦當大腦的手腳:Mac、任何 Linux(含沒有螢幕的)、已登入的 Windows。貼上對應的那一行就會裝好並完成第一次配對,不用帳號密碼。它會在開機或登入後自動執行,只讓這個大腦使用。", p); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { if ui.add(secondary_button("產生配對碼")).clicked() { @@ -693,7 +693,7 @@ impl App { if !self.state.remote.host_token.is_empty() { setting_card(ui, p, |ui| { ui.horizontal(|ui| { - ui.label(RichText::new(t("大腦")).size(FONT_BASE).strong()); + ui.label(RichText::new(t("大腦")).size(FONT_BASE).strong().family(crate::bold())); help_mark(ui, "帳號裡選一台 AnyBot 當大腦(通常是跟帳號伺服器放在一起、一直開著的那台)。所有 Bot、聊天、記憶和例行任務都放在大腦上,由它思考和排程。其他電腦打開 AnyBot 看到的都是同一份,同時也是大腦的手腳:大腦的 Bot 可以透過裝置連結操作它們。大腦連不到時,這裡還能看之前的對話,但不能傳訊息,連回來就恢復。", p); }); let s = &self.state.remote; diff --git a/src/app/vault_ui.rs b/src/app/vault_ui.rs index 1c3f493..f898a72 100644 --- a/src/app/vault_ui.rs +++ b/src/app/vault_ui.rs @@ -126,7 +126,7 @@ impl App { let items = self.vault_items(); // Header: title and 「新項目」. ui.horizontal(|ui| { - ui.label(RichText::new(t("保險庫")).strong().size(FONT_XL)); + ui.label(RichText::new(t("保險庫")).strong().family(crate::bold()).size(FONT_XL)); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { let open = self.vault.dialog.is_some(); let b = ui.add_enabled(!open, primary_button("新項目", p)); diff --git a/src/app/welcome_ui.rs b/src/app/welcome_ui.rs index 3c995dd..2ade71b 100644 --- a/src/app/welcome_ui.rs +++ b/src/app/welcome_ui.rs @@ -19,7 +19,7 @@ impl App { ui.add_space((ui.available_height() * 0.12).clamp(24.0, 90.0)); ui.vertical_centered(|ui| { ui.set_max_width(w); - ui.label(RichText::new(t("歡迎使用 AnyBot")).size(26.0).strong().color(p.text)); + ui.label(RichText::new(t("歡迎使用 AnyBot")).size(26.0).strong().family(crate::bold()).color(p.text)); ui.add_space(4.0); ui.label(RichText::new(t("跟著下面的步驟,一分鐘就能開始聊天。")).size(FONT_BASE).color(p.text2)); ui.add_space(22.0); @@ -34,7 +34,7 @@ impl App { setting_card(ui, p, |ui| { ui.horizontal(|ui| { ui.spinner(); - ui.label(RichText::new(t("正在同步帳號裡的 Bot…")).strong()); + ui.label(RichText::new(t("正在同步帳號裡的 Bot…")).strong().family(crate::bold())); }); if !status.is_empty() { hint(ui, status, p); @@ -67,7 +67,7 @@ impl App { }); ui.add_space(6.0); setting_card(ui, p, |ui| { - ui.label(RichText::new(t("在別台電腦用過 AnyBot?")).strong()); + ui.label(RichText::new(t("在別台電腦用過 AnyBot?")).strong().family(crate::bold())); if signed_in { let note = self.rm.note.lock().unwrap().clone(); hint(ui, if note.is_empty() { "已登入帳號。帳號裡沒有別的 Bot,從上面建立第一個吧。".to_string() } else { note }, p); @@ -107,7 +107,7 @@ fn step(ui: &mut egui::Ui, p: Palette, n: u32, title: &str, done: bool, body: im let mark = if done { "✓".to_string() } else { n.to_string() }; ui.painter().text(r.center(), egui::Align2::CENTER_CENTER, mark, egui::FontId::proportional(13.0), if done { Color32::WHITE } else { p.on_primary }); ui.add_space(4.0); - ui.label(RichText::new(t(title)).size(FONT_BASE).strong().color(p.text)); + ui.label(RichText::new(t(title)).size(FONT_BASE).strong().family(crate::bold()).color(p.text)); }); ui.horizontal(|ui| { ui.add_space(32.0); diff --git a/src/main.rs b/src/main.rs index ea31860..2c5c343 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,6 +111,23 @@ pub const HUNINN: &[u8] = include_bytes!("../fonts/jf-openhuninn-2.1.ttf"); /// 思源黑體 (Noto Sans TC Regular, SIL OFL 1.1), bundled: plain, clear, the same on every computer. pub const NOTO_TC: &[u8] = include_bytes!("../fonts/NotoSansTC-Regular.otf"); +/// 思源黑體's bold weight, for titles, bold words and the main button of a choice. +pub const NOTO_TC_BOLD: &[u8] = include_bytes!("../fonts/NotoSansTC-Bold.otf"); + +/// The family bold text is set in (`RichText::family(bold())`, `FontId::new(size, bold())`). +/// With 思源黑體 it is the real bold weight; 粉圓體 and the system font have one weight here, so +/// it is the same font as the rest (see `has_bold`). +pub fn bold() -> egui::FontFamily { + egui::FontFamily::Name("bold".into()) +} + +static HAS_BOLD: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + +/// The chosen font has a real bold weight (else bold is drawn by other means, or not at all). +pub fn has_bold() -> bool { + HAS_BOLD.load(std::sync::atomic::Ordering::Relaxed) +} + /// "noto" (思源黑體, the default), "huninn" (粉圓體) or "system". pub fn font_choice() -> String { model::State::path().parent().and_then(|d| std::fs::read_to_string(d.join("font.txt")).ok()).map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).unwrap_or_else(|| "noto".into()) @@ -173,6 +190,15 @@ pub fn load_fonts(ctx: &egui::Context) { let at = mono.iter().position(|f| f == "cjk").unwrap_or(mono.len()); mono.insert(at, name.into()); } + // Bold: the same list with the bold weight in front, where there is one. + let mut heavy = fonts.families.get(&egui::FontFamily::Proportional).cloned().unwrap_or_default(); + let noto = font_choice() == "noto"; + if noto { + fonts.font_data.insert("noto-bold".into(), egui::FontData::from_static(NOTO_TC_BOLD).into()); + heavy.insert(0, "noto-bold".into()); + } + HAS_BOLD.store(noto, std::sync::atomic::Ordering::Relaxed); + fonts.families.insert(bold(), heavy); ctx.set_fonts(fonts); }