主題產生器進設定(底色/對比/強調色/密度/慶祝)+側欄細條+時段問候+目標撒花

Quiet Shell 收尾四件(A3/B2/B3/C/D),一次落地:

- C 產生器:theme::shell(tone, accent, contrast, dark)——三個旋紐生成整個殼
  (表面=紙朝墨等距階梯、文字=墨回紙、圖表六色=強調色轉色相);設定 › 一般
  外觀新增 底色(冷→暖)、對比(0.75→1.35,拉整個殼的階層一起調)、強調色
  (黏土/靛藍/苔綠/藍綠/玫紅/琥珀/石板/墨黑)、重設。預設=紙,舊設定檔 serde
  補預設。ANYBOT_SHOT_SHELL=tone,accent,contrast 出概念圖
- B3 密度:寬鬆(9/7)/緊湊(8/5) 全域間距開關
- B2 側欄:選中 Bot 不再整條深底——強調色 3px 細條+淺底(Linear 式)
- D1 撒花:只在 /goal 目標達成時,該聊天上撒 1.4 秒彩帶(chart_cat 六色,
  淡出收尾);設定 › 一般「慶祝動畫」可關;純裝飾,不擋任何操作
- D3 問候:新對話依時段先問「早安/午安/晚上好/夜深了」
- 淺深判定改成亮度函數 theme::is_dark(原先拿 pane 和 LIGHT 常數比對——
  底色旋紐一調就破);markdown 連結色、灰字、遮罩四處跟著改
- 手機 theme-color meta 換紙色;元件庫調查:egui_dock/notify/shadcn-egui
  都不引入(自有設計系統+鎖 egui 版本),缺的取色器用八點自家版

已驗證: cargo test 505 全綠(新增 theme 產生器 5 測:預設=紙、對比單調、
冷暖心跳、is_dark 跟旋紐不跟常數;含 layout_audit 三寬度新設定區塊不破版);
clippy 31=基線;截圖取樣:冷灰 pane(246,245,247)、紙 pane(248,247,245)、
側欄黏土細條 52px、墨黑殼 0px(強調色確實跟隨)、深色苔綠 152px
未驗證: 撒花只在真 /goal 達成出現,截圖模式不渲染(未目視彩帶飛的樣子,
落點/速度未調校);i18n 新字串(早安/靛藍等)靠自動翻譯,英日語未逐條核;
手機端不吃旋紐(只有 meta 色),自訂色手機同步是下一輪
This commit is contained in:
daniel wang 2026-11-16 17:32:42 +08:00
parent 723074f50b
commit dcd9bee7d5
9 changed files with 304 additions and 47 deletions

View File

@ -1509,7 +1509,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- **用 / 指定技能**(現在只打「/」只列指令,打字後才找這個 Bot 自己的技能,見「「/」清單只放指令」):輸入框第一個字打「/」,上面就列出開著的技能(名稱開頭符合的先、名稱含有的次之、再來是說明裡有的,例如「/簡報」找到 pptx);點一下,或 ↑↓ 選、Enter/Tab 帶入,輸入框變成「/pptx 」接著打要做的事,Esc 關掉清單。電腦和手機都有,Bot 正在做事時不列(那時打的字會併進正在做的事)。送出後由大腦認出「/名稱」,在這則訊息後面替模型加一行「使用者用 /pptx 指定了技能「pptx」:先用 use_skill 讀出它的完整做法」,所以從手機、訊息管道打的也算;不是技能名稱的(例如 /Users/… 路徑)不加。新加的技能(技能市集、GitHub 安裝、Bot 存的或自己學會的、「教我做」)馬上就在清單裡:電腦直接讀技能名單(大腦的螢幕讀的是大腦同步過來的那份);手機每次打出新的「/」會向大腦再拿一次名單,拿到前先列手上已有的。篩選本身不連網,也不多送東西給模型(技能清單本來就在系統指示裡)。 - **用 / 指定技能**(現在只打「/」只列指令,打字後才找這個 Bot 自己的技能,見「「/」清單只放指令」):輸入框第一個字打「/」,上面就列出開著的技能(名稱開頭符合的先、名稱含有的次之、再來是說明裡有的,例如「/簡報」找到 pptx);點一下,或 ↑↓ 選、Enter/Tab 帶入,輸入框變成「/pptx 」接著打要做的事,Esc 關掉清單。電腦和手機都有,Bot 正在做事時不列(那時打的字會併進正在做的事)。送出後由大腦認出「/名稱」,在這則訊息後面替模型加一行「使用者用 /pptx 指定了技能「pptx」:先用 use_skill 讀出它的完整做法」,所以從手機、訊息管道打的也算;不是技能名稱的(例如 /Users/… 路徑)不加。新加的技能(技能市集、GitHub 安裝、Bot 存的或自己學會的、「教我做」)馬上就在清單裡:電腦直接讀技能名單(大腦的螢幕讀的是大腦同步過來的那份);手機每次打出新的「/」會向大腦再拿一次名單,拿到前先列手上已有的。篩選本身不連網,也不多送東西給模型(技能清單本來就在系統指示裡)。
- **/goal 目標**(照 Claude Code 的 /goal 做):給 Bot 一個「做到什麼程度才算完成」的條件,它就一輪接一輪做下去,不用每一步都叫它。關鍵是**做事的模型不能自己宣布完成**:每一輪結束後,另一個模型(Bot 的「執行步驟用的模型」,通常是快速模型;設成「關閉」就用 Bot 自己的模型)只看這段對話(Bot 說的話、用了哪些工具、工具回了什麼),判斷條件成立了沒有。 - **/goal 目標**(照 Claude Code 的 /goal 做):給 Bot 一個「做到什麼程度才算完成」的條件,它就一輪接一輪做下去,不用每一步都叫它。關鍵是**做事的模型不能自己宣布完成**:每一輪結束後,另一個模型(Bot 的「執行步驟用的模型」,通常是快速模型;設成「關閉」就用 Bot 自己的模型)只看這段對話(Bot 說的話、用了哪些工具、工具回了什麼),判斷條件成立了沒有。
- **用法**:「/goal 所有測試都通過,而且 clippy 沒有新的警告」設定並馬上開始做(已經有目標就換掉);「/goal」看目前的目標、做了多久、檢查了幾輪、最近一次檢查的理由;「/goal clear」清除(stop、off、reset、none、cancel、清除、取消、停止也可以)。在 / 清單最上面,標「指令和技能」。電腦、大腦的螢幕、手機打的都算,由大腦處理;訊息管道(Slack、Telegram…)和團隊成員打的不算指令,別人不能替你設目標。條件最多 4000 字;群組聊天還不能設目標。「清除聊天記錄」和「開始新對話」會連目標一起清掉;分享 Bot 的檔案不含目標。 - **用法**:「/goal 所有測試都通過,而且 clippy 沒有新的警告」設定並馬上開始做(已經有目標就換掉);「/goal」看目前的目標、做了多久、檢查了幾輪、最近一次檢查的理由;「/goal clear」清除(stop、off、reset、none、cancel、清除、取消、停止也可以)。在 / 清單最上面,標「指令和技能」。電腦、大腦的螢幕、手機打的都算,由大腦處理;訊息管道(Slack、Telegram…)和團隊成員打的不算指令,別人不能替你設目標。條件最多 4000 字;群組聊天還不能設目標。「清除聊天記錄」和「開始新對話」會連目標一起清掉;分享 Bot 的檔案不含目標。
- **檢查的結果**:還沒達成 → AnyBot 自己送出一則標「目標」的「還沒達成:(理由)」開始下一輪,理由就是下一步該做什麼;達成 → 聊天裡一行「目標達成:…(N 輪 · 多久)」,目標清掉;做不到 → 「目標做不到,已清除:…」;Bot 在等你回答或動手(登入、付款、做決定)→「目標暫停,等你回覆:…」,不會一直空轉。 - **檢查的結果**:還沒達成 → AnyBot 自己送出一則標「目標」的「還沒達成:(理由)」開始下一輪,理由就是下一步該做什麼;達成 → 聊天裡一行「目標達成:…(N 輪 · 多久)」,目標清掉,這個聊天上撒一下彩帶(慶祝動畫,設定 › 一般可關);做不到 → 「目標做不到,已清除:…」;Bot 在等你回答或動手(登入、付款、做決定)→「目標暫停,等你回覆:…」,不會一直空轉。
- **煞車**(比 Claude Code 嚴,因為 AnyBot 一輪可以做很多步、用的是你自己的金鑰):一個目標做 20 輪還沒達成就暫停問你;連續 3 輪都沒有用任何工具(只是在說話)就暫停;這一輪出錯、你按了停止(兩輪之間正在檢查時按也算)、檢查的模型沒回應、AnyBot 重新啟動過,也都是暫停。重新啟動後按中斷卡片上的「繼續」,目標也跟著接下去。暫停時目標還在,**傳一句話(例如「繼續」)就接著做**,用完 20 輪的再給 20 輪;不要了就 /goal clear。 - **煞車**(比 Claude Code 嚴,因為 AnyBot 一輪可以做很多步、用的是你自己的金鑰):一個目標做 20 輪還沒達成就暫停問你;連續 3 輪都沒有用任何工具(只是在說話)就暫停;這一輪出錯、你按了停止(兩輪之間正在檢查時按也算)、檢查的模型沒回應、AnyBot 重新啟動過,也都是暫停。重新啟動後按中斷卡片上的「繼續」,目標也跟著接下去。暫停時目標還在,**傳一句話(例如「繼續」)就接著做**,用完 20 輪的再給 20 輪;不要了就 /goal clear。
- **看得到的地方**:輸入框上方一行「目標進行中 · 12 分 · 3 輪」(檢查時是「正在檢查有沒有達成…」,暫停時是「目標暫停 · 原因」),滑過去看條件和最近一次的理由,右邊「清除目標」;窄視窗時字會縮成「…」,不會擠掉按鈕。AnyBot 自己的那幾行(達成、暫停、狀態)在聊天中間用小字顯示,不是 Bot 的話,**不會送給模型**,也不算檢查的證據。手機一樣,大腦的螢幕看到的是大腦同步過來的。 - **看得到的地方**:輸入框上方一行「目標進行中 · 12 分 · 3 輪」(檢查時是「正在檢查有沒有達成…」,暫停時是「目標暫停 · 原因」),滑過去看條件和最近一次的理由,右邊「清除目標」;窄視窗時字會縮成「…」,不會擠掉按鈕。AnyBot 自己的那幾行(達成、暫停、狀態)在聊天中間用小字顯示,不是 Bot 的話,**不會送給模型**,也不算檢查的證據。手機一樣,大腦的螢幕看到的是大腦同步過來的。
- **通知**:目標進行中的每一輪不再各通知一次「完成了」;達成、做不到、暫停時才通知(你不在電腦前時,手機也會收到),例如「Master 達成目標了」「Master 在等你回覆」。 - **通知**:目標進行中的每一輪不再各通知一次「完成了」;達成、做不到、暫停時才通知(你不在電腦前時,手機也會收到),例如「Master 達成目標了」「Master 在等你回覆」。
@ -1534,7 +1534,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- **需要你允許**:不再是蓋住整個視窗的彈出視窗,改成固定在輸入框上方的黃色卡片,上面的聊天照樣看得到,下面的輸入框照樣可以打字告訴它怎麼改。輸入框空著時 Enter 允許、Esc 拒絕(卡片出現 0.6 秒後才算,免得原本要按的 Enter 誤答);游標在輸入框裡也一樣(以前輸入框先把 Enter 當成「送出」拿走,框是空的什麼都沒送出,也沒有允許)。框裡有字時 Enter 照樣是送出。要你親自處理的步驟(接管畫面)還是聊天裡的卡片。 - **需要你允許**:不再是蓋住整個視窗的彈出視窗,改成固定在輸入框上方的黃色卡片,上面的聊天照樣看得到,下面的輸入框照樣可以打字告訴它怎麼改。輸入框空著時 Enter 允許、Esc 拒絕(卡片出現 0.6 秒後才算,免得原本要按的 Enter 誤答);游標在輸入框裡也一樣(以前輸入框先把 Enter 當成「送出」拿走,框是空的什麼都沒送出,也沒有允許)。框裡有字時 Enter 照樣是送出。要你親自處理的步驟(接管畫面)還是聊天裡的卡片。
- **黃色只代表「需要你」**:允許卡片、臉上的黃點、側邊欄 Bot 上的黃點、設定裡「更新」旁的黃點(有新版)。有新訊息是強調色(黏土橘)小點。 - **黃色只代表「需要你」**:允許卡片、臉上的黃點、側邊欄 Bot 上的黃點、設定裡「更新」旁的黃點(有新版)。有新訊息是強調色(黏土橘)小點。
- **標題列**:Bot 的名字在左邊(按一下開對話詳細資訊),右邊「分享」和「⋯」不再有圓框;圖示線條粗一點(2.25)。 - **標題列**:Bot 的名字在左邊(按一下開對話詳細資訊),右邊「分享」和「⋯」不再有圓框;圖示線條粗一點(2.25)。
- **新對話**:Bot 的臉放大、一句「嗨,我是 …」和它的描述,下面三個可以直接點的開頭(點了把字放進輸入框)。 - **新對話**:Bot 的臉放大、依時段的問候(早安/午安/晚上好/夜深了)、一句「嗨,我是 …」和它的描述,下面三個可以直接點的開頭(點了把字放進輸入框)。
- **設定**:左邊分頁只有文字,選中的黑底白字;每組設定一張白色細框卡片,一列一件事(左邊名稱、右邊控制項,名稱下最多一行小字,其餘說明在「?」裡);選項是分段按鈕,開關是黑軌白鈕。「一般」的名稱改成白話(聊天的顏色、用意思找記憶、Bot 可以翻的資料夾)。「整合」分成三頁(訊息管道、連接器、技能);訊息管道先列「已連接」(標記、名稱 · 種類、誰回覆、狀態、開關、⋯ 裡移除),「新增管道」是八個方塊,點了才在下面打開那一種的表單。權限頁的「直接操作」「自動審核」也是開關。 - **設定**:左邊分頁只有文字,選中的黑底白字;每組設定一張白色細框卡片,一列一件事(左邊名稱、右邊控制項,名稱下最多一行小字,其餘說明在「?」裡);選項是分段按鈕,開關是黑軌白鈕。「一般」的名稱改成白話(聊天的顏色、用意思找記憶、Bot 可以翻的資料夾)。「整合」分成三頁(訊息管道、連接器、技能);訊息管道先列「已連接」(標記、名稱 · 種類、誰回覆、狀態、開關、⋯ 裡移除),「新增管道」是八個方塊,點了才在下面打開那一種的表單。權限頁的「直接操作」「自動審核」也是開關。
- **手機**:聊天跟著 Bot 的顏色、Bot 的回覆不用泡泡、允許卡片是黃色、輸入框是墨色框線;工作中在對話最後顯示 Bot 的小臉和跟電腦上一樣的那句「正在…」。 - **手機**:聊天跟著 Bot 的顏色、Bot 的回覆不用泡泡、允許卡片是黃色、輸入框是墨色框線;工作中在對話最後顯示 Bot 的小臉和跟電腦上一樣的那句「正在…」。
- **自己進化**:一件事做了 5 步以上(操作電腦、網頁、指令,不算記憶和設定),回答完後在背景回頭看一次:這是在網站或程式上動手操作的事(填表、發文、回留言、上傳下載、改設定),就把這次真的成功的最短做法存成技能(用畫面上的名字,不寫編號和座標;繞路和失敗寫成「注意」;使用者說過的偏好寫進去);已經有同一件事的技能就合併成更好的一版,照著做而且很順就不動。回覆下面會多一行「(學會了新做法「…」)」或「(把做法「…」更新了)」。系統指示要 Bot 開始做事前先看技能清單、有符合的先 use_skill。實測(httpbin 訂 pizza,真的 Grok):第一次 11 步學到技能;第二次先讀技能、10 步 24 秒一次做完,回頭看後判斷不用改。 - **自己進化**:一件事做了 5 步以上(操作電腦、網頁、指令,不算記憶和設定),回答完後在背景回頭看一次:這是在網站或程式上動手操作的事(填表、發文、回留言、上傳下載、改設定),就把這次真的成功的最短做法存成技能(用畫面上的名字,不寫編號和座標;繞路和失敗寫成「注意」;使用者說過的偏好寫進去);已經有同一件事的技能就合併成更好的一版,照著做而且很順就不動。回覆下面會多一行「(學會了新做法「…」)」或「(把做法「…」更新了)」。系統指示要 Bot 開始做事前先看技能清單、有符合的先 use_skill。實測(httpbin 訂 pizza,真的 Grok):第一次 11 步學到技能;第二次先讀技能、10 步 24 秒一次做完,回頭看後判斷不用改。
@ -1852,6 +1852,8 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- 淺色:米白紙底、側欄深一階、卡片純白;文字是帶暖調的黑。深色:暖黑三階(不藍黑)。 - 淺色:米白紙底、側欄深一階、卡片純白;文字是帶暖調的黑。深色:暖黑三階(不藍黑)。
- 強調色(連結、選中、新訊息點、focus)是黏土橘;殼本身幾乎全灰階,**黃色只代表「需要你」**,紅只代表危險,圖表才有意識地用色(一套暖家族六色,見第 27 節頁面圖表)。 - 強調色(連結、選中、新訊息點、focus)是黏土橘;殼本身幾乎全灰階,**黃色只代表「需要你」**,紅只代表危險,圖表才有意識地用色(一套暖家族六色,見第 27 節頁面圖表)。
- 設定 › 一般 › 外觀有三個旋紐:**底色**(藍灰→米白)、**對比**(柔和→鮮明,整個殼的階層、細線、文字深淺一起調)、**強調色**(黏土、靛藍、苔綠、藍綠、玫紅、琥珀、石板、墨黑八色,圖表六色跟著轉);預設就是「紙」。同處有**密度**(寬鬆/緊湊)和**慶祝動畫**開關;「外殼顏色重設」把三個旋紐歸零。側欄選中的 Bot 是一條強調色細條+淺底,不整條上色。
- 工作完成撒彩帶:只在 /goal 目標達成時(不是每輪結束),落在該 Bot 的聊天上約 1.4 秒;設定 › 一般可關。
### 頭像 ### 頭像

View File

@ -6,7 +6,7 @@
設定視窗,分頁由上到下: 設定視窗,分頁由上到下:
- 「一般」: - 「一般」:
- 外觀:主題、聊天的顏色、字型、語言(選單和 Bot 回答用的語言)。 - 外觀:主題、底色(冷→暖滑桿)、對比(柔和→鮮明滑桿)、強調色(八個點:黏土、靛藍、苔綠、藍綠、玫紅、琥珀、石板、墨黑)、密度(寬鬆/緊湊)、慶祝動畫(開/關,目標達成時撒彩帶)、外殼顏色重設(回預設「紙」)、聊天的顏色、字型、語言(選單和 Bot 回答用的語言)。
- 記憶與文件:用意思找記憶(本機模型/Ollama/關閉)、Bot 可以翻的資料夾([memory](memory.md))。 - 記憶與文件:用意思找記憶(本機模型/Ollama/關閉)、Bot 可以翻的資料夾([memory](memory.md))。
- 通知:Bot 做完或等你時通知、需要你時響一聲([phone](phone.md))。Mac 上的通知是 AnyBot.app 自己發的(貓的圖示),點一下打開那個 Bot;從建置資料夾直接跑(不是 .app)時改用系統的 display notification,圖示會是「工序指令編寫程式」。 - 通知:Bot 做完或等你時通知、需要你時響一聲([phone](phone.md))。Mac 上的通知是 AnyBot.app 自己發的(貓的圖示),點一下打開那個 Bot;從建置資料夾直接跑(不是 .app)時改用系統的 display notification,圖示會是「工序指令編寫程式」。
- Bot:時區,例行任務和提醒用([routines](routines.md))。 - Bot:時區,例行任務和提醒用([routines](routines.md))。

View File

@ -9,8 +9,8 @@
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="AnyBot"> <meta name="apple-mobile-web-app-title" content="AnyBot">
<meta name="theme-color" content="#161616" media="(prefers-color-scheme: dark)"> <meta name="theme-color" content="#1e1d1b" media="(prefers-color-scheme: dark)">
<meta name="theme-color" content="#f5f5f5" media="(prefers-color-scheme: light)"> <meta name="theme-color" content="#faf9f6" media="(prefers-color-scheme: light)">
<link rel="manifest" href="manifest.webmanifest"> <link rel="manifest" href="manifest.webmanifest">
<link rel="icon" href="icon.svg" type="image/svg+xml"> <link rel="icon" href="icon.svg" type="image/svg+xml">
<link rel="icon" href="icon-192.png" type="image/png" sizes="192x192"> <link rel="icon" href="icon-192.png" type="image/png" sizes="192x192">

View File

@ -20,7 +20,7 @@ use crate::model::{Accent, Bot, Message, Role, State, Theme, ToolStatus, TurnOut
use crate::providers::{self, AppCall, Approval, ApprovalAnswer, ApprovalKind, ChatRequest, ProviderKind, StreamEvent, ALL_PROVIDERS}; use crate::providers::{self, AppCall, Approval, ApprovalAnswer, ApprovalKind, ChatRequest, ProviderKind, StreamEvent, ALL_PROVIDERS};
use crate::tools; use crate::tools;
use crate::i18n::t; use crate::i18n::t;
use crate::theme::{Palette, DARK, LIGHT}; use crate::theme::{is_dark, Palette, LIGHT};
mod attach_ui; mod attach_ui;
mod channels_ui; mod channels_ui;
@ -322,6 +322,8 @@ pub struct App {
faces: HashMap<u64, sidebar_ui::Face>, faces: HashMap<u64, sidebar_ui::Face>,
/// When each bot last finished a turn well (its face above the input smiles for a moment). /// When each bot last finished a turn well (its face above the input smiles for a moment).
cheer: HashMap<u64, Instant>, cheer: HashMap<u64, Instant>,
/// 撒花: a /goal just landed (bot, when) — a short confetti over that chat (設定 › 一般可關).
confetti: Option<(u64, Instant)>,
/// The bot's writing face: (words in the answer, when the last one arrived), so the nod /// The bot's writing face: (words in the answer, when the last one arrived), so the nod
/// keeps time with the words flowing out. /// keeps time with the words flowing out.
write_len: HashMap<u64, (usize, f64)>, write_len: HashMap<u64, (usize, f64)>,
@ -536,6 +538,7 @@ impl App {
menu_for: None, menu_for: None,
faces: HashMap::new(), faces: HashMap::new(),
cheer: HashMap::new(), cheer: HashMap::new(),
confetti: None,
write_len: HashMap::new(), write_len: HashMap::new(),
think_len: HashMap::new(), think_len: HashMap::new(),
pen_run: HashMap::new(), pen_run: HashMap::new(),
@ -602,6 +605,15 @@ impl App {
if std::env::var("ANYBOT_SHOT_THEME").as_deref() == Ok("dark") { if std::env::var("ANYBOT_SHOT_THEME").as_deref() == Ok("dark") {
app.state.theme = Theme::Dark; app.state.theme = Theme::Dark;
} }
// Shell dials for concept pictures: ANYBOT_SHOT_SHELL=tone,accent,contrast.
if let Ok(v) = std::env::var("ANYBOT_SHOT_SHELL") {
let mut it = v.split(',');
if let (Some(t), Some(a), Some(c)) = (it.next().and_then(|x| x.parse().ok()), it.next(), it.next().and_then(|x| x.parse().ok())) {
app.state.shell_tone = t;
app.state.shell_accent = a.to_string();
app.state.shell_contrast = c;
}
}
// Optional view for checking the dialogs in a picture. // Optional view for checking the dialogs in a picture.
match std::env::var("ANYBOT_SHOT_VIEW").as_deref() { match std::env::var("ANYBOT_SHOT_VIEW").as_deref() {
Ok("chat") => app.state.selected = 1, Ok("chat") => app.state.selected = 1,
@ -1157,13 +1169,47 @@ impl App {
app app
} }
/// 撒花: a short burst over the chat whose /goal just landed; 1.4 s, fades out, and it
/// never constrains anything — it is confetti, not a gate. Off in 設定 › 一般.
fn confetti_overlay(&self, ctx: &egui::Context) {
let Some((bot, t0)) = self.confetti else { return };
if !self.state.celebrate || bot != self.state.selected || self.screenshot.is_some() {
return;
}
let t = t0.elapsed().as_secs_f32();
if t > 1.4 {
return;
}
let rect = ctx.content_rect();
let paint = ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::unique("confetti")));
let fade = ((1.4 - t) / 0.45).clamp(0.0, 1.0);
for i in 0..28 {
let seed = (i as f32 * 0.618034).fract();
let x = rect.left() + 16.0 + (rect.width() - 32.0) * seed;
let y = rect.top() + 40.0 + t * (150.0 + 240.0 * ((i as f32 * 7.13).fract()));
if y > rect.bottom() - 8.0 {
continue;
}
let drift = (t * 3.5 + seed * 12.0).sin() * 16.0;
let col = self.pal.chart_cat[i % 6].linear_multiply(fade);
let c = egui::pos2(x + drift, y);
let ang = seed * 12.0 + t * 6.0;
let (cs, sn) = (ang.cos(), ang.sin());
let pts = [egui::vec2(-3.5, -2.25), egui::vec2(3.5, -2.25), egui::vec2(3.5, 2.25), egui::vec2(-3.5, 2.25)]
.map(|d| c + egui::vec2(d.x * cs - d.y * sn, d.x * sn + d.y * cs));
paint.add(egui::Shape::convex_polygon(pts.to_vec(), col, Stroke::NONE));
}
ctx.request_repaint_after(std::time::Duration::from_millis(16));
}
fn apply_theme(&mut self, ctx: &egui::Context) { fn apply_theme(&mut self, ctx: &egui::Context) {
let dark = match self.state.theme { let dark = match self.state.theme {
Theme::Light => false, Theme::Light => false,
Theme::Dark => true, Theme::Dark => true,
Theme::System => ctx.input(|i| i.raw.system_theme) == Some(egui::Theme::Dark), Theme::System => ctx.input(|i| i.raw.system_theme) == Some(egui::Theme::Dark),
}; };
self.pal = if dark { DARK } else { LIGHT }; // The shell from the person's three dials (設定 › 一般); defaults reproduce 「纸」.
self.pal = crate::theme::shell(self.state.shell_tone, &self.state.shell_accent, self.state.shell_contrast, dark);
// Screenshot concept themes for picking a colour direction (see theme.rs `shot_palette`). // Screenshot concept themes for picking a colour direction (see theme.rs `shot_palette`).
if let Ok(t) = std::env::var("ANYBOT_SHOT_PAL") { if let Ok(t) = std::env::var("ANYBOT_SHOT_PAL") {
if let Some(p) = crate::theme::shot_palette(&t, dark) { if let Some(p) = crate::theme::shot_palette(&t, dark) {
@ -1209,8 +1255,10 @@ impl App {
s.spacing.menu_margin = Margin::same(6); s.spacing.menu_margin = Margin::same(6);
s.spacing.menu_spacing = 0.0; s.spacing.menu_spacing = 0.0;
s.visuals.popup_shadow = egui::epaint::Shadow { offset: [0, 10], blur: 30, spread: 0, color: Color32::from_black_alpha(52) }; s.visuals.popup_shadow = egui::epaint::Shadow { offset: [0, 10], blur: 30, spread: 0, color: Color32::from_black_alpha(52) };
s.spacing.item_spacing = vec2(9.0, 7.0); // 寬鬆/緊湊 density (設定 › 一般): the rhythm of the whole shell in one switch.
s.spacing.button_padding = vec2(11.0, 6.0); let (gap, pad) = if self.state.dense { (vec2(8.0, 5.0), vec2(10.0, 4.0)) } else { (vec2(9.0, 7.0), vec2(11.0, 6.0)) };
s.spacing.item_spacing = gap;
s.spacing.button_padding = pad;
// Scrollbars like the web's: a thin quiet rail that widens under the pointer. // Scrollbars like the web's: a thin quiet rail that widens under the pointer.
s.spacing.scroll.floating = true; s.spacing.scroll.floating = true;
s.spacing.scroll.bar_width = 8.0; s.spacing.scroll.bar_width = 8.0;
@ -1232,7 +1280,7 @@ impl App {
fn bot_color(&self, b: &Bot) -> Color32 { fn bot_color(&self, b: &Bot) -> Color32 {
let c = avatar::color(&b.color); let c = avatar::color(&b.color);
// A black avatar would vanish on the dark page: lift it to a dark grey there. // A black avatar would vanish on the dark page: lift it to a dark grey there.
if self.pal.pane != LIGHT.pane && (c.r() as u32 + c.g() as u32 + c.b() as u32) < 120 { if is_dark(self.pal) && (c.r() as u32 + c.g() as u32 + c.b() as u32) < 120 {
return Color32::from_gray(0x4a); return Color32::from_gray(0x4a);
} }
c c
@ -3363,6 +3411,10 @@ 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);
// 問候依時段(和時區設定一起):先打招呼,再報名字。
let hour: u32 = chrono::Local::now().format("%H").to_string().parse().unwrap_or(12);
let hello = match hour { 5..=11 => "早安", 12..=17 => "午安", 18..=22 => "晚上好", _ => "夜深了" };
ui.label(RichText::new(t(hello)).size(FONT_LG).color(p.text3));
ui.label(RichText::new(t("嗨,我是 {name}").replace("{name}", &bot.name)).size(28.0).strong().family(crate::bold()).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());
@ -3854,7 +3906,7 @@ impl App {
let screen = ctx.content_rect(); let screen = ctx.content_rect();
egui::Area::new(egui::Id::unique("approval-dim")).order(egui::Order::Foreground).fixed_pos(screen.min).interactable(true).show(ctx, |ui| { egui::Area::new(egui::Id::unique("approval-dim")).order(egui::Order::Foreground).fixed_pos(screen.min).interactable(true).show(ctx, |ui| {
let (rect, _) = ui.allocate_exact_size(screen.size(), egui::Sense::click()); let (rect, _) = ui.allocate_exact_size(screen.size(), egui::Sense::click());
ui.painter().rect_filled(rect, 0, Color32::from_black_alpha(if p.pane == LIGHT.pane { 70 } else { 120 })); ui.painter().rect_filled(rect, 0, Color32::from_black_alpha(if is_dark(p) { 120 } else { 70 }));
}); });
let mut answer = None; let mut answer = None;
let mut later = false; let mut later = false;
@ -4588,7 +4640,7 @@ impl App {
} }
setting_card(ui, p, |ui| { setting_card(ui, p, |ui| {
setting_title(ui, "頭像", "", p); setting_title(ui, "頭像", "", p);
let inactive_grey = if p.pane == LIGHT.pane { Color32::from_gray(185) } else { Color32::from_gray(90) }; let inactive_grey = if is_dark(p) { Color32::from_gray(90) } else { Color32::from_gray(185) };
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 6.0; ui.spacing_mut().item_spacing.x = 6.0;
for s in avatar::SHAPES { for s in avatar::SHAPES {
@ -4927,6 +4979,55 @@ impl App {
theme_changed = true; theme_changed = true;
} }
}); });
card_row(ui, p, "底色", "", "整個殼的色溫:偏左藍灰、偏右米白。", |ui| {
let before = self.state.shell_tone;
ui.add(egui::Slider::new(&mut self.state.shell_tone, 0.0..=1.0).show_value(false).text(" "));
if self.state.shell_tone != before {
self.dirty = true;
}
});
card_row(ui, p, "對比", "", "拉高:分層、細線和文字階級更明顯。", |ui| {
let before = self.state.shell_contrast;
ui.add(egui::Slider::new(&mut self.state.shell_contrast, 0.75..=1.35).show_value(false).text(" "));
if self.state.shell_contrast != before {
self.dirty = true;
}
});
card_row(ui, p, "強調色", "", "選中項、連結和新訊息點的顏色;圖表六色跟著它轉。", |ui| {
let darkish = self.pal.pane.r() < 128;
for (name, label, light, darkv) in crate::theme::ACCENTS {
let (rect, r) = ui.allocate_exact_size(vec2(26.0, 26.0), egui::Sense::click());
let c = rect.center();
ui.painter().circle_filled(c, 10.0, if darkish { darkv } else { light });
if self.state.shell_accent == name {
ui.painter().circle_stroke(c, 13.0, Stroke::new(2.0, p.text));
}
if r.on_hover_text(t(label)).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() && self.state.shell_accent != name {
self.state.shell_accent = name.to_string();
self.dirty = true;
}
}
});
card_row(ui, p, "密度", "", "緊湊:行距和按鈕縮一點,一屏看更多。", |ui| {
if let Some(v) = segmented(ui, p, self.state.dense, &[(false, "寬鬆"), (true, "緊湊")]) {
self.state.dense = v;
self.dirty = true;
}
});
card_row(ui, p, "慶祝動畫", "", "工作完成時撒一下彩帶。", |ui| {
if let Some(v) = segmented(ui, p, self.state.celebrate, &[(true, "開"), (false, "關")]) {
self.state.celebrate = v;
self.dirty = true;
}
});
card_row(ui, p, "外殼顏色重設", "", "底色、強調色、對比回到預設(紙)。", |ui| {
if ui.button(t("重設")).clicked() {
self.state.shell_tone = 1.0;
self.state.shell_accent = "clay".into();
self.state.shell_contrast = 1.0;
self.dirty = true;
}
});
card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| { card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| {
// Two dots (from the right): black, and the bots' own colours. // Two dots (from the right): black, and the bots' own colours.
for a in [Accent::Black, Accent::BotColor] { for a in [Accent::Black, Accent::BotColor] {
@ -6011,6 +6112,7 @@ impl eframe::App for App {
self.file_viewer(ctx); self.file_viewer(ctx);
self.splash(ctx); self.splash(ctx);
self.drop_overlay(ctx); self.drop_overlay(ctx);
self.confetti_overlay(ctx);
// Keep the routine clock ticking while the window sits idle. // Keep the routine clock ticking while the window sits idle.
if !self.demo { if !self.demo {
ctx.request_repaint_after(std::time::Duration::from_secs(15)); ctx.request_repaint_after(std::time::Duration::from_secs(15));
@ -6919,7 +7021,7 @@ fn dialog_max_height(ctx: &egui::Context) -> f32 {
/// A centred dialog over a dimmed window: title and × on top, then the caller's body. /// A centred dialog over a dimmed window: title and × on top, then the caller's body.
/// Returns true when the person asked to close it (×, Esc, or a click outside when `outside_closes`). /// Returns true when the person asked to close it (×, Esc, or a click outside when `outside_closes`).
fn dialog(ctx: &egui::Context, id: &str, title: &str, width: f32, outside_closes: bool, p: Palette, content: impl FnOnce(&mut egui::Ui)) -> bool { fn dialog(ctx: &egui::Context, id: &str, title: &str, width: f32, outside_closes: bool, p: Palette, content: impl FnOnce(&mut egui::Ui)) -> bool {
let dark = p.pane != LIGHT.pane; let dark = is_dark(p);
let mut close = false; let mut close = false;
// Read before the content runs: a text box drops its caret on Esc while it draws, so asked // Read before the content runs: a text box drops its caret on Esc while it draws, so asked
// afterwards it would always say "no box had the caret". // afterwards it would always say "no box had the caret".

View File

@ -243,6 +243,7 @@ impl App {
b.goal = None; b.goal = None;
self.goal_note(bot_id, &note); self.goal_note(bot_id, &note);
self.goal_tell(bot_id, &format!("{name} {title}"), &note); self.goal_tell(bot_id, &format!("{name} {title}"), &note);
self.confetti = Some((bot_id, Instant::now()));
} }
Next::Pause { note, title } => { Next::Pause { note, title } => {
self.goal_note(bot_id, &note); self.goal_note(bot_id, &note);

View File

@ -606,7 +606,7 @@ impl App {
/// links that open in the browser. /// links that open in the browser.
fn md_spans(&mut self, ui: &mut egui::Ui, spans: &[Span], size: f32, col: Color32, heading: bool) { fn md_spans(&mut self, ui: &mut egui::Ui, spans: &[Span], size: f32, col: Color32, heading: bool) {
let p = self.pal; let p = self.pal;
let link_col = if p.pane == LIGHT.pane { Color32::from_rgb(0x0b, 0x6d, 0xd3) } else { Color32::from_rgb(0x5a, 0xa9, 0xff) }; let link_col = if crate::theme::is_dark(p) { Color32::from_rgb(0x5a, 0xa9, 0xff) } else { Color32::from_rgb(0x0b, 0x6d, 0xd3) };
let mut job = egui::text::LayoutJob::default(); let mut job = egui::text::LayoutJob::default();
// 粉圓體 has one weight: bold words (and headings) are drawn a second time half a pixel // 粉圓體 has one weight: bold words (and headings) are drawn a second time half a pixel
// to the right, from a twin layout where everything else is transparent. // to the right, from a twin layout where everything else is transparent.
@ -1088,7 +1088,7 @@ impl App {
fn md_code(&mut self, ui: &mut egui::Ui, lang: &str, text: &str, col: Color32) { fn md_code(&mut self, ui: &mut egui::Ui, lang: &str, text: &str, col: Color32) {
let p = self.pal; let p = self.pal;
let dark = p.pane != LIGHT.pane; let dark = crate::theme::is_dark(p);
let key = key_of(text, dark); let key = key_of(text, dark);
let resp = Frame::new().fill(p.hover.gamma_multiply(0.7)).stroke(Stroke::new(1.0, p.border)).corner_radius(12).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| { let resp = Frame::new().fill(p.hover.gamma_multiply(0.7)).stroke(Stroke::new(1.0, p.border)).corner_radius(12).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| {
ui.set_width(ui.available_width()); ui.set_width(ui.available_width());
@ -1160,7 +1160,7 @@ impl App {
if streaming { if streaming {
return self.md_code(ui, "mermaid", src, col); return self.md_code(ui, "mermaid", src, col);
} }
let dark = p.pane != LIGHT.pane; let dark = crate::theme::is_dark(p);
let key = key_of(src, dark); let key = key_of(src, dark);
if !self.md.diagrams.contains_key(&key) { if !self.md.diagrams.contains_key(&key) {
// Keep a long chat from growing forever: every diagram is a GPU texture. Past a // Keep a long chat from growing forever: every diagram is a GPU texture. Past a
@ -1284,7 +1284,7 @@ impl App {
}) else { }) else {
return; return;
}; };
let dark = self.pal.pane != LIGHT.pane; let dark = crate::theme::is_dark(self.pal);
if let Ok(img) = crate::diagram::render(&src, dark, 2.0) { if let Ok(img) = crate::diagram::render(&src, dark, 2.0) {
let dir = dirs::download_dir().unwrap_or_else(std::env::temp_dir); let dir = dirs::download_dir().unwrap_or_else(std::env::temp_dir);
let path = dir.join(format!("圖表-{}.png", chrono::Local::now().format("%Y%m%d-%H%M%S"))); let path = dir.join(format!("圖表-{}.png", chrono::Local::now().format("%Y%m%d-%H%M%S")));

View File

@ -834,8 +834,14 @@ impl App {
// Drag a bot onto another group to move it. // Drag a bot onto another group to move it.
resp.dnd_set_drag_payload(id); resp.dnd_set_drag_payload(id);
let dragged = resp.dragged(); let dragged = resp.dragged();
let fill = if selected { p.active } else if resp.hovered() || dragged { p.hover } else { Color32::TRANSPARENT }; // 選中不再整條上色(細條在下方說「你在這」);選中和滑過同色,靜一點。
let fill = if selected || resp.hovered() || dragged { p.hover } else { Color32::TRANSPARENT };
ui.painter().rect_filled(rect, 12, fill); ui.painter().rect_filled(rect, 12, fill);
if selected {
// 「你在這」的安靜說法:一條 3 px 的強調色細條,不整條上色(Linear 的選中)。
let strip = egui::Rect::from_min_size(rect.left_center() + vec2(3.0, -11.0), vec2(3.0, 22.0));
ui.painter().rect_filled(strip, 2.0, p.accent);
}
let face = egui::Rect::from_min_size(rect.min + vec2(8.0, 7.0), vec2(40.0, 40.0)); let face = egui::Rect::from_min_size(rect.min + vec2(8.0, 7.0), vec2(40.0, 40.0));
self.live_face(ui, id, face, true); self.live_face(ui, id, face, true);
let tx = rect.left() + 56.0; let tx = rect.left() + 56.0;

View File

@ -640,6 +640,20 @@ pub struct State {
pub next_id: u64, pub next_id: u64,
pub theme: Theme, pub theme: Theme,
pub accent: Accent, pub accent: Accent,
/// 外殼產生器(設定 › 一般):色調 0 冷…1 暖、強調色名(見 theme::ACCENTS)、對比 0.75 柔和…1.35 鮮明。
/// 預設 1/clay/1 就是「紙」。舊設定檔沒這幾個欄位時照預設補。
#[serde(default = "default_shell_tone")]
pub shell_tone: f32,
#[serde(default = "default_shell_accent")]
pub shell_accent: String,
#[serde(default = "default_shell_contrast")]
pub shell_contrast: f32,
/// 緊湊間距(設定 › 一般);關=寬鬆。
#[serde(default)]
pub dense: bool,
/// 工作完成時的慶祝動畫(設定 › 一般)。
#[serde(default = "default_true")]
pub celebrate: bool,
#[serde(default)] #[serde(default)]
pub providers: std::collections::BTreeMap<String, ProviderSettings>, pub providers: std::collections::BTreeMap<String, ProviderSettings>,
#[serde(default)] #[serde(default)]
@ -785,6 +799,18 @@ fn first_routine_id() -> u64 {
1 1
} }
fn default_shell_tone() -> f32 {
1.0
}
fn default_shell_accent() -> String {
"clay".into()
}
fn default_shell_contrast() -> f32 {
1.0
}
fn default_true() -> bool {
true
}
fn default_sidebar_width() -> f32 { fn default_sidebar_width() -> f32 {
crate::app::SIDEBAR_DEFAULT_WIDTH crate::app::SIDEBAR_DEFAULT_WIDTH
} }
@ -1166,6 +1192,11 @@ impl State {
next_id: 1, next_id: 1,
theme: Theme::Light, theme: Theme::Light,
accent: Accent::BotColor, accent: Accent::BotColor,
shell_tone: 1.0,
shell_accent: "clay".into(),
shell_contrast: 1.0,
dense: false,
celebrate: true,
providers: Default::default(), providers: Default::default(),
sidebar_collapsed: false, sidebar_collapsed: false,
embed_model: String::new(), embed_model: String::new(),

View File

@ -78,6 +78,8 @@ pub const LIGHT: Palette = Palette {
// primary hover #dbdbdb; translucent tokens are the ink at hover 6%, active 8%, agent bubble 4%, // primary hover #dbdbdb; translucent tokens are the ink at hover 6%, active 8%, agent bubble 4%,
// user bubble 18%, text 66/54%, border 10%. Accent blue/0 #1884fc, danger red/0 #fc2c3e. // user bubble 18%, text 66/54%, border 10%. Accent blue/0 #1884fc, danger red/0 #fc2c3e.
// Measured from the original's dark window: chat rgb 19, sidebar 16, bubbles/cards 31–33. // Measured from the original's dark window: chat rgb 19, sidebar 16, bubbles/cards 31–33.
// Kept as the documented reference of 「纸 dark」; the live dark palette comes from `shell`.
#[allow(dead_code)]
pub const DARK: Palette = Palette { pub const DARK: Palette = Palette {
pane: hexa(0x1e, 0x1d, 0x1b, 0xff), pane: hexa(0x1e, 0x1d, 0x1b, 0xff),
sidebar: hexa(0x19, 0x18, 0x17, 0xff), sidebar: hexa(0x19, 0x18, 0x17, 0xff),
@ -140,41 +142,76 @@ pub fn shot_palette(name: &str, dark: bool) -> Option<Palette> {
("moss", true) => (rgb(0xec, 0xf0, 0xea), rgb(0x15, 0x18, 0x15), rgb(0x7f, 0xaa, 0x8a), rgb(0xdd, 0x6f, 0x66), rgb(0x76, 0xc0, 0x90)), ("moss", true) => (rgb(0xec, 0xf0, 0xea), rgb(0x15, 0x18, 0x15), rgb(0x7f, 0xaa, 0x8a), rgb(0xdd, 0x6f, 0x66), rgb(0x76, 0xc0, 0x90)),
_ => return None, _ => return None,
}; };
let (accent, focus) = (accent, accent); Some(build(ink, paper, accent, danger, up, 1.0, dark))
// The ladder: every surface is the paper stepped toward the ink; every text is the ink
// stepped back toward the paper. Equal steps are what makes it read as one system.
let step = |k: f32| mix(paper, ink, k);
let six = |l: f32| [hsl_shift(accent, 0.0, 0.52, l), hsl_shift(accent, 52.0, 0.42, l), hsl_shift(accent, 110.0, 0.40, l), hsl_shift(accent, 190.0, 0.45, l), hsl_shift(accent, 265.0, 0.40, l), hsl_shift(accent, 325.0, 0.12, l)];
let cat = if dark { six(0.62) } else { six(0.48) };
Some(Palette {
pane: paper,
sidebar: step(0.045),
elevated: if dark { step(0.10) } else { rgb(0xff, 0xff, 0xff) },
hover: with(ink, 15),
active: with(ink, 26),
primary: ink,
text: ink,
text2: mix(ink, paper, 0.34),
text3: mix(ink, paper, 0.50),
on_primary: paper,
bubble_user: if dark { with(ink, 46) } else { ink },
border: with(ink, if dark { 26 } else { 20 }),
focus,
accent,
danger,
attention: rgb(0xd9, 0xa4, 0x41),
attention_bg: with(rgb(0xd9, 0xa4, 0x41), if dark { 38 } else { 26 }),
muted: if dark { step(0.10) } else { step(0.035) },
chart_cat: cat,
grid: with(ink, 14),
up,
})
} }
const fn rgb(r: u8, g: u8, b: u8) -> Color32 { const fn rgb(r: u8, g: u8, b: u8) -> Color32 {
Color32::from_rgb(r, g, b) Color32::from_rgb(r, g, b)
} }
/// The accents the person can pick (設定 › 一般): name, 中文名, light, dark.
pub const ACCENTS: [(&str, &str, Color32, Color32); 8] = [
("clay", "黏土", rgb(0xc0, 0x62, 0x44), rgb(0xd8, 0x83, 0x66)),
("indigo", "靛藍", rgb(0x5e, 0x6a, 0xd2), rgb(0x7c, 0x87, 0xe0)),
("moss", "苔綠", rgb(0x4a, 0x7c, 0x59), rgb(0x7f, 0xaa, 0x8a)),
("teal", "藍綠", rgb(0x2e, 0x7d, 0x77), rgb(0x5f, 0xa8, 0xa0)),
("rose", "玫紅", rgb(0xb0, 0x44, 0x6e), rgb(0xd6, 0x7e, 0xa0)),
("amber", "琥珀", rgb(0xb0, 0x7f, 0x2e), rgb(0xd9, 0xa4, 0x41)),
("slate", "石板", rgb(0x64, 0x74, 0x8b), rgb(0x94, 0xa3, 0xb8)),
("ink", "墨黑", rgb(0x22, 0x20, 0x1e), rgb(0xe8, 0xe6, 0xe1)),
];
/// The shell from three inputs (Linear's method, in the settings): `tone` 0=cool…1=warm,
/// `accent` one of `ACCENTS`, `contrast` 0.75柔和…1.35鮮明 (1 = as designed). Surfaces step
/// from paper toward ink; text is ink stepped back; the chart family rotates the accent's hue.
pub fn shell(tone: f32, accent: &str, contrast: f32, dark: bool) -> Palette {
let tone = tone.clamp(0.0, 1.0);
let c = contrast.clamp(0.6, 1.5);
// Cool end is Linear's neutral grey; warm end is 「纸」 (the shipped default, tone=1).
let (paper, ink) = if dark {
(mix(rgb(0x10, 0x11, 0x13), rgb(0x1e, 0x1d, 0x1b), tone), mix(rgb(0xf1, 0xf1, 0xf3), rgb(0xf2, 0xf0, 0xeb), tone))
} else {
(mix(rgb(0xf6, 0xf6, 0xf8), rgb(0xfa, 0xf9, 0xf6), tone), mix(rgb(0x20, 0x21, 0x24), rgb(0x25, 0x22, 0x1f), tone))
};
let a = ACCENTS.iter().find(|(n, _, _, _)| *n == accent).unwrap_or(&ACCENTS[0]);
let (danger, up) = if dark { (rgb(0xe2, 0x6e, 0x6e), rgb(0x6f, 0xb9, 0x7d)) } else { (rgb(0xb4, 0x2a, 0x2a), rgb(0x2e, 0x7d, 0x3f)) };
build(ink, paper, if dark { a.3 } else { a.2 }, danger, up, c, dark)
}
/// Shared body of `shell` and `shot_palette`: the ladder. `contrast` scales every step of it
/// (surfaces, hairlines, text fades, chart chroma) — one dial, the whole shell follows.
fn build(ink: Color32, paper: Color32, accent: Color32, danger: Color32, up: Color32, contrast: f32, dark: bool) -> Palette {
let step = |k: f32| mix(paper, ink, k * contrast);
let s = (0.52 * contrast).clamp(0.15, 0.8);
let six = |l: f32| [hsl_shift(accent, 0.0, s, l), hsl_shift(accent, 52.0, s * 0.8, l), hsl_shift(accent, 110.0, s * 0.77, l), hsl_shift(accent, 190.0, s * 0.87, l), hsl_shift(accent, 265.0, s * 0.77, l), hsl_shift(accent, 325.0, s * 0.23, l)];
let cat = if dark { six(0.62) } else { six(0.48) };
Palette {
pane: paper,
// In light the ladder steps down from the page toward ink; in dark the sidebar steps
// down toward black (a dark sidebar is a darker dark, not a lighter one — Linear).
sidebar: if dark { mix(paper, rgb(0, 0, 0), 0.17 * contrast) } else { step(0.045) },
elevated: if dark { step(0.10) } else { rgb(0xff, 0xff, 0xff) },
hover: with(ink, (15.0 * contrast) as u8),
active: with(ink, (26.0 * contrast) as u8),
primary: ink,
text: ink,
text2: mix(ink, paper, 0.34 / contrast),
text3: mix(ink, paper, 0.50 / contrast),
on_primary: paper,
bubble_user: if dark { with(ink, 46) } else { ink },
border: with(ink, ((if dark { 26.0 } else { 20.0 }) * contrast) as u8),
focus: accent,
accent,
danger,
attention: rgb(0xd9, 0xa4, 0x41),
attention_bg: with(rgb(0xd9, 0xa4, 0x41), ((if dark { 38.0 } else { 26.0 }) * contrast) as u8),
muted: if dark { step(0.10) } else { step(0.035) },
chart_cat: cat,
grid: with(ink, (14.0 * contrast) as u8),
up,
}
}
fn with(c: Color32, a: u8) -> Color32 { fn with(c: Color32, a: u8) -> Color32 {
Color32::from_rgba_unmultiplied(c.r(), c.g(), c.b(), a) Color32::from_rgba_unmultiplied(c.r(), c.g(), c.b(), a)
} }
@ -225,3 +262,81 @@ fn hsl_to_rgb(h: f32, s: f32, l: f32) -> Color32 {
}; };
rgb(((r + m) * 255.0).round() as u8, ((g + m) * 255.0).round() as u8, ((b + m) * 255.0).round() as u8) rgb(((r + m) * 255.0).round() as u8, ((g + m) * 255.0).round() as u8, ((b + m) * 255.0).round() as u8)
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn shell_defaults_land_on_the_shipped_paper_palette() {
// tone=1 (warm) + clay + contrast 1 must reproduce 「纸」 within rounding.
let s = shell(1.0, "clay", 1.0, false);
assert_eq!(s.pane, LIGHT.pane);
assert_eq!(s.text, LIGHT.text);
assert_eq!(s.accent, LIGHT.accent);
// The ladder goes the right way: sidebar darker than pane, elevated lighter.
assert!(s.sidebar.r() < s.pane.r());
assert!(s.elevated.r() >= s.pane.r());
// Text hierarchy by brightness, not size: in light mode primary text is the darkest
// thing on the page, and each rank steps back toward the paper.
assert!(luma(s.text) < luma(s.text2));
assert!(luma(s.text2) < luma(s.text3));
assert!(luma(s.text3) < luma(s.pane));
// Dark mode is the mirror: text lighter than every surface.
let d = shell(1.0, "clay", 1.0, true);
assert!(luma(d.text) > luma(d.pane) + 40.0);
assert!(luma(d.pane) > luma(d.sidebar));
}
#[test]
fn contrast_dial_moves_the_whole_shell_monotonically() {
let soft = shell(1.0, "clay", 0.75, false);
let mid = shell(1.0, "clay", 1.0, false);
let sharp = shell(1.0, "clay", 1.35, false);
// Surfaces step further from the page, hairlines darken, text fades deepen.
assert!(soft.sidebar.r() > mid.sidebar.r() && mid.sidebar.r() > sharp.sidebar.r());
assert!(soft.border.a() < mid.border.a() && mid.border.a() < sharp.border.a());
assert!(luma(soft.text2) > luma(mid.text2) && luma(mid.text2) > luma(sharp.text2));
// Nothing leaves the valid range at the edges.
for c in [0.6, 1.5] {
let p = shell(0.0, "ink", c, true);
let _ = [p.pane, p.sidebar, p.text2, p.border, p.grid];
}
}
#[test]
fn tone_slides_cool_to_warm_and_accents_are_taken_verbatim() {
let cool = shell(0.0, "indigo", 1.0, false);
let warm = shell(1.0, "indigo", 1.0, false);
// The warm paper's red channel sits above the cool one's; same ink warmth rule.
assert!(warm.pane.r() as i32 - warm.pane.b() as i32 > cool.pane.r() as i32 - cool.pane.b() as i32);
assert_eq!(cool.accent, rgb(0x5e, 0x6a, 0xd2));
assert_eq!(shell(0.5, "moss", 1.0, true).accent, rgb(0x7f, 0xaa, 0x8a));
// An unknown accent falls back to clay, never panics.
assert_eq!(shell(0.5, "what", 1.0, false).accent, rgb(0xc0, 0x62, 0x44));
}
/// Perceptual-ish brightness for ordering checks (Rec. 709).
fn luma(c: Color32) -> f32 {
0.2126 * c.r() as f32 + 0.7152 * c.g() as f32 + 0.0722 * c.b() as f32
}
}
/// Whether the palette reads dark. A luma test, not `pane == DARK.pane`: the tone dial moves
/// the pane's colour, and every light/dark branch in the app must follow it.
pub fn is_dark(p: Palette) -> bool {
(0.2126 * p.pane.r() as f32 + 0.7152 * p.pane.g() as f32 + 0.0722 * p.pane.b() as f32) < 128.0
}
#[cfg(test)]
mod dark_tests {
use super::*;
#[test]
fn is_dark_follows_the_tone_dial_not_a_constant() {
assert!(!is_dark(LIGHT));
assert!(is_dark(DARK));
// The coolest light shell (blue-grey pane) is still light, the warmest dark still dark.
assert!(!is_dark(shell(0.0, "indigo", 1.35, false)));
assert!(is_dark(shell(1.0, "clay", 0.75, true)));
}
}