桌面版排版:長字不氣球、設定不重疊、批准卡不頂出輸入框
- 聊天:氣泡、工作狀態列、批准/問題/交接卡裡的長網址、超長單字與 多行文字不再撐破左右邊框;批准與問題卡高度上限 45%(最少 160px), 卡內部自己捲,composer 永遠看得到(新增四個聊天排版測試場景) - 設定:form_row/setting_row/sec_row_s 的英文字標籤依像素截斷加…; 右側控制區可換行;伺服器與技能清單名字加 truncate;瀏覽器設定檔列 改 horizontal_wrapped,提示文字用 row_hint 只佔剩餘寬度; 「你的瀏覽器」說明文字手動斷行(英文單字中間不切、中文逐字可切) - dialog_body 寬度以視窗寬度上限收斂,窄視窗不再溢出卡片 - drops_ui 測試改過 t() 比較,不再受其他測試改全域語言影響
This commit is contained in:
parent
3c0b4d2bec
commit
ec73947133
142
src/app.rs
142
src/app.rs
|
|
@ -3493,11 +3493,18 @@ impl App {
|
||||||
}
|
}
|
||||||
let shown = self.ask_shown.entry(bot.id).or_insert_with(Instant::now).elapsed().as_secs_f32();
|
let shown = self.ask_shown.entry(bot.id).or_insert_with(Instant::now).elapsed().as_secs_f32();
|
||||||
let mut answer = None;
|
let mut answer = None;
|
||||||
|
// (長理由不許把輸入框頂出螢幕:卡片照內容估高、照窗口高度封頂,裡面的東西在卡面裡往下捲。
|
||||||
|
// 下方的列問不到剩餘高度,所以捲動區用估出來的固定高度。)
|
||||||
|
let reason = self.approvals.get(&bot.id).map(|a| a.reason.clone()).unwrap_or_default();
|
||||||
|
let cap = (ui.ctx().content_rect().height() * 0.45).max(160.0);
|
||||||
|
let body = ask_dock_height(&reason, ui.available_width(), cap);
|
||||||
Frame::new().fill(p.attention_bg).stroke(Stroke::new(2.0, p.attention)).corner_radius(20).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
Frame::new().fill(p.attention_bg).stroke(Stroke::new(2.0, p.attention)).corner_radius(20).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
answer = self.approval_body(ui, bot, true);
|
egui::ScrollArea::vertical().id_salt(("ask-dock", bot.id)).max_height(body).min_scrolled_height(body).auto_shrink([false, false]).show(ui, |ui| {
|
||||||
ui.add_space(2.0);
|
answer = self.approval_body(ui, bot, true);
|
||||||
ui.label(RichText::new(t("輸入框空著時:Enter 允許,Esc 拒絕")).size(11.5).color(p.text2));
|
ui.add_space(2.0);
|
||||||
|
ui.label(RichText::new(t("輸入框空著時:Enter 允許,Esc 拒絕")).size(11.5).color(p.text2));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
if answer.is_none() && draft_empty && !typing && shown > 0.6 && !egui::Popup::is_any_open(ctx) {
|
if answer.is_none() && draft_empty && !typing && shown > 0.6 && !egui::Popup::is_any_open(ctx) {
|
||||||
|
|
@ -3557,8 +3564,12 @@ impl App {
|
||||||
Skip,
|
Skip,
|
||||||
}
|
}
|
||||||
let mut act = None;
|
let mut act = None;
|
||||||
|
// (選項再多也不許把輸入框頂出螢幕:卡面照內容估高、照窗口高度封頂,裡面在卡面裡往下捲。)
|
||||||
|
let cap = (ui.ctx().content_rect().height() * 0.45).max(160.0);
|
||||||
|
let body = ask_card_height(q, ui.available_width(), cap);
|
||||||
Frame::new().fill(p.attention_bg).stroke(Stroke::new(2.0, p.attention)).corner_radius(20).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
Frame::new().fill(p.attention_bg).stroke(Stroke::new(2.0, p.attention)).corner_radius(20).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
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 {
|
if qs.len() > 1 {
|
||||||
ui.label(RichText::new(format!("{} 問你 · {}/{}", bot.name, step + 1, qs.len())).size(12.0).color(p.text2));
|
ui.label(RichText::new(format!("{} 問你 · {}/{}", bot.name, step + 1, qs.len())).size(12.0).color(p.text2));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3627,6 +3638,7 @@ impl App {
|
||||||
act = Some(Act::Skip);
|
act = Some(Act::Skip);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
match act {
|
match act {
|
||||||
|
|
@ -4217,16 +4229,21 @@ impl App {
|
||||||
}
|
}
|
||||||
let current = crate::botbrowser::current();
|
let current = crate::botbrowser::current();
|
||||||
for name in crate::botbrowser::choices() {
|
for name in crate::botbrowser::choices() {
|
||||||
ui.horizontal(|ui| {
|
// (Radio + name + description + buttons: in a narrow window this overflows the
|
||||||
|
// card, so the buttons wrap onto a second line inside it.)
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
ui.set_width(ui.available_width());
|
||||||
let mut on = name == current;
|
let mut on = name == current;
|
||||||
if ui.radio_value(&mut on, true, RichText::new(&name).strong().family(crate::bold())).clicked() && name != current {
|
if ui.radio_value(&mut on, true, RichText::new(&name).strong().family(crate::bold())).clicked() && name != current {
|
||||||
let _ = crate::botbrowser::set_current(&name);
|
let _ = crate::botbrowser::set_current(&name);
|
||||||
}
|
}
|
||||||
if name == current {
|
if name == current {
|
||||||
ui.label(RichText::new(t("使用中")).size(11.5).color(p.accent));
|
ui.add(egui::Label::new(RichText::new(t("使用中")).size(11.5).color(p.accent)).truncate());
|
||||||
}
|
}
|
||||||
if name == crate::botbrowser::PERSON_PROFILE {
|
if name == crate::botbrowser::PERSON_PROFILE {
|
||||||
ui.label(RichText::new(t("你平常的 Chrome,切到哪個設定檔就讀哪個")).size(11.5).color(p.text2));
|
// (A plain label expands to its text's natural width and runs over the
|
||||||
|
// buttons: it must take only the room left in the row.)
|
||||||
|
row_hint(ui, "你平常的 Chrome,切到哪個設定檔就讀哪個", 130.0, p.text2);
|
||||||
if crate::axread::trusted(false) {
|
if crate::axread::trusted(false) {
|
||||||
crate::icons::label(ui, crate::icons::Icon::Check, &t("輔助使用已打開"), 11.5, p.text3);
|
crate::icons::label(ui, crate::icons::Icon::Check, &t("輔助使用已打開"), 11.5, p.text3);
|
||||||
} else if ui.small_button(t("打開輔助使用")).on_hover_text(t("macOS 要你允許一次,AnyBot 才看得到你的瀏覽器視窗")).clicked() && !crate::axread::trusted(true) {
|
} else if ui.small_button(t("打開輔助使用")).on_hover_text(t("macOS 要你允許一次,AnyBot 才看得到你的瀏覽器視窗")).clicked() && !crate::axread::trusted(true) {
|
||||||
|
|
@ -4236,7 +4253,7 @@ impl App {
|
||||||
}
|
}
|
||||||
let firefox = name.ends_with(crate::botbrowser::FIREFOX_MARK);
|
let firefox = name.ends_with(crate::botbrowser::FIREFOX_MARK);
|
||||||
if firefox {
|
if firefox {
|
||||||
ui.label(RichText::new(t("你自己的 Firefox 設定檔:要讓 Bot 用,請從這裡開啟(先關掉它原本的視窗)")).size(11.5).color(p.text2));
|
row_hint(ui, "你自己的 Firefox 設定檔:要讓 Bot 用,請從這裡開啟(先關掉它原本的視窗)", 100.0, p.text2);
|
||||||
}
|
}
|
||||||
if ui.small_button(t("開啟視窗")).on_hover_text(t("打開這個設定檔的瀏覽器視窗,在裡面登入網站")).clicked() {
|
if ui.small_button(t("開啟視窗")).on_hover_text(t("打開這個設定檔的瀏覽器視窗,在裡面登入網站")).clicked() {
|
||||||
let note = self.browser_note.clone();
|
let note = self.browser_note.clone();
|
||||||
|
|
@ -4268,8 +4285,8 @@ impl App {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.add(egui::TextEdit::singleline(&mut self.new_browser_profile).hint_text(t("新設定檔名稱,例如 工作")).desired_width(180.0));
|
ui.add(egui::TextEdit::singleline(&mut self.new_browser_profile).hint_text(t("新設定檔名稱,例如 工作")).desired_width(ui.available_width().min(180.0).max(90.0)));
|
||||||
let ok = crate::botbrowser::check_name(&self.new_browser_profile).is_ok();
|
let ok = crate::botbrowser::check_name(&self.new_browser_profile).is_ok();
|
||||||
if ui.add_enabled(ok, egui::Button::new("新增設定檔")).clicked() {
|
if ui.add_enabled(ok, egui::Button::new("新增設定檔")).clicked() {
|
||||||
let r = crate::botbrowser::add(&self.new_browser_profile).and_then(|n| crate::botbrowser::set_current(&n));
|
let r = crate::botbrowser::add(&self.new_browser_profile).and_then(|n| crate::botbrowser::set_current(&n));
|
||||||
|
|
@ -4282,9 +4299,51 @@ impl App {
|
||||||
});
|
});
|
||||||
let note = self.browser_note.lock().unwrap().clone();
|
let note = self.browser_note.lock().unwrap().clone();
|
||||||
if !note.is_empty() {
|
if !note.is_empty() {
|
||||||
ui.label(RichText::new(note).size(11.5).color(p.text2));
|
// (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, ¬e, ui.available_width() - 2.0, 11.5)).size(11.5).color(p.text2));
|
||||||
}
|
}
|
||||||
ui.label(RichText::new(t("選「你的瀏覽器」:Bot 從畫面讀你平常的 Chrome(macOS 會請你打開一次「輔助使用」),你在 Chrome 切到哪個設定檔,它就看哪個;讀之前會先問你。其他的是 AnyBot 自己的視窗,各自登入一次就好。")).size(11.0).color(p.text3));
|
// (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 the card's width by hand: at spaces where words exist, between
|
||||||
|
// characters for runs without them. Each line's width is measured as a whole.)
|
||||||
|
let hint_txt: String = {
|
||||||
|
let full = t("選「你的瀏覽器」:Bot 從畫面讀你平常的 Chrome(macOS 會請你打開一次「輔助使用」),你在 Chrome 切到哪個設定檔,它就看哪個;讀之前會先問你。其他的是 AnyBot 自己的視窗,各自登入一次就好。");
|
||||||
|
let font = egui::FontId::proportional(11.0);
|
||||||
|
// (A wrapped column reports infinite `available_width`; the card's own rect is
|
||||||
|
// always finite, so the wrap width comes from the wider of the two.)
|
||||||
|
// (A ScrollArea body gets infinite max_rect; its clip rect is the viewport.)
|
||||||
|
let max_w = (ui.max_rect().width().min(ui.clip_rect().width()) - 36.0 - 2.0).max(80.0);
|
||||||
|
let w = |x: &str| ui.painter().layout_no_wrap(x.to_string(), font.clone(), egui::Color32::WHITE).size().x;
|
||||||
|
// (A break may fall before any CJK character, or before a Latin word.)
|
||||||
|
let breakable = |chars: &[char], i: usize| -> bool {
|
||||||
|
let c = chars[i];
|
||||||
|
let cjk = !c.is_ascii_alphanumeric() && !('a'..='z').contains(&c) && !('A'..='Z').contains(&c);
|
||||||
|
cjk || (i > 0 && !cjk && (chars[i - 1] == ' ' || { let p = chars[i - 1]; !p.is_ascii_alphanumeric() && p != '\'' }))
|
||||||
|
};
|
||||||
|
let mut out = String::new();
|
||||||
|
for para in full.split('\n') {
|
||||||
|
let chars: Vec<char> = para.chars().collect();
|
||||||
|
let mut start = 0usize;
|
||||||
|
for i in 1..=chars.len() {
|
||||||
|
if i == chars.len() || (breakable(&chars, i) && w(&chars[start..i].iter().collect::<String>()) > max_w) {
|
||||||
|
// (Trim trailing spaces off the line before emitting it.)
|
||||||
|
let mut end = i;
|
||||||
|
while end > start + 1 && chars[end - 1] == ' ' {
|
||||||
|
end -= 1;
|
||||||
|
}
|
||||||
|
out.extend(&chars[start..end]);
|
||||||
|
out.push('\n');
|
||||||
|
start = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if start < chars.len() {
|
||||||
|
out.extend(&chars[start..]);
|
||||||
|
out.push('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.trim_end().to_string()
|
||||||
|
};
|
||||||
|
ui.label(RichText::new(hint_txt).size(11.0).color(p.text3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The bot's routines: what repeats, when it runs next, pause / run now / delete.
|
/// The bot's routines: what repeats, when it runs next, pause / run now / delete.
|
||||||
|
|
@ -6556,6 +6615,34 @@ const COMPOSER_TOP: f32 = 3.0;
|
||||||
|
|
||||||
/// How tall the words' box is: one 28 px row for a line, then as tall as the words, up to
|
/// How tall the words' box is: one 28 px row for a line, then as tall as the words, up to
|
||||||
/// `max_h` (beyond that it scrolls).
|
/// `max_h` (beyond that it scrolls).
|
||||||
|
/// Lines a wrapped text takes at `width`: greedy on spaces, over-long runs counted by
|
||||||
|
/// characters. (The dock's row can't report a remaining height, so card heights are estimated.)
|
||||||
|
fn wrapped_lines(text: &str, width: f32, char_w: f32) -> f32 {
|
||||||
|
let per = (width / char_w).max(8.0);
|
||||||
|
let mut lines = 0.0;
|
||||||
|
for para in text.lines() {
|
||||||
|
let mut n = (para.chars().count() as f32 / per).ceil();
|
||||||
|
if para.contains(' ') {
|
||||||
|
n = 1.0 + ((para.chars().count() as f32 + para.matches(' ').count() as f32) / per - 1.0).ceil();
|
||||||
|
}
|
||||||
|
lines += n.max(1.0);
|
||||||
|
}
|
||||||
|
lines.max(1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The approval card's content height: title + label line + the monospace box + buttons + hint.
|
||||||
|
fn ask_dock_height(reason: &str, width: f32, cap: f32) -> f32 {
|
||||||
|
let detail = reason.split_once(':').map(|(_, d)| d).unwrap_or(reason);
|
||||||
|
let cw = ((width - 92.0).max(120.0) / 74.0).clamp(5.5, 9.0); // monospace 12.5 glyph width, kept sane
|
||||||
|
(wrapped_lines(detail, (width - 92.0).max(120.0), cw) * 17.0 + 168.0).min(cap)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The question card's content height: header + question + option rows + field + buttons.
|
||||||
|
fn ask_card_height(q: &crate::ask::Question, width: f32, cap: f32) -> f32 {
|
||||||
|
let q_lines = wrapped_lines(&q.question, (width - 64.0).max(120.0), 16.0);
|
||||||
|
(26.0 + q_lines * 21.0 + q.options.len() as f32 * 44.0 + 122.0).min(cap)
|
||||||
|
}
|
||||||
|
|
||||||
fn composer_box_h(text_h: f32, max_h: f32) -> f32 {
|
fn composer_box_h(text_h: f32, max_h: f32) -> f32 {
|
||||||
(text_h + COMPOSER_TOP + 3.0).clamp(28.0, max_h.max(28.0))
|
(text_h + COMPOSER_TOP + 3.0).clamp(28.0, max_h.max(28.0))
|
||||||
}
|
}
|
||||||
|
|
@ -6725,14 +6812,20 @@ fn setting_row(ui: &mut egui::Ui, p: Palette, label: &str, desc: &str, control:
|
||||||
Frame::new().fill(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(14).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
Frame::new().fill(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(14).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let w = (ui.available_width() * 0.5).max(180.0);
|
// (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.horizontal(|ui| {
|
||||||
ui.set_width(w);
|
ui.set_width(w);
|
||||||
ui.spacing_mut().item_spacing.x = 4.0;
|
ui.spacing_mut().item_spacing.x = 4.0;
|
||||||
ui.label(RichText::new(t(label)).size(FONT_BASE).color(p.text));
|
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);
|
help_mark(ui, desc, p);
|
||||||
});
|
});
|
||||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
// (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);
|
ui.horizontal(control);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -6754,6 +6847,16 @@ fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A rounded group of related settings, like a macOS settings card.
|
/// A rounded group of related settings, like a macOS settings card.
|
||||||
|
/// A label inside a row of buttons: it takes the row's remaining width minus `keep` px kept
|
||||||
|
/// for the buttons that follow, so it truncates with「…」instead of pushing them off the card.
|
||||||
|
fn row_hint(ui: &mut egui::Ui, text: &str, keep: f32, color: egui::Color32) {
|
||||||
|
let w = (ui.available_width() - keep).max(60.0);
|
||||||
|
let full = t(text);
|
||||||
|
let cut = sidebar_ui::shorten_width(ui, &full, w, 11.5);
|
||||||
|
let (rect, _) = ui.allocate_exact_size(vec2(w, 14.0), egui::Sense::hover());
|
||||||
|
ui.painter().text(rect.left_top(), egui::Align2::LEFT_CENTER, cut, egui::FontId::proportional(11.5), color);
|
||||||
|
}
|
||||||
|
|
||||||
fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
||||||
let r = Frame::new()
|
let r = Frame::new()
|
||||||
.fill(p.elevated)
|
.fill(p.elevated)
|
||||||
|
|
@ -6773,7 +6876,10 @@ fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::U
|
||||||
fn form_row(ui: &mut egui::Ui, label: &str, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
|
fn form_row(ui: &mut egui::Ui, label: &str, p: Palette, body: impl FnOnce(&mut egui::Ui)) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let (rect, _) = ui.allocate_exact_size(vec2(FORM_LABEL_WIDTH, 28.0), egui::Sense::hover());
|
let (rect, _) = ui.allocate_exact_size(vec2(FORM_LABEL_WIDTH, 28.0), egui::Sense::hover());
|
||||||
ui.painter().text(rect.left_center(), egui::Align2::LEFT_CENTER, t(label), egui::FontId::proportional(FONT_SM), p.text2);
|
// (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);
|
body(ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -6876,6 +6982,10 @@ fn forced_dialog_scroll() -> Option<f32> {
|
||||||
|
|
||||||
/// The scrolling middle of a dialog, `reserve` px kept free for its footer.
|
/// The scrolling middle of a dialog, `reserve` px kept free for its footer.
|
||||||
fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug, max_height: f32, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug, max_height: f32, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
||||||
|
// (The body must be laid out at the viewport width: egui hands a ScrollArea's body
|
||||||
|
// infinite width, so rows that size themselves from `available_width` (settings rows,
|
||||||
|
// cards) grew past the window and every line they wrapped spilled off-screen.)
|
||||||
|
let viewport_width = ui.available_width().min(ui.ctx().content_rect().width());
|
||||||
let mut area = egui::ScrollArea::vertical();
|
let mut area = egui::ScrollArea::vertical();
|
||||||
if let Some(y) = forced_dialog_scroll() {
|
if let Some(y) = forced_dialog_scroll() {
|
||||||
area = area.vertical_scroll_offset(y);
|
area = area.vertical_scroll_offset(y);
|
||||||
|
|
@ -6885,7 +6995,7 @@ fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug,
|
||||||
.auto_shrink([false, true])
|
.auto_shrink([false, true])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
Frame::new().inner_margin(Margin { left: 20, right: 20, top: 16, bottom: 16 }).show(ui, |ui| {
|
Frame::new().inner_margin(Margin { left: 20, right: 20, top: 16, bottom: 16 }).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width((viewport_width - 40.0).max(200.0));
|
||||||
ui.spacing_mut().item_spacing.y = 6.0;
|
ui.spacing_mut().item_spacing.y = 6.0;
|
||||||
body(ui)
|
body(ui)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -502,7 +502,8 @@ impl App {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|ui| {
|
|ui| {
|
||||||
ui.label(RichText::new(&name).strong().family(crate::bold()).size(FONT_BASE));
|
// (长的伺服器名字在行尾的按钮前截断,不会压到「重新连线」。)
|
||||||
|
ui.add(egui::Label::new(RichText::new(&name).strong().family(crate::bold()).size(FONT_BASE)).truncate());
|
||||||
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
||||||
ui.painter().circle_filled(r.center(), 4.0, col);
|
ui.painter().circle_filled(r.center(), 4.0, col);
|
||||||
ui.add(egui::Label::new(RichText::new(&text).size(11.5).color(p.text3)).truncate()).on_hover_text(&text);
|
ui.add(egui::Label::new(RichText::new(&text).size(11.5).color(p.text3)).truncate()).on_hover_text(&text);
|
||||||
|
|
@ -631,7 +632,8 @@ impl App {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|ui| {
|
|ui| {
|
||||||
ui.label(RichText::new(&name).strong().family(crate::bold()).size(FONT_SM).color(name_col)).on_hover_text(&description);
|
// (长的技能名字在行尾的按钮前截断,不会压到「检视」。)
|
||||||
|
ui.add(egui::Label::new(RichText::new(&name).strong().family(crate::bold()).size(FONT_SM).color(name_col)).truncate()).on_hover_text(&description);
|
||||||
if files > 0 {
|
if files > 0 {
|
||||||
ui.label(RichText::new(format!("{files} 檔")).size(11.0).color(p.accent));
|
ui.label(RichText::new(format!("{files} 檔")).size(11.0).color(p.accent));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1348,20 +1348,27 @@ fn sec_row_s(ui: &mut egui::Ui, p: Palette, label: &str, status: &str, help: &st
|
||||||
Frame::new().inner_margin(Margin::symmetric(14, 10)).show(ui, |ui| {
|
Frame::new().inner_margin(Margin::symmetric(14, 10)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let w = (ui.available_width() * 0.58).max(200.0);
|
// (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.vertical(|ui| {
|
||||||
ui.set_width(w);
|
ui.set_width(w);
|
||||||
ui.spacing_mut().item_spacing.y = 2.0;
|
ui.spacing_mut().item_spacing.y = 2.0;
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 4.0;
|
ui.spacing_mut().item_spacing.x = 4.0;
|
||||||
ui.label(RichText::new(t(label)).size(FONT_BASE).color(p.text));
|
// (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);
|
help_mark(ui, help, p);
|
||||||
});
|
});
|
||||||
if !status.is_empty() {
|
if !status.is_empty() {
|
||||||
ui.add(egui::Label::new(RichText::new(t(status)).size(FONT_SM).color(p.text2)).truncate());
|
ui.add(egui::Label::new(RichText::new(t(status)).size(FONT_SM).color(p.text2)).truncate());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
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;
|
ui.spacing_mut().item_spacing.x = 6.0;
|
||||||
control(ui)
|
control(ui)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -395,11 +395,12 @@ mod tests {
|
||||||
fn a_row_says_where_the_parcel_is() {
|
fn a_row_says_where_the_parcel_is() {
|
||||||
let now = crate::model::now_ms();
|
let now = crate::model::now_ms();
|
||||||
let row = |state: &str, note: &str| json!({"state": state, "note": note, "sent": 1, "bytes": 4, "to_name": "Mac mini", "at": now});
|
let row = |state: &str, note: &str| json!({"state": state, "note": note, "sent": 1, "bytes": 4, "to_name": "Mac mini", "at": now});
|
||||||
assert_eq!(state_words(&row("uploading", ""), now), ("正在交給大腦 25%".into(), false));
|
// (The words follow the menus' language, which other tests may set: compare through t().)
|
||||||
assert_eq!(state_words(&row("sending", ""), now), ("傳送中 25%".into(), false));
|
assert_eq!(state_words(&row("uploading", ""), now), (format!("{} 25%", t("正在交給大腦")), false));
|
||||||
assert!(state_words(&row("waiting", "目前離線"), now).0.contains("等「Mac mini」"));
|
assert_eq!(state_words(&row("sending", ""), now), (format!("{} 25%", t("傳送中")), false));
|
||||||
|
assert!(state_words(&row("waiting", "目前離線"), now).0.contains(&format!("{}「Mac mini」", t("等"))));
|
||||||
assert!(state_words(&row("waiting", "「Mac mini」的 AnyBot 要先更新才收得到"), now).0.contains("要先更新"));
|
assert!(state_words(&row("waiting", "「Mac mini」的 AnyBot 要先更新才收得到"), now).0.contains("要先更新"));
|
||||||
assert_eq!(state_words(&row("done", ""), now), ("已送達 · 剛剛".into(), false));
|
assert_eq!(state_words(&row("done", ""), now), (format!("{} · {}", t("已送達"), crate::pages::ago(now, now)), false));
|
||||||
assert_eq!(state_words(&row("failed", "磁碟滿了"), now), ("沒有送達:磁碟滿了".into(), true));
|
assert_eq!(state_words(&row("failed", "磁碟滿了"), now), (format!("{}:{}", t("沒有送達"), "磁碟滿了"), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,53 @@ fn scenes() -> Vec<(&'static str, Open)> {
|
||||||
a.panel = Some(panel_ui::PanelTab::Library);
|
a.panel = Some(panel_ui::PanelTab::Library);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"聊天:工作中(長狀態、長網址、超長單字)",
|
||||||
|
Box::new(|a: &mut App| {
|
||||||
|
let id = a.state.selected;
|
||||||
|
if let Some(b) = a.state.bot_mut(id) {
|
||||||
|
b.messages.push(Message::user("看看這個 https://example.com/a/very/very/long/url/that/keeps/going/through/the/whole/window/path/segment?query=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaEND 還有 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaEND"));
|
||||||
|
b.messages.push(Message::assistant("文字裡的超長英數混合字串會把氣泡撐破:supercalifragilisticexpialidocioussupercalifragilisticexpialidocioussupercalifragilisticexpialidociousEND 还有中文夹在中间很长的句子不分隔的情况测试测试测试END", "模型"));
|
||||||
|
}
|
||||||
|
let (reply, _keep) = std::sync::mpsc::channel::<ApprovalAnswer>();
|
||||||
|
let _ = &reply;
|
||||||
|
a.streams.insert(id, Live { cancel: Arc::new(AtomicBool::new(false)), started: Instant::now(), last: Instant::now(), produced: true, status: Some("執行中:npm run build --progress=false --some-really-long-flag-name-abcdefghijklmnopqrstuvwxyz-0123456789 --more".into()), paused: false, paused_at: None, unattended: false, steer: Arc::new(Mutex::new(vec![])), direct: Arc::new(AtomicBool::new(false)), turn_id: "audit-turn".into(), turn: 0 });
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"聊天:需要你允許(長理由)",
|
||||||
|
Box::new(|a: &mut App| {
|
||||||
|
let id = a.state.selected;
|
||||||
|
let (reply, _keep) = std::sync::mpsc::channel::<ApprovalAnswer>();
|
||||||
|
let _ = &reply;
|
||||||
|
a.approvals.insert(id, Approval { call_id: "audit-ask".into(), tool: "shell".into(), reason: format!("執行:{}", "rm -rf ./build && very_long_command --with-a-single-unbreakable-token-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ".repeat(3)), grant: String::new(), reply, kind: ApprovalKind::Action });
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"聊天:問題卡(長問題長選項)",
|
||||||
|
Box::new(|a: &mut App| {
|
||||||
|
let id = a.state.selected;
|
||||||
|
let (reply, _keep) = std::sync::mpsc::channel::<ApprovalAnswer>();
|
||||||
|
let _ = &reply;
|
||||||
|
let qs = serde_json::json!({"questions": [
|
||||||
|
{"question": "請選一個要彙整的資料夾(名字很長的資料夾在伺服器上的深層路徑裡)", "options": [
|
||||||
|
"客戶服務與售後追蹤小組・每週報表整理專用資料夾(台北辦公室)",
|
||||||
|
"Extremely Long Option Name That Keeps Going And Going And Going Without Breaking Anywhere",
|
||||||
|
], "multiple": true},
|
||||||
|
{"question": "寄件日期", "default": "2026-07-30"}
|
||||||
|
]});
|
||||||
|
a.approvals.insert(id, Approval { call_id: "audit-q".into(), tool: crate::ask::TOOL.into(), reason: qs.to_string(), grant: String::new(), reply, kind: ApprovalKind::Question });
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"聊天:需要處理(長指示)",
|
||||||
|
Box::new(|a: &mut App| {
|
||||||
|
let id = a.state.selected;
|
||||||
|
let (reply, _keep) = std::sync::mpsc::channel::<ApprovalAnswer>();
|
||||||
|
let _ = &reply;
|
||||||
|
a.approvals.insert(id, Approval { call_id: "audit-h".into(), tool: String::new(), reason: format!("請在這台電腦上登入公司入口網站並通過驗證碼,帳號是 someone@example-company.com.tw,驗證說明:{}", "請依畫面上的提示完成驗證".repeat(8)), grant: crate::model::BOT_COMPUTER_NAME.into(), reply, kind: ApprovalKind::Handoff });
|
||||||
|
}),
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"Bot 設定",
|
"Bot 設定",
|
||||||
Box::new(|a: &mut App| {
|
Box::new(|a: &mut App| {
|
||||||
|
|
@ -265,5 +312,3 @@ fn the_check_sees_cut_and_overlapping_text() {
|
||||||
assert!(found.iter().any(|p| p.starts_with("疊在一起") && p.contains("停止")), "{found:?}");
|
assert!(found.iter().any(|p| p.starts_with("疊在一起") && p.contains("停止")), "{found:?}");
|
||||||
assert!(found.iter().any(|p| p.starts_with("被切掉") && p.contains("03:00")), "{found:?}");
|
assert!(found.iter().any(|p| p.starts_with("被切掉") && p.contains("03:00")), "{found:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue