AnyBot/src/app/models_ui.rs

54 lines
3.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 設定 › 模型: every model service as a tile — its mark, its name, whether it is ready, where it
// runs — in one column with the page (it used to be a list beside the page, beside the settings
// list: three columns of words). A press opens the service's page (its key, address, model).
use super::*;
impl App {
/// The tiles; returns the one pressed.
pub(super) fn provider_grid(&mut self, ui: &mut egui::Ui) -> Option<ProviderKind> {
let p = self.pal;
let mut picked = None;
let gap = 10.0;
let width = ui.available_width();
let cols = if width >= 560.0 { 3 } else { 2 };
let w = ((width - gap * (cols as f32 - 1.0)) / cols as f32).floor();
for row in ALL_PROVIDERS.chunks(cols) {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = gap;
for &k in row {
let ps = self.state.provider(k);
let ready = providers::ready(k, &ps.api_key);
let runs = providers::runs_at(k, &providers::resolve_base(k, &ps.base_url));
let (rect, r) = ui.allocate_exact_size(vec2(w, 76.0), egui::Sense::click());
let paint = ui.painter();
paint.rect(rect, R_L, if r.hovered() { p.hover } else { p.elevated }, Stroke::new(1.0, p.border), egui::StrokeKind::Inside);
let mark = egui::Rect::from_min_size(rect.min + vec2(14.0, 14.0), vec2(34.0, 34.0));
crate::icons::provider_mark(paint, mark, k, R_M);
let left = mark.right() + 12.0;
let room = rect.right() - 12.0 - left;
let name = sidebar_ui::shorten_width(ui, k.label(), room, FONT_BASE);
paint.text(egui::pos2(left, mark.top() + 1.0), egui::Align2::LEFT_TOP, name, egui::FontId::new(FONT_BASE, crate::bold()), p.text);
// Ready: a green dot and 可以用; else what is missing, quietly.
let y = mark.top() + 24.0;
let (words, col) = if ready { (t("可以用"), p.text2) } else if k == ProviderKind::ChatGpt { (t("還沒登入"), p.text3) } else { (t("還沒設定"), p.text3) };
let mut x = left;
if ready {
paint.circle_filled(egui::pos2(x + 4.0, y + 8.0), 4.0, p.up);
x += 13.0;
}
paint.text(egui::pos2(x, y), egui::Align2::LEFT_TOP, &words, egui::FontId::proportional(FONT_SM), col);
// Where it runs: the ones that keep the chats at home in green.
let tag = if matches!(runs, providers::RunsAt::Cloud(_)) { p.text3 } else { p.up };
paint.text(rect.right_bottom() - vec2(12.0, 10.0), egui::Align2::RIGHT_BOTTOM, t(runs.short()), egui::FontId::proportional(FONT_XS), tag);
if r.on_hover_text(runs.words(self.brain_for_words().as_deref())).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
picked = Some(k);
}
}
});
ui.add_space(gap);
}
picked
}
}