diff --git a/FEATURES.md b/FEATURES.md index c969787..668ee52 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -2300,7 +2300,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) ## 側邊欄:釘選與分區(照原版重做,2026-11-04) -- 釘選的 Bot 放在最上面的大頭像格子裡(主要 Bot 第一個,有星星)。右鍵「釘選/取消釘選」,或把 Bot 拖進格子(第一次拖時出現「拖曳到此處以釘選」);格子內可拖曳排序;拖到分區會取消釘選並移過去。 +- 釘選的 Bot 放在最上面的大頭像格子裡(主要 Bot 第一個,有星星)。一排最多兩個:只有一個時放中間,兩個左右排,單數時最後一個自己一排、放中間;側邊欄拉多寬都一樣(很窄時一排一個)。右鍵「釘選/取消釘選」,或把 Bot 拖進格子(第一次拖時出現「拖曳到此處以釘選」);格子內可拖曳排序;拖到分區會取消釘選並移過去。 - 分區:Bot 右鍵「移至 ▸」列出所有分區(含未分區,✓ 目前的)和「建立分區」;還沒有分區時是「移至新分區」。新分區放最上面,名字「新增分區」並直接進入改名(Enter/點別處儲存,Esc 取消)。 - 分區標題右鍵(或 ⋯):重新命名、上移、下移、刪除;未分區只有上移/下移。刪除會先確認「其中的 Bot 會移至 未分區,不會刪除任何 Bot。」只有一個清單時,「Bot」標題右鍵可「建立分區」。 diff --git a/src/app.rs b/src/app.rs index 59970c6..61b2e21 100644 --- a/src/app.rs +++ b/src/app.rs @@ -276,6 +276,15 @@ impl App { let demo = screenshot.is_some() && std::env::var("ANYBOT_SHOT_REAL").is_err(); let mut state = if demo { State::demo() } else { State::load() }; if demo { + // ANYBOT_SHOT_PINS=n: the grid at the top shows n bots (the main one and n-1 pinned). + if let Some(n) = std::env::var("ANYBOT_SHOT_PINS").ok().and_then(|v| v.parse::().ok()) { + let primary = state.primary_bot; + let mut kept = 1; + for b in state.bots.iter_mut().filter(|b| b.pinned && b.id != primary) { + b.pinned = kept < n; + kept += 1; + } + } state.skills = crate::skills::BUILTIN_SKILLS .iter() .filter(|b| b.default_on) diff --git a/src/app/sidebar_ui.rs b/src/app/sidebar_ui.rs index 473a47d..b8c60c8 100644 --- a/src/app/sidebar_ui.rs +++ b/src/app/sidebar_ui.rs @@ -603,7 +603,8 @@ impl App { } ui.add_space(10.0); let w = ui.available_width(); - let cols = ((w / 92.0).floor() as usize).max(1); + // At most two to a row, however wide the sidebar (one when it's very narrow). + let cols = ((w / 92.0).floor() as usize).clamp(1, PIN_COLS); let tile_w = w / cols as f32; let tile_h = 100.0; // Room for one more tile while a bot that isn't pinned yet is dragged over. @@ -611,7 +612,8 @@ impl App { let rows = tiles.len().div_ceil(cols).max(1); let grid_h = rows as f32 * tile_h + if showing_zone { 58.0 } else { 0.0 }; let (area, _) = ui.allocate_exact_size(vec2(w, grid_h), egui::Sense::hover()); - let rect_of = |i: usize| egui::Rect::from_min_size(area.min + vec2((i % cols) as f32 * tile_w, (i / cols) as f32 * tile_h), vec2(tile_w, tile_h)); + let n = tiles.len(); + let rect_of = |i: usize| egui::Rect::from_min_size(area.min + tile_offset(i, n, cols, tile_w, tile_h, w), vec2(tile_w, tile_h)); for (i, id) in tiles.iter().enumerate() { self.pin_tile(ui, rect_of(i), *id, Some(*id) == primary); } @@ -916,6 +918,18 @@ impl App { } } +/// Most tiles to a row in the grid at the top. +const PIN_COLS: usize = 2; + +/// Where tile `i` of `n` sits in the grid (from its top left): rows of `cols`, and a row that +/// isn't full — one bot alone, or the last of an odd number — in the middle. +fn tile_offset(i: usize, n: usize, cols: usize, tile_w: f32, tile_h: f32, w: f32) -> egui::Vec2 { + let (row, col) = (i / cols, i % cols); + let in_row = n.saturating_sub(row * cols).clamp(1, cols); + let left = (w - in_row as f32 * tile_w) / 2.0; + vec2(left + col as f32 * tile_w, row as f32 * tile_h) +} + pub(super) fn shorten_width(ui: &egui::Ui, s: &str, max_w: f32, size: f32) -> String { let w = |x: &str| ui.painter().layout_no_wrap(x.to_string(), egui::FontId::proportional(size), Color32::WHITE).size().x; if w(s) <= max_w { @@ -937,6 +951,22 @@ pub(super) fn shorten_width(ui: &egui::Ui, s: &str, max_w: f32, size: f32) -> St mod tests { use super::*; + #[test] + fn tiles_two_to_a_row_and_a_lone_one_in_the_middle() { + let at = |i, n| { + let v = tile_offset(i, n, 2, 130.0, 100.0, 260.0); + (v.x, v.y) + }; + assert_eq!(at(0, 1), (65.0, 0.0), "one bot: in the middle"); + assert_eq!((at(0, 2), at(1, 2)), ((0.0, 0.0), (130.0, 0.0)), "two: side by side"); + assert_eq!((at(0, 3), at(1, 3), at(2, 3)), ((0.0, 0.0), (130.0, 0.0), (65.0, 100.0)), "three: the third alone in the middle"); + assert_eq!(at(3, 4), (130.0, 100.0)); + // A slot past the end (where a dragged bot would land) is the next place in the grid. + assert_eq!(at(2, 2), (65.0, 100.0)); + // A very narrow sidebar: one to a row, each in the middle. + assert_eq!(tile_offset(1, 2, 1, 80.0, 100.0, 80.0), vec2(0.0, 100.0)); + } + #[test] fn bump_and_rand() { assert_eq!(bump(0.0, 0.0, 1.0), 0.0);