design: 共用元件(kit.rs)+套用到設定與對話框——一種區段、群組、設定列、卡片,不再卡中卡

- 新增 src/app/kit.rs:區段、群組、設定列、卡片、欄位、說明、按鈕、分段選擇、對話框底部,
  檔頭寫明用法和規則(卡片裡不放卡片、一個畫面一顆實心按鈕);從 app.rs 搬出 14 個元件
- 電腦頁自己的那套(sec_title/sec_card/sec_row/sec_note)改成共用元件的別名:小標、列高、
  列間細線和其他設定頁一樣;拿掉 setting_row(瀏覽器設定檔的兩個選項不再是卡中卡,
  「更新」頁改成一組群組+「疑難排解」區段;版本號直接顯示在列上)
- 設定左邊的分頁:選中改成淡底加粗字(不再是黑色膠囊)
- 說明字 12 → 13 px(灰一階的 32 處、會換行的 8 處);hint、欄位小標也是 13
- 20 個寫死的語意色(四種綠、紅、橘)換成色板的 up/danger/attention;連結用強調色
- Bot 設定底部「團隊成員可以使用這個 Bot」一行,說明放進「?」(以前換行、勾選框錯位)
- 看守測試:寫死顏色上限 88 → 66;kit.rs 以外自己畫的「底色+外框」卡片只准變少(17)

已驗證: cargo test 518 全過(排版檢查、規格比對、看守)、clippy 21=基線;設定 › 一般/電腦/
整合、Bot 設定、例行任務、右側面板截圖目視
未驗證: 使用者機器上的實際視窗
This commit is contained in:
王性驊 2026-11-16 22:07:07 +08:00
parent 7b1ec67754
commit 58413d8580
17 changed files with 327 additions and 318 deletions

View File

@ -1910,6 +1910,19 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- 中文和英文用同一套字型(介面思源黑體、閱讀思源宋體),基準線和大小對得齊;缺的字用系統字型(蘋方等)補。程式碼用 **SF Mono**,沒有就用 Menlo。
- 「·」分隔號前後不加空格。
### 共用元件(`src/app/kit.rs`)
每個設定頁、對話框都用同一組元件,不自己畫框:
- **區段**:13 px 灰色粗體小標,上方 24、下方 8(每個設定頁一樣;以前「電腦」頁的小標是另一種淡灰細字)。
- **群組**:一張卡(細框、圓角 14)裝一組設定列,列與列之間一條細線。
- **設定列**:左邊名稱 14 px(可以多一行 13 px 灰色狀態)和「?」說明,右邊開關、選單或按鈕;名稱太長就「…」,不會擠掉右邊。
- **卡片**:一整塊有標題、有欄位的內容(Bot 設定的「Bot 資料」「頭像」等)。**卡片裡不再放卡片**(以前「瀏覽器設定檔」裡的兩個選項各自是一張小卡;「更新」頁每一列都是一張卡)。
- **欄位**:上面 13 px 灰色小標,下面輸入框。**說明**:13 px 灰字(以前 12 px 更淡的灰)。
- **按鈕**:實心(一個畫面一顆主要動作)、淡底、紅色;刪除這種不能回頭的按兩次。
- 設定左邊的分頁:選中的是淡底加粗字(以前是一整顆黑色膠囊)。
- 測試看守:畫面程式裡自己畫的「底色+外框」卡片只准變少(`kit.rs` 以外)。
### 讀的文字(回答和頁面,像 Notion 的文件)
- 段落之間 12(頁面 16)px;標題上方留得比下方多(# 22、## 18、### 16 粗)。

View File

@ -8,7 +8,7 @@
- 搜尋「搜尋 Bot 和訊息」:上面列名字或描述相符的 Bot,下面「訊息」列你和 Bot 說過的話和附件檔名(含過去的對話,最多 40 筆),點一筆就捲到那則訊息。
- Bot 選單:「釘選」/「取消釘選」、「移至」、「標示為已讀」/「標示為未讀」、「設為主要 Bot」、「編輯 Bot…」、「記憶…」、「開始新對話」、「過去的對話」、「分享與匯出」(「匯出 Bot(分享給別人)…」「匯出文字記錄…」「匯入 Bot…」「複製對話 ID」)、「重新啟動這個 Bot」、「清除聊天記錄」、「刪除」。
- 建立:「新增 Bot」,或「從範本建立」(研究助理、寫作夥伴、電腦助手、客服助理、開發助手)。新 Bot 沿用目前選中 Bot 的供應商和模型,電腦工具關著。
- 「Bot 設定」:「Bot 資料」(「Bot 名稱」「Bot 描述」和大頭像,同一張卡);「個人檔案」(Soul 與指示、擅長(什麼事找它)、不找它做的事);「頭像」(14 種形狀平均排成兩列;10 種顏色和「自訂」同一列;按「自訂」出現一格一格的色盤——12 個色相各四種深淺加一列灰階,直接點,沒有滑桿——和「色碼」欄,打完整的 #rrggbb 才換色);「AI 供應商與模型」(供應商、「模型名稱」、「選擇」、「執行步驟用的模型」、「思考模式」);「電腦操作」;「能力」;「技能」;「記憶」;最下面「釘選到側邊欄」「團隊成員可以使用這個 Bot(看得到它的聊天、頁面和檔案)」。
- 「Bot 設定」:「Bot 資料」(「Bot 名稱」「Bot 描述」和大頭像,同一張卡);「個人檔案」(Soul 與指示、擅長(什麼事找它)、不找它做的事);「頭像」(14 種形狀平均排成兩列;10 種顏色和「自訂」同一列;按「自訂」出現一格一格的色盤——12 個色相各四種深淺加一列灰階,直接點,沒有滑桿——和「色碼」欄,打完整的 #rrggbb 才換色);「AI 供應商與模型」(供應商、「模型名稱」、「選擇」、「執行步驟用的模型」、「思考模式」);「電腦操作」;「能力」;「技能」;「記憶」;最下面「釘選到側邊欄」「團隊成員可以使用這個 Bot」(「?」說明:團隊成員看得到它的聊天、頁面和檔案)。
- Soul 與指示只有它自己讀;描述、擅長、不找它做的事、會的技能、在哪幾台電腦做事會寫進其他 Bot 的同事名冊。
- 能力 11 類:「上網」「瀏覽器」「看螢幕與操作」「檔案與指令」「Mac App」「連接器」「電話、簡訊、X」「例行任務」「頁面」「和其他 Bot 合作」「管理 App」。沒勾的工具不提供給它,也不寫進說明。記憶、技能、問你問題、傳檔案到聊天、表情和卡片每個 Bot 都有。
- 供應商:xAI Grok、OpenAI、Claude、Google Gemini、OpenRouter、OpenCode Go、Ollama(本機)、自訂(OpenAI 相容),每個 Bot 各選各的。

View File

@ -23,6 +23,8 @@ use crate::i18n::t;
use crate::theme::{is_dark, Palette, LIGHT};
mod attach_ui;
mod kit;
use kit::*;
mod channels_ui;
mod computers_ui;
mod screens_ui;
@ -3400,7 +3402,7 @@ impl App {
});
}
if self.meeting_on() {
let red = Color32::from_rgb(0xfc, 0x2c, 0x3e);
let red = p.danger;
if crate::icons::pill(&mut right, crate::icons::Icon::Record, &t("正在錄會議 · 結束"), red, Color32::WHITE, 36.0).on_hover_text(t("停止錄音,轉成文字記錄")).clicked() {
let ctx = right.ctx().clone();
self.voice_toggle(&ctx, bot.id);
@ -3461,7 +3463,7 @@ impl App {
ui.add_space(6.0);
ui.label(RichText::new(format!("{} · {}", bot.provider.label(), bot.model)).size(FONT_XS).color(p.text3));
if bot.tools_enabled {
ui.add(egui::Label::new(RichText::new(format!("可以在「{}」裡查看、修改檔案和執行指令,動手前會先問你", bot.workdir)).size(FONT_XS).color(p.text3)).wrap());
ui.add(egui::Label::new(RichText::new(format!("可以在「{}」裡查看、修改檔案和執行指令,動手前會先問你", bot.workdir)).size(FONT_SM).color(p.text3)).wrap());
}
let ps = self.state.provider(bot.provider);
if bot.provider.needs_key() && providers::resolve_key(bot.provider, &ps.api_key).is_empty() {
@ -3590,7 +3592,7 @@ impl App {
egui::ScrollArea::vertical().id_salt(("ask-dock", bot.id)).max_height(body).min_scrolled_height(body).auto_shrink([false, false]).show(ui, |ui| {
answer = self.approval_body(ui, bot, true);
ui.add_space(2.0);
ui.label(RichText::new(t("輸入框空著時:Enter 允許,Esc 拒絕")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("輸入框空著時:Enter 允許,Esc 拒絕")).size(FONT_SM).color(p.text2));
});
});
ui.add_space(6.0);
@ -3658,13 +3660,13 @@ impl App {
ui.set_width(ui.available_width());
egui::ScrollArea::vertical().id_salt(("ask-dock", bot.id, call_id.clone())).max_height(body).min_scrolled_height(body).auto_shrink([false, false]).show(ui, |ui| {
if qs.len() > 1 {
ui.label(RichText::new(format!("{} 問你 · {}/{}", bot.name, step + 1, qs.len())).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("{} 問你 · {}/{}", bot.name, step + 1, qs.len())).size(FONT_SM).color(p.text2));
} else {
ui.label(RichText::new(format!("{} 問你", bot.name)).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("{} 問你", bot.name)).size(FONT_SM).color(p.text2));
}
ui.add(egui::Label::new(RichText::new(&q.question).strong().family(crate::bold()).size(FONT_READ)).wrap());
if q.multiple {
ui.label(RichText::new(t("可以選好幾個")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("可以選好幾個")).size(FONT_SM).color(p.text2));
}
ui.add_space(6.0);
let typed_id = egui::Id::unique(("ask-typed", bot.id, &call_id, step));
@ -4056,7 +4058,7 @@ impl App {
let (r, _) = ui.allocate_exact_size(vec2(3.0, 18.0), egui::Sense::hover());
ui.painter().rect_filled(r, R_S, p.accent);
let short: String = q.lines().next().unwrap_or("").chars().take(60).collect();
ui.label(RichText::new(format!("{}{short}…", t("引用:"))).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("{}{short}…", t("引用:"))).size(FONT_SM).color(p.text2));
if ui.add(egui::Button::new(RichText::new("×").size(FONT_SM).color(p.text3)).frame(false)).clicked() {
self.quoting.remove(&bot.id);
}
@ -4150,7 +4152,7 @@ impl App {
self.model_picker(ui, bot);
} else {
let names: Vec<String> = bot.members.iter().filter_map(|m| self.state.bot(*m)).map(|b| b.name.clone()).collect();
ui.label(RichText::new(format!("{}{}", t("成員:"), names.join("、"))).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("{}{}", t("成員:"), names.join("、"))).size(FONT_SM).color(p.text2));
}
});
ui.allocate_ui_with_layout(vec2(text_w, box_h), Layout::top_down(Align::Min), |ui| {
@ -4190,7 +4192,7 @@ impl App {
// No voice set up: no 語音聊天, just the send arrow, resting.
round_tool(ui, crate::icons::Icon::ArrowUp, p.active, p.text3).on_hover_text(t("輸入訊息後傳送"));
} else {
let fill = if in_call { Color32::from_rgb(0xfc, 0x2c, 0x3e) } else { colour };
let fill = if in_call { p.danger } else { colour };
let tip = match call {
Some((id, phase)) if id == bot.id => format!("{} · {}", t(phase.label()), t("結束通話")),
_ => t("發起語音聊天"),
@ -4207,7 +4209,7 @@ impl App {
if let Some(started) = self.voice_recording(bot.id) {
let secs = started.elapsed().as_secs();
let tt = ui.input(|i| i.time) as f32;
let red = Color32::from_rgb(0xfc, 0x2c, 0x3e);
let red = p.danger;
let fill = red.gamma_multiply(0.75 + 0.25 * (tt * 3.0).sin().abs());
if crate::icons::pill(ui, crate::icons::Icon::Record, &format!("{:02}:{:02}", secs / 60, secs % 60), fill, Color32::WHITE, 28.0).on_hover_text(crate::i18n::t("停止錄音並轉成文字")).clicked() {
self.voice_toggle(ctx, bot.id);
@ -4238,14 +4240,14 @@ impl App {
self.notice = None;
}
ui.with_layout(Layout::left_to_right(Align::Center).with_main_wrap(true), |ui| {
ui.add(egui::Label::new(RichText::new(n).size(FONT_XS).color(p.accent)).wrap());
ui.add(egui::Label::new(RichText::new(n).size(FONT_SM).color(p.accent)).wrap());
});
});
}
if !queued.is_empty() {
let first: String = queued.last().unwrap().chars().take(30).collect();
let more = if queued.len() > 1 { format!(" 等 {} 則", queued.len()) } else { String::new() };
ui.add(egui::Label::new(RichText::new(format!("已排入「{first}」{more},Bot 會在下一步看到")).size(FONT_XS).color(p.accent)).wrap());
ui.add(egui::Label::new(RichText::new(format!("已排入「{first}」{more},Bot 會在下一步看到")).size(FONT_SM).color(p.accent)).wrap());
}
});
ui.add_space(10.0);
@ -4296,12 +4298,12 @@ impl App {
ui.label(RichText::new(t("需要 Chrome、Brave、Edge、Chromium 或 Firefox 才能用 AnyBot 自己的瀏覽器。")).size(FONT_XS).color(p.text3));
return;
}
setting_row(ui, p, "做完就關掉瀏覽器", "Bot 做完一件事,就把它用過的瀏覽器視窗整個關掉(登入都還在,下次會再打開);別的 Bot 還在用的不關", |ui| {
card_row(ui, p, "做完就關掉瀏覽器", "", "Bot 做完一件事,就把它用過的瀏覽器視窗整個關掉(登入都還在,下次會再打開);別的 Bot 還在用的不關", |ui| {
if ui.add(egui::Checkbox::without_text(&mut self.state.close_browsers_when_done)).changed() {
self.dirty = true;
}
});
setting_row(ui, p, "發布前檢查", "Bot 在瀏覽器送出留言、貼文或訊息前,先請另一個模型照規則看一遍(簡體字、AI 腔、帳號規則);沒通過就不送,告訴 Bot 哪裡要改", |ui| {
card_row(ui, p, "發布前檢查", "", "Bot 在瀏覽器送出留言、貼文或訊息前,先請另一個模型照規則看一遍(簡體字、AI 腔、帳號規則);沒通過就不送,告訴 Bot 哪裡要改", |ui| {
if ui.add(egui::Checkbox::without_text(&mut self.state.send_check)).changed() {
self.dirty = true;
}
@ -4380,7 +4382,7 @@ impl App {
ui.horizontal(|ui| {
// (Under the name, past the radio button.)
ui.add_space(26.0);
ui.label(RichText::new(text).size(FONT_XS).color(p.text2));
ui.label(RichText::new(text).size(FONT_SM).color(p.text2));
});
}
ui.add_space(4.0);
@ -4400,7 +4402,7 @@ impl App {
let note = self.browser_note.lock().unwrap().clone();
if !note.is_empty() {
// (A one-line label in a wrapped ui expands past the card: give it the card's width.)
ui.label(RichText::new(sidebar_ui::shorten_width(ui, &note, ui.available_width() - 2.0, 11.5)).size(FONT_XS).color(p.text2));
ui.label(RichText::new(sidebar_ui::shorten_width(ui, &note, ui.available_width() - 2.0, 11.5)).size(FONT_SM).color(p.text2));
}
// (egui's own wrapping uses the style's fixed wrap width, not this column's, and breaks
// only at spaces — a long CJK run with no spaces runs past the card. Break the text to
@ -4472,7 +4474,7 @@ impl App {
}
hint(ui, r.prompt.clone(), p);
if r.target_sends > 0 {
ui.label(RichText::new(appctl::target_words(r)).size(FONT_XS).color(p.text2));
ui.label(RichText::new(appctl::target_words(r)).size(FONT_SM).color(p.text2));
}
// Why AnyBot paused it, and how its latest runs went (the newest first).
if r.paused && !r.paused_why.is_empty() {
@ -4496,7 +4498,7 @@ impl App {
if r.runs.len() > 1 {
egui::CollapsingHeader::new(RichText::new(format!("{}({})", t("執行紀錄"), r.runs.len())).size(FONT_XS).color(p.text3)).id_salt(("routine-runs", bot.id, r.id)).show(ui, |ui| {
for run in r.runs.iter().rev() {
ui.label(RichText::new(crate::routines::describe_run(run, &r.schedule.timezone)).size(FONT_XS).color(p.text2));
ui.label(RichText::new(crate::routines::describe_run(run, &r.schedule.timezone)).size(FONT_SM).color(p.text2));
evidence(ui, run);
}
});
@ -4641,7 +4643,7 @@ impl App {
avatar::avatar(ui, 64.0, &b.shape, avatar::color(&b.color));
ui.vertical(|ui| {
let w = ui.available_width();
ui.label(RichText::new(t("Bot 名稱")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("Bot 名稱")).size(FONT_SM).color(p.text2));
ui.add(egui::TextEdit::singleline(&mut b.name).desired_width(w));
field_label(ui, "Bot 描述", p);
// (Two lines that wrap: a description is a sentence, not a name.)
@ -4817,7 +4819,7 @@ impl App {
hint(ui, "在它自己的電腦上可以自由做事(看不到你的檔案);在你的電腦上,改檔案和會改變東西的指令會先問你。密碼和金鑰檔一律不碰。", p);
if !b.allow_rules.is_empty() {
ui.add_space(6.0);
ui.label(RichText::new(t("已設定「一律允許」")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("已設定「一律允許」")).size(FONT_SM).color(p.text2));
let mut remove = None;
ui.horizontal_wrapped(|ui| {
for (i, g) in b.allow_rules.iter().enumerate() {
@ -4887,7 +4889,12 @@ impl App {
ui.with_layout(Layout::top_down(Align::Min), |ui| {
ui.spacing_mut().item_spacing.y = 4.0;
ui.checkbox(&mut b.pinned, t("釘選到側邊欄"));
ui.checkbox(&mut b.team, t("團隊成員可以使用這個 Bot(看得到它的聊天、頁面和檔案)"));
// (One line: what it lets teammates see is in the 「?」, not a wrapping label.)
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0;
ui.checkbox(&mut b.team, t("團隊成員可以使用這個 Bot"));
help_mark(ui, "團隊成員看得到它的聊天、頁面和檔案", p);
});
});
});
});
@ -4958,9 +4965,9 @@ impl App {
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, R_M, if on { p.primary } else { p.hover });
ui.painter().rect_filled(rect, R_M, if on { p.active } else { p.hover });
}
let col = if on { p.on_primary } else { p.text };
let col = if on { p.text } else { p.text2 };
let _ = icon;
let font = if on { egui::FontId::new(FONT_BASE, crate::bold()) } else { egui::FontId::proportional(FONT_BASE) };
ui.painter().text(rect.left_center() + vec2(12.0, 0.0), egui::Align2::LEFT_CENTER, t(name), font, col);
@ -5203,31 +5210,37 @@ impl App {
}
SettingsTab::Updates => {
section(ui, "AnyBot 更新", p);
setting_row(ui, p, "版本", &crate::version::full(self.exe_built), |ui| {
rows_card(ui, p, |ui| {
card_row(ui, p, "版本", &crate::version::full(self.exe_built), "", |ui| {
if let Some(tm) = self.newer_build {
ui.label(RichText::new(format!("{}{}", t("有更新的版本:"), crate::version::time_label(Some(tm)))).size(FONT_XS).color(p.accent));
} else {
ui.label(RichText::new(t("已是最新版本")).size(FONT_XS).color(p.text3));
}
});
setting_row(ui, p, "自動更新", "在你離開時自動換成新版本,你的 Bot 和工作都會保留", |ui| {
card_row(ui, p, "自動更新", "", "在你離開時自動換成新版本,你的 Bot 和工作都會保留", |ui| {
if ui.add(egui::Checkbox::without_text(&mut self.state.auto_update_when_away)).changed() {
self.dirty = true;
}
});
hint(ui, "螢幕鎖定或螢幕保護程式開著、10 分鐘沒動作、而且沒有 Bot 在工作時,才會自己換成新版本。", p);
setting_row(ui, p, "園丁報告", "平日早上有例行任務失敗或走冤枉路、週一有例行任務太耗時,就在主要 Bot 的聊天裡說一聲;沒事不說", |ui| {
card_row(ui, p, "園丁報告", "", "平日早上有例行任務失敗或走冤枉路、週一有例行任務太耗時,就在主要 Bot 的聊天裡說一聲;沒事不說", |ui| {
if ui.add(egui::Checkbox::without_text(&mut self.state.garden_reports)).changed() {
self.dirty = true;
}
});
});
ui.add_space(crate::theme::sp::S2);
hint(ui, "螢幕鎖定或螢幕保護程式開著、10 分鐘沒動作、而且沒有 Bot 在工作時,才會自己換成新版本。", p);
self.improvements_section(ui, p);
setting_row(ui, p, "重新啟動", "App 不太對勁時用:進行中的工作會停下,聊天記錄都會保留", |ui| {
section(ui, "疑難排解", p);
rows_card(ui, p, |ui| {
card_row(ui, p, "重新啟動", "", "App 不太對勁時用:進行中的工作會停下,聊天記錄都會保留", |ui| {
let label = if self.relaunching { "正在重新啟動…" } else { "重新啟動 AnyBot" };
if ui.add_enabled(!self.relaunching, secondary_button(label)).clicked() {
relaunch = true;
}
});
});
}
SettingsTab::Voice => {
egui::ScrollArea::vertical().id_salt("voice-settings").auto_shrink([false, false]).max_height(page_h - 60.0).show(ui, |ui| self.voice_settings(ui));
@ -5347,7 +5360,7 @@ impl App {
}
let dot = rect.left_center() + vec2(14.0, 0.0);
if ready {
ui.painter().circle_filled(dot, 4.0, Color32::from_rgb(0x2e, 0xa0, 0x43));
ui.painter().circle_filled(dot, 4.0, p.up);
} else {
ui.painter().circle_stroke(dot, 3.5, Stroke::new(1.2, p.text3));
}
@ -6805,53 +6818,7 @@ fn pill_icon(ui: &mut egui::Ui, icon: crate::icons::Icon, p: Palette) -> egui::R
r.on_hover_cursor(egui::CursorIcon::PointingHand)
}
/// 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(16.0);
ui.horizontal(|ui| {
ui.add_space(4.0);
ui.label(RichText::new(t(title)).size(FONT_XS).family(crate::bold()).color(p.text2));
});
ui.add_space(2.0);
}
/// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no
/// waiting for the pointer to be still), and a click keeps it open until the next click.
fn help_mark(ui: &mut egui::Ui, text: &str, p: Palette) {
if text.trim().is_empty() {
return;
}
let (rect, r) = ui.allocate_exact_size(vec2(18.0, 18.0), egui::Sense::click());
let pinned_id = r.id.with("pinned");
let mut pinned = ui.ctx().data(|d| d.get_temp::<bool>(pinned_id)).unwrap_or(false);
if r.clicked() {
pinned = !pinned;
} else if pinned && ui.input(|i| i.pointer.any_pressed()) && !r.hovered() {
pinned = false;
}
ui.ctx().data_mut(|d| d.insert_temp(pinned_id, pinned));
let show = r.hovered() || pinned;
let col = if show { p.text } else { p.text3 };
ui.painter().circle_stroke(rect.center(), 6.5, Stroke::new(1.1, col));
// (A glyph sized to its 14 px ring, an icon rather than text on the type scale.)
const HELP_GLYPH: f32 = 10.0;
ui.painter().text(rect.center() + vec2(0.0, 0.5), egui::Align2::CENTER_CENTER, "?", egui::FontId::proportional(HELP_GLYPH), col);
if show {
let text = t(text);
egui::Area::new(r.id.with("help"))
.order(egui::Order::Tooltip)
.fixed_pos(rect.left_bottom() + vec2(-4.0, 6.0))
.constrain(true)
.interactable(false)
.show(ui.ctx(), |ui| {
Frame::popup(ui.style()).corner_radius(R_M).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| {
ui.set_max_width(300.0);
ui.add(egui::Label::new(RichText::new(text).size(FONT_SM).color(p.text)).wrap());
});
});
}
r.on_hover_cursor(egui::CursorIcon::Help);
}
/// One setting: its name (with「?」for the explanation) on the left, its control on the right.
/// The pages inside a settings page (設定 › 整合: 訊息管道, 連接器, 技能): words on a hairline, the
@ -6880,105 +6847,11 @@ fn sub_tabs(ui: &mut egui::Ui, p: Palette, cur: &mut u8, names: &[&str]) {
}
}
/// 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(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(R_L).inner_margin(Margin::symmetric(16, 1)).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_BASE).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_BASE).color(p.text)).truncate());
help_mark(ui, help, p);
});
left.add(egui::Label::new(RichText::new(t(sub)).size(FONT_SM).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(R_M).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(R_M).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).stroke(Stroke::new(1.0, p.border)).corner_radius(R_L).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
// (The words column must leave room for the controls: the old 180px floor pushed
// wide button groups past the card's right edge in a narrow window, and the
// right-to-left column overflowed left, shoving the rows below out of place.)
let avail = ui.available_width();
let w = (avail * 0.5).max(140.0).min((avail - 170.0).max(90.0));
ui.horizontal(|ui| {
ui.set_width(w);
ui.spacing_mut().item_spacing.x = 4.0;
let cut = sidebar_ui::shorten_width(ui, &t(label), (w - 20.0).max(40.0), FONT_BASE);
ui.label(RichText::new(cut).size(FONT_BASE).color(p.text));
help_mark(ui, desc, p);
});
// (Wide button groups wrap to a second line inside the card, never past its edge.)
ui.with_layout(Layout::right_to_left(Align::Center).with_main_wrap(true), |ui| {
ui.horizontal(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().family(crate::bold()).size(FONT_BASE));
help_mark(ui, desc, p);
});
ui.add_space(4.0);
}
/// Small grey text under a setting.
fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) {
ui.add(egui::Label::new(RichText::new(t(&text.into())).size(FONT_XS).color(p.text3)).wrap());
}
/// 自訂顏色, to click rather than drag: `avatar::custom_swatches` as a grid as wide as the card
/// (twelve across, square cells), then a 色碼 box for an exact colour. Writes `color` only on a
@ -7009,7 +6882,7 @@ fn avatar_color_grid(ui: &mut egui::Ui, p: Palette, color: &mut String) {
ui.add_space(6.0);
// (One row as tall as the text box, everything centred on it.)
ui.allocate_ui_with_layout(vec2(ui.available_width(), 28.0), Layout::left_to_right(Align::Center), |ui| {
ui.label(RichText::new(t("色碼")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("色碼")).size(FONT_SM).color(p.text2));
// What is typed stays while typing; the colour changes once it is a full code.
let id = ui.scope_id().with("avatar-hex");
let mut draft = ui.data(|d| d.get_temp::<String>(id)).unwrap_or_else(|| color.clone());
@ -7028,50 +6901,11 @@ fn avatar_color_grid(ui: &mut egui::Ui, p: Palette, color: &mut String) {
});
}
/// 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 {
let r = Frame::new()
.fill(p.elevated)
.stroke(Stroke::new(1.0, p.border))
.corner_radius(R_L)
.inner_margin(Margin::symmetric(16, 14))
.show(ui, |ui| {
ui.set_width(ui.available_width());
body(ui)
})
.inner;
ui.add_space(12.0);
r
}
/// A label column so form rows line up.
fn form_row(ui: &mut egui::Ui, label: &str, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
ui.horizontal(|ui| {
let (rect, _) = ui.allocate_exact_size(vec2(FORM_LABEL_WIDTH, 28.0), egui::Sense::hover());
// (English labels are longer than the column; painted un-truncated they run under the
// control on the right. Cut them to the column width.)
let label = sidebar_ui::shorten_width(ui, &t(label), rect.width(), FONT_SM);
ui.painter().text(rect.left_center(), egui::Align2::LEFT_CENTER, label, egui::FontId::proportional(FONT_SM), p.text2);
body(ui);
});
}
fn field_label(ui: &mut egui::Ui, text: &str, p: Palette) {
ui.add_space(4.0);
ui.label(RichText::new(t(text)).size(FONT_XS).color(p.text2));
}
fn primary_button(text: &str, p: Palette) -> egui::Button<'static> {
egui::Button::new(RichText::new(t(text)).color(p.on_primary).strong().family(crate::bold())).fill(p.primary).corner_radius(R_M).min_size(vec2(72.0, 30.0))
}
fn secondary_button(text: &str) -> egui::Button<'static> {
egui::Button::new(t(text)).corner_radius(R_M).min_size(vec2(64.0, 30.0))
}
fn danger_button(text: &str, p: Palette) -> egui::Button<'static> {
egui::Button::new(RichText::new(t(text)).color(Color32::WHITE).strong().family(crate::bold())).fill(p.danger).corner_radius(R_M).min_size(vec2(72.0, 30.0))
}
/// Tallest a dialog may be: the window minus a margin above and below.
fn dialog_max_height(ctx: &egui::Context) -> f32 {
@ -7275,16 +7109,6 @@ fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug,
.inner
}
/// The bottom bar of a dialog: a line above, buttons laid out right to left.
fn dialog_footer(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
let top = ui.cursor().top();
ui.painter().hline(ui.max_rect().x_range(), top, Stroke::new(1.0, p.border));
Frame::new().inner_margin(Margin::symmetric(20, 12)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 6.0;
ui.horizontal(|ui| body(ui));
});
}
#[cfg(test)]

View File

@ -233,7 +233,7 @@ impl App {
}
let (col, text) = match statuses.get(&c.id) {
_ if !c.enabled => (p.text3, t("已暫停")),
Some(s) if s.ok => (Color32::from_rgb(0x0b, 0x7f, 0x48), if s.received > 0 { format!("{}(收到 {} 則)", s.note, s.received) } else { s.note.clone() }),
Some(s) if s.ok => (p.up, if s.received > 0 { format!("{}(收到 {} 則)", s.note, s.received) } else { s.note.clone() }),
Some(s) => (p.danger, s.note.clone()),
None => (p.text3, t("連線中…")),
};
@ -357,7 +357,7 @@ impl App {
}
let msg = self.ch.ms_login.lock().unwrap().0.clone();
if !msg.is_empty() {
ui.label(RichText::new(msg).size(FONT_XS).color(p.text2));
ui.label(RichText::new(msg).size(FONT_SM).color(p.text2));
}
});
} else if matches!(k, Kind::IMessage | Kind::Email) {
@ -400,7 +400,7 @@ impl App {
});
let note = self.ch.note.lock().unwrap().clone();
if !note.is_empty() {
ui.label(RichText::new(note).size(FONT_XS).color(p.text2));
ui.label(RichText::new(note).size(FONT_SM).color(p.text2));
}
});
}
@ -484,7 +484,7 @@ impl App {
let one = &st["servers"][s.name.as_str()];
let (col, text) = match (s.enabled, one["tools"].as_u64(), one["error"].as_str()) {
(false, _, _) => (p.text3, "已關閉".to_string()),
(_, Some(n), _) => (Color32::from_rgb(0x14, 0xc3, 0x70), format!("已連上,{n} 個工具")),
(_, Some(n), _) => (p.up, format!("已連上,{n} 個工具")),
(_, _, Some(e)) => (p.danger, format!("{at}{e}")),
_ if busy => (p.text3, "連線中…".to_string()),
_ => (p.text3, "未連線".to_string()),
@ -497,7 +497,7 @@ impl App {
remove = Some(i);
}
ui.add(computers_ui::toggle(&mut s.enabled)).on_hover_text(t("開啟"));
if s.enabled && ui.add(egui::Button::new(RichText::new(t("重新連線")).size(FONT_XS).color(p.text2)).frame(false)).on_hover_text(t("再連一次,看連不連得上")).clicked() {
if s.enabled && ui.add(egui::Button::new(RichText::new(t("重新連線")).size(FONT_SM).color(p.text2)).frame(false)).on_hover_text(t("再連一次,看連不連得上")).clicked() {
reconnect = Some(name.clone());
}
},
@ -583,7 +583,7 @@ impl App {
setting_title(ui, "可以用的工具", "", p);
for t in tools {
let s = |i: usize| t[i].as_str().unwrap_or("");
ui.label(RichText::new(format!("{} · {}", s(0), s(1))).size(FONT_XS).color(p.text2)).on_hover_text(s(2));
ui.label(RichText::new(format!("{} · {}", s(0), s(1))).size(FONT_SM).color(p.text2)).on_hover_text(s(2));
}
});
}
@ -614,7 +614,7 @@ impl App {
|ui| {
// Two presses: it goes with its folder (scripts and all), and can't come back.
if self.ch.skill_confirm.as_deref() == Some(name.as_str()) {
if ui.add(egui::Button::new(RichText::new(t("取消")).size(FONT_XS).color(p.text2)).frame(false)).clicked() {
if ui.add(egui::Button::new(RichText::new(t("取消")).size(FONT_SM).color(p.text2)).frame(false)).clicked() {
self.ch.skill_confirm = None;
}
if ui.add(egui::Button::new(RichText::new(t("確定刪除(連檔案)")).size(FONT_XS).color(p.danger)).frame(false)).clicked() {
@ -624,7 +624,7 @@ impl App {
} else if ui.add(egui::Button::new(RichText::new(t("刪除")).size(FONT_XS).color(p.danger)).frame(false)).clicked() {
self.ch.skill_confirm = Some(name.clone());
}
if ui.add(egui::Button::new(RichText::new(t(if is_open { "收起" } else { "檢視" })).size(FONT_XS).color(p.text2)).frame(false)).clicked() {
if ui.add(egui::Button::new(RichText::new(t(if is_open { "收起" } else { "檢視" })).size(FONT_SM).color(p.text2)).frame(false)).clicked() {
self.ch.skill_open = if is_open { None } else { Some(name.clone()) };
}
if ui.add(computers_ui::toggle(&mut k.enabled)).on_hover_text(t("開啟")).changed() {
@ -651,11 +651,11 @@ impl App {
.inner_margin(Margin::symmetric(10, 8))
.show(ui, |ui| {
if !k.resources.is_empty() {
ui.label(RichText::new(format!("隨附檔案:{}", k.resources.join("、"))).monospace().size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("隨附檔案:{}", k.resources.join("、"))).monospace().size(FONT_SM).color(p.text2));
ui.add_space(4.0);
}
let preview: String = k.instructions.chars().take(1800).collect();
ui.label(RichText::new(preview).size(FONT_XS).color(p.text2));
ui.label(RichText::new(preview).size(FONT_SM).color(p.text2));
});
}
}
@ -825,7 +825,7 @@ impl App {
});
hint(ui, "帳號密碼怎麼交給伺服器:在指令、環境變數、網址或標頭裡寫「{username}」「{password}」,就填在那裡(例如環境變數 SCC_USER={username} SCC_PASS={password});都沒寫的話,本機伺服器會收到環境變數 MCP_USERNAME、MCP_PASSWORD,遠端伺服器收到 Authorization: Basic。", p);
if !self.ch.new_mcp_hint.is_empty() {
ui.label(RichText::new(&self.ch.new_mcp_hint).size(FONT_XS).color(p.text2));
ui.label(RichText::new(&self.ch.new_mcp_hint).size(FONT_SM).color(p.text2));
}
// A 「{…}」 left in the address or the header can only fail (the 帳號/密碼 slots are filled when connecting).
let unfilled = crate::mcp::Server::unfilled(cmd) || crate::mcp::Server::unfilled(headers);
@ -980,7 +980,7 @@ fn skill_status(ui: &mut egui::Ui, ch: &ChannelUi, busy: bool, p: Palette) {
if busy {
ui.label(RichText::new(t("處理中…")).size(FONT_XS).color(p.text3));
} else if let Some((ok, msg)) = ch.skill_note.lock().unwrap().clone() {
ui.label(RichText::new(msg).size(FONT_XS).color(if ok { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.danger }));
ui.label(RichText::new(msg).size(FONT_XS).color(if ok { p.up } else { p.danger }));
}
}

View File

@ -72,8 +72,8 @@ type RuntimeFacts = (bool, Option<String>);
fn status_color(r: &Run, p: Palette) -> Color32 {
match r {
Run::Running => Color32::from_rgb(0x14, 0xc3, 0x70),
Run::Starting(_) | Run::Rebuilding(..) => Color32::from_rgb(0xf6, 0x94, 0x12),
Run::Running => p.up,
Run::Starting(_) | Run::Rebuilding(..) => p.attention,
Run::Failed(_) => p.danger,
_ => p.text3,
}
@ -276,7 +276,7 @@ impl App {
let status = t(if *online { "目前在線上" } else { "離線" });
sec_row_s(ui, p, name, &format!("{} · {status}", t("同一個帳號")), "", |ui| {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
ui.painter().circle_filled(r.center(), 3.0, if *online { Color32::from_rgb(0x22, 0xa0, 0x55) } else { p.text3 });
ui.painter().circle_filled(r.center(), 3.0, if *online { p.up } else { p.text3 });
});
}
@ -525,7 +525,7 @@ impl App {
Frame::new().inner_margin(Margin::symmetric(14, 6)).show(ui, |ui| {
Frame::new().fill(p.hover).corner_radius(R_M).inner_margin(Margin::symmetric(10, 8)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.label(RichText::new(d).monospace().size(FONT_XS).color(p.text2));
ui.label(RichText::new(d).monospace().size(FONT_SM).color(p.text2));
});
});
}
@ -604,7 +604,7 @@ impl App {
if ui.add(egui::Button::new(RichText::new(t("刪除")).size(FONT_XS).color(p.danger)).frame(false)).clicked() {
remove = Some(n.clone());
}
if ui.add(egui::Button::new(RichText::new(t("取代")).size(FONT_XS).color(p.text2)).frame(false)).clicked() {
if ui.add(egui::Button::new(RichText::new(t("取代")).size(FONT_SM).color(p.text2)).frame(false)).clicked() {
self.cu.new_secret = (n.clone(), String::new());
self.cu.replace_secret = Some(n.clone());
}
@ -703,7 +703,7 @@ impl App {
ui.label(RichText::new(t("(沒有紀錄)")).size(FONT_XS).color(p.text3));
}
for l in lines.iter().rev().take(30) {
ui.label(RichText::new(l).monospace().size(FONT_XS).color(p.text2));
ui.label(RichText::new(l).monospace().size(FONT_SM).color(p.text2));
}
});
}
@ -1110,7 +1110,7 @@ impl App {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
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 { p.danger });
let text = if held { "你正在操作,Bot 已暫停".to_string() } else { format!("{who} 正在操作你的電腦") };
ui.label(RichText::new(text).size(FONT_SM).strong().family(crate::bold()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
@ -1186,7 +1186,7 @@ impl App {
}
});
if !self.cu.teach_error.is_empty() {
ui.add(egui::Label::new(RichText::new(&self.cu.teach_error).size(FONT_XS).color(p.danger)).wrap());
ui.add(egui::Label::new(RichText::new(&self.cu.teach_error).size(FONT_SM).color(p.danger)).wrap());
}
hint(ui, "按下開始後照平常的方式操作;做完按畫面上方的「完成」。會記錄點擊、打字和捲動,並且每 0.5 秒拍一張螢幕畫面(需要「螢幕與系統錄音」權限),完成後合成錄影;每一步會留一張當時的畫面給 Bot 看。不會擋住或改變你的操作。", p);
let mut remove = None;
@ -1206,10 +1206,10 @@ impl App {
}
});
});
egui::CollapsingHeader::new(RichText::new(t("步驟")).size(FONT_XS).color(p.text2)).id_salt(("demo", bot_id, i)).show(ui, |ui| {
egui::CollapsingHeader::new(RichText::new(t("步驟")).size(FONT_SM).color(p.text2)).id_salt(("demo", bot_id, i)).show(ui, |ui| {
for (n, s) in d.steps.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(RichText::new(format!("{}. {s}", n + 1)).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("{}. {s}", n + 1)).size(FONT_SM).color(p.text2));
if let Some(shot) = d.shots.get(n).filter(|x| !x.is_empty()) {
if ui.add(egui::Button::new(RichText::new(t("畫面")).size(FONT_XS).color(p.accent)).frame(false)).on_hover_text(t("打開這一步當時的畫面")).clicked() {
crate::preview::open_with_system(&shot.to_string());
@ -1252,7 +1252,7 @@ impl App {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
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, p.danger.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().family(crate::bold()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
@ -1315,74 +1315,27 @@ pub(super) fn toggle(on: &mut bool) -> impl egui::Widget + '_ {
/// its right), then a card of rows (12 px corners, a hairline, 8 px top and bottom).
const SEC_GAP: f32 = 28.0;
// 電腦頁的區段、群組、列、說明:共用元件(kit.rs)的別名,和其他設定頁長得一樣。
fn sec_title(ui: &mut egui::Ui, title: &str, p: Palette, accessory: impl FnOnce(&mut egui::Ui)) {
ui.add_space(SEC_GAP * 0.5);
ui.horizontal(|ui| {
ui.add_space(14.0);
ui.label(RichText::new(t(title)).size(FONT_SM).color(p.text2));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add_space(4.0);
accessory(ui);
});
});
ui.add_space(8.0);
section_with(ui, title, p, accessory);
}
fn sec_card(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
Frame::new()
.fill(p.elevated)
.stroke(Stroke::new(1.0, p.border))
.corner_radius(R_L)
.inner_margin(Margin::symmetric(0, 8))
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 0.0;
body(ui)
});
ui.add_space(SEC_GAP * 0.5);
rows_card(ui, p, body);
}
/// A row: the setting's name (「?」 explains on hover) on the left, its control on the right.
fn sec_row(ui: &mut egui::Ui, p: Palette, label: &str, help: &str, control: impl FnOnce(&mut egui::Ui)) {
sec_row_s(ui, p, label, "", help, control)
card_row(ui, p, label, "", help, control);
}
/// A row with a short status line under the name (目前在線上、上次快照…).
fn sec_row_s(ui: &mut egui::Ui, p: Palette, label: &str, status: &str, help: &str, control: impl FnOnce(&mut egui::Ui)) {
Frame::new().inner_margin(Margin::symmetric(14, 10)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
// (The words column must leave room for the controls: long English labels and
// wide buttons used to overflow left, pushing rows below them out of the card.)
let avail = ui.available_width();
let w = (avail * 0.58).max(200.0).min((avail - 250.0).max(120.0));
ui.vertical(|ui| {
ui.set_width(w);
ui.spacing_mut().item_spacing.y = 2.0;
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0;
// (Long English names are cut with … inside the words column, leaving the
// 「?」 mark in the card; a truncate-label alone would push it out.)
let cut = sidebar_ui::shorten_width(ui, &t(label), (w - 20.0).max(40.0), FONT_BASE);
ui.label(RichText::new(cut).size(FONT_BASE).color(p.text));
help_mark(ui, help, p);
});
if !status.is_empty() {
ui.add(egui::Label::new(RichText::new(t(status)).size(FONT_SM).color(p.text2)).truncate());
}
});
let ctl = Layout::right_to_left(Align::Center).with_main_wrap(true); // (wide button groups wrap to a second line instead of overflowing left)
ui.with_layout(ctl, |ui| {
ui.spacing_mut().item_spacing.x = 6.0;
control(ui)
});
});
});
card_row(ui, p, label, status, help, control);
}
/// A small note inside a card.
fn sec_note(ui: &mut egui::Ui, p: Palette, text: &str) {
Frame::new().inner_margin(Margin { left: 14, right: 14, top: 0, bottom: 6 }).show(ui, |ui| {
ui.add(egui::Label::new(RichText::new(t(text)).size(FONT_XS).color(p.text3)).wrap());
Frame::new().inner_margin(Margin { left: 4, right: 4, top: 4, bottom: 8 }).show(ui, |ui| {
hint(ui, text, p);
});
}

209
src/app/kit.rs Normal file
View File

@ -0,0 +1,209 @@
//! 共用元件:每個畫面都從這裡拿,不自己畫框、不自己定字級。
//!
//! 依 Claude 的設計原則(卡片樣式按角色用、重複的元素長得一樣)與設計規格(theme.rs):
//!
//! - **區段** `section` / `section_with`:13 px 灰色粗體小標,上方 24、下方 8。設定的每一頁都用它。
//! - **群組** `rows_card`:一張卡(elevated 底、細框、圓角 14),裝一組**設定列**;列與列之間
//! 自動一條細線。一頁的設定就是「區段+群組」一組一組往下排。
//! - **設定列** `card_row`:左邊名稱(14)、可選的一行狀態(13 灰)和「?」說明,右邊控制項;
//! 控制項先排、名稱拿剩下的寬度(太長就「…」)。高 52,有狀態 62。
//! - **卡片** `setting_card` + `setting_title`:給一整塊有標題、有欄位的內容(Bot 設定的幾段)。
//! 卡片裡放列、欄位、文字——**不再放卡片**(卡中卡是畫面亂的主因)。
//! - **欄位** `field_label`(13 灰小標)+輸入框;**表單列** `form_row`(固定寬的標籤欄)。
//! - **說明** `hint`:13 px 灰字,設定下面的一兩句話。`help_mark` 是名稱旁的「?」。
//! - **按鈕** `primary_button`(實心,一個畫面一顆)、`secondary_button`(淡底)、`danger_button`;
//! 刪除這種不能回頭的,用紅字無底按鈕並按兩次確認(由呼叫的地方做)。
//! - **分段選擇** `segmented`;**對話框底部** `dialog_footer`(左:影響內容本身的;右:完成)。
use super::*;
use crate::theme::sp;
/// A group heading inside a settings page (like the original's section titles).
pub(super) fn section(ui: &mut egui::Ui, title: &str, p: Palette) {
section_with(ui, title, p, |_| {});
}
/// A section heading with something at its right end (a name, a button).
pub(super) fn section_with(ui: &mut egui::Ui, title: &str, p: Palette, accessory: impl FnOnce(&mut egui::Ui)) {
ui.add_space(sp::S5);
ui.horizontal(|ui| {
ui.add_space(sp::S1);
ui.label(RichText::new(t(title)).size(FONT_SM).family(crate::bold()).color(p.text2));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add_space(sp::S1);
accessory(ui);
});
});
ui.add_space(sp::S2);
}
/// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no
/// waiting for the pointer to be still), and a click keeps it open until the next click.
pub(super) fn help_mark(ui: &mut egui::Ui, text: &str, p: Palette) {
if text.trim().is_empty() {
return;
}
let (rect, r) = ui.allocate_exact_size(vec2(18.0, 18.0), egui::Sense::click());
let pinned_id = r.id.with("pinned");
let mut pinned = ui.ctx().data(|d| d.get_temp::<bool>(pinned_id)).unwrap_or(false);
if r.clicked() {
pinned = !pinned;
} else if pinned && ui.input(|i| i.pointer.any_pressed()) && !r.hovered() {
pinned = false;
}
ui.ctx().data_mut(|d| d.insert_temp(pinned_id, pinned));
let show = r.hovered() || pinned;
let col = if show { p.text } else { p.text3 };
ui.painter().circle_stroke(rect.center(), 6.5, Stroke::new(1.1, col));
// (A glyph sized to its 14 px ring, an icon rather than text on the type scale.)
const HELP_GLYPH: f32 = 10.0;
ui.painter().text(rect.center() + vec2(0.0, 0.5), egui::Align2::CENTER_CENTER, "?", egui::FontId::proportional(HELP_GLYPH), col);
if show {
let text = t(text);
egui::Area::new(r.id.with("help"))
.order(egui::Order::Tooltip)
.fixed_pos(rect.left_bottom() + vec2(-4.0, 6.0))
.constrain(true)
.interactable(false)
.show(ui.ctx(), |ui| {
Frame::popup(ui.style()).corner_radius(R_M).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| {
ui.set_max_width(300.0);
ui.add(egui::Label::new(RichText::new(text).size(FONT_SM).color(p.text)).wrap());
});
});
}
r.on_hover_cursor(egui::CursorIcon::Help);
}
/// A group of settings: one quiet card, its rows (`card_row`) divided by hairlines.
pub(super) fn rows_card(ui: &mut egui::Ui, p: Palette, rows: impl FnOnce(&mut egui::Ui)) {
Frame::new().fill(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(R_L).inner_margin(Margin::symmetric(16, 1)).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`).
pub(super) 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_BASE).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_BASE).color(p.text)).truncate());
help_mark(ui, help, p);
});
left.add(egui::Label::new(RichText::new(t(sub)).size(FONT_SM).color(p.text2)).truncate());
}
}
/// A choice among a few: the one chosen is the raised, bold one. Returns a new choice.
pub(super) 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(R_M).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(R_M).min_size(vec2(0.0, 26.0))).clicked() && !on {
picked = Some(*v);
}
}
});
});
picked
}
pub(super) 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().family(crate::bold()).size(FONT_BASE));
help_mark(ui, desc, p);
});
ui.add_space(4.0);
}
/// Small grey text under a setting.
pub(super) fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) {
ui.add(egui::Label::new(RichText::new(t(&text.into())).size(FONT_SM).color(p.text2)).wrap());
}
/// A rounded group of related settings, like a macOS settings card.
pub(super) fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
let r = Frame::new()
.fill(p.elevated)
.stroke(Stroke::new(1.0, p.border))
.corner_radius(R_L)
.inner_margin(Margin::symmetric(16, 14))
.show(ui, |ui| {
ui.set_width(ui.available_width());
body(ui)
})
.inner;
ui.add_space(12.0);
r
}
/// A label column so form rows line up.
pub(super) fn form_row(ui: &mut egui::Ui, label: &str, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
ui.horizontal(|ui| {
let (rect, _) = ui.allocate_exact_size(vec2(FORM_LABEL_WIDTH, 28.0), egui::Sense::hover());
// (English labels are longer than the column; painted un-truncated they run under the
// control on the right. Cut them to the column width.)
let label = sidebar_ui::shorten_width(ui, &t(label), rect.width(), FONT_SM);
ui.painter().text(rect.left_center(), egui::Align2::LEFT_CENTER, label, egui::FontId::proportional(FONT_SM), p.text2);
body(ui);
});
}
pub(super) fn field_label(ui: &mut egui::Ui, text: &str, p: Palette) {
ui.add_space(sp::S2);
ui.label(RichText::new(t(text)).size(FONT_SM).color(p.text2));
ui.add_space(sp::S1 * 0.5);
}
pub(super) fn primary_button(text: &str, p: Palette) -> egui::Button<'static> {
egui::Button::new(RichText::new(t(text)).color(p.on_primary).strong().family(crate::bold())).fill(p.primary).corner_radius(R_M).min_size(vec2(72.0, 30.0))
}
pub(super) fn secondary_button(text: &str) -> egui::Button<'static> {
egui::Button::new(t(text)).corner_radius(R_M).min_size(vec2(64.0, 30.0))
}
pub(super) fn danger_button(text: &str, p: Palette) -> egui::Button<'static> {
egui::Button::new(RichText::new(t(text)).color(Color32::WHITE).strong().family(crate::bold())).fill(p.danger).corner_radius(R_M).min_size(vec2(72.0, 30.0))
}
/// The bottom bar of a dialog: a line above, buttons laid out right to left.
pub(super) fn dialog_footer(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
let top = ui.cursor().top();
ui.painter().hline(ui.max_rect().x_range(), top, Stroke::new(1.0, p.border));
Frame::new().inner_margin(Margin::symmetric(20, 12)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 6.0;
ui.horizontal(|ui| body(ui));
});
}

View File

@ -616,7 +616,8 @@ impl App {
/// links that open in the browser.
fn md_spans(&mut self, ui: &mut egui::Ui, spans: &[Span], size: f32, col: Color32, heading: bool) {
let p = self.pal;
let link_col = if crate::theme::is_dark(p) { Color32::from_rgb(0x5a, 0xa9, 0xff) } else { Color32::from_rgb(0x0b, 0x6d, 0xd3) };
// Links in the accent (the shell's one colour for 「you can go here」), underlined.
let link_col = p.accent;
let mut job = egui::text::LayoutJob::default();
let mut ranges: Vec<(std::ops::Range<usize>, String)> = vec![];
let mut strikes: Vec<std::ops::Range<usize>> = vec![];
@ -714,7 +715,7 @@ impl App {
ui.set_width(tile_w - 30.0);
ui.vertical(|ui| {
ui.spacing_mut().item_spacing.y = 3.0;
ui.add(egui::Label::new(RichText::new(label).size(FONT_XS).color(p.text3)).wrap());
ui.add(egui::Label::new(RichText::new(label).size(FONT_SM).color(p.text3)).wrap());
// A long value (a phrase, not a number) a size smaller, so it doesn't fill
// the tile — with or without a direction in front.
// A direction up front is a verdict: green up, red down (the arrow or
@ -732,7 +733,7 @@ impl App {
Some(false) => p.danger,
None => p.text2,
};
ui.add(egui::Label::new(RichText::new(note).size(FONT_XS).color(nc)).wrap());
ui.add(egui::Label::new(RichText::new(note).size(FONT_SM).color(nc)).wrap());
}
});
});
@ -932,7 +933,7 @@ impl App {
}
ui.end_row();
for (i, label) in labels.iter().enumerate() {
ui.add_sized([lw, 15.0], egui::Label::new(RichText::new(label).size(FONT_XS).color(p.text2)).truncate());
ui.add_sized([lw, 15.0], egui::Label::new(RichText::new(label).size(FONT_SM).color(p.text2)).truncate());
for ci in 1..cols.len() {
let text = if pie && ci == 2 {
format!("{:.0}%", vals[i] / total * 100.0)
@ -1008,7 +1009,7 @@ impl App {
let p = self.pal;
let items = crate::pages::steps(src);
let n = items.len();
let green = Color32::from_rgb(0x2e, 0xa0, 0x43);
let green = p.up;
for (i, (st, name, note)) in items.iter().enumerate() {
let top = ui.cursor().top();
let x = ui.cursor().left() + 9.0;

View File

@ -58,7 +58,7 @@ impl App {
});
if page.revision > 1 && !page.note.is_empty() {
ui.add_space(6.0);
ui.add(egui::Label::new(RichText::new(format!("{}:{}", t("最近更新"), page.note)).size(FONT_XS).color(p.text2)).wrap());
ui.add(egui::Label::new(RichText::new(format!("{}:{}", t("最近更新"), page.note)).size(FONT_SM).color(p.text2)).wrap());
}
});
});
@ -115,7 +115,7 @@ impl App {
ui.label(RichText::new(meta).size(FONT_XS).color(p.text3));
if !old && !shown.note.is_empty() && shown.revision > 1 {
ui.add_space(sp::S1);
ui.add(egui::Label::new(RichText::new(format!("{}:{}", t("這一版更新了"), shown.note)).size(FONT_XS).color(p.text3)).wrap());
ui.add(egui::Label::new(RichText::new(format!("{}:{}", t("這一版更新了"), shown.note)).size(FONT_SM).color(p.text3)).wrap());
}
if old {
ui.add_space(sp::S3);

View File

@ -225,7 +225,7 @@ impl App {
}
ui.painter().rect_stroke(box_r, R_S, Stroke::new(1.0, p.border), egui::StrokeKind::Inside);
if running {
ui.painter().circle_filled(box_r.right_top() + vec2(-6.0, 6.0), 3.5, Color32::from_rgb(0x14, 0xc3, 0x70));
ui.painter().circle_filled(box_r.right_top() + vec2(-6.0, 6.0), 3.5, p.up);
}
let tip = if running { t("看「{name}」的螢幕,也可以取得控制權自己操作") } else { t("叫醒「{name}」並看它的螢幕") }.replace("{name}", &own_name);
view = r.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(tip).clicked();

View File

@ -124,7 +124,7 @@ impl App {
return;
}
ui.add_space(6.0);
ui.label(RichText::new(t("可以用的電腦")).size(FONT_XS).color(p.text2));
ui.label(RichText::new(t("可以用的電腦")).size(FONT_SM).color(p.text2));
let mut on: Vec<String> = b.computers.clone().unwrap_or_else(|| all.iter().map(|c| c.0.clone()).collect());
let mut changed = false;
ui.horizontal_wrapped(|ui| {

View File

@ -247,7 +247,7 @@ impl App {
}
Frame::new().fill(p.hover).corner_radius(R_M).inner_margin(Margin::symmetric(10, 8)).show(ui, |ui| {
ui.horizontal(|ui| {
ui.add(egui::Label::new(RichText::new(&line).monospace().size(FONT_XS)).selectable(true).wrap());
ui.add(egui::Label::new(RichText::new(&line).monospace().size(FONT_SM)).selectable(true).wrap());
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.add(secondary_button("複製")).clicked() {
crate::platform::copy_text(ui.ctx(), &line);
@ -705,7 +705,7 @@ impl App {
ui.horizontal(|ui| {
let ok = status == "已連線";
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
ui.painter().circle_filled(r.center(), 4.0, if ok { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
ui.painter().circle_filled(r.center(), 4.0, if ok { p.up } else { p.text3 });
ui.label(RichText::new(format!("{} · {}", s.relay_user, s.relay_url)).size(FONT_BASE));
ui.label(RichText::new(if status.is_empty() { "—".to_string() } else { status }).size(FONT_XS).color(p.text3));
});
@ -815,7 +815,7 @@ impl App {
if self.mir.on {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
ui.painter().circle_filled(r.center(), 4.0, if self.mir.online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
ui.painter().circle_filled(r.center(), 4.0, if self.mir.online { p.up } else { p.text3 });
ui.label(RichText::new(status).size(FONT_SM).color(p.text2));
});
ui.horizontal(|ui| {
@ -841,7 +841,7 @@ impl App {
for (id, name, online) in peers {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
ui.painter().circle_filled(r.center(), 4.0, if online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
ui.painter().circle_filled(r.center(), 4.0, if online { p.up } else { p.text3 });
ui.label(RichText::new(&name).size(FONT_SM));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.add_enabled(online, secondary_button("改用它當大腦")).clicked() {
@ -1017,7 +1017,7 @@ impl App {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
if !id.is_empty() {
ui.painter().circle_filled(r.center(), 4.0, if *online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
ui.painter().circle_filled(r.center(), 4.0, if *online { p.up } else { p.text3 });
}
let me = *id == self.state.remote.host_id;
ui.label(RichText::new(format!("{name}{}", if me { "(這台)" } else { "" })).size(FONT_SM));

View File

@ -54,7 +54,7 @@ impl App {
ui.horizontal(|ui| {
ui.add(egui::Spinner::new().size(12.0));
let doing = to.as_ref().and_then(|b| self.streams.contains_key(&b.id).then(|| self.working_phrase(ctx.input(|i| i.time), b)).flatten());
ui.label(RichText::new(format!("「{them}」{}", doing.map(|d| format!(":{d}")).unwrap_or_else(|| "正在處理…".into()))).size(FONT_XS).color(p.text2));
ui.label(RichText::new(format!("「{them}」{}", doing.map(|d| format!(":{d}")).unwrap_or_else(|| "正在處理…".into()))).size(FONT_SM).color(p.text2));
});
ctx.request_repaint_after(std::time::Duration::from_millis(500));
}

View File

@ -264,7 +264,7 @@ impl App {
);
hint(ui, "每次填入前都會先問你。資料加密存在這台電腦上,金鑰放在系統鑰匙圈。登入時保險庫沒有的網站,也會找 macOS 鑰匙圈和 1Password(裝了 op 指令並登入時)。", p);
if !self.vault.note.is_empty() {
ui.label(RichText::new(&self.vault.note).size(FONT_XS).color(p.text2));
ui.label(RichText::new(&self.vault.note).size(FONT_SM).color(p.text2));
}
}

View File

@ -461,7 +461,7 @@ impl App {
fn status_line(&self, ui: &mut egui::Ui, ok: bool, why: &str) {
let p = self.pal;
let (mark, text, col) = if ok { ("✓", t("可以用"), Color32::from_rgb(0x2e, 0xa0, 0x43)) } else { ("·", t(why), p.text3) };
let (mark, text, col) = if ok { ("✓", t("可以用"), p.up) } else { ("·", t(why), p.text3) };
ui.label(RichText::new(format!("{mark} {text}")).size(FONT_SM).color(col));
}

View File

@ -102,7 +102,7 @@ fn step(ui: &mut egui::Ui, p: Palette, n: u32, title: &str, done: bool, body: im
setting_card(ui, p, |ui| {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(vec2(24.0, 24.0), egui::Sense::hover());
let fill = if done { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.primary };
let fill = if done { p.up } else { p.primary };
ui.painter().circle_filled(r.center(), 12.0, fill);
let mark = if done { "✓".to_string() } else { n.to_string() };
ui.painter().text(r.center(), egui::Align2::CENTER_CENTER, mark, egui::FontId::proportional(FONT_SM), if done { Color32::WHITE } else { p.on_primary });

View File

@ -1,7 +1,8 @@
// English and 日本語 for the window's chrome: (繁體中文, English, 日本語).
// Keys are the Chinese source strings exactly as written in the code.
pub const ROWS: &[(&str, &str, &str)] = &[
("團隊成員可以使用這個 Bot(看得到它的聊天、頁面和檔案)", "Teammates may use this bot (they see its chat, pages and files)", "チームメンバーがこの Bot を使える(会話・ページ・ファイルが見えます)"),
("團隊成員可以使用這個 Bot", "Teammates may use this bot", "チームメンバーがこの Bot を使える"),
("團隊成員看得到它的聊天、頁面和檔案", "Teammates see its chat, pages and files", "チームメンバーに会話・ページ・ファイルが見えます"),
("指令 · ↑↓ 選擇,Enter 帶入,Esc 關閉(打字可以找技能)", "Commands · ↑↓ to choose, Enter to insert, Esc to close (type to find skills)", "コマンド · ↑↓ で選択、Enter で入力、Esc で閉じる(入力するとスキルを検索)"),
("找其他 Bot 一起來 · ↑↓ 選擇,Enter 帶入,Esc 關閉", "Bring in another bot · ↑↓ to choose, Enter to insert, Esc to close", "ほかの Bot を呼ぶ · ↑↓ で選択、Enter で入力、Esc で閉じる"),
("每個 Bot 都帶著", "Every bot carries it", "すべての Bot が持っています"),

View File

@ -435,7 +435,10 @@ mod spec_tests {
/// its diameter, not type; `0` radius is "square".)
#[test]
fn no_new_literal_sizes_radii_or_colours() {
const COLOURS_LEFT: usize = 88;
const COLOURS_LEFT: usize = 66;
// Frames drawn as a card (a fill and a border) outside the kit: only ever fewer — a
// card is the kit's `setting_card` / `rows_card`, and never inside another card.
const CARDS_LEFT: usize = 17;
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
let mut files = vec![dir.join("app.rs")];
for e in std::fs::read_dir(dir.join("app")).unwrap().flatten() {
@ -445,10 +448,14 @@ mod spec_tests {
}
}
let starts_digit = |rest: &str| rest.trim_start().chars().next().is_some_and(|c| c.is_ascii_digit());
let (mut sizes, mut radii, mut colours) = (vec![], vec![], 0usize);
let (mut sizes, mut radii, mut colours, mut cards) = (vec![], vec![], 0usize, 0usize);
for f in &files {
let text = std::fs::read_to_string(f).unwrap();
let kit = f.ends_with("kit.rs");
for (n, line) in text.lines().enumerate() {
if !kit && line.contains("Frame::new()") && line.contains(".fill(") && line.contains(".stroke(") {
cards += 1;
}
let at = format!("{}:{}", f.file_name().unwrap().to_string_lossy(), n + 1);
for pat in [".size(", "FontId::proportional(", "FontId::monospace(", "FontId::new("] {
for (i, _) in line.match_indices(pat) {
@ -473,6 +480,7 @@ mod spec_tests {
assert!(sizes.is_empty(), "font sizes off the scale (use FONT_*): {sizes:?}");
assert!(radii.is_empty(), "corner radii off the spec (use R_S / R_M / R_L / R_FULL): {radii:?}");
assert!(colours <= COLOURS_LEFT, "{colours} colours written outside the palette (was {COLOURS_LEFT}): take them from Palette");
assert!(cards <= CARDS_LEFT, "{cards} hand-made cards outside kit.rs (was {CARDS_LEFT}): use setting_card / rows_card");
}
#[test]