外觀: a real bold weight, and 設定 › 一般 as cards of rows

- 思源黑體 Bold is bundled next to Regular: titles, bold words and headings in replies, the chosen page and
  choice are set in it (粉圓體 and the system font keep their one weight; replies still fake bold there)
- 設定 › 一般 rearranged: 外觀, 記憶與文件, 通知, Bot, 帳戶 — each a card whose rows hold one thing, the name on the
  left and its control on the right, at most one small line under the name, the rest behind the ?
- choices are one segmented control everywhere on the page; switches instead of checkboxes; plain names
  (聊天的顏色, 用意思找記憶, Bot 可以翻的資料夾)
- the page list: the chosen page in ink, a yellow dot on 更新 when a newer build waits
- cards on the other pages take the same quiet fill and corners

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
This commit is contained in:
王性驊 2026-11-11 21:54:24 +08:00
parent 6a84abcaeb
commit f0b417f7cc
15 changed files with 298 additions and 177 deletions

BIN
fonts/NotoSansTC-Bold.otf Normal file

Binary file not shown.

View File

@ -146,6 +146,8 @@ pub struct App {
save_now: bool, save_now: bool,
/// 設定 › 一般 › 文件索引: the path being typed for a new folder. /// 設定 › 一般 › 文件索引: the path being typed for a new folder.
doc_new: String, 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). /// Turns that AnyBot stopping cut off, found at start (see resume_interrupted).
interrupted: Vec<crate::oplog::Interrupted>, interrupted: Vec<crate::oplog::Interrupted>,
last_tick: Instant, last_tick: Instant,
@ -351,6 +353,7 @@ impl App {
delivered: vec![], delivered: vec![],
save_now: false, save_now: false,
doc_new: String::new(), doc_new: String::new(),
doc_new_bad: false,
interrupted, interrupted,
last_tick: Instant::now(), last_tick: Instant::now(),
show_routines: None, show_routines: None,
@ -2522,7 +2525,7 @@ impl App {
} }
let right_w = bar.right() - right.min_rect().left(); let right_w = bar.right() - right.min_rect().left();
// Left: the bot's name, plain; a press opens the conversation's details. // 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 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 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)); 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); self.live_face(ui, bot.id, face, true);
ui.vertical(|ui| { ui.vertical(|ui| {
ui.add_space(22.0); 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() }; 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()); 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, ApprovalKind::Action | ApprovalKind::Handoff => None,
}; };
let mut answer = 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); ui.add_space(2.0);
let (head, detail) = reason.split_once(':').unwrap_or(("", reason.as_str())); let (head, detail) = reason.split_once(':').unwrap_or(("", reason.as_str()));
match note { match note {
@ -2630,7 +2633,7 @@ impl App {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let once = if kind == ApprovalKind::Action { "允許" } else { "允許這一次" }; let once = if kind == ApprovalKind::Action { "允許" } else { "允許這一次" };
ui.spacing_mut().button_padding = vec2(14.0, 7.0); 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); answer = Some(ApprovalAnswer::Once);
} }
let always = match kind { 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 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); let words = sidebar_ui::shorten_width(&at, &words, at.available_width() - 8.0, 13.5);
if waiting { 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 { } else {
chat_ui::shimmer(&mut at, &words, col.gamma_multiply(0.75), col, 13.5); 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.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.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(egui::Label::new(RichText::new(&instruction).size(13.5).color(p.text2)).wrap());
ui.add_space(8.0); ui.add_space(8.0);
// The screen, 16:10, with 「接管」 on it. // The screen, 16:10, with 「接管」 on it.
@ -3170,7 +3173,7 @@ impl App {
for name in crate::botbrowser::choices() { for name in crate::botbrowser::choices() {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let mut on = name == current; 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); let _ = crate::botbrowser::set_current(&name);
} }
if name == current { if name == current {
@ -3270,7 +3273,7 @@ impl App {
for r in &bot.routines { for r in &bot.routines {
setting_card(ui, p, |ui| { setting_card(ui, p, |ui| {
ui.horizontal(|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 { if r.paused {
ui.label(RichText::new(t("已暫停")).size(11.5).color(p.text3)); 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; ui.spacing_mut().item_spacing.y = 2.0;
use crate::icons::Icon; 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)] { 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); let on = self.settings_tab == tab || (tab == SettingsTab::General && self.settings_tab == SettingsTab::Remote);
if on || r.hovered() { 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); 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() { if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
self.settings_tab = tab; self.settings_tab = tab;
} }
@ -3695,93 +3703,33 @@ impl App {
ui.spacing_mut().item_spacing = vec2(8.0, 6.0); 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 { dialog_body(ui, ("settings-page", self.settings_tab as u8), page_h, |ui| match self.settings_tab {
SettingsTab::General => { SettingsTab::General => {
section(ui, "帳戶", p); // One thing a row, in plain words; what needs explaining is behind the ?.
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;
}
});
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 {
self.state.embed_model = match k {
"local" => String::new(),
other => other.to_string(),
};
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| {
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.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..]);
}
}
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); section(ui, "外觀", p);
setting_row(ui, p, "主題", "為 AnyBot 選擇淺色或深色外觀", |ui| { rows_card(ui, p, |ui| {
for (th, n) in [(Theme::System, "跟隨系統"), (Theme::Dark, "深色"), (Theme::Light, "淺色")] { card_row(ui, p, "主題", "", "", |ui| {
if ui.selectable_value(&mut self.state.theme, th, t(n)).clicked() { if let Some(th) = segmented(ui, p, self.state.theme, &[(Theme::Light, "淺色"), (Theme::Dark, "深色"), (Theme::System, "跟著系統")]) {
self.state.theme = th;
theme_changed = true; theme_changed = true;
} }
}
}); });
setting_row(ui, p, "強調色", "用 Bot 的顏色為 1:1 Bot 訊息和卡片上色,或保持黑色", |ui| { card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| {
for (a, n) in [(Accent::Black, "黑色"), (Accent::BotColor, "Bot 顏色")] { if let Some(a) = segmented(ui, p, self.state.accent, &[(Accent::BotColor, "跟著 Bot"), (Accent::Black, "只用黑色")]) {
if ui.selectable_value(&mut self.state.accent, a, t(n)).clicked() { self.state.accent = a;
self.dirty = true; self.dirty = true;
} }
}
}); });
setting_row(ui, p, "字型", "AnyBot 畫面使用的字型", |ui| { card_row(ui, p, "字型", "", "思源黑體有粗體;粉圓體和系統字型只有一種粗細。", |ui| {
let cur = crate::font_choice(); let cur = crate::font_choice();
for (v, n) in [("noto", "思源黑體"), ("system", "系統字型"), ("huninn", "粉圓體")] { if let Some(v) = segmented(ui, p, cur.as_str(), &[("noto", "思源黑體"), ("system", "系統字型"), ("huninn", "粉圓體")]) {
if ui.selectable_label(cur == v, t(n)).clicked() && cur != v {
if let Some(d) = State::path().parent() { if let Some(d) = State::path().parent() {
let _ = std::fs::create_dir_all(d); let _ = std::fs::create_dir_all(d);
let _ = std::fs::write(d.join("font.txt"), v); let _ = std::fs::write(d.join("font.txt"), v);
} }
crate::load_fonts(ctx); crate::load_fonts(ctx);
} }
}
}); });
setting_row(ui, p, "語言", "選擇 AnyBot 選單和 Bot 回答使用的語言", |ui| { 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 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() }; 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| { egui::ComboBox::from_id_salt("language").selected_text(shown).height(360.0).show_ui(ui, |ui| {
@ -3800,19 +3748,86 @@ impl App {
} }
}); });
}); });
if !matches!(crate::i18n::lang().as_str(), "zh-TW" | "zh-CN" | "en" | "ja") { });
hint(ui, "選單會用英文顯示;Bot 會用你選的語言回答。", p); section(ui, "記憶與文件", p);
} rows_card(ui, p, |ui| {
section(ui, "通知", p); // 用意思找記憶 (語意搜尋): 本機模型 (default) / Ollama / 關閉; how it is now is behind the ?.
setting_row(ui, p, "通知", "Bot 完成任務或等你處理時通知你", |ui| { let choice = match self.state.embed_model.trim() {
if ui.add(egui::Checkbox::without_text(&mut self.state.notify)).changed() { "" | "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(),
};
crate::embed::configure(&crate::embed::ollama_base(&self.state.provider(crate::providers::ProviderKind::Ollama).base_url), &self.state.embed_model);
self.dirty = true; self.dirty = true;
} }
}); });
hint(ui, "視窗不在最前面,或 90 秒沒有動鍵盤滑鼠,就會通知。登入帳號後也會推播到手機。", p); ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
setting_row(ui, p, "需要你時發出提示音", "Bot 要你允許某件事、或要你親自處理一個步驟時,響一聲(就算你正在看 AnyBot)", |ui| { 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() {
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.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 {
self.doc_new_bad = true;
}
}
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;
}
});
});
section(ui, "通知", p);
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; let before = self.state.alert_sound;
if ui.add(egui::Checkbox::without_text(&mut self.state.alert_sound)).changed() { if ui.add(computers_ui::toggle(&mut self.state.alert_sound)).changed() {
self.dirty = true; self.dirty = true;
// Turned on: let the person hear what it sounds like. // Turned on: let the person hear what it sounds like.
if !before { if !before {
@ -3820,25 +3835,35 @@ impl App {
} }
} }
}); });
});
section(ui, "Bot", p); section(ui, "Bot", p);
setting_row(ui, p, "時區", "設定 Bot 用於排程和提醒的時區", |ui| { rows_card(ui, p, |ui| {
if ui.add(egui::TextEdit::singleline(&mut self.state.timezone).desired_width(150.0)).changed() { let bad = self.state.timezone.parse::<chrono_tz::Tz>().is_err();
self.dirty = true; card_row(ui, p, "時區", if bad { "看不懂這個時區,請用像 Asia/Taipei 這樣的名稱" } else { "" }, "Bot 排例行任務和提醒時用的時區", |ui| {
}
if ui.add(secondary_button("用這台電腦的")).clicked() { if ui.add(secondary_button("用這台電腦的")).clicked() {
self.state.timezone = crate::routines::local_timezone(); self.state.timezone = crate::routines::local_timezone();
self.dirty = true; self.dirty = true;
} }
}); if ui.add(egui::TextEdit::singleline(&mut self.state.timezone).desired_width(150.0)).changed() {
if self.state.timezone.parse::<chrono_tz::Tz>().is_err() { self.dirty = true;
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() { 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()); crate::preview::reveal(&State::path());
} }
}); });
});
} }
SettingsTab::Updates => { SettingsTab::Updates => {
section(ui, "AnyBot 更新", p); section(ui, "AnyBot 更新", p);
@ -3980,7 +4005,7 @@ impl App {
ui.vertical(|ui| { ui.vertical(|ui| {
let k = self.settings_provider; let k = self.settings_provider;
let w = ui.available_width(); 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); hint(ui, k.key_help(), p);
ui.add_space(6.0); ui.add_space(6.0);
let ps = self.state.provider_mut(k); 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); crate::icons::paint(ui.painter(), r, icon, p.text2);
ui.vertical(|ui| { ui.vertical(|ui| {
ui.spacing_mut().item_spacing.y = 1.0; 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()) { if let Some(st) = v["subtitle"].as_str().filter(|x| !x.is_empty()) {
ui.label(RichText::new(st).size(FONT_XS).color(p.text3)); 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). /// A group heading inside a settings page (like the original's section titles).
fn section(ui: &mut egui::Ui, title: &str, p: Palette) { fn section(ui: &mut egui::Ui, title: &str, p: Palette) {
ui.add_space(14.0); ui.add_space(16.0);
ui.label(RichText::new(t(title)).size(FONT_SM).strong().color(p.text3)); ui.label(RichText::new(t(title)).size(FONT_LG).family(crate::bold()).color(p.text));
ui.add_space(2.0); ui.add_space(4.0);
} }
/// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no /// 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. /// 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<T: PartialEq + Copy>(ui: &mut egui::Ui, p: Palette, cur: T, options: &[(T, &str)]) -> Option<T> {
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)) { 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.set_width(ui.available_width());
ui.horizontal(|ui| { ui.horizontal(|ui| {
let w = (ui.available_width() * 0.5).max(180.0); 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) { fn setting_title(ui: &mut egui::Ui, title: &str, desc: &str, p: Palette) {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0; 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); help_mark(ui, desc, p);
}); });
ui.add_space(4.0); ui.add_space(4.0);
@ -5127,9 +5219,8 @@ fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) {
/// A rounded group of related settings, like a macOS settings card. /// A rounded group of related settings, like a macOS settings card.
fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R { fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
let r = Frame::new() let r = Frame::new()
.fill(p.hover.gamma_multiply(0.6)) .fill(card_fill(p))
.stroke(Stroke::new(1.0, p.border.gamma_multiply(0.6))) .corner_radius(16)
.corner_radius(12)
.inner_margin(Margin::symmetric(16, 14)) .inner_margin(Margin::symmetric(16, 14))
.show(ui, |ui| { .show(ui, |ui| {
ui.set_width(ui.available_width()); 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> { 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> { 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> { 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. /// 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| { Frame::new().inner_margin(Margin { left: 20, right: 12, top: 12, bottom: 12 }).show(ui, |ui| {
ui.set_width(ui.available_width()); ui.set_width(ui.available_width());
ui.horizontal(|ui| { 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)); ui.add_space((ui.available_width() - 28.0).max(0.0));
// Drawn, not a glyph: not every Chinese font has "✕". // Drawn, not a glyph: not every Chinese font has "✕".
let (rect, r) = ui.allocate_exact_size(vec2(28.0, 28.0), egui::Sense::click()); let (rect, r) = ui.allocate_exact_size(vec2(28.0, 28.0), egui::Sense::click());

View File

@ -191,7 +191,7 @@ impl App {
setting_card(ui, p, |ui| { setting_card(ui, p, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(RichText::new(c.kind.label()).size(FONT_XS).color(p.text2)); 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 st = statuses.get(&c.id);
let (col, text) = match st { let (col, text) = match st {
_ if !c.enabled => (p.text3, "已暫停".to_string()), _ if !c.enabled => (p.text3, "已暫停".to_string()),
@ -389,7 +389,7 @@ impl App {
ui.checkbox(&mut s.enabled, t("開啟")); ui.checkbox(&mut s.enabled, t("開啟"));
}, },
|ui| { |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()); let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
ui.painter().circle_filled(r.center(), 4.0, col); 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); 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| {
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 { if files > 0 {
ui.label(RichText::new(format!("{files} 檔")).size(11.0).color(p.accent)); ui.label(RichText::new(format!("{files} 檔")).size(11.0).color(p.accent));
} }
@ -513,7 +513,7 @@ impl App {
} }
}, },
|ui| { |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); 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); 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| {
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); 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| {
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); 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| {
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() { if e["header"].is_object() {
ui.label(RichText::new(t("要金鑰")).size(11.0).color(p.accent)); ui.label(RichText::new(t("要金鑰")).size(11.0).color(p.accent));
} }

View File

@ -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))); 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. // 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)); 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() { if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
picked = Some(i); picked = Some(i);

View File

@ -1071,13 +1071,13 @@ impl App {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover()); 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) }); 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} 正在操作你的電腦") }; 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| { 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() { if !held && ui.add(egui::Button::new(RichText::new(t("停止")).size(FONT_XS)).corner_radius(14)).clicked() {
stop_bot = Some(who.clone()); stop_bot = Some(who.clone());
} }
let label = if held { "交還給 Bot" } else { "取得控制權" }; 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; 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| { Frame::new().fill(p.elevated).corner_radius(10).inner_margin(Margin::symmetric(12, 8)).show(ui, |ui| {
ui.set_width(ui.available_width()); ui.set_width(ui.available_width());
ui.horizontal(|ui| { 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.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| { 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() { 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; 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())); 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(); 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| { 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() { if ui.add(egui::Button::new(RichText::new(crate::i18n::t("取消")).size(FONT_XS)).corner_radius(14)).clicked() {
cancel = true; 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; finish = true;
} }
}); });
@ -1248,7 +1248,7 @@ impl App {
} }
/// An on/off switch (the original's toggle, size md). /// 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 { move |ui: &mut egui::Ui| -> egui::Response {
let size = vec2(36.0, 20.0); let size = vec2(36.0, 20.0);
let (rect, mut r) = ui.allocate_exact_size(size, egui::Sense::click()); let (rect, mut r) = ui.allocate_exact_size(size, egui::Sense::click());

View File

@ -222,7 +222,7 @@ impl App {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.vertical(|ui| { ui.vertical(|ui| {
ui.spacing_mut().item_spacing.y = 2.0; 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 { 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::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) { Preview::Pdf => match fv.job.as_ref().map(|j| j.lock().unwrap().total) {

View File

@ -534,6 +534,10 @@ impl App {
strikes.push(chars..chars + n); strikes.push(chars..chars + n);
} }
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(); let mut twin = fmt.clone();
if !(heading || s.bold) { if !(heading || s.bold) {
twin.color = Color32::TRANSPARENT; twin.color = Color32::TRANSPARENT;
@ -546,7 +550,7 @@ impl App {
} }
job.wrap.max_width = ui.available_width(); job.wrap.max_width = ui.available_width();
bold_job.wrap.max_width = job.wrap.max_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 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 label = egui::Label::new(job).sense(if ranges.is_empty() { egui::Sense::hover() } else { egui::Sense::click() });
let resp = ui.add(label); 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()); 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. // 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 }; 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() { if !note.is_empty() {
ui.add(egui::Label::new(RichText::new(note).size(11.5).color(p.text3)).wrap()); 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); let mut t = RichText::new(name).size(TRANSCRIPT_FONT).color(c);
if *st == crate::pages::Step::Now { if *st == crate::pages::Step::Now {
t = t.strong(); t = t.strong().family(crate::bold());
} }
ui.add(egui::Label::new(t).wrap()); ui.add(egui::Label::new(t).wrap());
if !note.is_empty() { 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| { 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.set_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 0.0; 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); ui.add_space(4.0);
for (i, b) in inner.iter().enumerate() { for (i, b) in inner.iter().enumerate() {
if i > 0 { if i > 0 {

View File

@ -399,7 +399,7 @@ impl App {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0; ui.spacing_mut().item_spacing.x = 4.0;
ui.label(RichText::new(t(label)).size(FONT_SM).color(p.text3)); 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));
}); });
} }
}); });

View File

@ -1360,7 +1360,7 @@ impl App {
ui.set_max_width(TRANSCRIPT_MAX_WIDTH.min(ui.available_width() - 48.0)); 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| { 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.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] { for line in [reason, tail] {
if !line.is_empty() { if !line.is_empty() {
ui.add(egui::Label::new(RichText::new(line).size(FONT_SM).color(p.text2)).wrap()); ui.add(egui::Label::new(RichText::new(line).size(FONT_SM).color(p.text2)).wrap());

View File

@ -23,7 +23,7 @@ impl App {
// The page's beginning: the title, then a few lines fading out. // 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| { Frame::new().inner_margin(Margin { left: 18, right: 18, top: 16, bottom: 12 }).show(ui, |ui| {
ui.set_width(ui.available_width()); 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); ui.add_space(8.0);
let lines = crate::pages::preview(&page, 4); let lines = crate::pages::preview(&page, 4);
let n = lines.len().max(1) as f32; let n = lines.len().max(1) as f32;
@ -88,7 +88,7 @@ impl App {
let close = dialog(ctx, "page-view", "頁面", w, true, p, |ui| { let close = dialog(ctx, "page-view", "頁面", w, true, p, |ui| {
dialog_body(ui, ("page-body", id), h, |ui| { dialog_body(ui, ("page-body", id), h, |ui| {
ui.spacing_mut().item_spacing.y = 0.0; 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); ui.add_space(6.0);
let mut meta = format!("{} · {} {}", bot_name, t("更新於"), crate::pages::when(shown.updated)); let mut meta = format!("{} · {} {}", bot_name, t("更新於"), crate::pages::when(shown.updated));
if cur.revision > 1 || old { if cur.revision > 1 || old {

View File

@ -66,7 +66,7 @@ impl App {
self.edit_bot = Some((bot.clone(), false)); self.edit_bot = Some((bot.clone(), false));
} }
ui.add_space(14.0); 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() { if !bot.description.is_empty() {
ui.add_space(3.0); ui.add_space(3.0);
ui.add(egui::Label::new(RichText::new(&bot.description).size(12.0).color(p.text3)).truncate()); ui.add(egui::Label::new(RichText::new(&bot.description).size(12.0).color(p.text3)).truncate());

View File

@ -182,7 +182,7 @@ impl App {
ui.add_space(6.0); ui.add_space(6.0);
ui.separator(); ui.separator();
ui.horizontal(|ui| { 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); help_mark(ui, "讓另一台電腦當大腦的手腳:Mac、任何 Linux(含沒有螢幕的)、已登入的 Windows。貼上對應的那一行就會裝好並完成第一次配對,不用帳號密碼。它會在開機或登入後自動執行,只讓這個大腦使用。", p);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| { ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.add(secondary_button("產生配對碼")).clicked() { if ui.add(secondary_button("產生配對碼")).clicked() {
@ -693,7 +693,7 @@ impl App {
if !self.state.remote.host_token.is_empty() { if !self.state.remote.host_token.is_empty() {
setting_card(ui, p, |ui| { setting_card(ui, p, |ui| {
ui.horizontal(|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); help_mark(ui, "帳號裡選一台 AnyBot 當大腦(通常是跟帳號伺服器放在一起、一直開著的那台)。所有 Bot、聊天、記憶和例行任務都放在大腦上,由它思考和排程。其他電腦打開 AnyBot 看到的都是同一份,同時也是大腦的手腳:大腦的 Bot 可以透過裝置連結操作它們。大腦連不到時,這裡還能看之前的對話,但不能傳訊息,連回來就恢復。", p);
}); });
let s = &self.state.remote; let s = &self.state.remote;

View File

@ -126,7 +126,7 @@ impl App {
let items = self.vault_items(); let items = self.vault_items();
// Header: title and 「新項目」. // Header: title and 「新項目」.
ui.horizontal(|ui| { 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| { ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
let open = self.vault.dialog.is_some(); let open = self.vault.dialog.is_some();
let b = ui.add_enabled(!open, primary_button("新項目", p)); let b = ui.add_enabled(!open, primary_button("新項目", p));

View File

@ -19,7 +19,7 @@ impl App {
ui.add_space((ui.available_height() * 0.12).clamp(24.0, 90.0)); ui.add_space((ui.available_height() * 0.12).clamp(24.0, 90.0));
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.set_max_width(w); 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.add_space(4.0);
ui.label(RichText::new(t("跟著下面的步驟,一分鐘就能開始聊天。")).size(FONT_BASE).color(p.text2)); ui.label(RichText::new(t("跟著下面的步驟,一分鐘就能開始聊天。")).size(FONT_BASE).color(p.text2));
ui.add_space(22.0); ui.add_space(22.0);
@ -34,7 +34,7 @@ impl App {
setting_card(ui, p, |ui| { setting_card(ui, p, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.spinner(); ui.spinner();
ui.label(RichText::new(t("正在同步帳號裡的 Bot…")).strong()); ui.label(RichText::new(t("正在同步帳號裡的 Bot…")).strong().family(crate::bold()));
}); });
if !status.is_empty() { if !status.is_empty() {
hint(ui, status, p); hint(ui, status, p);
@ -67,7 +67,7 @@ impl App {
}); });
ui.add_space(6.0); ui.add_space(6.0);
setting_card(ui, p, |ui| { 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 { if signed_in {
let note = self.rm.note.lock().unwrap().clone(); let note = self.rm.note.lock().unwrap().clone();
hint(ui, if note.is_empty() { "已登入帳號。帳號裡沒有別的 Bot,從上面建立第一個吧。".to_string() } else { note }, p); 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() }; 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.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.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.horizontal(|ui| {
ui.add_space(32.0); ui.add_space(32.0);

View File

@ -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. /// 思源黑體 (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"); 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". /// "noto" (思源黑體, the default), "huninn" (粉圓體) or "system".
pub fn font_choice() -> String { 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()) 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()); let at = mono.iter().position(|f| f == "cjk").unwrap_or(mono.len());
mono.insert(at, name.into()); 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); ctx.set_fonts(fonts);
} }