One design system for the desktop app: a shared scale and one set of controls on every screen (R2.9) (#1862)
No files matched your search
@@ -11,7 +11,8 @@ not used for modified versions.
|
||||
|
||||
| File | Font | Copyright | Source | Licence |
|
||||
|---|---|---|---|---|
|
||||
| `DMSans-Regular.ttf`, `DMSans-Medium.ttf`, `DMSans-Bold.ttf` | DM Sans 1.200 (body text, labels, headlines) | © 2014-2017 Indian Type Foundry, © 2019 Google LLC | https://github.com/googlefonts/dm-fonts (`Sans/Exports/`, commit 23aafb3) | `OFL-DMSans.txt` |
|
||||
| `Figtree-Variable.ttf` | Figtree, variable (text, labels and headings in the app) | © 2022 The Figtree Project Authors | https://github.com/google/fonts/tree/main/ofl/figtree (`Figtree[wght].ttf`, renamed) | `OFL-Figtree.txt` |
|
||||
| `DMSans-Regular.ttf`, `DMSans-Medium.ttf`, `DMSans-Bold.ttf` | DM Sans 1.200 (the macOS disk image's background) | © 2014-2017 Indian Type Foundry, © 2019 Google LLC | https://github.com/googlefonts/dm-fonts (`Sans/Exports/`, commit 23aafb3) | `OFL-DMSans.txt` |
|
||||
| `JetBrainsMono-Regular.ttf` | JetBrains Mono (code views) | © 2020 The JetBrains Mono Project Authors | https://github.com/JetBrains/JetBrainsMono | `OFL-JetBrainsMono.txt` |
|
||||
| `GeistMono-Regular.ttf`, `GeistMono-Medium.ttf` | Geist Mono (labels and buttons) | © 2024 The Geist Project Authors | https://github.com/vercel/geist-font (`fonts/GeistMono/ttf/`) | `OFL-GeistMono.txt` |
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ ArtCraft's mark blue `#4e7bfb`. It is not open source: see `LICENSE.txt`.
|
||||
The interface follows getartcraft.com too (`theme.rs`): its warm near-black and paper
|
||||
backgrounds and ink, its deep accent `#1659c4` (`theme::BRAND`) for filled controls so white text
|
||||
on them passes WCAG AA, its bright accent `#2d81ff` for hover and its light accent `#74aaff` for
|
||||
blue text on dark surfaces. Headings and text are DM Sans.
|
||||
blue text on dark surfaces. Headings and text are Figtree.
|
||||
|
||||
## Geometry
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Optional craft-fonts (fallbacks for CJK, Arabic, Thai, Hebrew, Devanagari…), following
|
||||
//! craft-fonts' `docs/integration.md`. Releases and CI set it.
|
||||
//!
|
||||
//! Unset `CRAFT_FONTS_DIR` (the default) embeds nothing and the app uses its own DM Sans/JetBrains
|
||||
//! Unset `CRAFT_FONTS_DIR` (the default) embeds nothing and the app uses its own Figtree/JetBrains
|
||||
//! Mono. Set it to an absolute path of a craft-fonts checkout to embed every font its manifest
|
||||
//! lists. A bad path is a warning unless `CRAFT_FONTS_REQUIRED=1`.
|
||||
//!
|
||||
|
||||
@@ -22,13 +22,32 @@ fn arg(args: &[String], name: &str) -> Option<String> {
|
||||
/// `--lang`: the UI language for every scene (English when absent).
|
||||
static LANG: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
||||
|
||||
/// `--light`: every scene in Studio Light.
|
||||
static LIGHT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
fn render(out: &std::path::Path, name: &str, w: f32, h: f32, scale: f32, make: impl FnOnce() -> CraftApp + 'static) {
|
||||
render_then(out, name, w, h, scale, make, |_| {});
|
||||
}
|
||||
|
||||
/// [`render`], after `act` has used the settled screen (a click that opens a list).
|
||||
fn render_then(
|
||||
out: &std::path::Path,
|
||||
name: &str,
|
||||
w: f32,
|
||||
h: f32,
|
||||
scale: f32,
|
||||
make: impl FnOnce() -> CraftApp + 'static,
|
||||
act: impl FnOnce(&mut egui_kittest::Harness<'static, CraftApp>),
|
||||
) {
|
||||
let mut harness =
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(w, h)).with_pixels_per_point(scale).with_max_steps(64).wgpu().build_eframe(move |cc| {
|
||||
CraftApp::setup_context(&cc.egui_ctx);
|
||||
let mut app = make();
|
||||
// A made-up folder: the default names the account of whoever renders the pictures.
|
||||
app.settings.projects_dir = Some(PathBuf::from("~/Documents/Craft Anything"));
|
||||
if LIGHT.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
app.settings.theme = "studio-light".into();
|
||||
}
|
||||
app.settings.language = LANG.get().cloned().unwrap_or_else(|| "en".into());
|
||||
craft_anything_ui_egui::i18n::set_language(&app.settings.language);
|
||||
app
|
||||
@@ -37,6 +56,7 @@ fn render(out: &std::path::Path, name: &str, w: f32, h: f32, scale: f32, make: i
|
||||
for _ in 0..24 {
|
||||
harness.step();
|
||||
}
|
||||
act(&mut harness);
|
||||
match harness.render() {
|
||||
Ok(img) => {
|
||||
let path = out.join(format!("{name}.png"));
|
||||
@@ -54,6 +74,7 @@ fn main() {
|
||||
let out = PathBuf::from(arg(&args, "--out-dir").unwrap_or_else(|| "target/snapshots".into()));
|
||||
let scale: f32 = arg(&args, "--scale").and_then(|s| s.parse().ok()).unwrap_or(1.5);
|
||||
let only = arg(&args, "--only");
|
||||
LIGHT.store(args.iter().any(|a| a == "--light"), std::sync::atomic::Ordering::Relaxed);
|
||||
if let Some(l) = arg(&args, "--lang") {
|
||||
let _ = LANG.set(l);
|
||||
}
|
||||
@@ -146,6 +167,56 @@ fn main() {
|
||||
a
|
||||
});
|
||||
}
|
||||
// Settings with the language list open: a dropdown's rows, the tick on the chosen one.
|
||||
if want("settings-dropdown") {
|
||||
render_then(
|
||||
&out,
|
||||
"settings-dropdown",
|
||||
w,
|
||||
h,
|
||||
scale,
|
||||
|| {
|
||||
let mut a = demo::app(demo::engine(Mode::Beginner, true));
|
||||
demo::fill_projects(&mut a);
|
||||
a.state.settings_open = true;
|
||||
a
|
||||
},
|
||||
|harness| {
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
harness.get_by_value("English").click();
|
||||
harness.step();
|
||||
// The list fades in on the clock.
|
||||
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
for _ in 0..12 {
|
||||
harness.step();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
// The title bar's Help menu, open.
|
||||
if want("help-menu") {
|
||||
render_then(
|
||||
&out,
|
||||
"help-menu",
|
||||
w,
|
||||
h,
|
||||
scale,
|
||||
|| {
|
||||
let mut a = demo::app(demo::engine(Mode::Beginner, true));
|
||||
demo::fill_projects(&mut a);
|
||||
a
|
||||
},
|
||||
|harness| {
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
harness.get_by_label("Help").click();
|
||||
harness.step();
|
||||
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
for _ in 0..12 {
|
||||
harness.step();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
if want("palette") {
|
||||
render(&out, "palette", w, h, scale, || {
|
||||
let mut a = demo::app(demo::engine(Mode::Experienced, true));
|
||||
|
||||
@@ -141,16 +141,16 @@ pub(crate) fn menu(app: &mut CraftApp, ui: &mut Ui, root: &Path) {
|
||||
let sel = CHOICES.iter().position(|(_, c)| *c == now).unwrap_or(0);
|
||||
// Every row has the same labels, which `segmented` makes its ids from.
|
||||
ui.push_id(row.name, |ui| {
|
||||
if let Some(c) = widgets::segmented(ui, &names, sel, 24.0).and_then(|i| CHOICES.get(i)) {
|
||||
if let Some(c) = widgets::segmented(ui, &names, sel, theme::ControlSize::Small).and_then(|i| CHOICES.get(i)) {
|
||||
picked = Some((row.kind, c.1));
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let note = tr("Default follows Auto mode: with it on, what can be undone goes ahead and the rest is refused; with it off, the builder asks.");
|
||||
ui.add(egui::Label::new(RichText::new(note).size(theme::SMALL).color(t.text_faint)).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(note).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL))).color(t.text_faint)).wrap());
|
||||
});
|
||||
if let Some((kind, choice)) = picked {
|
||||
app.set_approval(root, kind, choice);
|
||||
|
||||
@@ -40,22 +40,19 @@ pub fn agent_model_picker(ui: &mut Ui, picker: &mut AgentModelPicker) -> bool {
|
||||
}
|
||||
let default = if picker.context.backend.config.model == "opencode" { tr("OpenCode default") } else { tr("Model default") };
|
||||
let selected = picker.model.as_deref().unwrap_or(&default);
|
||||
let response = egui::ComboBox::from_id_salt(("agent-model", &picker.context.backend.config.name))
|
||||
.icon(widgets::combo_icon)
|
||||
.selected_text(selected)
|
||||
.show_ui(ui, |ui| {
|
||||
if ui.selectable_label(picker.model.is_none(), &default).clicked() {
|
||||
picker.model = None;
|
||||
let response = widgets::dropdown(("agent-model", &picker.context.backend.config.name)).selected_text(selected).show_ui(ui, |ui| {
|
||||
if widgets::menu_item(ui, picker.model.is_none(), &default).clicked() {
|
||||
picker.model = None;
|
||||
picker.thinking = None;
|
||||
}
|
||||
for model in models {
|
||||
let label = if model.name == model.id { model.name.clone() } else { format!("{} · {}", model.name, model.id) };
|
||||
if widgets::menu_item(ui, picker.model.as_ref() == Some(&model.id), label).clicked() && picker.model.as_ref() != Some(&model.id) {
|
||||
picker.model = Some(model.id.clone());
|
||||
picker.thinking = None;
|
||||
}
|
||||
for model in models {
|
||||
let label = if model.name == model.id { model.name.clone() } else { format!("{} · {}", model.name, model.id) };
|
||||
if ui.selectable_label(picker.model.as_ref() == Some(&model.id), label).clicked() && picker.model.as_ref() != Some(&model.id) {
|
||||
picker.model = Some(model.id.clone());
|
||||
picker.thinking = None;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
widgets::named(response.response, if picker.context.backend.config.model == "opencode" { "OpenCode model" } else { "Model" });
|
||||
let model = models.iter().find(|m| picker.model.as_ref() == Some(&m.id));
|
||||
let missing = picker.model.is_some() && model.is_none();
|
||||
@@ -67,15 +64,14 @@ pub fn agent_model_picker(ui: &mut Ui, picker: &mut AgentModelPicker) -> bool {
|
||||
let depths = model.map(|m| m.thinking.as_slice()).unwrap_or_default();
|
||||
ui.label(tr("Thinking depth"));
|
||||
let default_depth = tr("Model default");
|
||||
let response = egui::ComboBox::from_id_salt(("agent-thinking", &picker.context.backend.config.name))
|
||||
.icon(widgets::combo_icon)
|
||||
let response = widgets::dropdown(("agent-thinking", &picker.context.backend.config.name))
|
||||
.selected_text(picker.thinking.map(|d| d.title()).unwrap_or(&default_depth))
|
||||
.show_ui(ui, |ui| {
|
||||
if ui.selectable_label(picker.thinking.is_none(), &default_depth).clicked() {
|
||||
if widgets::menu_item(ui, picker.thinking.is_none(), &default_depth).clicked() {
|
||||
picker.thinking = None;
|
||||
}
|
||||
for depth in depths {
|
||||
if ui.selectable_label(picker.thinking == Some(*depth), depth.title()).clicked() {
|
||||
if widgets::menu_item(ui, picker.thinking == Some(*depth), depth.title()).clicked() {
|
||||
picker.thinking = Some(*depth);
|
||||
}
|
||||
}
|
||||
@@ -355,7 +351,7 @@ impl CraftApp {
|
||||
pub fn built_by(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let Some(default) = app.default_builder() else {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.warning);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.warning);
|
||||
ui.label(RichText::new(tr("Building needs a coding agent such as Claude Code, or an AI with an API key.")).size(theme::BODY).color(t.text_dim));
|
||||
if widgets::link(ui, "Set one up").clicked() {
|
||||
app.need_builder(false);
|
||||
@@ -374,13 +370,13 @@ pub fn built_by(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let shown = app.state.make.ai.clone().unwrap_or_else(|| automatic.clone());
|
||||
ui.label(RichText::new(tr("Built by")).size(theme::BODY).color(t.text_dim));
|
||||
let mut pick = None;
|
||||
let r = egui::ComboBox::from_id_salt("built-by").icon(widgets::combo_icon).selected_text(shown).width(220.0).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(app.state.make.ai.is_none(), automatic).on_hover_text(tr("Whatever Settings → AI builds with.")).clicked() {
|
||||
let r = widgets::dropdown("built-by").selected_text(shown).width(220.0).show_ui(ui, |ui| {
|
||||
if widgets::menu_item(ui, app.state.make.ai.is_none(), automatic).on_hover_text(tr("Whatever Settings → AI builds with.")).clicked() {
|
||||
pick = Some(None);
|
||||
}
|
||||
for c in &choices {
|
||||
let note = if c.found { format!("{} · {}", c.detail, tr("found on this computer; set up when you start")) } else { c.detail.clone() };
|
||||
if ui.selectable_label(app.state.make.ai.as_ref() == Some(&c.name), &c.name).on_hover_text(note).clicked() {
|
||||
if widgets::menu_item(ui, app.state.make.ai.as_ref() == Some(&c.name), &c.name).on_hover_text(note).clicked() {
|
||||
pick = Some(Some(c.name.clone()));
|
||||
}
|
||||
}
|
||||
@@ -399,7 +395,7 @@ pub fn need_builder_modal(app: &mut CraftApp, ui: &mut Ui, start: bool, close: &
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, "bot", 24.0, t.accent_ink);
|
||||
icons::paint(ui, rect, "bot", theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(theme::heading(tr("Set up a builder"), theme::CARD));
|
||||
ui.add(
|
||||
@@ -413,7 +409,7 @@ pub fn need_builder_modal(app: &mut CraftApp, ui: &mut Ui, start: bool, close: &
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
let found: Vec<BackendConfig> = app.found_agents().cloned().collect();
|
||||
if app.detecting {
|
||||
ui.horizontal(|ui| {
|
||||
@@ -442,7 +438,7 @@ pub fn need_builder_modal(app: &mut CraftApp, ui: &mut Ui, start: bool, close: &
|
||||
widgets::panel(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "bot", 18.0, t.accent);
|
||||
icons::show(ui, "bot", theme::icon::LG, t.accent);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(&b.name).font(theme::semibold(theme::SMALL)));
|
||||
ui.label(RichText::new(tr("Found on this computer")).color(t.text_faint).size(theme::CAPTION));
|
||||
@@ -461,9 +457,9 @@ pub fn need_builder_modal(app: &mut CraftApp, ui: &mut Ui, start: bool, close: &
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if !app.detecting && widgets::secondary(ui, Some("radar"), "Look again").on_hover_text(tr("After installing one, look for it again.")).clicked() {
|
||||
app.detect_backends();
|
||||
|
||||
@@ -138,9 +138,12 @@ pub fn ask_screen(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let side_w = 300.0_f32.min(ui.available_width() * 0.3);
|
||||
// What's open sits on the right; the app's sidebar is on the left.
|
||||
egui::Panel::right("ask-side").exact_size(side_w).resizable(false).frame(egui::Frame::new().fill(t.canvas).inner_margin(Margin::same(20))).show(ui, |ui| {
|
||||
target_card(app, ui);
|
||||
});
|
||||
egui::Panel::right("ask-side").exact_size(side_w).resizable(false).frame(egui::Frame::new().fill(t.canvas).inner_margin(theme::pad::ROOMY)).show(
|
||||
ui,
|
||||
|ui| {
|
||||
target_card(app, ui);
|
||||
},
|
||||
);
|
||||
egui::CentralPanel::default().frame(egui::Frame::new().fill(t.canvas).inner_margin(PANE_MARGIN)).show(ui, |ui| {
|
||||
conversation(app, ui, false);
|
||||
});
|
||||
@@ -155,16 +158,16 @@ fn target_card(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, crate::kind_icon(target.kind), 26.0, t.accent_ink);
|
||||
icons::paint(ui, rect, crate::kind_icon(target.kind), theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.add(egui::Label::new(theme::heading(&target.name, theme::CARD)).truncate());
|
||||
ui.label(RichText::new(crate::human_bytes(target.bytes.len())).color(t.text_faint).size(theme::CAPTION));
|
||||
});
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "What is it");
|
||||
ui.label(RichText::new(tr(target.kind.plain())).size(theme::BODY));
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if app.view.clean_room {
|
||||
widgets::pill(ui, "Clean room", t.success, t.raised).on_hover_text(tr("Nothing inside it is read."));
|
||||
@@ -184,13 +187,13 @@ fn target_card(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::card(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
widgets::caption(ui, "Try asking");
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let kind = app.view.active_target().map(|t| t.kind);
|
||||
ui.spacing_mut().item_spacing.y = 6.0;
|
||||
ui.spacing_mut().item_spacing.y = theme::space::SM;
|
||||
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| {
|
||||
for q in suggestions(kind) {
|
||||
if widgets::suggestion(ui, q).clicked() {
|
||||
@@ -199,12 +202,12 @@ fn target_card(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
widgets::toggle(ui, &mut app.state.explain_new, "Explain like I'm new")
|
||||
.on_hover_text(tr("Plain words, short sentences, and every technical word explained."));
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
if widgets::secondary(ui, Some("download"), "Export a report").on_hover_text(tr("Everything found so far, as a Markdown file.")).clicked() {
|
||||
app.export_report();
|
||||
}
|
||||
@@ -243,6 +246,12 @@ pub fn conversation(app: &mut CraftApp, ui: &mut Ui, dense: bool) {
|
||||
composer(app, ui, max_w, dense);
|
||||
});
|
||||
remember_composer_height(ui, comp_id, comp_h, r.response.rect.height());
|
||||
// A guess that was too tall leaves room under the box on that first frame; fill it, or the
|
||||
// console's panel shrinks by that much and keeps the size.
|
||||
let left = ui.available_height();
|
||||
if left > 0.0 {
|
||||
ui.add_space(left);
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep the prompt box's height for the next frame's layout. When it changed (a line added or
|
||||
@@ -302,21 +311,21 @@ fn greeting(app: &CraftApp, ui: &mut Ui, dense: bool) {
|
||||
ui.label(RichText::new(tr("Ask the agent about this target. It cites evidence for every claim.")).color(t.text_faint));
|
||||
return;
|
||||
}
|
||||
ui.add_space(24.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
let name = app.view.active_target().map(|t| t.name.clone());
|
||||
let title = match &name {
|
||||
Some(n) => crate::i18n::trf("What would you like to know about {name}?", &[("name", n)]),
|
||||
None => tr("What would you like to find out?"),
|
||||
};
|
||||
ui.label(theme::heading(title, theme::TITLE));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let sub = if app.state.backend.is_some() {
|
||||
"Ask in your own words. Every answer shows how sure we are, and the proof."
|
||||
} else {
|
||||
"No AI brain is set up, so answers come straight from the built-in engines. Add one any time for plain-words explanations."
|
||||
};
|
||||
ui.label(RichText::new(tr(sub)).color(t.text_dim));
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
}
|
||||
|
||||
fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, dense: bool) {
|
||||
@@ -366,10 +375,10 @@ enum ChatAction {
|
||||
}
|
||||
|
||||
/// The side of a message's copy button.
|
||||
const COPY: f32 = 22.0;
|
||||
const COPY: f32 = theme::ControlSize::Small.height();
|
||||
|
||||
fn margin(dense: bool) -> Margin {
|
||||
if dense { Margin::symmetric(10, 6) } else { Margin::symmetric(16, 12) }
|
||||
if dense { theme::pad::FIELD_COMPACT } else { theme::pad::ROW }
|
||||
}
|
||||
|
||||
pub(crate) fn bubble(t: &Tokens, user: bool, dense: bool) -> egui::Frame {
|
||||
@@ -387,7 +396,7 @@ fn copy_button(ui: &mut Ui, over: egui::Rect, at: egui::Pos2, text: &str) {
|
||||
if !(ui.rect_contains_pointer(over.union(at)) || ui.memory(|m| m.has_focus(slot.next_auto_id()))) {
|
||||
slot.set_opacity(0.0);
|
||||
}
|
||||
if icons::button(&mut slot, "copy", COPY, false, "Copy the message").clicked() {
|
||||
if icons::button(&mut slot, "copy", theme::ControlSize::Small, false, "Copy the message").clicked() {
|
||||
ui.ctx().copy_text(text.to_owned());
|
||||
}
|
||||
}
|
||||
@@ -425,7 +434,7 @@ pub(crate) fn answer_bubble(ui: &mut Ui, dense: bool, text: &str, content: impl
|
||||
pub(crate) fn activity_row(ui: &mut Ui, text: RichText) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.horizontal_top(|ui| {
|
||||
icons::show(ui, "activity", 14.0, t.accent);
|
||||
icons::show(ui, "activity", theme::icon::SM, t.accent);
|
||||
ui.add(egui::Label::new(text).wrap());
|
||||
});
|
||||
}
|
||||
@@ -441,7 +450,7 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
widgets::thinking(ui);
|
||||
}
|
||||
if let Some(b) = backend {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(crate::i18n::trf("Answered by {name}", &[("name", b)])).color(t.text_faint).size(theme::CAPTION));
|
||||
}
|
||||
});
|
||||
@@ -456,9 +465,9 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
Some(true) => ("check", t.success),
|
||||
Some(false) => ("triangle-alert", t.danger),
|
||||
};
|
||||
egui::Frame::new().fill(t.raised).corner_radius(t.r_sm()).inner_margin(Margin::symmetric(10, 3)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.raised).corner_radius(t.r_sm()).inner_margin(theme::pad::CHIP).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, icon, 13.0, col);
|
||||
icons::show(ui, icon, theme::icon::SM, col);
|
||||
ui.label(RichText::new(tool.replace('_', " ")).font(theme::mono(theme::CAPTION)).color(t.text_dim));
|
||||
});
|
||||
});
|
||||
@@ -467,22 +476,22 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
}
|
||||
});
|
||||
if let Some(e) = evidence {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
evidence_ui::proof_card(ui, e, dense, false);
|
||||
}
|
||||
}
|
||||
ChatItem::Proof { intro, evidence } => {
|
||||
if !intro.is_empty() {
|
||||
ui.label(RichText::new(intro).color(t.text_dim));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
evidence_ui::proof_card(ui, evidence, dense, open);
|
||||
}
|
||||
ChatItem::Consent { call_id, title, explanation, answer, .. } => {
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, t.warning)).corner_radius(t.r_lg()).inner_margin(Margin::same(14)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, t.warning)).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "shield", 18.0, t.warning);
|
||||
icons::show(ui, "shield", theme::icon::LG, t.warning);
|
||||
ui.label(RichText::new(crate::i18n::trf("May I run \"{title}\"?", &[("title", title)])).font(theme::semibold(theme::BODY)));
|
||||
});
|
||||
ui.label(RichText::new(explanation).color(t.text_dim));
|
||||
@@ -491,7 +500,7 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
.color(t.text_faint)
|
||||
.size(theme::CAPTION),
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
match answer {
|
||||
None => {
|
||||
ui.horizontal(|ui| {
|
||||
@@ -522,11 +531,11 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
.fill(t.card)
|
||||
.stroke(egui::Stroke::new(1.0, t.danger.gamma_multiply(0.6)))
|
||||
.corner_radius(t.r_lg())
|
||||
.inner_margin(Margin::same(12))
|
||||
.inner_margin(theme::pad::PANEL)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.danger);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.danger);
|
||||
ui.add(egui::Label::new(RichText::new(message).color(t.text)).wrap());
|
||||
});
|
||||
if let Some(r) = remediation {
|
||||
@@ -540,17 +549,17 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
|
||||
});
|
||||
}
|
||||
ChatItem::AddBrain => {
|
||||
egui::Frame::new().fill(t.accent_soft).corner_radius(t.r_lg()).inner_margin(Margin::same(14)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.accent_soft).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "sparkles", 20.0, t.accent_ink);
|
||||
icons::show(ui, "sparkles", theme::icon::LG, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(tr("Want answers in plain words?")).font(theme::semibold(theme::BODY)));
|
||||
ui.label(
|
||||
RichText::new(tr("Add an AI brain and I'll read this evidence for you, answer follow-up questions and point at the proof."))
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if widgets::primary_icon(ui, Some("plus"), "Add a brain", true).clicked() {
|
||||
actions.push(ChatAction::AddBrain);
|
||||
}
|
||||
@@ -583,7 +592,7 @@ pub fn rich_text(ui: &mut Ui, text: &str, with_glossary: bool) {
|
||||
}
|
||||
let trimmed = line.trim_start();
|
||||
if trimmed.is_empty() {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
continue;
|
||||
}
|
||||
if let Some(h) = trimmed.strip_prefix("### ").or_else(|| trimmed.strip_prefix("## ")).or_else(|| trimmed.strip_prefix("# ")) {
|
||||
@@ -701,7 +710,7 @@ fn paragraph(ui: &mut Ui, text: &str, bullet: bool, with_glossary: bool, body: &
|
||||
}
|
||||
|
||||
fn code_block(ui: &mut Ui, code: &str, t: &Tokens) {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(Margin::same(10)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(theme::pad::PANEL).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.add(egui::Label::new(RichText::new(code.trim_end()).font(theme::mono(theme::CAPTION)).color(t.text)).wrap());
|
||||
});
|
||||
|
||||
@@ -192,7 +192,7 @@ pub fn deep_needed(app: &mut CraftApp, ui: &mut Ui) {
|
||||
/// [`deep_needed`] as a dialog, for a look inside asked for anywhere else.
|
||||
pub fn deep_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
deep_needed(app, ui);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.vertical_centered(|ui| {
|
||||
if widgets::secondary(ui, None, "Not now").clicked() {
|
||||
*close = true;
|
||||
@@ -209,7 +209,7 @@ pub fn ghidra_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, if ready { "check" } else { "microscope" }, 24.0, t.accent_ink);
|
||||
icons::paint(ui, rect, if ready { "check" } else { "microscope" }, theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
let title = if ready {
|
||||
"Ghidra is ready"
|
||||
@@ -224,14 +224,15 @@ pub fn ghidra_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
let body = |ui: &mut Ui, text: String| ui.add(egui::Label::new(RichText::new(text).size(theme::BODY)).wrap());
|
||||
ui.add_space(theme::space::MD);
|
||||
let body =
|
||||
|ui: &mut Ui, text: String| ui.add(egui::Label::new(RichText::new(text).size(theme::BODY).line_height(Some(theme::leading(theme::BODY)))).wrap());
|
||||
let then = if app.ghidra.start_after.is_some() { tr("Your project starts as soon as it's done.") } else { String::new() };
|
||||
if ready {
|
||||
body(ui, tr("Deep mode now decompiles with Ghidra. The first look at a large program can take several minutes."));
|
||||
} else if let Some((fraction, message)) = &downloading {
|
||||
progress_bar(ui, *fraction, message);
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
body(
|
||||
ui,
|
||||
format!("{} {then}", tr("This keeps going in the background, and each download is checked against its publisher's checksum before it's used.")),
|
||||
@@ -253,7 +254,7 @@ pub fn ghidra_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
if !ready && downloading.is_none() {
|
||||
body(ui, tr("Without it, Deep mode uses Craft Anything's own decompiler, which is rougher."));
|
||||
}
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
if ready {
|
||||
let start = app.ghidra.start_after.is_some();
|
||||
@@ -323,12 +324,12 @@ pub fn ghidra_memory_setting(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let set = ghidra_memory(app);
|
||||
ui.vertical(|ui| {
|
||||
if let Some(i) = widgets::segmented(ui, &["Automatic", "Custom"], usize::from(set.is_some()), 30.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Automatic", "Custom"], usize::from(set.is_some()), theme::ControlSize::Medium) {
|
||||
// Custom starts from what a program of a few hundred MB wants.
|
||||
app.settings.engines.ghidra.memory_gb = (i == 1).then(|| ghidra::suggested_heap_gb(500 << 20));
|
||||
app.settings_changed();
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
match set {
|
||||
None => {
|
||||
let line = trf("Half of this computer's memory, up to {gb} GB.", &[("gb", &ghidra::HEAP_GB.end().to_string())]);
|
||||
@@ -474,12 +475,11 @@ pub fn assets_toggle(app: &mut CraftApp, ui: &mut Ui, mut on: bool) {
|
||||
&[("model", &p.model), ("picture", &p.picture)],
|
||||
)
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(note).color(if no_key { t.warning } else { t.text_dim }).size(theme::SMALL));
|
||||
if no_key && widgets::link(ui, "Add a fal.ai key").clicked() {
|
||||
app.state.modal = Some(Modal::Assets);
|
||||
}
|
||||
});
|
||||
let ink = if no_key { t.warning } else { t.text_faint };
|
||||
ui.add(egui::Label::new(RichText::new(note).color(ink).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION)))).wrap());
|
||||
if no_key && widgets::link(ui, "Add a fal.ai key").clicked() {
|
||||
app.state.modal = Some(Modal::Assets);
|
||||
}
|
||||
}
|
||||
|
||||
/// Asks for a fal.ai key when generated assets are turned on without one.
|
||||
@@ -489,13 +489,13 @@ pub fn assets_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, "boxes", 24.0, t.accent_ink);
|
||||
icons::paint(ui, rect, "boxes", theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(theme::heading(tr("Your fal.ai key"), theme::SECTION));
|
||||
ui.label(RichText::new(tr("Generated pictures and 3D models are made with fal.ai.")).color(t.text_dim));
|
||||
});
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new({
|
||||
@@ -509,15 +509,15 @@ pub fn assets_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let fal = fal::Fal::default();
|
||||
keys_link(ui, &fal);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if let Some(key) = key_field(app, ui, &fal, "Save") {
|
||||
*close = true;
|
||||
app.save_asset_key(fal.id().into(), key);
|
||||
}
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if widgets::secondary(ui, None, "Not now").clicked() {
|
||||
*close = true;
|
||||
app.set_generate_assets(false);
|
||||
@@ -575,7 +575,7 @@ pub fn assets_settings(app: &mut CraftApp, ui: &mut Ui) {
|
||||
);
|
||||
let all = AssetProviders::built_in();
|
||||
for provider in all.ids().into_iter().filter_map(|id| all.get(id)) {
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(provider.name()).size(theme::SMALL));
|
||||
let stored = app.asset_keys.as_ref().and_then(|k| k.get(provider.id()).copied());
|
||||
ui.push_id(provider.id(), |ui| {
|
||||
@@ -618,7 +618,7 @@ pub fn build_with(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let b = chosen(&app.kinds, &app.state.make);
|
||||
if let Some(f) = app.state.make.found.clone() {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "puzzle", 16.0, t.accent_ink);
|
||||
icons::show(ui, "puzzle", theme::icon::MD, t.accent_ink);
|
||||
ui.label(RichText::new(trf("Made with {engine}", &[("engine", &f.label())])).font(theme::semibold(theme::BODY)));
|
||||
});
|
||||
if !matches!(f.engine, game::Made::Unity | game::Made::Unreal | game::Made::Godot) {
|
||||
@@ -628,24 +628,24 @@ pub fn build_with(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.size(theme::SMALL),
|
||||
);
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(tr("Build with")).size(theme::BODY).color(t.text_dim));
|
||||
let names: Vec<&str> = Builder::ALL.iter().map(|b| b.name()).collect();
|
||||
// Nothing is selected while the request names another way to build.
|
||||
let sel = b.and_then(|b| Builder::ALL.iter().position(|x| *x == b)).unwrap_or(usize::MAX);
|
||||
if let Some(i) = widgets::segmented(ui, &names, sel, 32.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &names, sel, theme::ControlSize::Medium) {
|
||||
app.state.make.builder = Builder::ALL.get(i).copied();
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
match b {
|
||||
Some(b) => status_line(app, ui, b, true),
|
||||
None => {
|
||||
let named = app.kinds.named(&app.state.make.request, &crate::make::resolve_target(&app.state.make)).unwrap_or_default();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "check", 16.0, t.success);
|
||||
icons::show(ui, "check", theme::icon::MD, t.success);
|
||||
ui.label(
|
||||
RichText::new(trf("Built with {stack}, as you asked, so no game engine is needed.", &[("stack", named)]))
|
||||
.color(t.text_dim)
|
||||
@@ -688,17 +688,17 @@ fn status_line(app: &mut CraftApp, ui: &mut Ui, b: Builder, offer: bool) {
|
||||
let inv = app.game_engines.clone();
|
||||
ui.horizontal_wrapped(|ui| match &inv {
|
||||
None => {
|
||||
ui.add(crate::widgets::Spinner::new().size(14.0).color(t.accent));
|
||||
ui.add(crate::widgets::Spinner::new().size(theme::icon::SM).color(t.accent));
|
||||
ui.label(RichText::new(tr("Looking for game engines on this computer…")).color(t.text_dim).size(theme::SMALL));
|
||||
}
|
||||
Some(inv) if inv.ready(b) => {
|
||||
icons::show(ui, "check", 16.0, t.success);
|
||||
icons::show(ui, "check", theme::icon::MD, t.success);
|
||||
let v = inv.best(b).map(|i| i.version.clone()).unwrap_or_default();
|
||||
let what = if v.is_empty() { b.name().to_string() } else { format!("{} {v}", b.name()) };
|
||||
ui.label(RichText::new(trf("Ready: {what} is on this computer.", &[("what", &what)])).color(t.text_dim).size(theme::SMALL));
|
||||
}
|
||||
Some(inv) => {
|
||||
icons::show(ui, "download", 16.0, t.warning);
|
||||
icons::show(ui, "download", theme::icon::MD, t.warning);
|
||||
let text = if b == Builder::Unreal && inv.best(b).is_some() {
|
||||
tr(unreal_tools_missing(std::env::consts::OS))
|
||||
} else {
|
||||
@@ -802,7 +802,7 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
ui.set_width(520.0);
|
||||
let Some(inv) = app.game_engines.clone() else {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(crate::widgets::Spinner::new().size(16.0).color(t.accent));
|
||||
ui.add(crate::widgets::Spinner::new().size(theme::icon::MD).color(t.accent));
|
||||
ui.label(tr("Looking for game engines on this computer…"));
|
||||
});
|
||||
app.refresh_game_engines();
|
||||
@@ -818,14 +818,14 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, if ready { "check" } else { "download" }, 24.0, t.accent_ink);
|
||||
icons::paint(ui, rect, if ready { "check" } else { "download" }, theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
let title = if ready { trf("{name} is ready", &[("name", b.name())]) } else { trf("Get {name}", &[("name", b.name())]) };
|
||||
ui.label(theme::heading(title, theme::SECTION));
|
||||
ui.label(RichText::new(tr(b.needs())).color(t.text_dim));
|
||||
});
|
||||
});
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
|
||||
let list = steps(app, b, &inv);
|
||||
let current = list.iter().position(|s| !s.done);
|
||||
@@ -836,20 +836,22 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
let (r, _) = ui.allocate_exact_size(Vec2::splat(28.0), egui::Sense::hover());
|
||||
if s.done {
|
||||
ui.painter().rect_filled(r, r.width() / 2.0, t.success);
|
||||
icons::paint(ui, r, "check", 16.0, t.canvas);
|
||||
icons::paint(ui, r, "check", theme::icon::MD, t.canvas);
|
||||
} else {
|
||||
ui.painter().rect_stroke(r, r.width() / 2.0, egui::Stroke::new(1.0, if now { t.accent } else { t.field_border }), egui::StrokeKind::Inside);
|
||||
let g = widgets::label_galley(ui, &(i + 1).to_string(), 12.0, t.text);
|
||||
let g = widgets::label_galley(ui, &(i + 1).to_string(), theme::LABEL, t.text);
|
||||
ui.painter().galley_with_override_text_color(r.center() - g.size() / 2.0, g, if now { t.text } else { t.text_faint });
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(&s.title).font(theme::semibold(theme::BODY)).color(if s.done || now { t.text } else { t.text_dim }));
|
||||
if now || !s.done {
|
||||
ui.add(egui::Label::new(RichText::new(&s.detail).color(t.text_dim).size(theme::SMALL)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(&s.detail).color(t.text_dim).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL)))).wrap(),
|
||||
);
|
||||
}
|
||||
if now {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if let Some(a) = &s.action {
|
||||
let downloading = app.engine_download(b);
|
||||
match (a, downloading) {
|
||||
@@ -871,7 +873,7 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
if !s.done && current.is_some() && i > 0 {
|
||||
ui.label(RichText::new(tr("This updates by itself when it's done.")).color(t.text_faint).size(theme::SMALL));
|
||||
@@ -879,7 +881,7 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
}
|
||||
|
||||
match act {
|
||||
@@ -889,7 +891,7 @@ pub fn modal(app: &mut CraftApp, ui: &mut Ui, b: Builder, close: &mut bool) {
|
||||
None => {}
|
||||
}
|
||||
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
if ready {
|
||||
let label = if app.engine_flow.start_after { "Start building" } else { "Done" };
|
||||
@@ -933,9 +935,9 @@ pub fn progress_bar(ui: &mut Ui, fraction: Option<f32>, message: &str) {
|
||||
}
|
||||
};
|
||||
ui.painter().rect_filled(egui::Rect::from_x_y_ranges(bar.left() + bar.width() * from..=bar.left() + bar.width() * to, bar.y_range()), 3.0, t.accent);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let pct = fraction.map(|f| format!("{:.0}% · ", f * 100.0)).unwrap_or_default();
|
||||
ui.label(RichText::new(format!("{pct}{message}")).font(theme::mono(12.5)).color(t.text_dim));
|
||||
ui.label(RichText::new(format!("{pct}{message}")).font(theme::mono(theme::CODE)).color(t.text_dim));
|
||||
widgets::animate(ui, Duration::from_millis(100));
|
||||
}
|
||||
|
||||
@@ -956,11 +958,11 @@ pub fn settings_section(app: &mut CraftApp, ui: &mut Ui) {
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
for b in Builder::ALL {
|
||||
ui.label(RichText::new(b.name()).font(theme::semibold(theme::SMALL)));
|
||||
status_line(app, ui, b, true);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn proof_card(ui: &mut Ui, e: &Evidence, dense: bool, open: bool) {
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if !e.summary.is_empty() {
|
||||
ui.label(RichText::new(&e.summary).size(if dense { theme::SMALL } else { theme::BODY }));
|
||||
}
|
||||
@@ -56,7 +56,7 @@ fn details(ui: &mut Ui, e: &Evidence, t: &Tokens) {
|
||||
Some(lbl) => format!("{lbl} {}", l.value),
|
||||
None => l.value.clone(),
|
||||
};
|
||||
egui::Frame::new().fill(t.raised).corner_radius(t.r_sm()).inner_margin(Margin::symmetric(8, 3)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.raised).corner_radius(t.r_sm()).inner_margin(theme::pad::CHIP).show(ui, |ui| {
|
||||
ui.label(RichText::new(text).font(theme::mono(theme::CAPTION)).color(t.text)).on_hover_text(&l.kind);
|
||||
});
|
||||
}
|
||||
@@ -64,17 +64,17 @@ fn details(ui: &mut Ui, e: &Evidence, t: &Tokens) {
|
||||
ui.label(RichText::new(format!("+{}", e.locations.len() - 40)).color(t.text_faint));
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
if !e.limitations.is_empty() {
|
||||
widgets::caption(ui, "What we couldn't check");
|
||||
for l in &e.limitations {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "info", 13.0, t.warning);
|
||||
icons::show(ui, "info", theme::icon::SM, t.warning);
|
||||
ui.add(egui::Label::new(RichText::new(&l.message).color(t.text_dim)).wrap());
|
||||
});
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let cov = match e.coverage.status {
|
||||
@@ -96,21 +96,21 @@ fn details(ui: &mut Ui, e: &Evidence, t: &Tokens) {
|
||||
ui.ctx().copy_text(e.id.clone());
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if let Some(code) = crate::workbench::code_text(&e.result) {
|
||||
widgets::caption(ui, "The code");
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(Margin::same(10)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(theme::pad::PANEL).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.label(RichText::new(truncate(code, 4000)).font(theme::mono(theme::CAPTION)).color(t.text));
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
egui::CollapsingHeader::new(RichText::new(tr("The raw result")).color(t.text_dim).size(theme::CAPTION))
|
||||
.id_salt(("raw", &e.id))
|
||||
.default_open(false)
|
||||
.icon(widgets::disclosure_icon)
|
||||
.show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(Margin::same(8)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(theme::pad::TIGHT).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
json_tree(ui, "result", &e.result, 0);
|
||||
});
|
||||
@@ -133,7 +133,7 @@ const MAX_DEPTH: usize = 24;
|
||||
/// A collapsible, capped JSON tree in monospace.
|
||||
pub fn json_tree(ui: &mut Ui, key: &str, v: &Value, depth: usize) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let key_text = RichText::new(key).font(theme::mono(12.0)).color(t.accent_ink);
|
||||
let key_text = RichText::new(key).font(theme::mono(theme::CODE)).color(t.accent_ink);
|
||||
if depth > MAX_DEPTH {
|
||||
ui.label(RichText::new("…").color(t.text_faint));
|
||||
return;
|
||||
@@ -169,15 +169,15 @@ pub fn json_tree(ui: &mut Ui, key: &str, v: &Value, depth: usize) {
|
||||
}
|
||||
leaf => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 6.0;
|
||||
ui.label(RichText::new(format!("{key}:")).font(theme::mono(12.0)).color(t.accent_ink));
|
||||
ui.spacing_mut().item_spacing.x = theme::space::XS;
|
||||
ui.label(RichText::new(format!("{key}:")).font(theme::mono(theme::CODE)).color(t.accent_ink));
|
||||
let (text, col) = match leaf {
|
||||
Value::String(s) => (format!("\"{}\"", truncate(s, 400)), t.text),
|
||||
Value::Null => ("null".into(), t.text_faint),
|
||||
Value::Bool(b) => (b.to_string(), theme::WORKED_OUT),
|
||||
other => (other.to_string(), theme::SEEN_IT),
|
||||
};
|
||||
ui.add(egui::Label::new(RichText::new(text).font(theme::mono(12.0)).color(col)).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(text).font(theme::mono(theme::CODE)).color(col)).wrap());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -190,8 +190,8 @@ trait AppendText {
|
||||
impl AppendText for RichText {
|
||||
fn append_text(self, s: String, t: &Tokens) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(self.text(), 0.0, egui::TextFormat { font_id: theme::mono(12.0), color: t.accent_ink, ..Default::default() });
|
||||
job.append(&s, 0.0, egui::TextFormat { font_id: theme::mono(12.0), color: t.text_faint, ..Default::default() });
|
||||
job.append(self.text(), 0.0, egui::TextFormat { font_id: theme::mono(theme::CODE), color: t.accent_ink, ..Default::default() });
|
||||
job.append(&s, 0.0, egui::TextFormat { font_id: theme::mono(theme::CODE), color: t.text_faint, ..Default::default() });
|
||||
job.into()
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ pub fn ledger_row(ui: &mut Ui, e: &Evidence, selected: bool) -> bool {
|
||||
let resp = egui::Frame::new()
|
||||
.fill(if selected { t.accent_soft } else { t.card })
|
||||
.corner_radius(t.r_sm())
|
||||
.inner_margin(Margin::symmetric(8, 6))
|
||||
.inner_margin(theme::pad::FIELD_COMPACT)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
@@ -218,7 +218,12 @@ pub fn ledger_row(ui: &mut Ui, e: &Evidence, selected: bool) -> bool {
|
||||
ui.label(RichText::new(tr(crate::theme::confidence_label(Some(e.confidence)))).size(theme::TINY).color(col));
|
||||
});
|
||||
});
|
||||
ui.add(egui::Label::new(RichText::new(truncate(&e.summary, 160)).size(theme::CAPTION).color(t.text_dim)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(truncate(&e.summary, 160)).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION))).color(t.text_dim),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
})
|
||||
.response;
|
||||
let resp = resp.interact(egui::Sense::click());
|
||||
|
||||
@@ -25,14 +25,14 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
FirstRunStep::Done => done(app, ui),
|
||||
}
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
});
|
||||
// Where you are, the ArtCraft way: "02 / 04 AI", plus a progress hairline.
|
||||
let step = app.state.first_run.index();
|
||||
let y = full.bottom() - 34.0;
|
||||
let names = ["Welcome", "AI", "Purpose", "Ready"];
|
||||
let label = format!("{:02} / 04 {}", step + 1, tr(names.get(step).copied().unwrap_or_default()));
|
||||
let g = widgets::label_galley(ui, &label, 12.0, t.text_dim);
|
||||
let g = widgets::label_galley(ui, &label, theme::LABEL, t.text_dim);
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(full.center().x - g.size().x / 2.0, y - g.size().y / 2.0), g, t.text_dim);
|
||||
let track = egui::Rect::from_min_size(egui::pos2(full.left(), full.bottom() - 2.0), Vec2::new(full.width(), 2.0));
|
||||
ui.painter().rect_filled(track, 0.0, t.separator);
|
||||
@@ -40,7 +40,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if step > 0 && step < 3 {
|
||||
let r = egui::Rect::from_min_size(egui::pos2(full.left() + 24.0, y - 14.0), Vec2::new(120.0, 28.0));
|
||||
let resp = ui.interact(r, ui.id().with("fr-back"), egui::Sense::click());
|
||||
let g = widgets::label_galley(ui, &tr("← Back"), 12.0, t.text);
|
||||
let g = widgets::label_galley(ui, &tr("← Back"), theme::LABEL, t.text);
|
||||
let col = if resp.hovered() { t.text } else { t.text_dim };
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(r.left(), r.center().y - g.size().y / 2.0), g, col);
|
||||
widgets::focus_ring(ui, &resp, r);
|
||||
@@ -57,11 +57,11 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
fn welcome(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.add(crate::app_icon(132.0));
|
||||
ui.add_space(20.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
ui.label(theme::heading(tr("Craft Anything"), theme::TITLE));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(tr("Find out how any software works, then craft your own.")).size(theme::LEAD).color(t.text_dim));
|
||||
ui.add_space(36.0);
|
||||
ui.add_space(theme::space::XXL);
|
||||
let w = 270.0;
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(((ui.available_width() - (w * 2.0 + 16.0)) / 2.0).max(0.0));
|
||||
@@ -69,13 +69,13 @@ fn welcome(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.settings.mode = Mode::Beginner;
|
||||
app.state.first_run = FirstRunStep::Brain;
|
||||
}
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if choice_card(ui, w, "terminal", "Show me everything", "Every tool as well: a workbench with functions, bytes, references and evidence.").clicked() {
|
||||
app.settings.mode = Mode::Experienced;
|
||||
app.state.first_run = FirstRunStep::Brain;
|
||||
}
|
||||
});
|
||||
ui.add_space(20.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
if widgets::link(ui, "Skip setup").on_hover_text(tr("Start with Simple mode; you can set up AI later in Settings.")).clicked() {
|
||||
app.finish_first_run();
|
||||
}
|
||||
@@ -88,9 +88,9 @@ fn choice_card(ui: &mut Ui, w: f32, icon: &str, title: &str, blurb: &str) -> egu
|
||||
fn header(ui: &mut Ui, title: &str, sub: &str) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::heading(tr(title), theme::TITLE));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr(sub)).size(theme::BODY).color(t.text_dim));
|
||||
ui.add_space(22.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
}
|
||||
|
||||
fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
@@ -104,13 +104,13 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
match app.default_builder() {
|
||||
Some(b) => {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "check", 16.0, t.success);
|
||||
icons::show(ui, "check", theme::icon::MD, t.success);
|
||||
ui.label(RichText::new(crate::i18n::trf("{name} builds what you make.", &[("name", &b)])).color(t.text_dim));
|
||||
});
|
||||
}
|
||||
None => {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.warning);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.warning);
|
||||
ui.label(
|
||||
RichText::new(tr("Nothing can build yet: install Claude Code (and sign in to it once), or add an AI with an API key below."))
|
||||
.color(t.text_dim),
|
||||
@@ -118,7 +118,7 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
});
|
||||
}
|
||||
}
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let detected: Vec<Detected> = app.detected.clone().unwrap_or_default();
|
||||
let tab = crate::detect_tabs::bar(ui, &mut app.state.detect_tab, &detected);
|
||||
let list_h = (ui.ctx().content_rect().height() - 330.0).clamp(220.0, 520.0);
|
||||
@@ -129,13 +129,13 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
ui.add(crate::widgets::Spinner::new().color(t.accent));
|
||||
ui.label(RichText::new(tr("Looking for AI on this computer…")).color(t.text_dim));
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let mut shown = 0;
|
||||
for d in detected.iter().filter(|d| crate::detect_tabs::tab_of(d) == tab) {
|
||||
brain_card(app, ui, d);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
shown += 1;
|
||||
}
|
||||
if !app.detecting && shown == 0 && !detected.is_empty() {
|
||||
@@ -146,18 +146,18 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
widgets::card(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "radar", 22.0, t.text_faint);
|
||||
icons::show(ui, "radar", theme::icon::XL, t.text_faint);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(tr("We didn't find an AI on this computer yet")).font(theme::medium(theme::BODY)));
|
||||
ui.label(RichText::new(tr("You can add a Claude, ChatGPT or OpenRouter key, a local model (Ollama, LM Studio) or an agent you already use, later in Settings → AI.")).color(t.text_dim));
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
// A model server on another computer can't be found by looking here (#54, #98).
|
||||
crate::settings_ui::server_form(app, ui);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
// "No AI for now"
|
||||
let none_on = app.state.backend.is_none();
|
||||
let r = option_row(ui, "circle-stop", "No AI for now", "The built-in engines still show you everything they find.", none_on);
|
||||
@@ -166,7 +166,7 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
app.state.first_run = FirstRunStep::Purpose;
|
||||
}
|
||||
});
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(((ui.available_width() - 240.0) / 2.0).max(0.0));
|
||||
if widgets::secondary(ui, Some("refresh-cw"), "Look again").clicked() {
|
||||
@@ -195,13 +195,13 @@ fn brain_card(app: &mut CraftApp, ui: &mut Ui, d: &Detected) {
|
||||
.fill(if on { t.accent_soft } else { t.card })
|
||||
.stroke(egui::Stroke::new(1.0, if on { t.accent } else { t.card_border }))
|
||||
.corner_radius(t.r_lg())
|
||||
.inner_margin(egui::Margin::same(14));
|
||||
.inner_margin(theme::pad::CARD);
|
||||
frame.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(40.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.raised);
|
||||
icons::paint(ui, rect, kind_icon(d.suggestion.kind), 20.0, t.accent_ink);
|
||||
icons::paint(ui, rect, kind_icon(d.suggestion.kind), theme::icon::LG, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(theme::heading(&name, theme::CARD));
|
||||
ui.label(RichText::new(&d.reason).color(t.text_dim).size(theme::SMALL));
|
||||
@@ -222,7 +222,7 @@ fn brain_card(app: &mut CraftApp, ui: &mut Ui, d: &Detected) {
|
||||
// different key can be used without restarting the app.
|
||||
let pastable = d.needs_key || d.suggestion.base_url.as_deref().is_some_and(craft_anything_ai::openai::is_opencode_go);
|
||||
if pastable && !configured {
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal(|ui| {
|
||||
let key = app.key_inputs.entry(name.clone()).or_default();
|
||||
ui.add(
|
||||
@@ -253,11 +253,11 @@ fn option_row(ui: &mut Ui, icon: &str, title: &str, sub: &str, on: bool) -> egui
|
||||
ui.painter().rect(rect, t.radius_lg, fill, stroke, egui::StrokeKind::Inside);
|
||||
let ir = egui::Rect::from_min_size(rect.min + Vec2::new(14.0, 12.0), Vec2::splat(40.0));
|
||||
ui.painter().rect_filled(ir, t.radius, t.raised);
|
||||
icons::paint(ui, ir, icon, 20.0, if on { t.accent_ink } else { t.icon });
|
||||
icons::paint(ui, ir, icon, theme::icon::LG, if on { t.accent_ink } else { t.icon });
|
||||
ui.painter().text(egui::pos2(ir.right() + 14.0, rect.top() + 14.0), Align2::LEFT_TOP, tr(title), theme::semibold(theme::BODY), t.text);
|
||||
ui.painter().text(egui::pos2(ir.right() + 14.0, rect.top() + 35.0), Align2::LEFT_TOP, tr(sub), egui::FontId::proportional(theme::SMALL), t.text_dim);
|
||||
if on {
|
||||
icons::paint(ui, egui::Rect::from_center_size(egui::pos2(rect.right() - 26.0, rect.center().y), Vec2::splat(20.0)), "check", 18.0, t.accent);
|
||||
icons::paint(ui, egui::Rect::from_center_size(egui::pos2(rect.right() - 26.0, rect.center().y), Vec2::splat(20.0)), "check", theme::icon::LG, t.accent);
|
||||
}
|
||||
widgets::focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, on, tr(title)));
|
||||
@@ -273,10 +273,10 @@ fn purpose(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
if option_row(ui, purpose_icon(p), title, sub, on).clicked() {
|
||||
app.state.purpose = p;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
// Shown, not a hover tip in link colour: a click on it did nothing and read as broken (#71).
|
||||
ui.scope(|ui| {
|
||||
ui.set_max_width(width);
|
||||
@@ -287,7 +287,7 @@ fn purpose(app: &mut CraftApp, ui: &mut Ui, width: f32) {
|
||||
.size(theme::SMALL)
|
||||
.color(t.text_dim));
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if widgets::primary(ui, "Continue").clicked() {
|
||||
app.state.first_run = FirstRunStep::Done;
|
||||
}
|
||||
@@ -308,17 +308,17 @@ fn done(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(72.0), egui::Sense::hover());
|
||||
ui.painter().rect(rect, rect.width() / 2.0, t.accent_soft, egui::Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
|
||||
icons::paint(ui, rect, "check", 34.0, t.accent);
|
||||
ui.add_space(18.0);
|
||||
icons::paint(ui, rect, "check", theme::icon::XXL, t.accent);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.label(theme::heading(tr("You're all set"), theme::TITLE));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let brain = app.state.backend.clone().unwrap_or_else(|| tr("the built-in engines"));
|
||||
let builds = match app.default_builder() {
|
||||
Some(b) => crate::i18n::trf("{name} builds what you make; answers come from {brain}.", &[("name", &b), ("brain", &brain)]),
|
||||
None => crate::i18n::trf("Answers come from {brain}. To build, set up a coding agent in Settings → AI.", &[("brain", &brain)]),
|
||||
};
|
||||
ui.label(RichText::new(builds).size(theme::BODY).color(t.text_dim));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(
|
||||
RichText::new(tr(
|
||||
"Say what you want to make, or drop an app or file on the window to look inside it. Everything runs in Clean room mode unless you switch on Deep.",
|
||||
@@ -326,7 +326,7 @@ fn done(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.size(theme::BODY)
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.add_space(28.0);
|
||||
ui.add_space(theme::space::XXL);
|
||||
if widgets::primary_icon(ui, Some("rocket"), "Let's go", true).clicked() {
|
||||
app.finish_first_run();
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ pub fn make_line(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let picked = d.folder.is_some();
|
||||
// Where it goes (and what the files there are), then what can be changed, each on its own line.
|
||||
ui.horizontal(|ui| {
|
||||
crate::icons::show(ui, "folder", 14.0, t.text_faint);
|
||||
crate::icons::show(ui, "folder", theme::icon::SM, t.text_faint);
|
||||
ui.label(RichText::new(tr("Saved in")).size(theme::SMALL).color(t.text_dim));
|
||||
ui.add(egui::Label::new(RichText::new(&place).size(theme::SMALL).color(t.text)).truncate()).on_hover_text(&place);
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.add_space(22.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
if let Some(how) = how {
|
||||
ui.label(RichText::new(how).size(theme::SMALL).color(t.text_dim));
|
||||
if widgets::link(ui, "Change").clicked() {
|
||||
@@ -152,13 +152,13 @@ pub fn existing_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
};
|
||||
let (names, count) = app.state.make.folder_files.clone().unwrap_or_default();
|
||||
ui.label(theme::heading(tr("This folder already has files"), theme::SECTION));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let some = names.iter().take(4).cloned().collect::<Vec<_>>().join(", ");
|
||||
let more = if count > 4 { trf(" and {n} more", &[("n", &(count - 4).to_string())]) } else { String::new() };
|
||||
ui.add(egui::Label::new(RichText::new(format!("{}: {some}{more}.", folder.display())).color(t.text_dim)).wrap());
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr("How should the builder use them?")).color(t.text));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let current = app.state.make.existing;
|
||||
let size = Vec2::new(268.0, 168.0);
|
||||
let mut chosen = None;
|
||||
@@ -186,12 +186,12 @@ pub fn existing_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
chosen = Some(ExistingFiles::StartFrom);
|
||||
}
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let mut remember = app.state.make.remember_existing;
|
||||
if widgets::toggle(ui, &mut remember, "Don't ask again (you can change this in Settings)").changed() {
|
||||
app.state.make.remember_existing = remember;
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
if widgets::secondary(ui, None, "Cancel: don't use this folder").clicked() {
|
||||
clear(app);
|
||||
*close = true;
|
||||
|
||||
@@ -31,19 +31,19 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let full_w = ui.available_width();
|
||||
let w = full_w.min(1000.0) - 48.0;
|
||||
let pad = ((full_w - w) / 2.0).max(24.0);
|
||||
ui.add_space(40.0);
|
||||
ui.add_space(theme::space::XXL);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(pad);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(w);
|
||||
ui.label(theme::heading(tr("Game files"), theme::TITLE));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(
|
||||
RichText::new(tr("See what a game packs and save its pictures as PNG files. Only for games you made, or whose owner lets you."))
|
||||
.size(theme::BODY)
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
// Every look at a game's files reads them, which Clean room never does.
|
||||
if !app.settings.deep_mode {
|
||||
crate::engine_ui::deep_needed(app, ui);
|
||||
@@ -55,18 +55,18 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.pick(Pick::GameFolder);
|
||||
}
|
||||
if let Some(folder) = &app.state.game.folder {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
// Like every chosen folder: short, cut to fit the row, whole on hover.
|
||||
let full = folder.display().to_string();
|
||||
ui.add(egui::Label::new(RichText::new(crate::short_path(folder)).color(t.text_faint).size(theme::CAPTION)).truncate())
|
||||
.on_hover_text(full);
|
||||
}
|
||||
});
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
about(app, ui, w);
|
||||
archives(app, ui, w);
|
||||
contents(app, ui);
|
||||
ui.add_space(36.0);
|
||||
ui.add_space(theme::space::XXL);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -85,19 +85,19 @@ fn about(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
widgets::card(&t).show(ui, |ui| {
|
||||
ui.set_width(w - 34.0);
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "puzzle", 20.0, t.accent_ink);
|
||||
icons::show(ui, "puzzle", theme::icon::LG, t.accent_ink);
|
||||
ui.label(theme::heading(g["engine"].as_str().unwrap_or_default(), theme::CARD));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ask = widgets::primary_icon(ui, Some("message-square"), "Ask about this game", true).clicked();
|
||||
});
|
||||
});
|
||||
if let Some(note) = found["note"].as_str() {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(note).color(t.text_dim).size(theme::BODY));
|
||||
}
|
||||
let stack = g["stack"].as_array().cloned().unwrap_or_default();
|
||||
if !stack.is_empty() {
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Built with");
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for s in &stack {
|
||||
@@ -107,11 +107,11 @@ fn about(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
}
|
||||
let own = g["other_groups"].as_array().into_iter().flatten().filter_map(Value::as_str).collect::<Vec<_>>();
|
||||
if !own.is_empty() {
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Its own code");
|
||||
ui.label(RichText::new(own.join(", ")).color(t.text_dim).size(theme::SMALL));
|
||||
}
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let scenes = g["scenes"].as_u64().unwrap_or(0);
|
||||
let mut facts =
|
||||
vec![format!("{} · {} {}", crate::human_bytes(g["bytes"].as_u64().unwrap_or(0) as usize), g["files"].as_u64().unwrap_or(0), tr("files"))];
|
||||
@@ -120,7 +120,7 @@ fn about(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
}
|
||||
ui.label(RichText::new(facts.join(" · ")).color(t.text_faint).size(theme::CAPTION));
|
||||
});
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if ask {
|
||||
app.open_path(folder);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ fn archives(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
return;
|
||||
}
|
||||
widgets::caption(ui, "Archives");
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let mut open = None;
|
||||
for a in &g.archives {
|
||||
let (path, kind) = (a["path"].as_str().unwrap_or_default(), a["kind"].as_str().unwrap_or_default());
|
||||
@@ -157,7 +157,7 @@ fn archives(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
};
|
||||
ui.painter().rect_filled(rect, t.radius, fill);
|
||||
let icon_rect = egui::Rect::from_center_size(egui::pos2(rect.left() + 24.0, rect.center().y), Vec2::splat(20.0));
|
||||
icons::paint(ui, icon_rect, icon, 18.0, if selected { t.accent_ink } else { t.text_dim });
|
||||
icons::paint(ui, icon_rect, icon, theme::icon::LG, if selected { t.accent_ink } else { t.text_dim });
|
||||
let name = a["name"].as_str().unwrap_or(path);
|
||||
ui.painter().text(egui::pos2(rect.left() + 46.0, rect.center().y), egui::Align2::LEFT_CENTER, name, theme::medium(theme::SMALL), t.text);
|
||||
let detail = format!("{} · {}", tr(label), crate::human_bytes(a["size"].as_u64().unwrap_or(0) as usize));
|
||||
@@ -171,7 +171,7 @@ fn archives(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
if widgets::named(resp, name).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
|
||||
open = Some((path.to_string(), kind.to_string()));
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
if let Some((path, kind)) = open {
|
||||
open_archive(app, path, kind);
|
||||
@@ -200,17 +200,17 @@ fn contents(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let g = &app.state.game;
|
||||
let Some(open) = g.open.clone() else { return };
|
||||
let (_, _, saves) = kind_label(&g.open_kind);
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
let name = std::path::Path::new(&open).file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
ui.label(theme::heading(format!("{} {name}", tr("Inside")), theme::SECTION));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if g.loading {
|
||||
widgets::working(ui, "Reading what's inside…", None);
|
||||
return;
|
||||
}
|
||||
if g.open_kind == "unreal_iostore" {
|
||||
ui.label(RichText::new(tr("Pictures can't be saved from IoStore containers yet; you can see what's inside.")).color(t.text_faint).size(theme::CAPTION));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
let r = ui.add(
|
||||
egui::TextEdit::singleline(&mut app.state.game.filter)
|
||||
@@ -219,7 +219,7 @@ fn contents(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.frame(widgets::text_field_frame_compact(&t)),
|
||||
);
|
||||
widgets::named(r, "Filter the files");
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let needle = app.state.game.filter.trim().to_lowercase();
|
||||
let rows: Vec<Value> =
|
||||
app.state.game.rows.iter().filter(|r| needle.is_empty() || row_name(r).to_lowercase().contains(&needle)).take(SHOWN).cloned().collect();
|
||||
@@ -238,7 +238,7 @@ fn contents(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(row_detail(r)).color(t.text_faint).size(theme::CAPTION));
|
||||
});
|
||||
});
|
||||
ui.add_space(2.0);
|
||||
ui.add_space(theme::space::XXS);
|
||||
}
|
||||
let total = app.state.game.rows.len();
|
||||
if total > rows.len() && needle.is_empty() {
|
||||
@@ -284,17 +284,17 @@ pub fn permission_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(52.0), Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, "shield-check", 26.0, t.accent_ink);
|
||||
ui.add_space(10.0);
|
||||
icons::paint(ui, rect, "shield-check", theme::icon::XL, t.accent_ink);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.label(theme::heading(tr("Do you have permission?"), theme::SECTION));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(
|
||||
RichText::new(tr(
|
||||
"Only take pictures out of games you made, or whose owner allows it. A game's art is usually protected by copyright and by the game's licence.",
|
||||
))
|
||||
.color(t.text_dim),
|
||||
);
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::primary_icon(ui, Some("shield-check"), "I have permission", true).clicked() {
|
||||
app.state.game.permitted.clone_from(&app.state.game.folder);
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::state::{Modal, Screen};
|
||||
use crate::theme::{self, Tokens};
|
||||
use crate::{CraftApp, Pick, Route, icons, widgets};
|
||||
use craft_anything_engine::Consent;
|
||||
use egui::{Margin, RichText, Ui, Vec2};
|
||||
use egui::{RichText, Ui, Vec2};
|
||||
use serde_json::json;
|
||||
|
||||
/// Tools that open a website, best first.
|
||||
@@ -54,13 +54,13 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let w = full_w.min(1000.0) - 48.0;
|
||||
let pad = ((full_w - w) / 2.0).max(24.0);
|
||||
// Tight enough that Start is in view at 900 px with every choice showing (tested).
|
||||
ui.add_space(24.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(pad);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(w);
|
||||
crate::make::hero(app, ui, w);
|
||||
ui.add_space(36.0);
|
||||
ui.add_space(theme::space::XXL);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -76,26 +76,26 @@ pub fn modals(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
let t = Tokens::get(ctx);
|
||||
let mut close = false;
|
||||
let resp = egui::Modal::new(egui::Id::new("craft-modal"))
|
||||
.frame(egui::Frame::new().fill(t.card).corner_radius(t.r_lg()).inner_margin(Margin::same(24)).stroke(egui::Stroke::new(1.0, t.card_border)))
|
||||
.frame(egui::Frame::new().fill(t.card).corner_radius(t.r_lg()).inner_margin(theme::pad::ROOMY).stroke(egui::Stroke::new(1.0, t.card_border)))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(440.0);
|
||||
match &modal {
|
||||
Modal::ComingSoon { title, body, icon } => {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(52.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, icon, 26.0, t.accent_ink);
|
||||
ui.add_space(10.0);
|
||||
icons::paint(ui, rect, icon, theme::icon::XL, t.accent_ink);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.label(theme::heading(tr(title), theme::SECTION));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr(body)).color(t.text_dim));
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if widgets::primary(ui, "Got it").clicked() {
|
||||
close = true;
|
||||
}
|
||||
}
|
||||
Modal::Website => {
|
||||
ui.label(theme::heading(tr("Look at a website"), theme::SECTION));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let r = ui.add(
|
||||
egui::TextEdit::singleline(&mut app.state.url_input)
|
||||
.hint_text("https://example.com")
|
||||
@@ -110,7 +110,7 @@ pub fn modals(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
ui.data_mut(|d| d.insert_temp(opened, true));
|
||||
}
|
||||
let enter = r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
let ok = !app.state.url_input.trim().is_empty();
|
||||
if (widgets::primary_icon(ui, Some("globe"), "Open it", ok).clicked() || enter)
|
||||
@@ -137,7 +137,7 @@ pub fn modals(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
if let Some((_, title, blurb, steps)) = TUTORIALS.get(*i) {
|
||||
ui.label(theme::heading(tr(title), theme::SECTION));
|
||||
ui.label(RichText::new(tr(blurb)).color(t.text_dim));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
for (n, s) in steps.iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(24.0), egui::Sense::hover());
|
||||
@@ -151,9 +151,9 @@ pub fn modals(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
);
|
||||
ui.add(egui::Label::new(tr(s)).wrap());
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::primary_icon(ui, Some("folder-open"), "Open something", true).clicked() {
|
||||
app.pick(Pick::OpenFile);
|
||||
@@ -180,7 +180,7 @@ pub fn modals(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
Modal::About => {
|
||||
ui.label(theme::heading("Craft Anything", theme::SECTION));
|
||||
ui.label(RichText::new(format!("{} {}", tr("Version"), env!("CARGO_PKG_VERSION"))).color(t.text_dim));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
if widgets::primary(ui, "Close").clicked() {
|
||||
close = true;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,14 @@ pub fn show(ui: &mut egui::Ui, name: &str, size: f32, tint: Color32) -> Response
|
||||
resp
|
||||
}
|
||||
|
||||
/// Square icon button: transparent until hovered; `selected` gets the accent treatment.
|
||||
pub fn button(ui: &mut egui::Ui, name: &str, box_size: f32, selected: bool, tooltip: &str) -> Response {
|
||||
/// Square icon button at a control size: transparent until hovered; `selected` gets the accent
|
||||
/// treatment.
|
||||
pub fn button(ui: &mut egui::Ui, name: &str, size: crate::theme::ControlSize, selected: bool, tooltip: &str) -> Response {
|
||||
button_box(ui, name, size.height(), selected, tooltip)
|
||||
}
|
||||
|
||||
/// [`button`] in a box of any size, for the title bar, whose sizes follow the window's chrome.
|
||||
pub fn button_box(ui: &mut egui::Ui, name: &str, box_size: f32, selected: bool, tooltip: &str) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::splat(box_size), Sense::click());
|
||||
if selected {
|
||||
|
||||
@@ -146,9 +146,9 @@ pub fn card(ui: &mut Ui, a: &mut Asked, glossary: bool) {
|
||||
let mut toggle = false;
|
||||
ui.horizontal(|ui| {
|
||||
let name = if a.collapsed { "Show the answer" } else { "Hide the answer" };
|
||||
toggle |= icons::button(ui, if a.collapsed { "chevron-right" } else { "chevron-down" }, 22.0, false, name).clicked();
|
||||
toggle |= icons::button(ui, if a.collapsed { "chevron-right" } else { "chevron-down" }, theme::ControlSize::Small, false, name).clicked();
|
||||
let (icon, _) = ui.allocate_exact_size(egui::vec2(16.0, 16.0), egui::Sense::hover());
|
||||
icons::paint(ui, icon, "circle-help", 16.0, t.icon);
|
||||
icons::paint(ui, icon, "circle-help", theme::icon::MD, t.icon);
|
||||
let line = egui::Label::new(RichText::new(&a.question).font(theme::semibold(theme::BODY))).sense(egui::Sense::click()).selectable(false);
|
||||
let line = if a.collapsed { line.truncate() } else { line.wrap() };
|
||||
toggle |= ui.add(line).on_hover_cursor(egui::CursorIcon::PointingHand).clicked();
|
||||
@@ -159,12 +159,12 @@ pub fn card(ui: &mut Ui, a: &mut Asked, glossary: bool) {
|
||||
if a.collapsed {
|
||||
return;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
match &a.answer {
|
||||
None => widgets::thinking(ui),
|
||||
Some(Ok(ans)) => {
|
||||
chat::rich_text(ui, &ans.text, glossary);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let from = if ans.from_session { tr("from the builder's own memory of the build") } else { tr("from the project's files") };
|
||||
let cost = ans.cost_usd.map(|c| format!(" · ${c:.2}")).unwrap_or_default();
|
||||
ui.label(
|
||||
|
||||
@@ -695,7 +695,10 @@ impl CraftApp {
|
||||
theme::install_fonts(ctx);
|
||||
egui_extras::install_image_loaders(ctx);
|
||||
// The zoom keys are ours (`shortcuts`), so zoom stays inside ZOOM_RANGE.
|
||||
ctx.options_mut(|o| o.zoom_with_keyboard = false);
|
||||
ctx.options_mut(|o| {
|
||||
o.zoom_with_keyboard = false;
|
||||
o.input_options.line_scroll_speed = theme::WHEEL_STEP;
|
||||
});
|
||||
}
|
||||
|
||||
/// Gives the macOS app its menu bar (nothing elsewhere). Call once the window is open.
|
||||
@@ -806,6 +809,16 @@ impl CraftApp {
|
||||
self.toast_at.remove(i);
|
||||
}
|
||||
}
|
||||
// A confirmation takes the place of the one before it: two in a row (a switch flipped
|
||||
// and flipped back) would only pile up over the screen.
|
||||
if !error {
|
||||
while let Some(i) = self.state.toasts.iter().position(|(_, e)| !e) {
|
||||
self.state.toasts.remove(i);
|
||||
if i < self.toast_at.len() {
|
||||
self.toast_at.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.state.toasts.push((text, error));
|
||||
self.toast_at.push(Instant::now());
|
||||
// The oldest confirmations go first when there are too many; errors are kept longest.
|
||||
@@ -1110,9 +1123,9 @@ impl CraftApp {
|
||||
ProblemKind::Broken => "Part of the app got stuck, so it was stopped and the rest carried on. Your work is kept.",
|
||||
_ => "Part of the app is stuck. Restarting clears it, and your work is kept.",
|
||||
};
|
||||
egui::Panel::top("stuck-banner").frame(egui::Frame::new().fill(t.card).inner_margin(egui::Margin::symmetric(14, 8))).show(ui, |ui| {
|
||||
egui::Panel::top("stuck-banner").frame(egui::Frame::new().fill(t.card).inner_margin(theme::pad::BAR)).show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.danger);
|
||||
icons::show(ui, "triangle-alert", crate::theme::icon::MD, t.danger);
|
||||
ui.label(egui::RichText::new(i18n::tr(text)).color(t.text)).on_hover_text(problem.summary.clone());
|
||||
if let Some(path) = &problem.log
|
||||
&& widgets::secondary(ui, None, "Open log").on_hover_text(path.display().to_string()).clicked()
|
||||
@@ -1962,7 +1975,7 @@ impl CraftApp {
|
||||
egui::Panel::left("app-sidebar")
|
||||
.exact_size(sidebar::width(self, &ctx))
|
||||
.resizable(false)
|
||||
.frame(egui::Frame::new().fill(t.chrome).inner_margin(egui::Margin::symmetric(8, 0)))
|
||||
.frame(egui::Frame::new().fill(t.chrome).inner_margin(theme::pad::GUTTER))
|
||||
.show(ui, |ui| guard_ui(ui, "sidebar", |ui| sidebar::show(self, ui)));
|
||||
egui::CentralPanel::default().frame(egui::Frame::new().fill(t.canvas)).show(ui, |ui| {
|
||||
guard_ui(ui, "simple", |ui| match self.state.screen {
|
||||
@@ -1979,6 +1992,7 @@ impl CraftApp {
|
||||
settings_ui::show(self, &ctx);
|
||||
home::modals(self, &ctx);
|
||||
self.toasts(&ctx);
|
||||
widgets::text_focus_ring(&ctx);
|
||||
self.drop_overlay(&ctx);
|
||||
titlebar::window_edge(&ctx);
|
||||
titlebar::resize_edges(&ctx);
|
||||
@@ -2007,33 +2021,62 @@ impl CraftApp {
|
||||
return;
|
||||
}
|
||||
let t = theme::Tokens::get(ctx);
|
||||
let width = (ctx.content_rect().width() - 32.0).clamp(200.0, 640.0);
|
||||
// Under the title bar, in the middle. Anywhere a message sits it is over something (at
|
||||
// the bottom, the prompt box's switches just pressed; in a corner, a side panel; here, a
|
||||
// screen's tabs), so the card lets clicks through to what is under it. Only its close
|
||||
// button, drawn in a layer of its own, takes a click.
|
||||
let width = (ctx.content_rect().width() - 2.0 * theme::space::LG).clamp(200.0, 420.0);
|
||||
let mut dismiss = None;
|
||||
egui::Area::new(egui::Id::new("toasts")).order(egui::Order::Foreground).anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -16.0)).show(ctx, |ui| {
|
||||
ui.set_width(width);
|
||||
for (i, (text, error)) in self.state.toasts.iter().enumerate() {
|
||||
egui::Frame::new()
|
||||
.fill(t.raised)
|
||||
.stroke(egui::Stroke::new(1.0, if *error { t.danger.gamma_multiply(0.6) } else { t.card_border }))
|
||||
.corner_radius(t.r_lg())
|
||||
.shadow(egui::Shadow { offset: [0, 4], blur: 16, spread: 0, color: t.shadow })
|
||||
.inner_margin(egui::Margin::symmetric(14, 8))
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(width - 28.0);
|
||||
ui.horizontal(|ui| {
|
||||
let (icon, col) = if *error { ("triangle-alert", t.danger) } else { ("check", t.success) };
|
||||
icons::show(ui, icon, 15.0, col);
|
||||
ui.add(egui::Label::new(egui::RichText::new(text).color(if *error { t.text } else { t.text_dim })).wrap());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "x", 28.0, false, "Dismiss").clicked() {
|
||||
dismiss = Some(i);
|
||||
}
|
||||
// Where each card keeps room for its close button.
|
||||
let mut close_at = Vec::with_capacity(self.state.toasts.len());
|
||||
egui::Area::new(egui::Id::new("toasts"))
|
||||
.order(egui::Order::Foreground)
|
||||
.anchor(egui::Align2::CENTER_TOP, egui::vec2(0.0, titlebar::HEIGHT + theme::space::SM))
|
||||
.interactable(false)
|
||||
.fade_in(true)
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(width);
|
||||
ui.spacing_mut().item_spacing = egui::vec2(theme::space::SM, theme::space::XS);
|
||||
// The mark and the close button are boxes of one size, and the words between
|
||||
// them sit on that box's middle line: the same room on every side, however many
|
||||
// lines the message takes.
|
||||
let side = theme::ControlSize::Small.height();
|
||||
let line = theme::leading(theme::SMALL);
|
||||
let nudge = ((side - line) / 2.0).max(0.0);
|
||||
let inner = width - 2.0 * theme::space::MD - 2.0;
|
||||
for (i, (text, error)) in self.state.toasts.iter().enumerate() {
|
||||
egui::Frame::new()
|
||||
.fill(t.field)
|
||||
.stroke(egui::Stroke::new(1.0, t.card_border))
|
||||
.corner_radius(t.r_lg())
|
||||
.shadow(egui::Shadow { offset: [0, 8], blur: 24, spread: 0, color: t.shadow })
|
||||
.inner_margin(theme::pad::PANEL)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(inner);
|
||||
ui.horizontal_top(|ui| {
|
||||
let (icon, col) = if *error { ("triangle-alert", t.danger) } else { ("check", t.success) };
|
||||
let (mark, _) = ui.allocate_exact_size(egui::Vec2::splat(side), egui::Sense::hover());
|
||||
icons::paint(ui, mark, icon, theme::icon::MD, col);
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
ui.set_width(inner - 2.0 * (side + theme::space::SM));
|
||||
ui.add_space(nudge);
|
||||
ui.add(egui::Label::new(egui::RichText::new(text).size(theme::SMALL).line_height(Some(line)).color(t.text)).wrap());
|
||||
ui.add_space(nudge);
|
||||
});
|
||||
let (slot, _) = ui.allocate_exact_size(egui::Vec2::splat(side), egui::Sense::hover());
|
||||
close_at.push((i, slot));
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
for (i, slot) in close_at {
|
||||
egui::Area::new(egui::Id::new(("toast-close", i))).order(egui::Order::Tooltip).fixed_pos(slot.min).show(ctx, |ui| {
|
||||
if icons::button(ui, "x", theme::ControlSize::Small, false, "Dismiss").clicked() {
|
||||
dismiss = Some(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(i) = dismiss {
|
||||
self.state.toasts.remove(i);
|
||||
if i < self.toast_at.len() {
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::state::MakeDraft;
|
||||
use crate::theme::{self, Tokens};
|
||||
use crate::{CraftApp, Pick, icons, widgets};
|
||||
use craft_anything_engine::workspace::{ExistingFiles, Status, TargetRef};
|
||||
use egui::{Margin, RichText, Sense, Ui, Vec2};
|
||||
use egui::{RichText, Sense, Ui, Vec2};
|
||||
|
||||
const SUGGESTIONS_WEB: &[&str] = &["Recreate this website", "Recreate it with darker colours"];
|
||||
const SUGGESTIONS_APP: &[&str] = &["Make my own version of this app", "Recreate just its main feature"];
|
||||
@@ -82,7 +82,7 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let d = &mut app.state.make;
|
||||
let door = if d.look { 2 } else { usize::from(d.mine) };
|
||||
if let Some(i) = widgets::segmented_sized(ui, &["Make my own version", "Work on my project", "Just look inside"], door, 38.0, 12.5) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Make my own version", "Work on my project", "Just look inside"], door, theme::ControlSize::Large) {
|
||||
let left = d.mine && i != 1;
|
||||
(d.mine, d.look) = (i == 1, i == 2);
|
||||
if d.mine {
|
||||
@@ -95,7 +95,7 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
(d.folder, d.folder_files, d.existing) = (None, None, None);
|
||||
}
|
||||
}
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
if app.state.make.look {
|
||||
look(app, ui, w);
|
||||
return;
|
||||
@@ -105,23 +105,23 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
return;
|
||||
}
|
||||
ui.label(theme::heading(tr("What do you want to make?"), theme::TITLE));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(tr("Choose what to recreate, say what you want, then press Start.")).size(theme::LEAD).color(t.text_dim));
|
||||
ui.add_space(16.0);
|
||||
widgets::card(&t).inner_margin(Margin::same(20)).show(ui, |ui| {
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::card(&t).inner_margin(theme::pad::ROOMY).show(ui, |ui| {
|
||||
ui.set_width(w - 50.0);
|
||||
step_title(ui, 1, "What do you want to recreate?");
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
choose_target(app, ui);
|
||||
// How closely the original may be looked at, once there is one.
|
||||
let d = &app.state.make;
|
||||
if matches!(d.target, TargetRef::Local { .. }) || d.editing_url || !d.url.is_empty() {
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
look_inside(app, ui);
|
||||
}
|
||||
ui.add_space(20.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
step_title(ui, 2, "Say what you want");
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
// The example matches the tile picked above (a "recreate this website" hint under
|
||||
// "Nothing — start fresh" contradicts the choice).
|
||||
let d = &app.state.make;
|
||||
@@ -136,16 +136,17 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
let website = matches!(resolve_target(d), TargetRef::Website { .. }) || d.editing_url;
|
||||
let submit = request_box(app, ui, hint, (!website).then_some("Add pictures of the original (optional: screenshots help it look right)"));
|
||||
if app.state.make.request.trim().is_empty() {
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
suggestions(app, ui);
|
||||
}
|
||||
engine_choices(app, ui);
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
crate::builders::built_by(app, ui);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let ready = !app.state.make.request.trim().is_empty() && url_problem(&app.state.make.url).is_none() && app.creating.is_none();
|
||||
let start = widgets::primary_sized(ui, Some("sparkles"), "Start", ready, 50.0, 14.0);
|
||||
let start =
|
||||
ui.add(widgets::Button::new(widgets::ButtonKind::Primary, "Start").icon(Some("sparkles")).size(theme::ControlSize::Hero).enabled(ready));
|
||||
let start = if ready { start } else { start.on_disabled_hover_text(tr("Say what you want first.")) };
|
||||
if (start.clicked() || submit) && ready {
|
||||
app.start_make();
|
||||
@@ -153,7 +154,7 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
});
|
||||
});
|
||||
// Where it's saved: secondary to Start, so under it.
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
crate::folders::make_line(app, ui);
|
||||
});
|
||||
}
|
||||
@@ -163,13 +164,13 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
fn mine(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::heading(tr("Work on a project you already have"), theme::TITLE));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(tr("Pick its folder, say what you want, then press Start.")).size(theme::LEAD).color(t.text_dim));
|
||||
ui.add_space(16.0);
|
||||
widgets::card(&t).inner_margin(Margin::same(20)).show(ui, |ui| {
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::card(&t).inner_margin(theme::pad::ROOMY).show(ui, |ui| {
|
||||
ui.set_width(w - 50.0);
|
||||
step_title(ui, 1, "Where is your project?");
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
// A folder picked on Make for another use isn't this project's.
|
||||
let d = &app.state.make;
|
||||
let folder = d.folder.clone().filter(|_| d.existing == Some(ExistingFiles::Edit));
|
||||
@@ -183,11 +184,11 @@ fn mine(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
Some(f) => {
|
||||
let place = f.display().to_string();
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "folder", 16.0, t.icon);
|
||||
icons::show(ui, "folder", theme::icon::MD, t.icon);
|
||||
ui.add(egui::Label::new(RichText::new(&place).font(theme::semibold(theme::BODY))).truncate()).on_hover_text(&place);
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.add_space(24.0);
|
||||
ui.add_space(theme::space::XL);
|
||||
ui.label(RichText::new(tr("your files there are the app, edited in place")).size(theme::SMALL).color(t.text_dim));
|
||||
ui.label(RichText::new("·").size(theme::SMALL).color(t.text_faint));
|
||||
if widgets::link(ui, "Pick another folder…").clicked() {
|
||||
@@ -196,18 +197,19 @@ fn mine(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
});
|
||||
}
|
||||
}
|
||||
ui.add_space(20.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
step_title(ui, 2, "Say what you want");
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let submit = request_box(app, ui, "For example: add a dark mode", Some("Attach pictures (or drop or paste them here)"));
|
||||
engine_choices(app, ui);
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
crate::builders::built_by(app, ui);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let said = !app.state.make.request.trim().is_empty();
|
||||
let ready = folder.is_some() && said && app.creating.is_none();
|
||||
let start = widgets::primary_sized(ui, Some("sparkles"), "Start", ready, 50.0, 14.0);
|
||||
let start =
|
||||
ui.add(widgets::Button::new(widgets::ButtonKind::Primary, "Start").icon(Some("sparkles")).size(theme::ControlSize::Hero).enabled(ready));
|
||||
let start = if ready {
|
||||
start
|
||||
} else {
|
||||
@@ -258,9 +260,9 @@ fn request_box(app: &mut CraftApp, ui: &mut Ui, hint: &str, attach: Option<&str>
|
||||
/// For a game: the engine it's built with, and whether the builder may generate its assets.
|
||||
fn engine_choices(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if is_game(&app.kinds, &app.state.make) {
|
||||
ui.add_space(22.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
crate::engine_ui::build_with(app, ui);
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
let on = app.state.make.generate_assets;
|
||||
crate::engine_ui::assets_toggle(app, ui, on);
|
||||
}
|
||||
@@ -270,10 +272,10 @@ fn engine_choices(app: &mut CraftApp, ui: &mut Ui) {
|
||||
fn look(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::heading(tr("What do you want to look inside?"), theme::TITLE));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(tr("We only read it; nothing runs. Every answer shows how sure we are.")).size(theme::LEAD).color(t.text_dim));
|
||||
ui.add_space(22.0);
|
||||
widgets::card(&t).inner_margin(Margin::same(24)).show(ui, |ui| {
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::card(&t).inner_margin(theme::pad::ROOMY).show(ui, |ui| {
|
||||
ui.set_width(w - 50.0);
|
||||
// Each of these reads the original, which Clean room never does.
|
||||
if !app.settings.deep_mode {
|
||||
@@ -281,7 +283,7 @@ fn look(app: &mut CraftApp, ui: &mut Ui, w: f32) {
|
||||
return;
|
||||
}
|
||||
let size = Vec2::new(ui.available_width(), 72.0);
|
||||
ui.spacing_mut().item_spacing.y = 10.0;
|
||||
ui.spacing_mut().item_spacing.y = theme::space::SM;
|
||||
if widgets::choice_tile(ui, size, "app-window", "An app or a file", "See how a program works: what it does, what it talks to, what's inside.", false)
|
||||
.clicked()
|
||||
{
|
||||
@@ -304,9 +306,9 @@ fn step_title(ui: &mut Ui, n: u32, text: &str) {
|
||||
ui.horizontal(|ui| {
|
||||
let (r, _) = ui.allocate_exact_size(Vec2::splat(28.0), Sense::hover());
|
||||
ui.painter().rect(r, r.width() / 2.0, t.raised, egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
|
||||
let g = widgets::label_galley(ui, &n.to_string(), 13.0, t.text);
|
||||
let g = widgets::label_galley(ui, &n.to_string(), theme::SMALL, t.text);
|
||||
ui.painter().galley_with_override_text_color(r.center() - g.size() / 2.0, g, t.text);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(theme::heading(tr(text), theme::SECTION));
|
||||
});
|
||||
}
|
||||
@@ -317,7 +319,7 @@ fn choose_target(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let local = matches!(d.target, TargetRef::Local { .. }).then_some(d.game);
|
||||
let website = local.is_none() && (d.editing_url || !d.url.is_empty());
|
||||
let scratch = local.is_none() && !website;
|
||||
let gap = 10.0;
|
||||
let gap = theme::space::MD;
|
||||
let cols = if ui.available_width() > 760.0 { 4 } else { 2 };
|
||||
let tile_w = ((ui.available_width() - gap * (cols as f32 - 1.0)) / cols as f32).floor();
|
||||
let size = Vec2::new(tile_w, 60.0);
|
||||
@@ -362,7 +364,7 @@ fn choose_target(app: &mut CraftApp, ui: &mut Ui) {
|
||||
// Recomputed so the address field shows on the very frame "A website" is clicked.
|
||||
let website = !matches!(m.target, TargetRef::Local { .. }) && (m.editing_url || !m.url.is_empty());
|
||||
if let TargetRef::Local { path } = m.target.clone() {
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(tr("You chose:")).size(theme::BODY).color(t.text_dim));
|
||||
// A long name (an APK from a mirror) is cut short, whole on hover, so the row never widens the page.
|
||||
@@ -371,24 +373,24 @@ fn choose_target(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.add(egui::Label::new(RichText::new(crate::short_path(&path)).color(t.text_faint).size(theme::SMALL)).truncate());
|
||||
});
|
||||
} else if website {
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.label(RichText::new(tr("Type the website's address:")).size(theme::BODY).color(t.text_dim));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let r = ui.add(
|
||||
egui::TextEdit::singleline(&mut m.url)
|
||||
.hint_text("example.com")
|
||||
.desired_width(520.0)
|
||||
.font(egui::FontId::proportional(theme::LEAD))
|
||||
.frame(widgets::text_field_frame(&t).inner_margin(Margin::symmetric(14, 12))),
|
||||
.frame(widgets::text_field_frame(&t).inner_margin(theme::pad::ROW)),
|
||||
);
|
||||
if pick == Some(0) {
|
||||
r.request_focus();
|
||||
}
|
||||
// Say what's wrong right under the field, once something has been typed.
|
||||
if let Some(problem) = url_problem(&m.url) {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.danger);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.danger);
|
||||
ui.label(RichText::new(tr(problem)).color(t.danger).size(theme::BODY));
|
||||
});
|
||||
}
|
||||
@@ -403,9 +405,9 @@ fn look_inside(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(tr("How closely may Craft Anything look at it?")).size(theme::BODY).color(t.text_dim));
|
||||
ui.label(RichText::new(tr("For everything you make, like the switch in the title bar.")).size(theme::SMALL).color(t.text_faint));
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let deep = app.settings.deep_mode;
|
||||
let gap = 10.0;
|
||||
let gap = theme::space::MD;
|
||||
let size = Vec2::new(((ui.available_width() - gap) / 2.0).floor(), 72.0);
|
||||
let mut pick = None;
|
||||
ui.horizontal(|ui| {
|
||||
@@ -427,9 +429,9 @@ fn look_inside(app: &mut CraftApp, ui: &mut Ui) {
|
||||
return;
|
||||
}
|
||||
if app.settings.deep_mode && !app.ghidra_missing() {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "cpu", 16.0, t.icon);
|
||||
icons::show(ui, "cpu", theme::icon::MD, t.icon);
|
||||
let line = format!("{} {}", crate::engine_ui::ghidra_memory_words(app), tr("More makes a big program's first look faster."));
|
||||
ui.label(RichText::new(line).size(theme::SMALL).color(t.text_dim)).on_hover_text(crate::engine_ui::ghidra_memory_guide());
|
||||
if widgets::link(ui, "Change").clicked() {
|
||||
@@ -439,9 +441,9 @@ fn look_inside(app: &mut CraftApp, ui: &mut Ui) {
|
||||
});
|
||||
}
|
||||
if app.settings.deep_mode && app.ghidra_missing() {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.warning);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.warning);
|
||||
ui.label(RichText::new(tr("Ghidra isn't on this computer yet, so the built-in decompiler stands in.")).size(theme::SMALL).color(t.text_dim));
|
||||
if app.ghidra.job.is_none() && widgets::secondary(ui, Some("download"), "Get Ghidra").clicked() {
|
||||
app.state.modal = Some(crate::state::Modal::Ghidra);
|
||||
@@ -459,7 +461,7 @@ fn suggestions(app: &mut CraftApp, ui: &mut Ui) {
|
||||
TargetRef::None => SUGGESTIONS_NONE,
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = Vec2::new(8.0, 8.0);
|
||||
ui.spacing_mut().item_spacing = Vec2::splat(theme::space::SM);
|
||||
ui.label(RichText::new(tr("Ideas:")).size(theme::BODY).color(t.text_dim));
|
||||
for s in list.iter().take(2) {
|
||||
if widgets::suggestion(ui, s).clicked() {
|
||||
|
||||
@@ -66,30 +66,39 @@ impl CraftApp {
|
||||
|
||||
/// The right-click menu on a project in the sidebar.
|
||||
pub fn menu(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
if ui.button(tr("Rename…")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Rename…")).clicked() {
|
||||
ask_rename(app, ws);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr("Duplicate")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Duplicate")).clicked() {
|
||||
app.duplicate_project(&ws.root);
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_enabled(!app.runs.is_busy(&ws.root), egui::Button::new(tr("Delete…"))).on_disabled_hover_text(tr("Pause the build first.")).clicked() {
|
||||
if ui
|
||||
.add_enabled_ui(!app.runs.is_busy(&ws.root), |ui| widgets::menu_item(ui, false, tr("Delete…")))
|
||||
.inner
|
||||
.on_disabled_hover_text(tr("Pause the build first."))
|
||||
.clicked()
|
||||
{
|
||||
app.state.modal = Some(Modal::Delete(ws.root.clone()));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// The same, as quiet links on the project's page.
|
||||
pub fn buttons(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
if widgets::secondary(ui, None, "Rename").clicked() {
|
||||
pub fn rows(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
if widgets::action_row(ui, "file", "Rename", false).clicked() {
|
||||
ask_rename(app, ws);
|
||||
}
|
||||
if widgets::secondary(ui, Some("copy"), "Duplicate").on_hover_text(tr("A copy to try something else from here.")).clicked() {
|
||||
if widgets::action_row(ui, "copy", "Duplicate", false).on_hover_text(tr("A copy to try something else from here.")).clicked() {
|
||||
app.duplicate_project(&ws.root);
|
||||
}
|
||||
if !app.runs.is_busy(&ws.root) && icons::button(ui, "trash-2", 30.0, false, "Delete the project").clicked() {
|
||||
}
|
||||
|
||||
/// The row that deletes the project: last in its list, and not there while it builds.
|
||||
pub fn delete_row(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
if !app.runs.is_busy(&ws.root) && widgets::action_row(ui, "trash-2", "Delete the project", true).clicked() {
|
||||
app.state.modal = Some(Modal::Delete(ws.root.clone()));
|
||||
}
|
||||
}
|
||||
@@ -106,7 +115,7 @@ fn project<'a>(app: &'a CraftApp, root: &Path) -> Option<&'a Workspace> {
|
||||
pub fn rename_modal(app: &mut CraftApp, ui: &mut Ui, root: &Path, close: &mut bool) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::heading(tr("Rename the project"), theme::SECTION));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut app.state.rename_input).desired_width(f32::INFINITY).frame(widgets::text_field_frame(&t)));
|
||||
widgets::named(r.clone(), "Project name");
|
||||
if !r.has_focus() && !r.lost_focus() {
|
||||
@@ -114,8 +123,16 @@ pub fn rename_modal(app: &mut CraftApp, ui: &mut Ui, root: &Path, close: &mut bo
|
||||
}
|
||||
let ok = !app.state.rename_input.trim().is_empty();
|
||||
let enter = r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
ui.add(egui::Label::new(RichText::new(tr("Only its name changes; its folder stays where it is.")).color(t.text_faint).size(theme::SMALL)).wrap());
|
||||
ui.add_space(12.0);
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(tr("Only its name changes; its folder stays where it is."))
|
||||
.color(t.text_faint)
|
||||
.size(theme::SMALL)
|
||||
.line_height(Some(theme::leading(theme::SMALL))),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if (widgets::primary_icon(ui, None, "Rename", ok).clicked() || enter) && ok {
|
||||
let name = app.state.rename_input.trim().to_string();
|
||||
@@ -137,10 +154,10 @@ pub fn delete_modal(app: &mut CraftApp, ui: &mut Ui, root: &Path, close: &mut bo
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(40.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.raised);
|
||||
icons::paint(ui, rect, "trash-2", 20.0, t.danger);
|
||||
icons::paint(ui, rect, "trash-2", theme::icon::LG, t.danger);
|
||||
ui.label(theme::heading(trf("Delete {name}?", &[("name", &ws.manifest.name)]), theme::SECTION));
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
// What goes and what stays, in so many words: it can't be undone.
|
||||
let m = &ws.manifest;
|
||||
let what = if m.app_in_root || !m.start_files.is_empty() {
|
||||
@@ -149,12 +166,12 @@ pub fn delete_modal(app: &mut CraftApp, ui: &mut Ui, root: &Path, close: &mut bo
|
||||
tr("Its folder is deleted with everything in it: what was built, the checks and the conversation.")
|
||||
};
|
||||
ui.add(egui::Label::new(RichText::new(what).color(t.text_dim)).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(crate::short_path(&ws.root)).font(theme::mono(12.0)).color(t.text_faint)).truncate());
|
||||
ui.add_space(4.0);
|
||||
ui.add(egui::Label::new(RichText::new(crate::short_path(&ws.root)).font(theme::mono(theme::CODE)).color(t.text_faint)).truncate());
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr("This can't be undone.")).color(t.danger).size(theme::SMALL));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::secondary(ui, Some("trash-2"), "Delete it").clicked() {
|
||||
if widgets::danger(ui, Some("trash-2"), "Delete it").clicked() {
|
||||
app.delete_project(root);
|
||||
*close = true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::state::Screen;
|
||||
use crate::theme::{self, Tokens};
|
||||
use crate::{CraftApp, Pick, Route, icons, schema_form, widgets};
|
||||
use craft_anything_engine::{Consent, Mode};
|
||||
use egui::{Margin, RichText, Vec2};
|
||||
use egui::{RichText, Vec2};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum AppCommand {
|
||||
@@ -116,11 +116,11 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
.stroke(egui::Stroke::new(1.0, t.card_border))
|
||||
.corner_radius(t.r_lg())
|
||||
.shadow(ui.visuals().window_shadow)
|
||||
.inner_margin(Margin::same(10))
|
||||
.inner_margin(theme::pad::PANEL)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(width);
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "search", 18.0, t.text_faint);
|
||||
icons::show(ui, "search", theme::icon::LG, t.text_faint);
|
||||
let r = ui.add(
|
||||
egui::TextEdit::singleline(&mut app.state.palette.query)
|
||||
.hint_text(tr("Type a command or tool…"))
|
||||
@@ -128,13 +128,14 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
.desired_width(f32::INFINITY)
|
||||
.font(egui::FontId::proportional(theme::BODY)),
|
||||
);
|
||||
widgets::frameless_field(&r);
|
||||
r.request_focus();
|
||||
if r.changed() {
|
||||
app.state.palette.selected = 0;
|
||||
follow = true;
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical().max_height(420.0).show(ui, |ui| {
|
||||
if ranked.is_empty() {
|
||||
@@ -174,7 +175,7 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr("↑↓ to move · Enter to run · Esc to close")).color(t.text_faint).size(theme::TINY));
|
||||
});
|
||||
});
|
||||
@@ -266,16 +267,16 @@ fn form(app: &mut CraftApp, ctx: &egui::Context, tool: &str) {
|
||||
ui.label(RichText::new(spec.id).font(theme::mono(theme::CAPTION)).color(t.text_faint));
|
||||
if spec.effects.needs_consent() {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "shield", 14.0, t.warning);
|
||||
icons::show(ui, "shield", theme::icon::SM, t.warning);
|
||||
ui.label(RichText::new(tr("This runs code from the target or changes a device. Clicking Run is your OK.")).color(t.warning));
|
||||
});
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
schema_form::show(ui, &fields, &mut app.state.palette.form);
|
||||
if let Some(e) = &app.state.palette.form_error {
|
||||
ui.colored_label(t.danger, e);
|
||||
}
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::primary_icon(ui, Some("play"), "Run", true).clicked() {
|
||||
run = true;
|
||||
|
||||
@@ -152,7 +152,7 @@ pub fn section(app: &mut CraftApp, ui: &mut Ui, fold: bool) {
|
||||
let collapsed = app.state.pins_collapsed;
|
||||
let arrow = |ui: &mut Ui| {
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::splat(18.0), egui::Sense::click());
|
||||
icons::paint(ui, rect, if collapsed { "chevron-right" } else { "chevron-down" }, 14.0, t.icon);
|
||||
icons::paint(ui, rect, if collapsed { "chevron-right" } else { "chevron-down" }, theme::icon::SM, t.icon);
|
||||
resp
|
||||
};
|
||||
// Folded, the arrow stays where the heading was, so nothing moves.
|
||||
@@ -160,7 +160,7 @@ pub fn section(app: &mut CraftApp, ui: &mut Ui, fold: bool) {
|
||||
crate::sidebar::centred_row(ui, 18.0, arrow)
|
||||
} else {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Pinned");
|
||||
arrow(ui)
|
||||
})
|
||||
@@ -171,7 +171,7 @@ pub fn section(app: &mut CraftApp, ui: &mut Ui, fold: bool) {
|
||||
if r.clicked() {
|
||||
app.state.pins_collapsed = !collapsed;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if collapsed {
|
||||
crate::sidebar::section_gap(ui, fold, 14.0);
|
||||
return;
|
||||
@@ -203,36 +203,36 @@ pub fn section(app: &mut CraftApp, ui: &mut Ui, fold: bool) {
|
||||
/// The right-click menu on a pin.
|
||||
fn menu(app: &mut CraftApp, ui: &mut Ui, row: &PinRow) {
|
||||
if row.running {
|
||||
if ui.button(tr("Open another copy")).on_hover_text(tr("Copies share the files it saves beside itself.")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Open another copy")).on_hover_text(tr("Copies share the files it saves beside itself.")).clicked() {
|
||||
app.open_pin(row, true);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr("Close it")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Close it")).clicked() {
|
||||
app.stop_pin(row);
|
||||
ui.close();
|
||||
}
|
||||
} else if ui.button(tr("Open")).clicked() {
|
||||
} else if widgets::menu_item(ui, false, tr("Open")).clicked() {
|
||||
app.open_pin(row, false);
|
||||
ui.close();
|
||||
}
|
||||
// The project page's words for the same action.
|
||||
if ui.button(tr("Open folder")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Open folder")).clicked() {
|
||||
app.act("project_open_folder", json!({"project": row.project, "pin": row.pin.id}), tr("Open the folder"));
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr("Go to the project")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Go to the project")).clicked() {
|
||||
if let Some(ws) = app.projects.iter().find(|w| w.root == row.project).cloned() {
|
||||
app.open_workspace(ws);
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr("Rename…")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Rename…")).clicked() {
|
||||
app.state.rename_input = row.pin.name.clone();
|
||||
app.state.modal = Some(Modal::PinRename(row.project.clone(), row.pin.id));
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if ui.add_enabled(!row.running, egui::Button::new(tr("Remove…"))).on_disabled_hover_text(tr("Close it first.")).clicked() {
|
||||
if ui.add_enabled_ui(!row.running, |ui| widgets::menu_item(ui, false, tr("Remove…"))).inner.on_disabled_hover_text(tr("Close it first.")).clicked() {
|
||||
app.state.modal = Some(Modal::PinDelete(row.project.clone(), row.pin.id));
|
||||
ui.close();
|
||||
}
|
||||
@@ -248,9 +248,9 @@ pub fn pin_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.set_width(560.0);
|
||||
ui.label(theme::heading(tr("Pin this build"), theme::SECTION));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.add(egui::Label::new(RichText::new(tr("Keep it in the sidebar to open any time, whatever later builds change.")).color(t.text_dim)).wrap());
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let size = Vec2::new(268.0, 150.0);
|
||||
let mode = app.state.pin_draft.mode;
|
||||
ui.horizontal(|ui| {
|
||||
@@ -277,7 +277,7 @@ pub fn pin_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
app.state.pin_draft.mode = PinMode::Light;
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let (note, color) = match &app.state.pin_draft.size {
|
||||
None => (tr("Working out how much space a copy takes…"), t.text_faint),
|
||||
Some(Err(e)) => (e.clone(), t.danger),
|
||||
@@ -291,8 +291,8 @@ pub fn pin_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.add(egui::Label::new(RichText::new(note).color(color).size(theme::SMALL)).wrap());
|
||||
ui.add_space(10.0);
|
||||
ui.add(egui::Label::new(RichText::new(note).color(color).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL)))).wrap());
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Name (optional)");
|
||||
let r = ui.add(
|
||||
egui::TextEdit::singleline(&mut app.state.pin_draft.name)
|
||||
@@ -301,7 +301,7 @@ pub fn pin_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
.frame(widgets::text_field_frame(&t)),
|
||||
);
|
||||
widgets::named(r, "Pin name");
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
// A build with nothing to start can't be pinned; the estimate says so first.
|
||||
let ok = matches!(app.state.pin_draft.size, Some(Ok(_)));
|
||||
ui.horizontal(|ui| {
|
||||
@@ -320,7 +320,7 @@ pub fn pin_modal(app: &mut CraftApp, ui: &mut Ui, close: &mut bool) {
|
||||
pub fn rename_modal(app: &mut CraftApp, ui: &mut Ui, project: &Path, id: u32, close: &mut bool) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::heading(tr("Rename the pin"), theme::SECTION));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut app.state.rename_input).desired_width(f32::INFINITY).frame(widgets::text_field_frame(&t)));
|
||||
widgets::named(r.clone(), "Pin name");
|
||||
if !r.has_focus() && !r.lost_focus() {
|
||||
@@ -328,7 +328,7 @@ pub fn rename_modal(app: &mut CraftApp, ui: &mut Ui, project: &Path, id: u32, cl
|
||||
}
|
||||
let ok = !app.state.rename_input.trim().is_empty();
|
||||
let enter = r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if (widgets::primary_icon(ui, None, "Rename", ok).clicked() || enter) && ok {
|
||||
let name = app.state.rename_input.trim().to_string();
|
||||
@@ -348,7 +348,7 @@ pub fn delete_modal(app: &mut CraftApp, ui: &mut Ui, project: &Path, id: u32, cl
|
||||
return;
|
||||
};
|
||||
ui.label(theme::heading(trf("Remove {name}?", &[("name", &row.pin.name)]), theme::SECTION));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
// A copy may hold what the program saved; say so, since it can't be brought back.
|
||||
let what = if row.pin.mode.keeps_copy() {
|
||||
tr("Its copy is deleted, with anything it saved there. The project itself stays as it is.")
|
||||
@@ -357,12 +357,12 @@ pub fn delete_modal(app: &mut CraftApp, ui: &mut Ui, project: &Path, id: u32, cl
|
||||
};
|
||||
ui.add(egui::Label::new(RichText::new(what).color(t.text_dim)).wrap());
|
||||
if row.pin.mode.keeps_copy() {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr("This can't be undone.")).color(t.danger).size(theme::SMALL));
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::secondary(ui, Some("trash-2"), "Remove it").clicked() {
|
||||
if widgets::danger(ui, Some("trash-2"), "Remove it").clicked() {
|
||||
app.act("project_pin_delete", json!({"project": project, "pin": id, "confirm": true}), tr("Remove a pin"));
|
||||
*close = true;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use craft_anything_ai::rebuild::feed::{self, apply};
|
||||
use craft_anything_ai::rebuild::{self, AppKind, KindRegistry, KindWords, Note, RebuildRun, RunEvent, RunOptions, Started, Step, Stopped, TargetKind};
|
||||
use craft_anything_engine::inbox::{Answer, Inbox, Request, RequestKind};
|
||||
use craft_anything_engine::workspace::{CheckResult, Status, TargetRef, Workspace, suggest_name};
|
||||
use egui::{Color32, Margin, RichText, Ui, Vec2};
|
||||
use egui::{Color32, RichText, Ui, Vec2};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// ---- controller -------------------------------------------------------------------------------
|
||||
@@ -682,27 +682,27 @@ fn plan_divider(ui: &mut Ui, t: &Tokens, height: &mut Option<f32>, shown: f32) {
|
||||
fn checklist(ui: &mut Ui, steps: &[PlanStep], t: &Tokens, began: Option<std::time::Instant>, fold: bool, height: f32, shown_id: egui::Id) -> bool {
|
||||
let done = steps.iter().filter(|s| s.status == PlanStatus::Done).count();
|
||||
let mut folded = false;
|
||||
widgets::card(t).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
||||
widgets::card(t).inner_margin(theme::pad::ROW).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
widgets::caption(ui, "Plan");
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if fold && icons::button(ui, "x", 18.0, false, &tr("Fold the plan")).clicked() {
|
||||
if fold && icons::button(ui, "x", theme::ControlSize::Small, false, &tr("Fold the plan")).clicked() {
|
||||
folded = true;
|
||||
}
|
||||
if let Some(b) = began {
|
||||
ui.label(RichText::new(crate::usage::duration_words(b.elapsed())).font(theme::mono(12.0)).color(t.text_faint));
|
||||
ui.add(crate::widgets::Spinner::new().size(12.0).color(t.accent));
|
||||
ui.label(RichText::new(crate::usage::duration_words(b.elapsed())).font(theme::mono(theme::CODE)).color(t.text_faint));
|
||||
ui.add(crate::widgets::Spinner::new().size(theme::icon::XS).color(t.accent));
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
|
||||
}
|
||||
ui.label(
|
||||
RichText::new(trf("{done} of {all} done", &[("done", &done.to_string()), ("all", &steps.len().to_string())]))
|
||||
.font(theme::mono(12.0))
|
||||
.font(theme::mono(theme::CODE))
|
||||
.color(t.text_faint),
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let list =
|
||||
egui::ScrollArea::vertical().id_salt("plan-steps").max_height(height).min_scrolled_height(height).auto_shrink([false, true]).show(ui, |ui| {
|
||||
for s in steps {
|
||||
@@ -711,7 +711,7 @@ fn checklist(ui: &mut Ui, steps: &[PlanStep], t: &Tokens, began: Option<std::tim
|
||||
match s.status {
|
||||
PlanStatus::Done => {
|
||||
ui.painter().circle_filled(r.center(), 7.0, t.success);
|
||||
icons::paint(ui, r.shrink(4.0), "check", 10.0, t.canvas);
|
||||
icons::paint(ui, r.shrink(4.0), "check", theme::icon::XS, t.canvas);
|
||||
}
|
||||
PlanStatus::Doing => {
|
||||
ui.painter().circle_stroke(r.center(), 6.5, egui::Stroke::new(1.5, t.accent));
|
||||
@@ -854,22 +854,20 @@ fn asset_line(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
return;
|
||||
}
|
||||
widgets::caption(ui, "Generated assets");
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
crate::engine_ui::assets_toggle(app, ui, ws.manifest.generate_assets);
|
||||
let (n, spent) = app.facts.assets;
|
||||
if !ws.manifest.generate_assets && n == 0 {
|
||||
ui.add_space(12.0);
|
||||
return;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let budget = ws.manifest.asset_budget_usd;
|
||||
let amount = trf("{n} · ${spent} of ${budget}", &[("n", &n.to_string()), ("spent", &format!("{spent:.2}")), ("budget", &format!("{budget:.2}"))]);
|
||||
ui.label(RichText::new(amount).font(theme::mono(12.5)).color(if spent >= budget { t.warning } else { t.text_dim }));
|
||||
ui.label(RichText::new(amount).font(theme::mono(theme::CODE)).color(if spent >= budget { t.warning } else { t.text_dim }));
|
||||
let step = craft_anything_engines::assets::usd(app.asset_budget_step());
|
||||
if widgets::link(ui, &trf("Raise the budget by {amount}", &[("amount", &step)])).clicked() {
|
||||
app.raise_asset_budget();
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
|
||||
/// Which step is current, from the feed and the project's status, and whether it's being worked
|
||||
@@ -903,7 +901,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
egui::Panel::right("project-side")
|
||||
.exact_size(SIDE_W)
|
||||
.resizable(false)
|
||||
.frame(egui::Frame::new().fill(t.canvas).inner_margin(Margin::same(20)))
|
||||
.frame(egui::Frame::new().fill(t.canvas).inner_margin(theme::pad::ROOMY))
|
||||
.show(ui, |ui| egui::ScrollArea::vertical().show(ui, |ui| side(app, ui, &ws)));
|
||||
}
|
||||
let waiting = app.open_run().filter(|r| r.is_running()).map(RebuildRun::waiting).unwrap_or_default();
|
||||
@@ -946,69 +944,84 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
|
||||
fn side(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let m = &ws.manifest;
|
||||
widgets::card(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(48.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, make::project_icon(m), 24.0, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.add(egui::Label::new(theme::heading(&m.name, theme::CARD)).truncate());
|
||||
let (label, fg, bg) = make::status_shown(app, ws, &t);
|
||||
widgets::pill(ui, label, fg, bg);
|
||||
});
|
||||
// What it is: its mark, its name and how it stands, then where it came from.
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(theme::ControlSize::Large.height()), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, make::project_icon(m), theme::icon::LG, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = theme::space::XS;
|
||||
ui.add(egui::Label::new(theme::heading(&m.name, theme::CARD)).truncate());
|
||||
let (label, fg, bg) = make::status_shown(app, ws, &t);
|
||||
widgets::pill(ui, label, fg, bg);
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
if !matches!(m.target, TargetRef::None) {
|
||||
widgets::caption(ui, "From");
|
||||
ui.add(egui::Label::new(RichText::new(m.target.label()).color(t.text_dim)).truncate());
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
if !m.stack.is_empty() && !app.beginner() {
|
||||
widgets::caption(ui, "Built with");
|
||||
ui.label(RichText::new(&m.stack).color(t.text_dim));
|
||||
}
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
steps(app, ui, ws);
|
||||
ui.add_space(14.0);
|
||||
open_questions(app, ui);
|
||||
asset_line(app, ui, ws);
|
||||
if !matches!(m.target, TargetRef::None) {
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "From");
|
||||
ui.add(egui::Label::new(RichText::new(m.target.label()).color(t.text_dim)).truncate());
|
||||
}
|
||||
if !m.stack.is_empty() && !app.beginner() {
|
||||
ui.add_space(theme::space::SM);
|
||||
widgets::caption(ui, "Built with");
|
||||
ui.label(RichText::new(&m.stack).color(t.text_dim));
|
||||
}
|
||||
// The one thing to do with it, as wide as the panel.
|
||||
if outcome(app).is_some() {
|
||||
outcome_button(app, ui, ws, 32.0, 12.5);
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
outcome_button(app, ui, ws, theme::ControlSize::Medium, true);
|
||||
}
|
||||
// Pictures of the original: the look the builder matches (websites are photographed for it).
|
||||
if !matches!(m.target, TargetRef::Website { .. }) {
|
||||
let n = app.facts.references;
|
||||
if widgets::secondary(ui, Some("paperclip"), "Add pictures of the original")
|
||||
.on_hover_text(tr("Screenshots of how it should look. The builder opens each one and matches it."))
|
||||
.clicked()
|
||||
{
|
||||
app.pick(crate::Pick::Pictures);
|
||||
ui.add_space(theme::space::LG);
|
||||
steps(app, ui, ws);
|
||||
ui.add_space(theme::space::LG);
|
||||
open_questions(app, ui);
|
||||
if craft_anything_engines::game::Builder::from_stack(&m.stack).is_some() {
|
||||
widgets::card(&t).inner_margin(theme::pad::ROW).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
asset_line(app, ui, ws);
|
||||
});
|
||||
ui.add_space(theme::space::LG);
|
||||
}
|
||||
// Everything else there is to do with it: one list, one row each.
|
||||
widgets::card(&t).inner_margin(theme::pad::TIGHT).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.spacing_mut().item_spacing.y = theme::space::XXS;
|
||||
// Pictures of the original: the look the builder matches (websites are photographed for it).
|
||||
if !matches!(m.target, TargetRef::Website { .. }) {
|
||||
let n = app.facts.references;
|
||||
let note = if n == 0 { tr("None yet. Screenshots help it look right.") } else { trf("{n} picture(s) to match.", &[("n", &n.to_string())]) };
|
||||
if widgets::action_row(ui, "paperclip", "Add pictures of the original", false)
|
||||
.on_hover_text(tr("Screenshots of how it should look. The builder opens each one and matches it."))
|
||||
.clicked()
|
||||
{
|
||||
app.pick(crate::Pick::Pictures);
|
||||
}
|
||||
// Under its row, in line with the row's words.
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(theme::space::SM + theme::ControlSize::Medium.icon());
|
||||
ui.add(egui::Label::new(RichText::new(note).color(t.text_faint).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION)))).wrap());
|
||||
});
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
let note = if n == 0 { tr("None yet. Screenshots help it look right.") } else { trf("{n} picture(s) to match.", &[("n", &n.to_string())]) };
|
||||
ui.label(RichText::new(note).color(Tokens::get(ui.ctx()).text_dim).size(theme::SMALL));
|
||||
ui.add_space(8.0);
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if widgets::secondary(ui, Some("folder-open"), "Open folder").clicked() {
|
||||
if widgets::action_row(ui, "folder-open", "Open folder", false).clicked() {
|
||||
open_folder(app, ws);
|
||||
}
|
||||
if matches!(outcome(app), Some(Outcome::Program))
|
||||
&& widgets::secondary(ui, Some("pin"), "Pin this build").on_hover_text(tr("Keep this version in the sidebar to open any time.")).clicked()
|
||||
&& widgets::action_row(ui, "pin", "Pin this build", false).on_hover_text(tr("Keep this version in the sidebar to open any time.")).clicked()
|
||||
{
|
||||
app.ask_pin(&ws.root);
|
||||
}
|
||||
crate::manage::buttons(app, ui, ws);
|
||||
crate::manage::rows(app, ui, ws);
|
||||
if !app.beginner()
|
||||
&& widgets::secondary(ui, Some("microscope"), "Open in the workbench").on_hover_text(tr("The full toolset, evidence and logs.")).clicked()
|
||||
&& widgets::action_row(ui, "microscope", "Open in the workbench", false).on_hover_text(tr("The full toolset, evidence and logs.")).clicked()
|
||||
{
|
||||
app.state.screen = Screen::Workbench;
|
||||
}
|
||||
crate::manage::delete_row(app, ui, ws);
|
||||
});
|
||||
ui.add_space(theme::space::LG);
|
||||
}
|
||||
|
||||
/// How to see what was made: open the built site, or start the built program.
|
||||
@@ -1033,10 +1046,11 @@ fn outcome_words(kinds: &KindRegistry, ws: &Workspace) -> KindWords {
|
||||
}
|
||||
|
||||
/// The button that shows the result ("Play the game"); a program starts only on this click.
|
||||
fn outcome_button(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace, height: f32, text: f32) {
|
||||
fn outcome_button(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace, size: theme::ControlSize, wide: bool) {
|
||||
let Some(o) = outcome(app) else { return };
|
||||
let w = outcome_words(&app.kinds, ws);
|
||||
if widgets::primary_sized(ui, Some(w.icon), w.button, true, height, text).clicked() {
|
||||
let button = widgets::Button::new(widgets::ButtonKind::Primary, w.button).icon(Some(w.icon)).size(size);
|
||||
if ui.add(if wide { button.wide() } else { button }).clicked() {
|
||||
match o {
|
||||
Outcome::Site => app.open_preview(&ui.ctx().clone()),
|
||||
Outcome::Program => app.play(ws),
|
||||
@@ -1056,25 +1070,25 @@ fn open_questions(app: &CraftApp, ui: &mut Ui) {
|
||||
return;
|
||||
}
|
||||
let t = Tokens::get(ui.ctx());
|
||||
widgets::card(&t).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
||||
widgets::card(&t).inner_margin(theme::pad::ROW).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
widgets::caption(ui, "Open questions");
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
const SHOWN: usize = 5;
|
||||
for q in app.facts.open_questions.iter().take(SHOWN) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, "info", 14.0, t.text_dim);
|
||||
ui.add(egui::Label::new(RichText::new(q).size(theme::SMALL).color(t.text)).wrap());
|
||||
icons::show(ui, "info", theme::icon::SM, t.text_dim);
|
||||
ui.add(egui::Label::new(RichText::new(q).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL))).color(t.text)).wrap());
|
||||
});
|
||||
}
|
||||
if app.facts.open_questions.len() > SHOWN {
|
||||
let more = trf("and {n} more", &[("n", &(app.facts.open_questions.len() - SHOWN).to_string())]);
|
||||
ui.label(RichText::new(more).size(theme::SMALL).color(t.text_dim));
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.label(RichText::new(tr("Answer any of them in a message below.")).size(theme::SMALL).color(t.text_dim));
|
||||
});
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
}
|
||||
|
||||
fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
@@ -1082,10 +1096,10 @@ fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
let current = current_step(app, ws);
|
||||
let live = current.is_some_and(|(_, live)| live);
|
||||
let idx = current.and_then(|(c, _)| Step::ALL.iter().position(|s| *s == c));
|
||||
widgets::card(&t).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
||||
widgets::card(&t).inner_margin(theme::pad::ROW).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
widgets::caption(ui, "Progress");
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let row_h = 38.0;
|
||||
for (i, s) in Step::ALL.iter().enumerate() {
|
||||
// `here`: where a paused or interrupted build stopped.
|
||||
@@ -1106,10 +1120,10 @@ fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
let round = marker.width() / 2.0;
|
||||
if done {
|
||||
ui.painter().rect_filled(marker, round, t.text);
|
||||
icons::paint(ui, marker.shrink(5.0), "check", 14.0, t.canvas);
|
||||
icons::paint(ui, marker.shrink(5.0), "check", theme::icon::SM, t.canvas);
|
||||
} else if now {
|
||||
ui.painter().rect_filled(marker, round, t.accent);
|
||||
let g = widgets::label_galley(ui, &number, 11.0, t.on_accent);
|
||||
let g = widgets::label_galley(ui, &number, theme::CAPTION, t.on_accent);
|
||||
ui.painter().galley_with_override_text_color(marker.center() - g.size() / 2.0, g, t.on_accent);
|
||||
let pulse = (ui.input(|i| i.time) as f32 * 2.5).sin().abs();
|
||||
ui.painter().rect_stroke(
|
||||
@@ -1121,11 +1135,11 @@ fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
widgets::animate(ui, widgets::FRAME);
|
||||
} else if here {
|
||||
ui.painter().rect(marker, round, t.card, egui::Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);
|
||||
let g = widgets::label_galley(ui, &number, 11.0, t.accent_ink);
|
||||
let g = widgets::label_galley(ui, &number, theme::CAPTION, t.accent_ink);
|
||||
ui.painter().galley_with_override_text_color(marker.center() - g.size() / 2.0, g, t.accent_ink);
|
||||
} else {
|
||||
ui.painter().rect(marker, round, t.card, egui::Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
|
||||
let g = widgets::label_galley(ui, &number, 11.0, t.text_faint);
|
||||
let g = widgets::label_galley(ui, &number, theme::CAPTION, t.text_faint);
|
||||
ui.painter().galley_with_override_text_color(marker.center() - g.size() / 2.0, g, t.text_faint);
|
||||
}
|
||||
let x = marker.right() + 12.0;
|
||||
@@ -1159,28 +1173,36 @@ fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
}
|
||||
// How long it has worked and what the AI has used, live while it builds.
|
||||
if let Some(u) = app.usage.get(&ws.root).filter(|u| u.working() || !u.elapsed().is_zero()) {
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
let tip = || crate::usage::explain(&u.saved, "Every build of this project.");
|
||||
stat_row(ui, "Time spent", &crate::usage::duration_words(u.elapsed()));
|
||||
widgets::stat_row(ui, "Time spent", &crate::usage::duration_words(u.elapsed()));
|
||||
if u.saved.priced {
|
||||
let cost = crate::usage::cost_stat(&u.saved);
|
||||
stat_row(ui, cost.label, &cost.value).on_hover_text(tip());
|
||||
widgets::stat_row(ui, cost.label, &cost.value).on_hover_text(tip());
|
||||
// Said outright, not only on hover: on a subscription this isn't what they pay.
|
||||
if let Some(note) = cost.note {
|
||||
ui.add(egui::Label::new(RichText::new(tr(note)).color(Tokens::get(ui.ctx()).text_faint).size(theme::CAPTION)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(tr(note))
|
||||
.color(Tokens::get(ui.ctx()).text_faint)
|
||||
.size(theme::CAPTION)
|
||||
.line_height(Some(theme::leading(theme::CAPTION))),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
if u.saved.tokens() > 0 || u.saved.tokens_incomplete {
|
||||
let usage = crate::usage::token_total(&u.saved, false);
|
||||
stat_row(ui, "Tokens", &usage).on_hover_text(tip());
|
||||
widgets::stat_row(ui, "Tokens", &usage).on_hover_text(tip());
|
||||
}
|
||||
if u.working() {
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
if let Some(sim) = ws.manifest.checks.last().and_then(|c| c.similarity) {
|
||||
ui.add_space(14.0);
|
||||
stat_row(ui, "Likeness", &format!("{sim:.0}%"));
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::stat_row(ui, "Likeness", &format!("{sim:.0}%"));
|
||||
let (bar, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), 4.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(bar, 2.0, t.separator);
|
||||
let filled = egui::Rect::from_min_size(bar.min, Vec2::new(bar.width() * (sim / 100.0).clamp(0.0, 1.0) as f32, bar.height()));
|
||||
@@ -1189,29 +1211,6 @@ fn steps(app: &CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
});
|
||||
}
|
||||
|
||||
/// A caption on the left and its value on the right, or the value on a line of its own when the
|
||||
/// two would overlap: a right-to-left layout doesn't make room for what's already on the row.
|
||||
fn stat_row(ui: &mut Ui, label: &str, value: &str) -> egui::Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let text = RichText::new(value).font(theme::mono(13.0)).color(t.text);
|
||||
let value_width =
|
||||
egui::WidgetText::from(text.clone()).into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::FontSelection::Default).size().x;
|
||||
let caption_width = widgets::label_galley(ui, &tr(label), 12.0, t.text_faint).size().x;
|
||||
if caption_width + ui.spacing().item_spacing.x + value_width <= ui.available_width() {
|
||||
ui.horizontal(|ui| {
|
||||
widgets::caption(ui, label);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| ui.label(text));
|
||||
})
|
||||
.response
|
||||
} else {
|
||||
ui.vertical(|ui| {
|
||||
widgets::caption(ui, label);
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Max), |ui| ui.label(text));
|
||||
})
|
||||
.response
|
||||
}
|
||||
}
|
||||
|
||||
fn feed(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace, waiting: &[Note]) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let ctx = ui.ctx().clone();
|
||||
@@ -1231,20 +1230,20 @@ fn feed(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace, waiting: &[Note]) {
|
||||
// The finish line: a big, plain prompt to try what was made.
|
||||
if !app.running() && matches!(ws.manifest.status, Status::Ready) && outcome(app).is_some() {
|
||||
let w = outcome_words(&app.kinds, ws);
|
||||
widgets::card(&t).inner_margin(Margin::same(18)).show(ui, |ui| {
|
||||
widgets::card(&t).inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(44.0), egui::Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, rect, w.icon, 22.0, t.accent_ink);
|
||||
icons::paint(ui, rect, w.icon, theme::icon::XL, t.accent_ink);
|
||||
ui.vertical(|ui| {
|
||||
ui.label(theme::heading(tr(w.ready), theme::CARD));
|
||||
ui.label(RichText::new(tr("Try it out, then ask below for any changes.")).color(t.text_dim));
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| outcome_button(app, ui, ws, 44.0, 13.0));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| outcome_button(app, ui, ws, theme::ControlSize::Large, false));
|
||||
});
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
}
|
||||
// Waiting notes scroll with the conversation. The live activity comes after them so it
|
||||
// stays visible when the feed follows the latest work.
|
||||
@@ -1341,7 +1340,7 @@ fn run_details(app: &mut CraftApp, ui: &mut Ui, status_row: bool) {
|
||||
egui::CollapsingHeader::new(RichText::new(title).color(t.text_dim).size(theme::CAPTION)).id_salt("run_details").icon(widgets::disclosure_icon).show(
|
||||
ui,
|
||||
|ui| {
|
||||
widgets::card(&t).inner_margin(Margin::symmetric(10, 8)).show(ui, |ui| {
|
||||
widgets::card(&t).inner_margin(theme::pad::TIGHT).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
// The rows are exactly this tall, or the scroll area miscounts them.
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
@@ -1434,11 +1433,11 @@ fn draw_items(
|
||||
.fill(t.card)
|
||||
.stroke(egui::Stroke::new(1.0, t.danger.gamma_multiply(0.6)))
|
||||
.corner_radius(t.r_lg())
|
||||
.inner_margin(Margin::same(14))
|
||||
.inner_margin(theme::pad::CARD)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.danger);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.danger);
|
||||
ui.add(egui::Label::new(RichText::new(message).color(t.text)).wrap());
|
||||
});
|
||||
if let Some(r) = remediation {
|
||||
@@ -1452,7 +1451,7 @@ fn draw_items(
|
||||
let last = i + 1 == items.len();
|
||||
// A pause or a stop part-way gets the Continue card below instead.
|
||||
if last && !app.running() && !can_continue(app, ws) {
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::primary_icon(ui, Some("refresh-cw"), "Try again", true).clicked() {
|
||||
*retry = true;
|
||||
@@ -1496,8 +1495,8 @@ fn work(ui: &mut Ui, tools: &[(String, Option<bool>)], notes: &[String], advance
|
||||
Some(true) => ("check", t.success),
|
||||
Some(false) => ("triangle-alert", t.warning),
|
||||
};
|
||||
icons::show(ui, icon, 12.0, col);
|
||||
ui.label(RichText::new(tool.replace('_', " ")).font(theme::mono(12.5)).color(t.text_dim));
|
||||
icons::show(ui, icon, theme::icon::XS, col);
|
||||
ui.label(RichText::new(tool.replace('_', " ")).font(theme::mono(theme::CODE)).color(t.text_dim));
|
||||
});
|
||||
}
|
||||
for n in notes {
|
||||
@@ -1551,14 +1550,14 @@ fn continue_card(app: &mut CraftApp, ui: &mut Ui, ws: &Workspace) {
|
||||
("Paused", "Everything so far is kept. Continue picks up where it stopped.")
|
||||
};
|
||||
let mut go = false;
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, t.accent)).corner_radius(t.r_lg()).inner_margin(Margin::same(14)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, t.accent)).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "history", 18.0, t.accent);
|
||||
icons::show(ui, "history", theme::icon::LG, t.accent);
|
||||
ui.add(egui::Label::new(RichText::new(tr(title)).font(theme::semibold(theme::BODY))).wrap());
|
||||
});
|
||||
ui.add(egui::Label::new(RichText::new(tr(body)).color(t.text_dim)).wrap());
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal(|ui| {
|
||||
go = widgets::primary_icon(ui, Some("play"), "Continue", true).clicked();
|
||||
done_button(app, ui, ws);
|
||||
@@ -1583,10 +1582,10 @@ fn ask_card(app: &mut CraftApp, ui: &mut Ui, r: &Request, answered: Option<&str>
|
||||
let approval = r.kind == RequestKind::Approval;
|
||||
let border = if approval { t.warning } else { t.accent };
|
||||
let mut out = None;
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, border)).corner_radius(t.r_lg()).inner_margin(Margin::same(14)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.5, border)).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, if approval { "shield" } else { "circle-help" }, 18.0, border);
|
||||
icons::show(ui, if approval { "shield" } else { "circle-help" }, theme::icon::LG, border);
|
||||
let title = if approval { trf("May I {action}?", &[("action", &lower_first(&r.title))]) } else { r.title.clone() };
|
||||
ui.add(egui::Label::new(RichText::new(title).font(theme::semibold(theme::BODY))).wrap());
|
||||
});
|
||||
@@ -1596,13 +1595,13 @@ fn ask_card(app: &mut CraftApp, ui: &mut Ui, r: &Request, answered: Option<&str>
|
||||
.id_salt(("detail", &r.id))
|
||||
.icon(widgets::disclosure_icon)
|
||||
.show(ui, |ui| {
|
||||
ui.label(RichText::new(&r.detail).font(theme::mono(12.5)).color(t.text_dim));
|
||||
ui.label(RichText::new(&r.detail).font(theme::mono(theme::CODE)).color(t.text_dim));
|
||||
});
|
||||
} else {
|
||||
ui.add(egui::Label::new(RichText::new(&r.detail).color(t.text_dim)).wrap());
|
||||
}
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if let Some(a) = answered {
|
||||
ui.label(RichText::new(trf("You answered: {a}", &[("a", a)])).color(t.text_faint));
|
||||
return;
|
||||
@@ -1613,7 +1612,7 @@ fn ask_card(app: &mut CraftApp, ui: &mut Ui, r: &Request, answered: Option<&str>
|
||||
.color(t.text_faint)
|
||||
.size(theme::CAPTION),
|
||||
);
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
if widgets::primary(ui, "Allow once").clicked() {
|
||||
out = Some((r.id.clone(), Answer { allow: Some(true), ..Default::default() }, tr("Allowed once")));
|
||||
@@ -1635,7 +1634,7 @@ fn ask_card(app: &mut CraftApp, ui: &mut Ui, r: &Request, answered: Option<&str>
|
||||
}
|
||||
});
|
||||
if r.allow_text {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
let text = app.state.answers.entry(r.id.clone()).or_default();
|
||||
let resp = ui.add(
|
||||
@@ -1677,7 +1676,7 @@ fn claims_list(ui: &mut Ui, c: &CheckResult, t: &Tokens) {
|
||||
if c.claims.is_empty() && c.unknowns.is_empty() {
|
||||
return;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if !c.claims.is_empty() {
|
||||
let held = c.claims.iter().filter(|x| x.passed).count();
|
||||
let line = trf("{held} of {n} requirements met", &[("held", &held.to_string()), ("n", &c.claims.len().to_string())]);
|
||||
@@ -1685,8 +1684,8 @@ fn claims_list(ui: &mut Ui, c: &CheckResult, t: &Tokens) {
|
||||
}
|
||||
let row = |ui: &mut Ui, icon: &str, colour: Color32, text: String| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
icons::show(ui, icon, 14.0, colour);
|
||||
ui.add(egui::Label::new(RichText::new(text).size(theme::SMALL).color(colour)).wrap());
|
||||
icons::show(ui, icon, theme::icon::SM, colour);
|
||||
ui.add(egui::Label::new(RichText::new(text).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL))).color(colour)).wrap());
|
||||
});
|
||||
};
|
||||
for claim in c.claims.iter().filter(|x| !x.passed) {
|
||||
@@ -1710,7 +1709,7 @@ fn check_card(app: &mut CraftApp, ui: &mut Ui, ctx: &egui::Context, ws: &Workspa
|
||||
widgets::card(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "scan-search", 18.0, t.accent_ink);
|
||||
icons::show(ui, "scan-search", theme::icon::LG, t.accent_ink);
|
||||
let title = match c.similarity {
|
||||
Some(s) => trf("Check {n}: about {s}% like the original", &[("n", &c.round.to_string()), ("s", &format!("{s:.0}"))]),
|
||||
None => trf("Check {n}", &[("n", &c.round.to_string())]),
|
||||
@@ -1719,7 +1718,7 @@ fn check_card(app: &mut CraftApp, ui: &mut Ui, ctx: &egui::Context, ws: &Workspa
|
||||
});
|
||||
// The per-width measurements are for Advanced mode; a failed check's reason always shows.
|
||||
if !app.beginner() || c.similarity.is_none() {
|
||||
ui.add(egui::Label::new(RichText::new(&c.note).color(t.text_dim).size(theme::CAPTION)).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(&c.note).color(t.text_dim).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION)))).wrap());
|
||||
}
|
||||
claims_list(ui, c, &t);
|
||||
// Several pages: each one's likeness; clicking one shows its pictures below.
|
||||
@@ -1727,11 +1726,11 @@ fn check_card(app: &mut CraftApp, ui: &mut Ui, ctx: &egui::Context, ws: &Workspa
|
||||
let mut picked: usize = ui.data(|d| d.get_temp(picked_id)).unwrap_or(0);
|
||||
if c.pages.len() > 1 {
|
||||
picked = picked.min(c.pages.len() - 1);
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
for (i, p) in c.pages.iter().enumerate() {
|
||||
let text = format!("{} {:.0}%", if p.dir.is_empty() { tr("start page") } else { p.name.clone() }, p.similarity);
|
||||
let colour = if p.similarity >= app.settings.build.good_enough { t.text_dim } else { t.warning };
|
||||
if ui.selectable_label(i == picked, RichText::new(text).font(theme::mono(12.5)).color(colour)).clicked() {
|
||||
if ui.selectable_label(i == picked, RichText::new(text).font(theme::mono(theme::CODE)).color(colour)).clicked() {
|
||||
picked = i;
|
||||
ui.data_mut(|d| d.insert_temp(picked_id, i));
|
||||
}
|
||||
@@ -1743,7 +1742,7 @@ fn check_card(app: &mut CraftApp, ui: &mut Ui, ctx: &egui::Context, ws: &Workspa
|
||||
// Both pictures, read on a worker; nothing when either isn't there.
|
||||
let shots = c.similarity.map(|_| [("Original", app.thumb(ctx, &orig)), ("Your version", app.thumb(ctx, &built))]);
|
||||
if let Some(shots) = shots.filter(|s| !s.iter().any(|(_, t)| matches!(t, Thumb::Missing))) {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let w = (ui.available_width() - 12.0) / 2.0;
|
||||
ui.horizontal(|ui| {
|
||||
for (label, thumb) in shots {
|
||||
@@ -1775,7 +1774,7 @@ fn waiting_notes(app: &mut CraftApp, ui: &mut Ui, waiting: &[Note], t: &Tokens)
|
||||
ui.push_id(("waiting-note", note.id), |ui| {
|
||||
chat::user_bubble(ui, ¬e.shown, false);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "x", 22.0, false, "Take back: puts it in the box again").clicked() {
|
||||
if icons::button(ui, "x", theme::ControlSize::Small, false, "Take back: puts it in the box again").clicked() {
|
||||
take_back = Some(note.id);
|
||||
}
|
||||
// Said once, under the last note.
|
||||
@@ -1792,7 +1791,7 @@ fn waiting_notes(app: &mut CraftApp, ui: &mut Ui, waiting: &[Note], t: &Tokens)
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
if let Some(id) = take_back {
|
||||
app.unsend(id);
|
||||
@@ -1815,11 +1814,11 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, t: &Tokens, last_waitin
|
||||
if fold {
|
||||
app.fold_plan();
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
if let Some(n) = app.queue_position() {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "history", 15.0, t.accent_ink);
|
||||
icons::show(ui, "history", theme::icon::MD, t.accent_ink);
|
||||
let line = if n == 1 {
|
||||
tr("Waiting for another build to finish: this one starts next.")
|
||||
} else {
|
||||
@@ -1827,7 +1826,7 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, t: &Tokens, last_waitin
|
||||
};
|
||||
ui.label(RichText::new(line).color(t.text_dim).size(theme::SMALL));
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
// Pause was pressed and the build hasn't stopped yet: the button says so until it does.
|
||||
let open_root = app.workspace.as_ref().map(|w| w.root.clone());
|
||||
@@ -1946,22 +1945,25 @@ fn questions_switch(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let now = app.settings.questions_in(Some(&ws.manifest));
|
||||
let root = ws.root.clone();
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let (sending, asking) = (["Change it", "Just ask"], ["Ask me", "Decide yourself"]);
|
||||
let title = widgets::label_galley(ui, &tr(QUESTIONS_TITLE), theme::SMALL, t.text_dim).size().x;
|
||||
// The approvals menu's link, the space before it and one more item gap.
|
||||
let approvals = widgets::label_galley(ui, &tr("Approvals"), theme::BODY, t.text).size().x + 8.0;
|
||||
let gaps = ui.spacing().item_spacing.x * 4.0;
|
||||
// Room for the gaps and for enough of the hint to read: squeezed to nothing it sat on the title.
|
||||
let gaps = ui.spacing().item_spacing.x * 4.0 + theme::space::XXL;
|
||||
let title = title + approvals;
|
||||
// Side by side when both switches fit, else one under the other (a longer language, a narrow window).
|
||||
let fits = widgets::segmented_width(ui, &sending) + widgets::segmented_width(ui, &asking) + title + gaps <= ui.available_width();
|
||||
let fits =
|
||||
widgets::segmented_width(ui, &sending, theme::ControlSize::Small) + widgets::segmented_width(ui, &asking, theme::ControlSize::Small) + title + gaps
|
||||
<= ui.available_width();
|
||||
let hint = |ui: &mut Ui| {
|
||||
ui.add(egui::Label::new(RichText::new(tr("or start with /btw to just ask")).color(t.text_faint).size(theme::SMALL)).truncate());
|
||||
};
|
||||
let right = egui::Layout::right_to_left(egui::Align::Center);
|
||||
ui.horizontal(|ui| {
|
||||
// What sending does: ask for a change, or just ask about the build.
|
||||
if let Some(i) = widgets::segmented(ui, &sending, usize::from(app.state.just_ask), 24.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &sending, usize::from(app.state.just_ask), theme::ControlSize::Small) {
|
||||
app.state.just_ask = i == 1;
|
||||
}
|
||||
if fits {
|
||||
@@ -1974,7 +1976,7 @@ fn questions_switch(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
if !fits {
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| ui.with_layout(right, |ui| questions_controls(app, ui, now, &root, &t)));
|
||||
}
|
||||
}
|
||||
@@ -1985,10 +1987,10 @@ fn questions_controls(app: &mut CraftApp, ui: &mut Ui, now: craft_anything_engin
|
||||
use craft_anything_engine::workspace::Questions;
|
||||
// Right to left: the approvals menu at the end of the row.
|
||||
crate::approvals::menu(app, ui, root);
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
{
|
||||
let sel = usize::from(now == Questions::Decide);
|
||||
if let Some(i) = widgets::segmented(ui, &["Ask me", "Decide yourself"], sel, 24.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Ask me", "Decide yourself"], sel, theme::ControlSize::Small) {
|
||||
let mode = if i == 0 { Questions::Ask } else { Questions::Decide };
|
||||
app.set_questions(root, mode);
|
||||
}
|
||||
|
||||
@@ -136,9 +136,11 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
let mut out = PromptOut::default();
|
||||
let id = ui.make_persistent_id(("prompt-box", b.name));
|
||||
let focused = ui.memory(|m| m.has_focus(id));
|
||||
let stroke = egui::Stroke::new(1.0, if focused { t.text_faint } else { t.field_border });
|
||||
// The edge firms up as the box is typed in, eased like every other state.
|
||||
let how = ui.ctx().animate_bool_with_time(id.with("focus-edge"), focused, widgets::FOCUS_FADE);
|
||||
let stroke = egui::Stroke::new(1.0, crate::theme::mix(t.card_border, t.field_border, how));
|
||||
let frame = egui::Frame::new()
|
||||
.fill(t.card)
|
||||
.fill(t.field)
|
||||
.stroke(stroke)
|
||||
.corner_radius(t.r_lg())
|
||||
.shadow(egui::Shadow { offset: [0, 2], blur: 12, spread: 0, color: t.shadow })
|
||||
@@ -167,7 +169,9 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
let x = egui::Rect::from_min_size(rect.right_top() + egui::vec2(-26.0, 4.0), egui::Vec2::splat(22.0));
|
||||
ui.painter().circle_filled(x.center(), 10.0, t.card);
|
||||
// A child of its own, so the row's next tile isn't placed after it.
|
||||
if icons::button(&mut ui.new_child(egui::UiBuilder::new().max_rect(x)), "x", 22.0, false, &remove).clicked() {
|
||||
if icons::button(&mut ui.new_child(egui::UiBuilder::new().max_rect(x)), "x", theme::ControlSize::Small, false, &remove)
|
||||
.clicked()
|
||||
{
|
||||
out.remove = Some(i);
|
||||
}
|
||||
}
|
||||
@@ -180,9 +184,9 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
.inner_margin(Margin { left: 8, right: 2, top: 2, bottom: 2 })
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "paperclip", 13.0, t.icon);
|
||||
icons::show(ui, "paperclip", theme::icon::SM, t.icon);
|
||||
ui.add(egui::Label::new(RichText::new(&name).size(theme::SMALL)).truncate()).on_hover_text(p.display().to_string());
|
||||
if icons::button(ui, "x", 24.0, false, &remove).clicked() {
|
||||
if icons::button(ui, "x", theme::ControlSize::Small, false, &remove).clicked() {
|
||||
out.remove = Some(i);
|
||||
}
|
||||
});
|
||||
@@ -191,7 +195,7 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
let line = ui.fonts_mut(|f| f.row_height(&egui::FontId::proportional(b.font_size)));
|
||||
// Up at the very start (or in an empty box) takes back the last waiting message; it's
|
||||
@@ -240,6 +244,7 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
..egui::EventFilter::default()
|
||||
}),
|
||||
);
|
||||
widgets::frameless_field(&r);
|
||||
widgets::named(r.clone(), b.name);
|
||||
if r.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter) && !i.modifiers.shift) && !text.trim().is_empty() {
|
||||
out.send = true;
|
||||
@@ -255,10 +260,10 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
|
||||
if text.trim_start().starts_with('/') && !text.trim().contains(' ') {
|
||||
ui.label(RichText::new(format!("{} {}", tr("Commands:"), crate::slash::names())).size(theme::CAPTION).color(t.text_faint));
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.horizontal(|ui| {
|
||||
if let Some(tip) = b.attach
|
||||
&& icons::button(ui, "paperclip", 30.0, false, tip).clicked()
|
||||
&& icons::button(ui, "paperclip", theme::ControlSize::Medium, false, tip).clicked()
|
||||
{
|
||||
out.attach = true;
|
||||
}
|
||||
@@ -360,7 +365,7 @@ fn send_button(ui: &mut Ui, ready: bool) -> egui::Response {
|
||||
let (rect, resp) = ui.allocate_exact_size(egui::Vec2::splat(32.0), egui::Sense::click());
|
||||
let fill = if ready { crate::theme::mix(t.accent, t.accent_hover, widgets::hover_t(ui, &resp)) } else { t.raised };
|
||||
ui.painter().rect_filled(rect, t.radius, fill);
|
||||
icons::paint(ui, rect, "send", 16.0, if ready { t.on_accent } else { t.text_faint });
|
||||
icons::paint(ui, rect, "send", theme::icon::MD, if ready { t.on_accent } else { t.text_faint });
|
||||
widgets::focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tr("Send (Enter)")));
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(tr("Send (Enter)"))
|
||||
|
||||
@@ -134,7 +134,7 @@ pub fn show(ui: &mut Ui, fields: &[Field], values: &mut BTreeMap<String, String>
|
||||
for f in fields {
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(&f.name).font(theme::mono(12.5)));
|
||||
ui.label(RichText::new(&f.name).font(theme::mono(theme::CODE)));
|
||||
if f.required {
|
||||
ui.label(RichText::new("*").color(t.accent));
|
||||
}
|
||||
@@ -150,22 +150,19 @@ pub fn show(ui: &mut Ui, fields: &[Field], values: &mut BTreeMap<String, String>
|
||||
}
|
||||
}
|
||||
_ if !f.choices.is_empty() => {
|
||||
egui::ComboBox::from_id_salt(("choice", &f.name))
|
||||
.icon(widgets::combo_icon)
|
||||
.selected_text(if v.is_empty() { "—".to_string() } else { v.clone() })
|
||||
.show_ui(ui, |ui| {
|
||||
if !f.required {
|
||||
ui.selectable_value(v, String::new(), "—");
|
||||
}
|
||||
for c in &f.choices {
|
||||
ui.selectable_value(v, c.clone(), c);
|
||||
}
|
||||
});
|
||||
widgets::dropdown(("choice", &f.name)).selected_text(if v.is_empty() { "—".to_string() } else { v.clone() }).show_ui(ui, |ui| {
|
||||
if !f.required {
|
||||
widgets::menu_choice(ui, v, String::new(), "—");
|
||||
}
|
||||
for c in &f.choices {
|
||||
widgets::menu_choice(ui, v, c.clone(), c);
|
||||
}
|
||||
});
|
||||
}
|
||||
FieldKind::Json => {
|
||||
ui.add(
|
||||
egui::TextEdit::multiline(v)
|
||||
.font(theme::mono(12.0))
|
||||
.font(theme::mono(theme::CODE))
|
||||
.desired_rows(2)
|
||||
.desired_width(320.0)
|
||||
.hint_text("JSON")
|
||||
@@ -187,7 +184,12 @@ pub fn show(ui: &mut Ui, fields: &[Field], values: &mut BTreeMap<String, String>
|
||||
}
|
||||
}
|
||||
if !f.description.is_empty() {
|
||||
ui.add(egui::Label::new(RichText::new(&f.description).color(t.text_faint).size(theme::CAPTION)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(&f.description).color(t.text_faint).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION))),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
@@ -20,13 +20,13 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
// A modal (dimmed backdrop, Esc or a click outside closes) with a full-size close button;
|
||||
// egui's window close box is 14 px.
|
||||
let resp = egui::Modal::new(egui::Id::new("settings-window"))
|
||||
.frame(egui::Frame::new().fill(t.card).corner_radius(t.r_lg()).inner_margin(egui::Margin::same(20)).stroke(egui::Stroke::new(1.0, t.card_border)))
|
||||
.frame(egui::Frame::new().fill(t.card).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD).stroke(egui::Stroke::new(1.0, t.card_border)))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(680.0);
|
||||
ui.set_width((ctx.content_rect().width() - 2.0 * theme::space::XXL).clamp(560.0, 860.0));
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(theme::heading(tr("Settings"), theme::SECTION));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "x", 32.0, false, "Close").clicked() {
|
||||
if icons::button(ui, "x", theme::ControlSize::Medium, false, "Close").clicked() {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
@@ -34,16 +34,16 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
// An error (a save that failed) shows here too: the message bar is behind this window.
|
||||
if let Some(i) = app.state.toasts.iter().rposition(|(_, error)| *error) {
|
||||
let text = app.state.toasts[i].0.clone();
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 16.0, t.danger);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.danger);
|
||||
ui.add(egui::Label::new(RichText::new(text).color(t.danger)).wrap());
|
||||
if icons::button(ui, "x", 24.0, false, "Dismiss").clicked() {
|
||||
if icons::button(ui, "x", theme::ControlSize::Small, false, "Dismiss").clicked() {
|
||||
app.state.toasts.remove(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(150.0);
|
||||
@@ -74,7 +74,7 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
egui::pos2(rect.left() + 36.0, rect.center().y),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
tr(title),
|
||||
theme::medium(theme::SMALL),
|
||||
theme::medium(theme::BODY),
|
||||
if on { t.text } else { t.text_dim },
|
||||
);
|
||||
if r.clicked() {
|
||||
@@ -85,7 +85,9 @@ pub fn show(app: &mut CraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.separator();
|
||||
ui.add_space(theme::space::LG);
|
||||
ui.vertical(|ui| {
|
||||
// Exactly what's left of the window, with room for the scroll bar a long tab
|
||||
// gets, so no tab can widen the window (#68).
|
||||
@@ -122,21 +124,23 @@ fn row(ui: &mut Ui, title: &str, sub: &str, add: impl FnOnce(&mut Ui)) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(220.0);
|
||||
ui.label(RichText::new(tr(title)).font(theme::medium(theme::SMALL)));
|
||||
ui.set_width(280.0);
|
||||
ui.label(RichText::new(tr(title)).font(theme::medium(theme::BODY)));
|
||||
if !sub.is_empty() {
|
||||
ui.add(egui::Label::new(RichText::new(tr(sub)).color(t.text_faint).size(theme::CAPTION)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(tr(sub)).color(t.text_faint).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION)))).wrap(),
|
||||
);
|
||||
}
|
||||
});
|
||||
add(ui);
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
}
|
||||
|
||||
fn general(app: &mut CraftApp, ui: &mut Ui) {
|
||||
row(ui, "Mode", "Simple: say what you want and it's handled for you. Advanced: every tool, the evidence and the logs.", |ui| {
|
||||
let sel = usize::from(app.settings.mode == Mode::Experienced);
|
||||
if let Some(i) = widgets::segmented(ui, &["Simple", "Advanced"], sel, 30.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Simple", "Advanced"], sel, theme::ControlSize::Medium) {
|
||||
app.set_mode(if i == 0 { Mode::Beginner } else { Mode::Experienced });
|
||||
}
|
||||
});
|
||||
@@ -154,10 +158,11 @@ fn general(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let mut remove = None;
|
||||
for f in &app.settings.project_folders {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(12.0);
|
||||
crate::icons::show(ui, "folder", 14.0, Tokens::get(ui.ctx()).text_faint);
|
||||
ui.add(egui::Label::new(RichText::new(f.display().to_string()).font(theme::mono(12.0))).truncate());
|
||||
if crate::icons::button(ui, "x", 22.0, false, &trf("Stop listing {folder}", &[("folder", &f.display().to_string())])).clicked() {
|
||||
ui.add_space(theme::space::MD);
|
||||
crate::icons::show(ui, "folder", theme::icon::SM, Tokens::get(ui.ctx()).text_faint);
|
||||
ui.add(egui::Label::new(RichText::new(f.display().to_string()).font(theme::mono(theme::CODE))).truncate());
|
||||
if crate::icons::button(ui, "x", theme::ControlSize::Small, false, &trf("Stop listing {folder}", &[("folder", &f.display().to_string())])).clicked()
|
||||
{
|
||||
remove = Some(f.clone());
|
||||
}
|
||||
});
|
||||
@@ -167,9 +172,9 @@ fn general(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
row(ui, "When a folder you pick has files", "Whether they're the app to edit in place, or material the app starts from beside them.", |ui| {
|
||||
let current = crate::folders::EXISTING_CHOICES.iter().find(|(_, v)| *v == app.settings.existing_files).map_or("Ask each time", |(l, _)| *l);
|
||||
egui::ComboBox::from_id_salt("existing-files").icon(widgets::combo_icon).selected_text(tr(current)).show_ui(ui, |ui| {
|
||||
widgets::dropdown("existing-files").selected_text(tr(current)).show_ui(ui, |ui| {
|
||||
for (label, value) in crate::folders::EXISTING_CHOICES {
|
||||
if ui.selectable_label(app.settings.existing_files == value, tr(label)).clicked() {
|
||||
if widgets::menu_item(ui, app.settings.existing_files == value, tr(label)).clicked() {
|
||||
app.settings.existing_files = value;
|
||||
app.settings_changed();
|
||||
}
|
||||
@@ -178,7 +183,7 @@ fn general(app: &mut CraftApp, ui: &mut Ui) {
|
||||
});
|
||||
row(ui, "Theme", "", |ui| {
|
||||
let sel = usize::from(app.theme_kind() == ThemeKind::StudioLight);
|
||||
if let Some(i) = widgets::segmented(ui, &["Studio", "Studio Light"], sel, 30.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Studio", "Studio Light"], sel, theme::ControlSize::Medium) {
|
||||
app.settings.theme = ThemeKind::ALL.get(i).copied().unwrap_or_default().id().into();
|
||||
app.settings_changed();
|
||||
}
|
||||
@@ -201,14 +206,14 @@ fn language(app: &mut CraftApp, ui: &mut Ui) {
|
||||
row(ui, "Language", "", |ui| {
|
||||
let selected = (!app.settings.language.trim().is_empty()).then(|| crate::i18n::language_from_tag(&app.settings.language).unwrap_or("en"));
|
||||
let current = LANGUAGES.iter().find(|l| Some(l.code) == selected).map(|l| l.name).unwrap_or("System");
|
||||
egui::ComboBox::from_id_salt("lang").icon(widgets::combo_icon).selected_text(tr(current)).show_ui(ui, |ui| {
|
||||
if ui.selectable_label(app.settings.language.trim().is_empty(), tr("System")).clicked() {
|
||||
widgets::dropdown("lang").selected_text(tr(current)).show_ui(ui, |ui| {
|
||||
if widgets::menu_item(ui, app.settings.language.trim().is_empty(), tr("System")).clicked() {
|
||||
app.settings.language.clear();
|
||||
crate::i18n::set_language("");
|
||||
app.settings_changed();
|
||||
}
|
||||
for l in LANGUAGES {
|
||||
if ui.selectable_label(selected == Some(l.code), l.name).clicked() {
|
||||
if widgets::menu_item(ui, selected == Some(l.code), l.name).clicked() {
|
||||
app.settings.language = l.code.into();
|
||||
crate::i18n::set_language(l.code);
|
||||
app.settings_changed();
|
||||
@@ -230,7 +235,7 @@ fn path_field(ui: &mut Ui, value: &mut Option<PathBuf>, name: &str, hint: &str)
|
||||
.hint_text(tr(hint))
|
||||
// Up to 240, leaving room for a Choose… button after it, so a row never widens the window (#68).
|
||||
.desired_width((ui.available_width() - 34.0).clamp(120.0, 240.0))
|
||||
.font(theme::mono(12.0))
|
||||
.font(theme::mono(theme::CODE))
|
||||
.frame(widgets::text_field_frame_compact(&Tokens::get(ui.ctx()))),
|
||||
);
|
||||
widgets::named(r.clone(), &tr(name));
|
||||
@@ -254,12 +259,12 @@ fn engines(app: &mut CraftApp, ui: &mut Ui) {
|
||||
"Clean room never reads the original's code, files or page source: it works from what you can see. Deep reads them with every tool, and with Ghidra when it's installed. Every finding records which was used.",
|
||||
|ui| {
|
||||
let sel = usize::from(app.settings.deep_mode);
|
||||
if let Some(i) = widgets::segmented(ui, &["Clean room", "Deep"], sel, 30.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Clean room", "Deep"], sel, theme::ControlSize::Medium) {
|
||||
app.set_deep(i == 1);
|
||||
}
|
||||
},
|
||||
);
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
row(ui, "Ghidra", "Adds its decompiler to Deep mode. Craft Anything can download and set it up for you.", |ui| {
|
||||
crate::engine_ui::ghidra_status(app, ui);
|
||||
});
|
||||
@@ -270,12 +275,12 @@ fn engines(app: &mut CraftApp, ui: &mut Ui) {
|
||||
|ui| crate::engine_ui::ghidra_memory_setting(app, ui),
|
||||
);
|
||||
ui.label(RichText::new(crate::engine_ui::ghidra_memory_guide()).color(t.text_faint).size(theme::CAPTION));
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
row(ui, "Ghidra folder", "Leave empty to use the one Craft Anything sets up.", |ui| {
|
||||
if path_field(ui, &mut app.settings.engines.ghidra.install_dir, "Ghidra folder", "managed") {
|
||||
app.settings_changed();
|
||||
}
|
||||
if icons::button(ui, "folder-open", 26.0, false, "Choose…").clicked() {
|
||||
if icons::button(ui, "folder-open", theme::ControlSize::Small, false, "Choose…").clicked() {
|
||||
app.pick(Pick::GhidraDir);
|
||||
}
|
||||
});
|
||||
@@ -284,12 +289,12 @@ fn engines(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.settings_changed();
|
||||
}
|
||||
});
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
crate::engine_ui::settings_section(app, ui);
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Your own tool installs (optional)");
|
||||
ui.label(RichText::new(tr("Leave a path empty to use the managed install. We never need environment variables.")).color(t.text_faint).size(theme::CAPTION));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let mut changed = false;
|
||||
egui::Grid::new("tool-paths").num_columns(2).spacing([12.0, 6.0]).show(ui, |ui| {
|
||||
// Names and purposes come from the engine table; the override list matches it (tested).
|
||||
@@ -311,7 +316,7 @@ fn model_options_loading(ui: &mut Ui, backend: &str) {
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(tr("Context window"));
|
||||
egui::ComboBox::from_id_salt(("model-context", backend)).icon(widgets::combo_icon).selected_text(tr("Default")).show_ui(ui, |_| {});
|
||||
widgets::dropdown(("model-context", backend)).selected_text(tr("Default")).show_ui(ui, |_| {});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -324,9 +329,9 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
let t = Tokens::get(ui.ctx());
|
||||
crate::engine_ui::assets_settings(app, ui);
|
||||
ui.add_space(16.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::caption(ui, "Your brains");
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if app.backends.is_empty() {
|
||||
ui.label(RichText::new(tr("No AI is set up yet. The built-in engines still work; an AI adds plain-words answers.")).color(t.text_dim));
|
||||
}
|
||||
@@ -349,12 +354,26 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
for b in &app.backends {
|
||||
widgets::panel(&t).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
// The name and model on their own row (shortened, full text on hover), the buttons on a
|
||||
// row below that wraps: nothing overlaps however long the name or narrow the window.
|
||||
// One left edge for the whole card. The header: the name (shortened, full text on
|
||||
// hover), and at its end whether it's the one in use and the way to remove it.
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "bot", 18.0, if b.enabled { t.accent } else { t.text_faint });
|
||||
ui.vertical(|ui| {
|
||||
ui.add(egui::Label::new(RichText::new(&b.name).font(theme::semibold(theme::SMALL))).truncate());
|
||||
icons::show(ui, "bot", theme::icon::LG, if b.enabled { t.accent } else { t.text_faint });
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if confirming.as_ref() != Some(&b.name)
|
||||
&& icons::button(ui, "trash-2", theme::ControlSize::Small, false, &trf("Remove {name}", &[("name", &b.name)])).clicked()
|
||||
{
|
||||
ui.data_mut(|d| d.insert_temp(confirm_id, b.name.clone()));
|
||||
}
|
||||
if app.state.backend.as_ref() == Some(&b.name) {
|
||||
widgets::pill(ui, "In use", t.on_accent, t.accent);
|
||||
}
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.add(egui::Label::new(RichText::new(&b.name).font(theme::semibold(theme::BODY))).truncate());
|
||||
});
|
||||
});
|
||||
});
|
||||
{
|
||||
{
|
||||
let model_in_use = craft_anything_ai::model_in_use(b, app.backend_options.get(&b.name));
|
||||
let live_catalog = b.kind == BackendKind::AgentCli && craft_anything_ai::cli_agents::adapter_for(&b.model).has_model_catalog();
|
||||
// An API's model has its own line below; an agent app is named by its `model`.
|
||||
@@ -383,7 +402,12 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.style_mut().override_font_id = Some(egui::FontId::proportional(theme::CAPTION));
|
||||
let text = trf("It isn't there any more, so {program} runs in its place.", &[("program", instead)]);
|
||||
ui.add(egui::Label::new(RichText::new(text).color(t.warning).size(theme::CAPTION)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(text).color(t.warning).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION))),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
let path = std::path::Path::new(instead);
|
||||
if path.parent().is_some_and(|p| !p.as_os_str().is_empty()) && widgets::link(ui, "Use it").clicked() {
|
||||
use_program = Some((b.name.clone(), instead.clone()));
|
||||
@@ -402,7 +426,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
folder_drafts.remove(&b.name);
|
||||
}
|
||||
let mut text = folder_drafts.get(&b.name).cloned().unwrap_or_else(|| saved.clone());
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let label = ui.label(RichText::new(tr("Claude Code folder (CLAUDE_CONFIG_DIR)")).size(theme::CAPTION).color(t.text_dim));
|
||||
ui.label(
|
||||
RichText::new(tr("Its own sign-in, settings and conversations: another folder is another account. Empty: its usual folder."))
|
||||
@@ -424,7 +448,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if r.lost_focus() && text.trim() != saved {
|
||||
save_folder = Some((b.name.clone(), text.trim().to_string()));
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
// How hard it thinks: every Claude level for Claude, OpenAI's for the OpenAI-style APIs.
|
||||
let effort = craft_anything_ai::effort_in_use(b, app.backend_options.get(&b.name));
|
||||
@@ -436,7 +460,9 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.unwrap_or_else(|| app.backend_options.get(&b.name).and_then(|o| o.command.clone()).unwrap_or_default());
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(tr("Remote program"));
|
||||
ui.add(egui::TextEdit::singleline(&mut program).hint_text(&b.model).desired_width(200.0));
|
||||
ui.add(
|
||||
egui::TextEdit::singleline(&mut program).hint_text(&b.model).desired_width(200.0).frame(widgets::text_field_frame_compact(&t)),
|
||||
);
|
||||
if widgets::link(ui, "Apply").clicked() {
|
||||
remote_program = Some((b.name.clone(), program.clone()));
|
||||
}
|
||||
@@ -474,14 +500,13 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
} else if let Some(current) = model_in_use {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.style_mut().override_font_id = Some(egui::FontId::proportional(theme::CAPTION));
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(trf("Model: {model}", &[("model", ¤t)])).color(t.text_faint).size(theme::CAPTION))
|
||||
.truncate(),
|
||||
);
|
||||
match app.model_picker.as_ref().filter(|(n, _)| *n == b.name) {
|
||||
None => {
|
||||
if widgets::link(ui, "Change…").clicked() {
|
||||
if widgets::caption_link(ui, "Change…").clicked() {
|
||||
pick_model = Some(b.name.clone());
|
||||
}
|
||||
}
|
||||
@@ -490,9 +515,9 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(tr("Asking for its models…")).color(t.text_faint).size(theme::CAPTION));
|
||||
}
|
||||
Some((_, Some(models))) => {
|
||||
egui::ComboBox::from_id_salt(("model", &b.name)).icon(widgets::combo_icon).selected_text(¤t).show_ui(ui, |ui| {
|
||||
widgets::dropdown(("model", &b.name)).selected_text(¤t).show_ui(ui, |ui| {
|
||||
for m in models {
|
||||
if ui.selectable_label(*m == current, m).clicked() && *m != current {
|
||||
if widgets::menu_item(ui, *m == current, m).clicked() && *m != current {
|
||||
chosen_model = Some((b.name.clone(), m.clone()));
|
||||
}
|
||||
}
|
||||
@@ -502,14 +527,16 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let id = egui::Id::new(("other-model", &b.name));
|
||||
let mut other = ui.data_mut(|d| d.get_temp::<String>(id)).unwrap_or_default();
|
||||
let label = ui.label(RichText::new(tr("Another model")).color(t.text_faint).size(theme::CAPTION));
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut other).desired_width(140.0)).labelled_by(label.id);
|
||||
let r = ui
|
||||
.add(egui::TextEdit::singleline(&mut other).desired_width(140.0).frame(widgets::text_field_frame_compact(&t)))
|
||||
.labelled_by(label.id);
|
||||
let entered = r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
if (widgets::link(ui, "Use").clicked() || entered) && !other.trim().is_empty() && other.trim() != current {
|
||||
if (widgets::caption_link(ui, "Use").clicked() || entered) && !other.trim().is_empty() && other.trim() != current {
|
||||
chosen_model = Some((b.name.clone(), other.trim().to_string()));
|
||||
other.clear();
|
||||
}
|
||||
ui.data_mut(|d| d.insert_temp(id, other));
|
||||
if widgets::link(ui, "Cancel").clicked() {
|
||||
if widgets::caption_link(ui, "Cancel").clicked() {
|
||||
close_picker = true;
|
||||
}
|
||||
}
|
||||
@@ -517,11 +544,12 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if !effort_levels.is_empty() {
|
||||
ui.label(RichText::new(tr("Effort:")).color(t.text_faint).size(theme::CAPTION));
|
||||
let shown = effort.map_or("default", craft_anything_ai::Effort::as_str);
|
||||
egui::ComboBox::from_id_salt(("effort", &b.name)).icon(widgets::combo_icon).selected_text(shown).show_ui(ui, |ui| {
|
||||
widgets::dropdown(("effort", &b.name)).selected_text(shown).show_ui(ui, |ui| {
|
||||
// Claude always has a level; an OpenAI-style API is sent none until one is chosen.
|
||||
let unset = (effort_levels != craft_anything_ai::Effort::ALL).then_some(None);
|
||||
for e in unset.into_iter().chain(effort_levels.iter().map(|&e| Some(e))) {
|
||||
if ui.selectable_label(e == effort, e.map_or("default", craft_anything_ai::Effort::as_str)).clicked() && e != effort {
|
||||
if widgets::menu_item(ui, e == effort, e.map_or("default", craft_anything_ai::Effort::as_str)).clicked() && e != effort
|
||||
{
|
||||
chosen_effort = Some((b.name.clone(), e));
|
||||
}
|
||||
}
|
||||
@@ -541,15 +569,12 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.and_then(|value| choices.context.iter().find(|choice| choice.value == value))
|
||||
.map(|choice| tr(&choice.label))
|
||||
.unwrap_or_else(|| tr("Default"));
|
||||
egui::ComboBox::from_id_salt(("model-context", &b.name)).icon(widgets::combo_icon).selected_text(label).show_ui(
|
||||
ui,
|
||||
|ui| {
|
||||
changed |= ui.selectable_value(&mut draft.context, None, tr("Default")).changed();
|
||||
for choice in &choices.context {
|
||||
changed |= ui.selectable_value(&mut draft.context, Some(choice.value), tr(&choice.label)).changed();
|
||||
}
|
||||
},
|
||||
);
|
||||
widgets::dropdown(("model-context", &b.name)).selected_text(label).show_ui(ui, |ui| {
|
||||
changed |= widgets::menu_choice(ui, &mut draft.context, None, tr("Default"));
|
||||
for choice in &choices.context {
|
||||
changed |= widgets::menu_choice(ui, &mut draft.context, Some(choice.value), tr(&choice.label));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
if changed {
|
||||
@@ -559,7 +584,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
model_options_loading(ui, &b.name);
|
||||
if let Some(error) = &draft.error {
|
||||
ui.add(egui::Label::new(RichText::new(error).color(t.danger)).wrap());
|
||||
if icons::button(ui, "refresh-cw", 24.0, false, "Load model options").clicked() {
|
||||
if icons::button(ui, "refresh-cw", theme::ControlSize::Small, false, "Load model options").clicked() {
|
||||
tune_models.push(b.name.clone());
|
||||
}
|
||||
} else {
|
||||
@@ -571,8 +596,8 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
tune_models.push(b.name.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
// A key saved in the app silently wins over the environment's, so it can be replaced
|
||||
// here without removing the AI (#1358). Every API backend can need one; agent apps
|
||||
// sign in their own way. The field stays even when a key is saved, so a replacement
|
||||
@@ -581,15 +606,9 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
// A save or forget for this backend is still running: no later action may be
|
||||
// submitted until it finishes, so workers can't overtake one another. Other
|
||||
// backends keep their controls.
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.add_enabled_ui(!app.backend_key_pending.contains(&b.name), |ui| {
|
||||
if app.backend_keys.as_ref().and_then(|keys| keys.get(&b.name).copied()) == Some(true) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
widgets::pill(ui, "Key saved", t.success, t.raised);
|
||||
if widgets::secondary(ui, None, "Forget the key").clicked() {
|
||||
forget_key = Some(b.name.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
let saved = app.backend_keys.as_ref().and_then(|keys| keys.get(&b.name).copied()) == Some(true);
|
||||
let key = key_drafts.entry(b.name.clone()).or_default();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let r = ui.add(
|
||||
@@ -605,16 +624,18 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
// Keep the draft until the save succeeds; a failure must not lose it.
|
||||
save_key = Some((b.name.clone(), k));
|
||||
}
|
||||
if saved {
|
||||
widgets::pill(ui, "Key saved", t.success, t.raised);
|
||||
if widgets::ghost(ui, None, "Forget the key").clicked() {
|
||||
forget_key = Some(b.name.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.add_space(26.0);
|
||||
if app.state.backend.as_ref() == Some(&b.name) {
|
||||
widgets::pill(ui, "In use", t.on_accent, t.accent);
|
||||
} else if widgets::secondary(ui, None, "Use").clicked() {
|
||||
if app.state.backend.as_ref() != Some(&b.name) && widgets::secondary(ui, None, "Use").clicked() {
|
||||
pick = Some(b.name.clone());
|
||||
}
|
||||
// Who builds: the chosen one says so (click to go back to automatic).
|
||||
@@ -660,15 +681,13 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
// A key save or forget for this backend is still running: the save could
|
||||
// write the key back after the backend and its key are gone.
|
||||
ui.add_enabled_ui(!app.backend_key_pending.contains(&b.name), |ui| {
|
||||
if widgets::secondary(ui, Some("trash-2"), "Remove it and its key").clicked() {
|
||||
if widgets::danger(ui, Some("trash-2"), "Remove it and its key").clicked() {
|
||||
remove = Some(b.name.clone());
|
||||
}
|
||||
});
|
||||
if widgets::link(ui, "Keep it").clicked() {
|
||||
if widgets::ghost(ui, None, "Keep it").clicked() {
|
||||
ui.data_mut(|d| d.remove::<String>(confirm_id));
|
||||
}
|
||||
} else if icons::button(ui, "trash-2", 26.0, false, &trf("Remove {name}", &[("name", &b.name)])).clicked() {
|
||||
ui.data_mut(|d| d.insert_temp(confirm_id, b.name.clone()));
|
||||
}
|
||||
});
|
||||
if !b.enabled {
|
||||
@@ -682,7 +701,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(message).color(color).size(theme::CAPTION));
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
key_drafts.retain(|name, _| app.backends.iter().any(|backend| &backend.name == name));
|
||||
app.backend_key_inputs = key_drafts;
|
||||
@@ -753,7 +772,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if let Some(e) = extracts {
|
||||
app.set_role(craft_anything_ai::Role::Extractor, e);
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let detected = app.detected.clone().unwrap_or_default();
|
||||
widgets::caption(ui, "Found on this computer");
|
||||
let tab = ui
|
||||
@@ -767,7 +786,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
tab
|
||||
})
|
||||
.inner;
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if detected.is_empty() && !app.detecting {
|
||||
ui.label(
|
||||
RichText::new(tr("Nothing found yet. We look for API keys, local model servers (Ollama, LM Studio) and agent apps you already have. One on another port or computer can be added by its address below."))
|
||||
@@ -808,7 +827,9 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let mut left_ui =
|
||||
ui.new_child(egui::UiBuilder::new().max_rect(top.with_max_x(text_right.max(top.left()))).layout(egui::Layout::top_down(egui::Align::Min)));
|
||||
left_ui.add(egui::Label::new(RichText::new(&d.suggestion.name).font(theme::medium(theme::SMALL))).wrap());
|
||||
left_ui.add(egui::Label::new(RichText::new(&d.reason).color(t.text_faint).size(theme::CAPTION)).wrap());
|
||||
left_ui.add(
|
||||
egui::Label::new(RichText::new(&d.reason).color(t.text_faint).size(theme::CAPTION).line_height(Some(theme::leading(theme::CAPTION)))).wrap(),
|
||||
);
|
||||
ui.advance_cursor_after_rect(left_ui.min_rect().union(right));
|
||||
// A subscription key is worth pasting even when the environment already has one, so a
|
||||
// different key can be used without restarting the app.
|
||||
@@ -832,7 +853,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
server_form(app, ui);
|
||||
}
|
||||
@@ -842,10 +863,10 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
|
||||
/// The first run's AI step shows it too.
|
||||
pub(crate) fn server_form(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::caption(ui, "Add an AI by its address");
|
||||
ui.label(RichText::new(tr("Ollama or LM Studio on another computer, or any service that speaks the OpenAI API.")).color(t.text_faint).size(theme::CAPTION));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let form = &mut app.server_form;
|
||||
// `width` is the text's; the compact frame adds 8 points a side and its border.
|
||||
const FRAME: f32 = 18.0;
|
||||
@@ -924,7 +945,7 @@ fn builds(app: &mut CraftApp, ui: &mut Ui) {
|
||||
row(ui, "Builds at once", "How many projects may build at the same time. More wait their turn.", |ui| {
|
||||
changed |= number(ui, &mut b.parallel, 1..=8, "", "");
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if let Some(bytes) = app.pinned_copy_bytes {
|
||||
row(ui, "Pinned builds", "Size", |ui| {
|
||||
ui.label(craft_anything_engine::evidence::human_bytes(bytes));
|
||||
@@ -943,12 +964,12 @@ fn builds(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let table = craft_anything_engines::assets::Catalogue::built_in();
|
||||
row(ui, "Picture model", "What pictures and textures are made with.", |ui| {
|
||||
let current = table.image_model(a.image_model.as_deref()).or_else(|_| table.image_model(None)).map(|m| m.name.clone()).unwrap_or_default();
|
||||
egui::ComboBox::from_id_salt("image-model").icon(widgets::combo_icon).selected_text(current).show_ui(ui, |ui| {
|
||||
widgets::dropdown("image-model").selected_text(current).show_ui(ui, |ui| {
|
||||
for m in table.images() {
|
||||
let price = crate::usage::asset_cost_words(m.cost(craft_anything_engines::assets::Shape::Square));
|
||||
let label = format!("{} · {} {}", m.name, price, tr("a picture"));
|
||||
let on = a.image_model.as_deref() == Some(m.id.as_str());
|
||||
if ui.selectable_label(on, label).on_hover_text(&m.licence).clicked() && !on {
|
||||
if widgets::menu_item(ui, on, label).on_hover_text(&m.licence).clicked() && !on {
|
||||
a.image_model = Some(m.id.clone());
|
||||
changed = true;
|
||||
}
|
||||
@@ -974,7 +995,7 @@ fn plugins(app: &mut CraftApp, ui: &mut Ui) {
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let plugins = app.settings.plugins.mcp.clone();
|
||||
let wasm = app.settings.plugins.wasm.clone();
|
||||
if plugins.is_empty() && wasm.is_empty() {
|
||||
@@ -998,15 +1019,15 @@ fn plugins(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if widgets::toggle(ui, &mut app.settings.plugins.mcp[i].enabled, "On").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if icons::button(ui, "refresh-cw", 26.0, false, "Read its tools").clicked() {
|
||||
if icons::button(ui, "refresh-cw", theme::ControlSize::Small, false, "Read its tools").clicked() {
|
||||
app.act("plugins_refresh", serde_json::json!({"id": p.id}), tr("Read the plugin's tools"));
|
||||
}
|
||||
if icons::button(ui, "trash-2", 26.0, false, "Remove").clicked() {
|
||||
if icons::button(ui, "trash-2", theme::ControlSize::Small, false, "Remove").clicked() {
|
||||
app.act("plugins_remove", serde_json::json!({"id": p.id}), tr("Remove a plugin"));
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
for (i, p) in wasm.iter().enumerate() {
|
||||
widgets::panel(&t).show(ui, |ui| {
|
||||
@@ -1022,12 +1043,12 @@ fn plugins(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if widgets::toggle(ui, &mut app.settings.plugins.wasm[i].enabled, "On").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if icons::button(ui, "trash-2", 26.0, false, "Remove").clicked() {
|
||||
if icons::button(ui, "trash-2", theme::ControlSize::Small, false, "Remove").clicked() {
|
||||
app.act("plugins_remove", serde_json::json!({"id": p.id}), tr("Remove a plugin"));
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
if changed {
|
||||
app.settings_changed();
|
||||
@@ -1035,9 +1056,9 @@ fn plugins(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if !plugins.is_empty() || !wasm.is_empty() {
|
||||
ui.label(RichText::new(tr("Turning a plugin on or off takes effect from the next start.")).color(t.text_faint).size(theme::CAPTION));
|
||||
}
|
||||
ui.add_space(14.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
widgets::caption(ui, "Add a plugin");
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
let form = &mut app.state.plugin_form;
|
||||
ui.horizontal(|ui| {
|
||||
let id =
|
||||
@@ -1055,7 +1076,7 @@ fn plugins(app: &mut CraftApp, ui: &mut Ui) {
|
||||
);
|
||||
widgets::named(args, "Plugin arguments");
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let params = app.state.plugin_form.params();
|
||||
if widgets::primary_icon(ui, Some("plus"), "Add", params.is_some()).clicked()
|
||||
&& let Some(params) = params
|
||||
@@ -1080,7 +1101,7 @@ fn safety(app: &mut CraftApp, ui: &mut Ui) {
|
||||
);
|
||||
if !app.settings.ask_before_running {
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, "triangle-alert", 15.0, t.warning);
|
||||
icons::show(ui, "triangle-alert", theme::icon::MD, t.warning);
|
||||
ui.label(RichText::new(tr("Tools may now run code from what you open without asking. Turn this back on unless you're sure.")).color(t.warning));
|
||||
});
|
||||
}
|
||||
@@ -1101,7 +1122,7 @@ fn safety(app: &mut CraftApp, ui: &mut Ui) {
|
||||
|ui| {
|
||||
use craft_anything_engine::workspace::Questions;
|
||||
let sel = usize::from(app.settings.questions() == Questions::Decide);
|
||||
if let Some(i) = widgets::segmented(ui, &["Ask me", "Decide yourself"], sel, 30.0) {
|
||||
if let Some(i) = widgets::segmented(ui, &["Ask me", "Decide yourself"], sel, theme::ControlSize::Medium) {
|
||||
app.settings.questions = Some(if i == 0 { Questions::Ask } else { Questions::Decide });
|
||||
app.settings_changed();
|
||||
}
|
||||
@@ -1118,13 +1139,13 @@ fn safety(app: &mut CraftApp, ui: &mut Ui) {
|
||||
},
|
||||
);
|
||||
if let Some(p) = app.view.project.clone() {
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
widgets::caption(ui, &format!("{} {}", tr("Allowed in"), p));
|
||||
if app.view.project_allows.is_empty() {
|
||||
ui.label(RichText::new(tr("Nothing allowed yet.")).color(t.text_faint));
|
||||
}
|
||||
for tool in app.view.project_allows.clone() {
|
||||
ui.label(RichText::new(tool).font(theme::mono(12.0)));
|
||||
ui.label(RichText::new(tool).font(theme::mono(theme::CODE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
// Over the row icons when folded, in the corner when open.
|
||||
let layout = if fold { egui::Layout::top_down(egui::Align::Center) } else { egui::Layout::right_to_left(egui::Align::Min) };
|
||||
ui.with_layout(layout, |ui| {
|
||||
if icons::button(ui, icon, 24.0, false, tip).clicked() {
|
||||
if icons::button(ui, icon, theme::ControlSize::Small, false, tip).clicked() {
|
||||
app.state.sidebar_folded = !fold;
|
||||
}
|
||||
});
|
||||
@@ -65,12 +65,12 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
crate::pins::section(app, ui, fold);
|
||||
// Folded, the heading's words don't fit: the rule and the icon stay, on the same line, so
|
||||
// nothing moves when the sidebar folds.
|
||||
let refresh = |ui: &mut Ui| icons::button(ui, "refresh-cw", 22.0, false, "Look for projects again").clicked();
|
||||
let refresh = |ui: &mut Ui| icons::button(ui, "refresh-cw", theme::ControlSize::Small, false, "Look for projects again").clicked();
|
||||
let again = if fold {
|
||||
centred_row(ui, 22.0, refresh)
|
||||
} else {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
widgets::caption(ui, "Projects");
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), refresh).inner
|
||||
})
|
||||
@@ -79,7 +79,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if again {
|
||||
app.refresh_projects();
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
|
||||
if app.projects.is_empty() && !fold {
|
||||
egui::Frame::new().inner_margin(egui::Margin { left: 12, right: 8, top: 2, bottom: 2 }).show(ui, |ui| {
|
||||
@@ -111,7 +111,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
});
|
||||
});
|
||||
ui.painter().hline(ui.max_rect().x_range(), ui.cursor().top() + 1.0, egui::Stroke::new(1.0, t.separator));
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
if row(ui, "settings", "Settings", None, app.state.settings_open).clicked() {
|
||||
app.state.settings_open = !app.state.settings_open;
|
||||
}
|
||||
@@ -149,7 +149,13 @@ pub(crate) fn row(ui: &mut Ui, icon: &str, label: &str, status: Option<(egui::Co
|
||||
// Project names are shown as written; the app's own rows are translated.
|
||||
let text = if status.is_some() { label.to_string() } else { tr(label) };
|
||||
let icon_x = if fold { rect.center().x } else { rect.left() + 22.0 };
|
||||
icons::paint(ui, egui::Rect::from_center_size(egui::pos2(icon_x, rect.center().y), Vec2::splat(16.0)), icon, 16.0, if on { t.text } else { t.icon });
|
||||
icons::paint(
|
||||
ui,
|
||||
egui::Rect::from_center_size(egui::pos2(icon_x, rect.center().y), Vec2::splat(16.0)),
|
||||
icon,
|
||||
theme::icon::MD,
|
||||
if on { t.text } else { t.icon },
|
||||
);
|
||||
let name = match status {
|
||||
Some((_, s, _)) => format!("{text}, {}", tr(s)),
|
||||
None => text.clone(),
|
||||
@@ -180,7 +186,7 @@ pub(crate) fn row(ui: &mut Ui, icon: &str, label: &str, status: Option<(egui::Co
|
||||
match (pill, status) {
|
||||
(Some((color, g)), _) => {
|
||||
let r = egui::Rect::from_min_size(egui::pos2(rect.right() - 10.0 - g.size().x - 12.0, rect.center().y - 10.0), Vec2::new(g.size().x + 12.0, 20.0));
|
||||
ui.painter().rect_filled(r, t.r_sm(), color.gamma_multiply(0.16));
|
||||
ui.painter().rect_filled(r, r.height() / 2.0, color.gamma_multiply(0.16));
|
||||
ui.painter().galley(r.center() - g.size() / 2.0, g, color);
|
||||
}
|
||||
(None, Some((color, _, _))) => {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//! Design system: two themes (Studio dark, Studio Light), colour tokens, radii and type.
|
||||
//!
|
||||
//! A calm desktop look: neutral graphite (or near-white) surfaces, a slightly darker sidebar,
|
||||
//! soft rounded cards and controls, sentence-case DM Sans throughout, and ink-filled main buttons.
|
||||
//! lightly rounded cards and controls, sentence-case Figtree throughout, and ink-filled main buttons.
|
||||
//! Indigo is the app colour for highlights, progress, links and selection.
|
||||
//! Widgets read [`Tokens::get`] instead of hard-coding colours, so a theme switch applies everywhere.
|
||||
//! Confidence has its own fixed palette so "how sure are we" reads the same in both themes.
|
||||
|
||||
use craft_anything_engine::evidence::Confidence;
|
||||
use egui::{Color32, CornerRadius, FontData, FontDefinitions, FontFamily, FontId, Stroke, TextStyle, Visuals};
|
||||
use egui::epaint::text::VariationCoords;
|
||||
use egui::{Color32, CornerRadius, FontData, FontDefinitions, FontFamily, FontId, FontTweak, Stroke, TextStyle, Visuals};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -56,6 +57,8 @@ pub struct Tokens {
|
||||
pub card_border: Color32,
|
||||
/// A card a step above `card` (hovered cards, chips).
|
||||
pub raised: Color32,
|
||||
/// What can be typed in or pressed: a shade lighter than the card it sits on, so it reads
|
||||
/// as something to use.
|
||||
pub field: Color32,
|
||||
pub field_border: Color32,
|
||||
pub hover: Color32,
|
||||
@@ -118,10 +121,10 @@ impl Tokens {
|
||||
card: Color32::from_rgb(0x1b, 0x1c, 0x1f),
|
||||
card_border: Color32::from_rgb(0x34, 0x34, 0x36),
|
||||
raised: Color32::from_rgb(0x22, 0x23, 0x25),
|
||||
field: Color32::from_rgb(0x1b, 0x1c, 0x1f),
|
||||
field: Color32::from_rgb(0x22, 0x23, 0x26),
|
||||
field_border: Color32::from_rgb(0x6c, 0x6c, 0x6c),
|
||||
hover: Color32::from_rgb(0x22, 0x23, 0x25),
|
||||
pressed: Color32::from_rgb(0x2d, 0x2e, 0x30),
|
||||
hover: Color32::from_rgb(0x2a, 0x2b, 0x2e),
|
||||
pressed: Color32::from_rgb(0x33, 0x34, 0x37),
|
||||
text: Color32::from_rgb(0xf2, 0xf1, 0xee),
|
||||
text_dim: Color32::from_rgb(0xb3, 0xb3, 0xb2),
|
||||
text_faint: Color32::from_rgb(0x8d, 0x8d, 0x8d),
|
||||
@@ -137,9 +140,9 @@ impl Tokens {
|
||||
warning: BEST_GUESS,
|
||||
success: Color32::from_rgb(0x5b, 0xbf, 0x8f),
|
||||
code_bg: Color32::from_rgb(0x06, 0x06, 0x07),
|
||||
radius_sm: 6.0,
|
||||
radius: 8.0,
|
||||
radius_lg: 12.0,
|
||||
radius_sm: RADIUS_SM,
|
||||
radius: RADIUS,
|
||||
radius_lg: RADIUS_LG,
|
||||
},
|
||||
// getartcraft.com's light: warm paper (#f2f1ee), its sunken #e9e8e4 for the sidebar,
|
||||
// raised #faf9f7 for cards, ink #101014.
|
||||
@@ -150,7 +153,7 @@ impl Tokens {
|
||||
card: Color32::from_rgb(0xfa, 0xf9, 0xf7),
|
||||
card_border: Color32::from_rgb(0xce, 0xcd, 0xcb),
|
||||
raised: Color32::from_rgb(0xe9, 0xe8, 0xe4),
|
||||
field: Color32::from_rgb(0xfa, 0xf9, 0xf7),
|
||||
field: Color32::WHITE,
|
||||
field_border: Color32::from_rgb(0x86, 0x85, 0x85),
|
||||
hover: Color32::from_rgb(0xe4, 0xe4, 0xe1),
|
||||
pressed: Color32::from_rgb(0xdb, 0xda, 0xd8),
|
||||
@@ -169,9 +172,9 @@ impl Tokens {
|
||||
warning: Color32::from_rgb(0x9a, 0x67, 0x00),
|
||||
success: Color32::from_rgb(0x12, 0x75, 0x36),
|
||||
code_bg: Color32::from_rgb(0xe9, 0xe8, 0xe4),
|
||||
radius_sm: 6.0,
|
||||
radius: 8.0,
|
||||
radius_lg: 12.0,
|
||||
radius_sm: RADIUS_SM,
|
||||
radius: RADIUS,
|
||||
radius_lg: RADIUS_LG,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -196,15 +199,21 @@ impl Tokens {
|
||||
}
|
||||
}
|
||||
|
||||
/// Corners: tags and segments, controls and fields, cards and dialogs. Rounded, but only just.
|
||||
const RADIUS_SM: f32 = 4.0;
|
||||
const RADIUS: f32 = 6.0;
|
||||
const RADIUS_LG: f32 = 8.0;
|
||||
|
||||
fn tokens_id() -> egui::Id {
|
||||
egui::Id::new("craft-anything-theme")
|
||||
}
|
||||
|
||||
// ---- fonts -------------------------------------------------------------------------------------
|
||||
|
||||
pub static DM_SANS_REGULAR: &[u8] = include_bytes!("../../../assets/fonts/DMSans-Regular.ttf");
|
||||
pub static DM_SANS_MEDIUM: &[u8] = include_bytes!("../../../assets/fonts/DMSans-Medium.ttf");
|
||||
pub static DM_SANS_BOLD: &[u8] = include_bytes!("../../../assets/fonts/DMSans-Bold.ttf");
|
||||
/// Figtree, a variable font: one file set to each weight used here.
|
||||
pub static FIGTREE: &[u8] = include_bytes!("../../../assets/fonts/Figtree-Variable.ttf");
|
||||
/// The faces cut from it: text, labels, and headings and emphasis.
|
||||
const FIGTREE_FACES: [(&str, f32); 3] = [("Figtree", 400.0), ("Figtree-Medium", 500.0), ("Figtree-SemiBold", 600.0)];
|
||||
pub static JETBRAINS_MONO: &[u8] = include_bytes!("../../../assets/fonts/JetBrainsMono-Regular.ttf");
|
||||
|
||||
/// A font from the optional craft-fonts build input (empty unless built with `CRAFT_FONTS_DIR`).
|
||||
@@ -218,17 +227,15 @@ pub struct CraftFont {
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/craft_fonts.rs"));
|
||||
|
||||
/// Install DM Sans (three weights: body, labels and bold for headings; it has no static
|
||||
/// SemiBold), JetBrains Mono (code), plus any craft-fonts as fallbacks.
|
||||
/// Install Figtree (three weights: text, labels, and semibold for headings), JetBrains Mono
|
||||
/// (code), plus any craft-fonts as fallbacks.
|
||||
pub fn install_fonts(ctx: &egui::Context) {
|
||||
let mut fonts = FontDefinitions::default();
|
||||
let mut add = |name: &str, bytes: &'static [u8]| {
|
||||
fonts.font_data.insert(name.to_owned(), Arc::new(FontData::from_static(bytes)));
|
||||
};
|
||||
add("DMSans", DM_SANS_REGULAR);
|
||||
add("DMSans-Medium", DM_SANS_MEDIUM);
|
||||
add("DMSans-Bold", DM_SANS_BOLD);
|
||||
add("JetBrainsMono", JETBRAINS_MONO);
|
||||
for (name, weight) in FIGTREE_FACES {
|
||||
let tweak = FontTweak { coords: VariationCoords::new([(*b"wght", weight)]), ..Default::default() };
|
||||
fonts.font_data.insert(name.to_owned(), Arc::new(FontData::from_static(FIGTREE).tweak(tweak)));
|
||||
}
|
||||
fonts.font_data.insert("JetBrainsMono".to_owned(), Arc::new(FontData::from_static(JETBRAINS_MONO)));
|
||||
let mut fallbacks = Vec::new();
|
||||
let mut bold_fallbacks = Vec::new();
|
||||
for f in CRAFT_FONTS {
|
||||
@@ -243,7 +250,7 @@ pub fn install_fonts(ctx: &egui::Context) {
|
||||
// Sans first: a mincho/serif fallback makes Japanese and Chinese UI text look like prose.
|
||||
let fallbacks = sans_first(fallbacks);
|
||||
let bold_fallbacks = sans_first(bold_fallbacks);
|
||||
fonts.families.entry(FontFamily::Proportional).or_default().insert(0, "DMSans".to_owned());
|
||||
fonts.families.entry(FontFamily::Proportional).or_default().insert(0, "Figtree".to_owned());
|
||||
fonts.families.entry(FontFamily::Monospace).or_default().insert(0, "JetBrainsMono".to_owned());
|
||||
for fam in [FontFamily::Proportional, FontFamily::Monospace] {
|
||||
fonts.families.entry(fam).or_default().extend(fallbacks.iter().cloned());
|
||||
@@ -255,12 +262,12 @@ pub fn install_fonts(ctx: &egui::Context) {
|
||||
ctx.set_fonts(fonts);
|
||||
}
|
||||
|
||||
/// The medium and semibold families: DM Sans' own weight first, then a script's bold face from
|
||||
/// The medium and semibold families: Figtree's own weight first, then a script's bold face from
|
||||
/// craft-fonts where it has one, then the whole proportional stack. Without the bold fallback a
|
||||
/// heading in Japanese or Chinese fell back to that script's regular face, so it looked lighter
|
||||
/// than the Latin beside it (#1808).
|
||||
fn weighted_families(base: &[String], bold: &[String]) -> Vec<(FontFamily, Vec<String>)> {
|
||||
[("medium", "DMSans-Medium"), ("semibold", "DMSans-Bold")]
|
||||
[("medium", "Figtree-Medium"), ("semibold", "Figtree-SemiBold")]
|
||||
.into_iter()
|
||||
.map(|(fam, primary)| {
|
||||
let mut stack = vec![primary.to_owned()];
|
||||
@@ -316,20 +323,131 @@ pub fn semibold(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Name("semibold".into()))
|
||||
}
|
||||
/// The type scale: every text size in the interface is one of these.
|
||||
/// Headings (`heading`, DM Sans bold), largest first: a screen's title, a step or a dialog's
|
||||
/// Headings (`heading`, Figtree semibold), largest first: a screen's title, a step or a dialog's
|
||||
/// title, a card's or a list item's title.
|
||||
pub const TITLE: f32 = 26.0;
|
||||
pub const SECTION: f32 = 18.0;
|
||||
pub const CARD: f32 = 16.0;
|
||||
/// Text: the line under a title (and Simple mode's main field), reading text, secondary text
|
||||
/// and list rows, fine print (paths, counts, notes), and tags painted in tight spots.
|
||||
/// and list rows, the labels of small controls and section captions, fine print (paths, counts,
|
||||
/// notes), and tags painted in tight spots.
|
||||
pub const LEAD: f32 = 17.0;
|
||||
pub const BODY: f32 = 15.0;
|
||||
pub const SMALL: f32 = 14.0;
|
||||
pub const LABEL: f32 = 13.0;
|
||||
pub const CAPTION: f32 = 12.0;
|
||||
pub const TINY: f32 = 11.0;
|
||||
/// Code, paths and numbers in JetBrains Mono (the workbench's dense lists may use `TINY`).
|
||||
pub const CODE: f32 = 12.5;
|
||||
|
||||
/// A heading: DM Sans bold, at one of the heading sizes above.
|
||||
/// The spacing steps: every gap between things is one of these.
|
||||
pub mod space {
|
||||
/// A nudge between two lines that belong together.
|
||||
pub const XXS: f32 = 2.0;
|
||||
pub const XS: f32 = 4.0;
|
||||
pub const SM: f32 = 8.0;
|
||||
pub const MD: f32 = 12.0;
|
||||
pub const LG: f32 = 16.0;
|
||||
pub const XL: f32 = 24.0;
|
||||
pub const XXL: f32 = 32.0;
|
||||
}
|
||||
|
||||
/// Icon sizes.
|
||||
pub mod icon {
|
||||
pub const XS: f32 = 12.0;
|
||||
pub const SM: f32 = 14.0;
|
||||
pub const MD: f32 = 16.0;
|
||||
pub const LG: f32 = 20.0;
|
||||
pub const XL: f32 = 24.0;
|
||||
pub const XXL: f32 = 32.0;
|
||||
}
|
||||
|
||||
/// The padding inside frames, built from the spacing steps.
|
||||
pub mod pad {
|
||||
use egui::Margin;
|
||||
/// Around the rows of a menu or a dropdown's list.
|
||||
pub const MENU: Margin = Margin::same(4);
|
||||
/// Code blocks and dense workbench boxes.
|
||||
pub const TIGHT: Margin = Margin::same(8);
|
||||
pub const PANEL: Margin = Margin::same(12);
|
||||
pub const CARD: Margin = Margin::same(16);
|
||||
/// Dialogs, side panes and a screen's main card.
|
||||
pub const ROOMY: Margin = Margin::same(24);
|
||||
/// A card that holds one row.
|
||||
pub const ROW: Margin = Margin::symmetric(16, 12);
|
||||
/// A banner across the window.
|
||||
pub const BAR: Margin = Margin::symmetric(16, 8);
|
||||
/// A tag around a word or two.
|
||||
pub const CHIP: Margin = Margin::symmetric(8, 4);
|
||||
/// A strip that only keeps its content off the edges.
|
||||
pub const GUTTER: Margin = Margin::symmetric(8, 0);
|
||||
/// A text field as tall as a large control, and one as tall as a medium control.
|
||||
pub const FIELD: Margin = Margin::symmetric(12, 10);
|
||||
pub const FIELD_COMPACT: Margin = Margin::symmetric(8, 6);
|
||||
}
|
||||
|
||||
/// The sizes a control (button, icon button, switch, field) comes in. Height, label size, side
|
||||
/// padding and icon size go together, so two controls of one size always line up.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum ControlSize {
|
||||
/// Inline and dense: toolbars, rows of a list, the workbench.
|
||||
Small,
|
||||
/// The default.
|
||||
#[default]
|
||||
Medium,
|
||||
/// A screen's main switch or field.
|
||||
Large,
|
||||
/// The one action a screen is for (Simple mode's Start).
|
||||
Hero,
|
||||
}
|
||||
|
||||
impl ControlSize {
|
||||
pub const ALL: [ControlSize; 4] = [ControlSize::Small, ControlSize::Medium, ControlSize::Large, ControlSize::Hero];
|
||||
|
||||
pub const fn height(self) -> f32 {
|
||||
match self {
|
||||
ControlSize::Small => 24.0,
|
||||
ControlSize::Medium => 32.0,
|
||||
ControlSize::Large => 40.0,
|
||||
ControlSize::Hero => 48.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// The label's size (set in the medium weight).
|
||||
pub const fn text(self) -> f32 {
|
||||
match self {
|
||||
ControlSize::Small => LABEL,
|
||||
// The size of the text around it, and of what is typed into a field beside it.
|
||||
ControlSize::Medium | ControlSize::Large => BODY,
|
||||
ControlSize::Hero => CARD,
|
||||
}
|
||||
}
|
||||
|
||||
/// The room left and right of the label.
|
||||
pub const fn pad_x(self) -> f32 {
|
||||
match self {
|
||||
ControlSize::Small => space::MD,
|
||||
ControlSize::Medium => space::LG,
|
||||
ControlSize::Large | ControlSize::Hero => space::XL,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn icon(self) -> f32 {
|
||||
match self {
|
||||
ControlSize::Small => icon::SM,
|
||||
ControlSize::Medium | ControlSize::Large => icon::MD,
|
||||
ControlSize::Hero => icon::LG,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The line height for a paragraph set at `size`: a little more air than the font's own, which
|
||||
/// packs wrapped lines tightly.
|
||||
pub fn leading(size: f32) -> f32 {
|
||||
(size * 1.45).round()
|
||||
}
|
||||
|
||||
/// A heading: Figtree semibold, at one of the heading sizes above.
|
||||
pub fn heading(text: impl Into<String>, size: f32) -> egui::RichText {
|
||||
egui::RichText::new(text).font(semibold(size))
|
||||
}
|
||||
@@ -349,10 +467,9 @@ pub fn mix(a: Color32, b: Color32, t: f32) -> Color32 {
|
||||
Color32::from_rgba_premultiplied(m(a.r(), b.r()), m(a.g(), b.g()), m(a.b(), b.b()), m(a.a(), b.a()))
|
||||
}
|
||||
|
||||
/// A short label (captions, buttons, the title bar) in sentence case. `size` is the old
|
||||
/// uppercase-mono size; mixed-case DM Sans needs a point and a half more to read the same.
|
||||
/// A short label (captions, buttons, the title bar): Figtree medium at one of the text sizes.
|
||||
pub fn label_text(text: &str, size: f32) -> egui::RichText {
|
||||
egui::RichText::new(text).font(medium(size + 1.5))
|
||||
egui::RichText::new(text).font(medium(size))
|
||||
}
|
||||
|
||||
/// Scroll bars that can always be seen and grabbed. egui's thin preset paints the thumb in the
|
||||
@@ -362,16 +479,18 @@ pub fn label_text(text: &str, size: f32) -> egui::RichText {
|
||||
pub fn scroll_style() -> egui::style::ScrollStyle {
|
||||
egui::style::ScrollStyle {
|
||||
floating: true,
|
||||
bar_width: 10.0,
|
||||
bar_width: 8.0,
|
||||
floating_width: 6.0,
|
||||
floating_allocated_width: 8.0,
|
||||
handle_min_length: space::XXL,
|
||||
foreground_color: true,
|
||||
// No track: only the thumb shows, a pill that thickens a little under the pointer.
|
||||
dormant_background_opacity: 0.0,
|
||||
active_background_opacity: 0.5,
|
||||
interact_background_opacity: 0.8,
|
||||
active_background_opacity: 0.0,
|
||||
interact_background_opacity: 0.0,
|
||||
dormant_handle_opacity: SCROLL_THUMB_AT_REST,
|
||||
active_handle_opacity: 0.65,
|
||||
interact_handle_opacity: 0.85,
|
||||
active_handle_opacity: 0.6,
|
||||
interact_handle_opacity: 0.8,
|
||||
..egui::style::ScrollStyle::solid()
|
||||
}
|
||||
}
|
||||
@@ -379,12 +498,19 @@ pub fn scroll_style() -> egui::style::ScrollStyle {
|
||||
/// How opaque a scroll bar's thumb is at rest (over the text colour).
|
||||
const SCROLL_THUMB_AT_REST: f32 = 0.5;
|
||||
|
||||
/// How far one notch of the mouse wheel scrolls, in points. egui's own step is 40, which takes
|
||||
/// two or three turns for what a browser scrolls in one; it still eases to the new place.
|
||||
pub const WHEEL_STEP: f32 = 100.0;
|
||||
|
||||
/// Apply a theme. `roomy` = Beginner mode (bigger type, more air).
|
||||
pub fn apply(ctx: &egui::Context, kind: ThemeKind, roomy: bool) {
|
||||
let t = Tokens::for_kind(kind);
|
||||
ctx.data_mut(|d| d.insert_temp(tokens_id(), t));
|
||||
ctx.set_theme(if t.dark() { egui::Theme::Dark } else { egui::Theme::Light });
|
||||
let mut v = if t.dark() { Visuals::dark() } else { Visuals::light() };
|
||||
// Each glyph on a whole pixel. egui's default draws a glyph at one of four offsets inside a
|
||||
// pixel for more even spacing, which softens small text on a display at 100 %.
|
||||
v.text_options.subpixel_binning = false;
|
||||
v.panel_fill = t.chrome;
|
||||
v.window_fill = t.card;
|
||||
v.window_stroke = Stroke::new(1.0, t.card_border);
|
||||
@@ -398,26 +524,30 @@ pub fn apply(ctx: &egui::Context, kind: ThemeKind, roomy: bool) {
|
||||
v.window_corner_radius = t.r_lg();
|
||||
v.menu_corner_radius = t.r();
|
||||
v.window_shadow = egui::Shadow { offset: [0, 10], blur: 28, spread: 0, color: t.shadow };
|
||||
v.popup_shadow = egui::Shadow { offset: [0, 4], blur: 14, spread: 0, color: t.shadow };
|
||||
v.popup_shadow = egui::Shadow { offset: [0, 8], blur: 24, spread: 0, color: t.shadow };
|
||||
v.text_edit_bg_color = Some(t.field);
|
||||
v.selection.bg_fill = t.accent_soft;
|
||||
v.selection.stroke = Stroke::new(1.0, t.accent);
|
||||
v.handle_shape = egui::style::HandleShape::Circle;
|
||||
v.striped = false;
|
||||
v.indent_has_left_vline = false;
|
||||
let r = t.r_sm();
|
||||
// egui's own buttons, combo boxes and fields share the corner of ours.
|
||||
let r = t.r();
|
||||
let w = &mut v.widgets;
|
||||
w.noninteractive.bg_fill = t.card;
|
||||
w.noninteractive.weak_bg_fill = t.card;
|
||||
w.noninteractive.bg_stroke = Stroke::new(1.0, t.separator);
|
||||
w.noninteractive.fg_stroke = Stroke::new(1.0, t.text_dim);
|
||||
w.noninteractive.corner_radius = r;
|
||||
// Buttons and combo boxes are hairline boxes on the surface (weak fill transparent at rest).
|
||||
w.noninteractive.corner_radius = t.r_sm();
|
||||
// Buttons and combo boxes are field-coloured boxes with a hairline edge.
|
||||
// One edge for every control, ours and egui's: soft at rest, firmer under the pointer, the
|
||||
// app colour while it's pressed or open.
|
||||
for (wv, bg, weak, stroke) in [
|
||||
(&mut w.inactive, t.field, Color32::TRANSPARENT, t.field_border),
|
||||
(&mut w.hovered, t.hover, t.hover, t.text_faint),
|
||||
(&mut w.inactive, t.field, t.field, t.card_border),
|
||||
(&mut w.hovered, t.hover, t.hover, t.field_border),
|
||||
(&mut w.active, t.pressed, t.pressed, t.accent),
|
||||
(&mut w.open, t.hover, t.hover, t.field_border),
|
||||
// An open dropdown is edged in the app colour, like a field being typed in.
|
||||
(&mut w.open, t.hover, t.hover, t.accent),
|
||||
] {
|
||||
wv.bg_fill = bg;
|
||||
wv.weak_bg_fill = weak;
|
||||
@@ -427,23 +557,29 @@ pub fn apply(ctx: &egui::Context, kind: ThemeKind, roomy: bool) {
|
||||
wv.expansion = 0.0;
|
||||
}
|
||||
ctx.set_visuals(v);
|
||||
// Simple mode is for anyone, including people who find small text hard to read.
|
||||
let body = if roomy { 16.0 } else { 13.0 };
|
||||
// Simple mode is for anyone, including people who find small text hard to read. egui's own
|
||||
// controls (combo boxes, menu rows) are as tall as ours of the mode's size, with its label.
|
||||
let control = if roomy { ControlSize::Medium } else { ControlSize::Small };
|
||||
ctx.global_style_mut(|s| {
|
||||
s.text_styles = [
|
||||
(TextStyle::Small, FontId::proportional(if roomy { 13.5 } else { 11.0 })),
|
||||
(TextStyle::Body, FontId::proportional(body)),
|
||||
(TextStyle::Button, FontId::proportional(body)),
|
||||
(TextStyle::Small, FontId::proportional(if roomy { LABEL } else { TINY })),
|
||||
(TextStyle::Body, FontId::proportional(if roomy { BODY } else { LABEL })),
|
||||
(TextStyle::Button, FontId::proportional(control.text())),
|
||||
(TextStyle::Heading, semibold(if roomy { SECTION } else { CARD })),
|
||||
(TextStyle::Monospace, FontId::monospace(if roomy { 13.5 } else { 12.5 })),
|
||||
(TextStyle::Monospace, FontId::monospace(if roomy { LABEL } else { CODE })),
|
||||
]
|
||||
.into();
|
||||
s.spacing.item_spacing = if roomy { egui::vec2(10.0, 8.0) } else { egui::vec2(8.0, 5.0) };
|
||||
s.spacing.button_padding = if roomy { egui::vec2(12.0, 6.0) } else { egui::vec2(9.0, 4.0) };
|
||||
s.spacing.interact_size = egui::vec2(24.0, if roomy { 28.0 } else { 24.0 });
|
||||
s.spacing.menu_margin = egui::Margin::same(6);
|
||||
s.spacing.window_margin = egui::Margin::same(18);
|
||||
s.spacing.icon_width = 14.0;
|
||||
s.spacing.item_spacing = egui::vec2(space::SM, if roomy { space::SM } else { space::XS });
|
||||
// Padding that brings a line of the label up to the control's height; a row of plain text
|
||||
// stays as tall as a small control.
|
||||
let pad_y = ((control.height() - control.text() * 1.2) / 2.0).round();
|
||||
s.spacing.button_padding = egui::vec2(if roomy { space::MD } else { space::SM }, pad_y);
|
||||
s.spacing.interact_size = egui::Vec2::splat(ControlSize::Small.height());
|
||||
s.spacing.menu_margin = pad::MENU;
|
||||
// A dropdown's list shows nine rows and a half before it scrolls: the half row says there's more.
|
||||
s.spacing.combo_height = 9.5 * (ControlSize::Medium.height() + space::XXS);
|
||||
s.spacing.window_margin = pad::ROOMY;
|
||||
s.spacing.icon_width = icon::SM;
|
||||
s.spacing.scroll = scroll_style();
|
||||
s.spacing.tooltip_width = 320.0;
|
||||
s.interaction.tooltip_delay = 0.3;
|
||||
@@ -521,6 +657,63 @@ mod tests {
|
||||
assert!(checked > 40, "the source scan checked only {checked} text sizes");
|
||||
}
|
||||
|
||||
/// Outside this file nothing writes a gap, a frame's padding, a colour or a font size as a
|
||||
/// number: screens take them from the scale, so they can't drift apart again. (A size worked
|
||||
/// out from another, such as `body.size + 2.0`, is left to the reviewer.)
|
||||
#[test]
|
||||
fn screens_take_sizes_and_colours_from_the_scale() {
|
||||
let followed_by_digit =
|
||||
|line: &str, marker: &str| line.match_indices(marker).any(|(at, m)| line[at + m.len()..].starts_with(|c: char| c.is_ascii_digit()));
|
||||
let src = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
let mut found = Vec::new();
|
||||
let mut files = 0;
|
||||
for entry in std::fs::read_dir(&src).unwrap().flatten() {
|
||||
let path = entry.path();
|
||||
if path.extension().is_none_or(|e| e != "rs") || path.file_name().is_some_and(|n| n == "theme.rs") {
|
||||
continue;
|
||||
}
|
||||
files += 1;
|
||||
for (n, line) in std::fs::read_to_string(&path).unwrap().lines().enumerate() {
|
||||
if line.trim_start().starts_with("//") {
|
||||
continue;
|
||||
}
|
||||
let numbered =
|
||||
["add_space(", "Margin::same(", "Margin::symmetric(", "medium(", "semibold(", "mono(", "FontId::proportional(", "FontId::monospace("];
|
||||
let named = ["Color32::from_rgb", "Color32::from_gray", "Color32::WHITE", "Color32::BLACK"];
|
||||
if numbered.iter().any(|m| followed_by_digit(line, m)) || named.iter().any(|m| line.contains(m)) {
|
||||
found.push(format!("{}:{}: {}", path.file_name().unwrap().to_string_lossy(), n + 1, line.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(files > 10, "the source scan found only {files} files");
|
||||
assert!(
|
||||
found.is_empty(),
|
||||
"use the theme's scale (`space`, `pad`, the text sizes, `Tokens`):
|
||||
{}",
|
||||
found.join(
|
||||
"
|
||||
"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// Controls step up evenly, and each size's label and icon come from the scale.
|
||||
#[test]
|
||||
fn control_sizes_step_up_on_the_grid() {
|
||||
let texts = [TINY, CAPTION, LABEL, SMALL, BODY, CARD, LEAD, SECTION, TITLE];
|
||||
let icons = [icon::XS, icon::SM, icon::MD, icon::LG, icon::XL, icon::XXL];
|
||||
for pair in ControlSize::ALL.windows(2) {
|
||||
assert_eq!(pair[1].height() - pair[0].height(), space::SM, "{pair:?}");
|
||||
assert!(pair[1].text() >= pair[0].text() && pair[1].pad_x() >= pair[0].pad_x() && pair[1].icon() >= pair[0].icon(), "{pair:?}");
|
||||
}
|
||||
for size in ControlSize::ALL {
|
||||
assert!(texts.contains(&size.text()) && icons.contains(&size.icon()), "{size:?}");
|
||||
// The label and the padding around it fit the height.
|
||||
assert!(size.text() * 1.3 + space::XS <= size.height(), "{size:?}");
|
||||
}
|
||||
assert_eq!(ControlSize::default(), ControlSize::Medium);
|
||||
}
|
||||
|
||||
/// The text between `open`'s parenthesis and its match, or `None` when it isn't closed on
|
||||
/// this line.
|
||||
fn call_text(line: &str, open: usize) -> Option<&str> {
|
||||
@@ -668,7 +861,7 @@ mod tests {
|
||||
}
|
||||
|
||||
/// Releases are built with craft-fonts (#19), and so is CI; a build without them has only
|
||||
/// DM Sans, and shows other scripts as boxes.
|
||||
/// Figtree, and shows other scripts as boxes.
|
||||
#[test]
|
||||
fn with_craft_fonts_every_script_people_type_shows() {
|
||||
if CRAFT_FONTS.is_empty() {
|
||||
@@ -713,17 +906,17 @@ mod tests {
|
||||
/// Japanese or Chinese headings aren't lighter than the Latin beside them.
|
||||
#[test]
|
||||
fn a_heading_takes_a_scripts_bold_face_before_its_regular_one() {
|
||||
let base = vec!["DMSans".to_string(), "craft:japanese:regular".to_string()];
|
||||
let base = vec!["Figtree".to_string(), "craft:japanese:regular".to_string()];
|
||||
let bold = vec!["craft:japanese:bold".to_string()];
|
||||
let families = weighted_families(&base, &bold);
|
||||
let stack = |name: &str| {
|
||||
families.iter().find(|(f, _)| f == &FontFamily::Name(name.into())).map(|(_, s)| s.clone()).unwrap_or_else(|| panic!("{name} is installed"))
|
||||
};
|
||||
assert_eq!(stack("semibold"), ["DMSans-Bold", "craft:japanese:bold", "DMSans", "craft:japanese:regular"]);
|
||||
assert_eq!(stack("medium"), ["DMSans-Medium", "craft:japanese:bold", "DMSans", "craft:japanese:regular"]);
|
||||
assert_eq!(stack("semibold"), ["Figtree-SemiBold", "craft:japanese:bold", "Figtree", "craft:japanese:regular"]);
|
||||
assert_eq!(stack("medium"), ["Figtree-Medium", "craft:japanese:bold", "Figtree", "craft:japanese:regular"]);
|
||||
// Without a bold face the stack is what it always was.
|
||||
let regular_only = weighted_families(&base, &[]);
|
||||
assert_eq!(regular_only[1].1, ["DMSans-Bold", "DMSans", "craft:japanese:regular"]);
|
||||
assert_eq!(regular_only[1].1, ["Figtree-SemiBold", "Figtree", "craft:japanese:regular"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -769,8 +962,17 @@ mod tests {
|
||||
fn contrast_meets_wcag_aa_in_both_themes() {
|
||||
for k in ThemeKind::ALL {
|
||||
let t = Tokens::for_kind(k);
|
||||
// `success` is text too: the Clean room and Ready pills.
|
||||
for (name, fg) in [("text", t.text), ("text_dim", t.text_dim), ("text_faint", t.text_faint), ("accent_ink", t.accent_ink), ("success", t.success)] {
|
||||
// `success` is text too (the Clean room and Ready pills), and so is `danger` (warnings
|
||||
// in words).
|
||||
let inks = [
|
||||
("text", t.text),
|
||||
("text_dim", t.text_dim),
|
||||
("text_faint", t.text_faint),
|
||||
("accent_ink", t.accent_ink),
|
||||
("success", t.success),
|
||||
("danger", t.danger),
|
||||
];
|
||||
for (name, fg) in inks {
|
||||
for bg in [t.canvas, t.card, t.chrome, t.raised] {
|
||||
assert!(contrast(fg, bg) >= 4.5, "{k:?} {name} on {bg:?}: {:.2}", contrast(fg, bg));
|
||||
}
|
||||
@@ -779,8 +981,10 @@ mod tests {
|
||||
// Send's icon on its hover colour (an icon, so 3:1).
|
||||
assert!(contrast(t.on_accent, t.accent_hover) >= 3.0, "{k:?} icon on the hover colour: {:.2}", contrast(t.on_accent, t.accent_hover));
|
||||
assert!(contrast(t.field_border, t.canvas) >= 3.0, "{k:?} control borders: {:.2}", contrast(t.field_border, t.canvas));
|
||||
// Main buttons are ink-filled with the canvas colour as their label.
|
||||
// Main buttons are ink-filled with the canvas colour as their label; a button that
|
||||
// deletes is filled in the danger colour, with the same label.
|
||||
assert!(contrast(t.canvas, t.text) >= 4.5, "{k:?} main buttons");
|
||||
assert!(contrast(t.canvas, t.danger) >= 4.5, "{k:?} buttons that delete: {:.2}", contrast(t.canvas, t.danger));
|
||||
assert_eq!(t.accent, BRAND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use egui::{RichText, Ui, Vec2};
|
||||
pub const NATIVE_FRAME: bool = cfg!(target_os = "macos");
|
||||
/// Height of the custom title bar. On macOS it matches the system's title bar, so its window
|
||||
/// buttons sit centred in it.
|
||||
const HEIGHT: f32 = if NATIVE_FRAME { 32.0 } else { 40.0 };
|
||||
pub const HEIGHT: f32 = if NATIVE_FRAME { 32.0 } else { 40.0 };
|
||||
/// Height of the switches and buttons in the bar.
|
||||
const CONTROL: f32 = if NATIVE_FRAME { 26.0 } else { 30.0 };
|
||||
/// How close to the window edge the pointer must be to resize.
|
||||
@@ -30,12 +30,6 @@ fn scale(ctx: &egui::Context) -> f32 {
|
||||
if NATIVE_FRAME { 1.0 / ctx.zoom_factor() } else { 1.0 }
|
||||
}
|
||||
|
||||
/// A size for `label_text` / `label_galley` that comes out as `size` scaled by `s`: they add a
|
||||
/// fixed 1.5 pt to the size they're given.
|
||||
fn label(size: f32, s: f32) -> f32 {
|
||||
(size + 1.5) * s - 1.5
|
||||
}
|
||||
|
||||
/// The title bar across the top of the window.
|
||||
pub fn bar(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
@@ -71,17 +65,22 @@ pub fn edge_at(ctx: &egui::Context) -> Option<ResizeDirection> {
|
||||
}
|
||||
|
||||
/// A 1 px edge around the window (the native frame is off), so it doesn't melt into the desktop.
|
||||
/// Windows draws a line of its own along the top of a window without a frame; a second one from
|
||||
/// us made the top edge twice as thick as the others, so there the top is left to it.
|
||||
pub fn window_edge(ctx: &egui::Context) {
|
||||
if NATIVE_FRAME || maximized(ctx) {
|
||||
return;
|
||||
}
|
||||
let t = Tokens::get(ctx);
|
||||
ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::new("window-edge"))).rect_stroke(
|
||||
ctx.content_rect(),
|
||||
0.0,
|
||||
egui::Stroke::new(1.0, t.field_border),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
let painter = ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::new("window-edge")));
|
||||
let stroke = egui::Stroke::new(1.0, t.card_border);
|
||||
let r = ctx.content_rect().shrink(0.5);
|
||||
if !cfg!(windows) {
|
||||
painter.hline(r.x_range(), r.top(), stroke);
|
||||
}
|
||||
painter.hline(r.x_range(), r.bottom(), stroke);
|
||||
painter.vline(r.left(), r.y_range(), stroke);
|
||||
painter.vline(r.right(), r.y_range(), stroke);
|
||||
}
|
||||
|
||||
/// Resizing from the window edges (the native frame is off, so we provide it).
|
||||
@@ -118,8 +117,8 @@ fn window_button(ui: &mut Ui, icon: &str, tip: &str, close: bool) -> egui::Respo
|
||||
if hot {
|
||||
ui.painter().rect_filled(rect, 0.0, if close { t.danger } else { t.hover });
|
||||
}
|
||||
let col = if hot && close { egui::Color32::WHITE } else { t.icon };
|
||||
icons::paint(ui, egui::Rect::from_center_size(rect.center(), Vec2::splat(14.0)), icon, 14.0, col);
|
||||
let col = if hot && close { t.on_accent } else { t.icon };
|
||||
icons::paint(ui, egui::Rect::from_center_size(rect.center(), Vec2::splat(14.0)), icon, theme::icon::SM, col);
|
||||
widgets::focus_ring(ui, &resp, rect.shrink(3.0));
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tr(tip)));
|
||||
resp.on_hover_text(tr(tip))
|
||||
@@ -149,29 +148,25 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.painter().line_segment([egui::pos2(bar.left(), bar.bottom() - s), egui::pos2(x, bar.bottom() - s)], egui::Stroke::new(2.0 * s, t.accent));
|
||||
}
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 10.0 * s;
|
||||
ui.spacing_mut().item_spacing.x = theme::space::SM * s;
|
||||
// Room for macOS's buttons, kept in full screen too: they slide back in when the pointer
|
||||
// reaches the top of the screen, and land there instead of over the app mark.
|
||||
ui.add_space(if NATIVE_FRAME { NATIVE_BUTTONS_WIDTH } else { 12.0 } * s);
|
||||
if ui.add(crate::app_icon(22.0 * s).sense(egui::Sense::click())).on_hover_text(tr("Home")).clicked() {
|
||||
app.state.screen = Screen::Home;
|
||||
}
|
||||
ui.label(theme::label_text("Craft Anything", label(12.0, s)).color(t.text).strong());
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
ui.menu_button(tr("Help"), |ui| {
|
||||
if ui.button(tr("Check for Updates…")).clicked() {
|
||||
app.updates.check(ui.ctx());
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
ui.label(theme::label_text("Craft Anything", theme::LABEL * s).color(t.text).strong());
|
||||
let in_project = app.state.screen == Screen::Project;
|
||||
let project = if in_project { app.workspace.as_ref().map(|w| w.manifest.name.clone()) } else { app.view.project.clone() };
|
||||
let target = if in_project { None } else { app.view.active_target().map(|t| (t.name.clone(), t.kind)) };
|
||||
if project.is_some() || target.is_some() {
|
||||
// Room either side of the divider, so the app's name and what's open read apart.
|
||||
ui.add_space(theme::space::XS * s);
|
||||
rule(ui);
|
||||
ui.add_space(theme::space::XS * s);
|
||||
}
|
||||
if let Some(p) = project {
|
||||
ui.label(theme::label_text(&p, label(12.0, s)).color(t.text_dim));
|
||||
ui.label(theme::label_text(&p, theme::LABEL * s).color(t.text_dim));
|
||||
if target.is_some() {
|
||||
ui.label(RichText::new("/").color(t.text_faint));
|
||||
}
|
||||
@@ -195,9 +190,21 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
rule(ui);
|
||||
}
|
||||
ui.spacing_mut().item_spacing.x = 10.0 * s;
|
||||
ui.spacing_mut().item_spacing.x = theme::space::SM * s;
|
||||
// Without window buttons on the right, keep the controls off the window's rounded corner.
|
||||
ui.add_space(if NATIVE_FRAME { 12.0 } else { 4.0 } * s);
|
||||
// Help sits at the end of the bar, apart from what changes how the app works.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let help = icons::button_box(ui, "circle-help", CONTROL * s, false, "Help");
|
||||
egui::Popup::from_toggle_button_response(&help).show(|ui| {
|
||||
if widgets::menu_item(ui, false, tr("Check for Updates…")).clicked() {
|
||||
app.updates.check(ui.ctx());
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
rule(ui);
|
||||
}
|
||||
if let Some((title, fraction, message)) = download {
|
||||
if download_pill(ui, &title, fraction).on_hover_text(message).clicked() {
|
||||
app.state.modal = Some(match app.engine_flow.job {
|
||||
@@ -218,12 +225,12 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
usage_pill(app, ui);
|
||||
return;
|
||||
}
|
||||
if icons::button(ui, "settings", CONTROL * s, app.state.settings_open, "Settings").clicked() {
|
||||
if icons::button_box(ui, "settings", CONTROL * s, app.state.settings_open, "Settings").clicked() {
|
||||
app.state.settings_open = !app.state.settings_open;
|
||||
}
|
||||
rule(ui);
|
||||
let sel = usize::from(app.mode() == Mode::Experienced);
|
||||
if let Some(i) = widgets::segmented_scaled(ui, &["Simple", "Advanced"], sel, CONTROL - 2.0, 12.0, s) {
|
||||
if let Some(i) = widgets::segmented_scaled(ui, &["Simple", "Advanced"], sel, CONTROL - 2.0, theme::LABEL, s) {
|
||||
app.set_mode(if i == 0 { Mode::Beginner } else { Mode::Experienced });
|
||||
}
|
||||
rule(ui);
|
||||
@@ -248,7 +255,7 @@ fn usage_pill(app: &CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let text = if u.priced { crate::usage::cost_short(u) } else { crate::usage::token_total(u, true) };
|
||||
let r = widgets::pill_sized(ui, &text, t.text_dim, t.raised, label(11.0, scale(ui.ctx())));
|
||||
let r = widgets::pill_sized(ui, &text, t.text_dim, t.raised, theme::CAPTION * scale(ui.ctx()));
|
||||
r.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, &text));
|
||||
r.on_hover_ui(|ui| {
|
||||
ui.label(RichText::new(tr("AI use this session")).font(theme::semibold(theme::SMALL)));
|
||||
@@ -264,7 +271,7 @@ fn download_pill(ui: &mut Ui, title: &str, fraction: Option<f32>) -> egui::Respo
|
||||
None => title.to_string(),
|
||||
};
|
||||
let s = scale(ui.ctx());
|
||||
let g = widgets::label_galley(ui, &text, label(12.0, s), t.text);
|
||||
let g = widgets::label_galley(ui, &text, theme::LABEL * s, t.text);
|
||||
let size = Vec2::new(g.size().x + (26.0 + 52.0) * s, 26.0 * s);
|
||||
let (rect, resp) = ui.allocate_exact_size(size, egui::Sense::click());
|
||||
let h = widgets::hover_t(ui, &resp);
|
||||
@@ -288,7 +295,7 @@ fn deep_toggle(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let missing = app.ghidra_missing();
|
||||
let label = tr(if deep { "Deep" } else { "Clean room" });
|
||||
let s = scale(ui.ctx());
|
||||
let g = widgets::label_galley(ui, &label, self::label(12.0, s), t.text);
|
||||
let g = widgets::label_galley(ui, &label, theme::LABEL * s, t.text);
|
||||
let size = Vec2::new(g.size().x + 64.0 * s, CONTROL * s);
|
||||
let (rect, resp) = ui.allocate_exact_size(size, egui::Sense::click());
|
||||
let fill = if resp.hovered() { t.hover } else { egui::Color32::TRANSPARENT };
|
||||
@@ -302,7 +309,7 @@ fn deep_toggle(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let how = ui.ctx().animate_bool(resp.id, deep);
|
||||
ui.painter().rect_filled(sw, 6.0 * s, if deep { t.accent } else { t.pressed });
|
||||
let knob_x = egui::lerp(sw.left() + 6.0 * s..=sw.right() - 6.0 * s, how);
|
||||
ui.painter().circle_filled(egui::pos2(knob_x, sw.center().y), 4.5 * s, egui::Color32::WHITE);
|
||||
ui.painter().circle_filled(egui::pos2(knob_x, sw.center().y), 4.5 * s, t.on_accent);
|
||||
widgets::focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Checkbox, true, !deep, tr("Clean room")));
|
||||
let resp = resp.on_hover_ui(|ui| {
|
||||
@@ -334,22 +341,22 @@ fn backend_picker(app: &mut CraftApp, ui: &mut Ui) {
|
||||
spacing.button_padding *= s;
|
||||
spacing.icon_width *= s;
|
||||
spacing.icon_spacing *= s;
|
||||
egui::ComboBox::from_id_salt("backend-picker")
|
||||
.selected_text(theme::label_text(¤t, label(12.0, s)).color(if app.state.backend.is_some() { t.text } else { t.text_dim }))
|
||||
widgets::dropdown("backend-picker")
|
||||
.selected_text(theme::label_text(¤t, theme::LABEL * s).color(if app.state.backend.is_some() { t.text } else { t.text_dim }))
|
||||
.icon(move |ui, rect, _, _| icons::paint(ui, rect.expand(2.0 * s), "chevron-down", 14.0 * s, Tokens::get(ui.ctx()).icon))
|
||||
.width(190.0 * s)
|
||||
.show_ui(ui, |ui| {
|
||||
for b in &app.backends {
|
||||
let on = app.state.backend.as_ref() == Some(&b.name);
|
||||
if ui.selectable_label(on, &b.name).on_hover_text(format!("{:?} · {}", b.kind, b.model)).clicked() {
|
||||
if widgets::menu_item(ui, on, &b.name).on_hover_text(format!("{:?} · {}", b.kind, b.model)).clicked() {
|
||||
choice = Some(Some(b.name.clone()));
|
||||
}
|
||||
}
|
||||
if ui.selectable_label(app.state.backend.is_none(), tr("No AI (built-in engines only)")).clicked() {
|
||||
if widgets::menu_item(ui, app.state.backend.is_none(), tr("No AI (built-in engines only)")).clicked() {
|
||||
choice = Some(None);
|
||||
}
|
||||
ui.separator();
|
||||
if ui.selectable_label(false, tr("Set up a brain…")).clicked() {
|
||||
if widgets::menu_item(ui, false, tr("Set up a brain…")).clicked() {
|
||||
setup = true;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Native release checks and verified installation through craft-update's platform helpers.
|
||||
use crate::i18n::{tr, trf};
|
||||
use crate::widgets::{Button, ButtonKind};
|
||||
use craft_update::pins::{Choice, Pins};
|
||||
use craft_update::{App, Http, Paths, Platform, Release, Stop, self_update};
|
||||
use std::sync::mpsc::{Receiver, TryRecvError, channel};
|
||||
@@ -167,16 +168,12 @@ impl Updates {
|
||||
ui.horizontal(|ui| {
|
||||
if let Some(release) = &self.release {
|
||||
ui.hyperlink_to(tr("Releases"), &release.html_url);
|
||||
install = ui
|
||||
.add_enabled(
|
||||
safe_to_install && self.installable && self.worker.is_none() && self.restart.is_none(),
|
||||
egui::Button::new(tr("Update and restart")),
|
||||
)
|
||||
.clicked();
|
||||
let ready = safe_to_install && self.installable && self.worker.is_none() && self.restart.is_none();
|
||||
install = ui.add(Button::new(ButtonKind::Primary, "Update and restart").enabled(ready)).clicked();
|
||||
} else {
|
||||
ui.hyperlink_to(tr("Releases"), APP.releases_url());
|
||||
}
|
||||
again = ui.add_enabled(self.worker.is_none() && !self.installing, egui::Button::new(tr("Check again"))).clicked();
|
||||
again = ui.add(Button::new(ButtonKind::Secondary, "Check again").enabled(self.worker.is_none() && !self.installing)).clicked();
|
||||
});
|
||||
});
|
||||
self.open = open || self.installing;
|
||||
@@ -239,7 +236,11 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn draw(updates: &mut Updates, safe: bool, close: bool) -> egui::FullOutput {
|
||||
// The app's fonts, as its own context has them (they apply from the second pass): the
|
||||
// window's buttons are set in them.
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear();
|
||||
let mut input = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(640.0, 400.0))), ..Default::default() };
|
||||
if close {
|
||||
input.viewports.entry(egui::ViewportId::ROOT).or_default().events.push(egui::ViewportEvent::Close);
|
||||
@@ -408,7 +409,13 @@ mod tests {
|
||||
fn the_manual_result_window_is_visible_without_network() -> Result<(), String> {
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
let mut updates = Updates { open: true, message: "You're up to date.".into(), ..Updates::default() };
|
||||
let mut first = true;
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(640.0, 360.0)).build_ui(|ui| {
|
||||
if std::mem::take(&mut first) {
|
||||
crate::theme::install_fonts(ui.ctx());
|
||||
ui.ctx().request_repaint();
|
||||
return;
|
||||
}
|
||||
updates.show(ui.ctx(), true);
|
||||
});
|
||||
harness.run();
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
use crate::i18n::tr;
|
||||
use crate::icons;
|
||||
use crate::theme::{self, Tokens, confidence_color, confidence_label};
|
||||
use crate::theme::{self, ControlSize, Tokens, confidence_color, confidence_label};
|
||||
use craft_anything_engine::evidence::Confidence;
|
||||
use egui::{Color32, Frame, Margin, Response, RichText, Sense, Stroke, Ui, Vec2};
|
||||
use egui::{Color32, Frame, Response, RichText, Sense, Stroke, Ui, Vec2};
|
||||
|
||||
/// Lay out `text` in the label style ([`theme::label_text`]) for painting.
|
||||
pub fn label_galley(ui: &Ui, text: &str, size: f32, color: Color32) -> std::sync::Arc<egui::Galley> {
|
||||
@@ -21,14 +21,15 @@ pub fn hover_t(ui: &Ui, resp: &Response) -> f32 {
|
||||
ui.ctx().animate_bool_with_time(resp.id.with("hover-t"), resp.hovered() || resp.has_focus(), 0.12)
|
||||
}
|
||||
|
||||
/// The frame every text field uses: a field-coloured box with a 3:1 border and roomy padding.
|
||||
/// The frame every text field uses: a field-coloured box with the edge every control has at
|
||||
/// rest, and roomy padding.
|
||||
pub fn text_field_frame(t: &Tokens) -> Frame {
|
||||
Frame::new().fill(t.field).stroke(Stroke::new(1.0, t.field_border)).corner_radius(t.r()).inner_margin(Margin::symmetric(12, 10))
|
||||
Frame::new().fill(t.field).stroke(Stroke::new(1.0, t.card_border)).corner_radius(t.r()).inner_margin(theme::pad::FIELD)
|
||||
}
|
||||
|
||||
/// The text-field frame for dense panels (filters, offsets, forms).
|
||||
pub fn text_field_frame_compact(t: &Tokens) -> Frame {
|
||||
text_field_frame(t).inner_margin(Margin::symmetric(8, 6))
|
||||
text_field_frame(t).inner_margin(theme::pad::FIELD_COMPACT)
|
||||
}
|
||||
|
||||
/// A switch with a label, in place of a checkbox. Flips `on` when clicked.
|
||||
@@ -38,7 +39,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool, label: &str) -> Response {
|
||||
let wrap = (ui.available_width() - 42.0).max(80.0);
|
||||
let g = (!label.is_empty()).then(|| ui.painter().layout(tr(label), egui::FontId::proportional(theme::SMALL), t.text, wrap));
|
||||
let w = 32.0 + g.as_ref().map_or(0.0, |g| g.size().x + 10.0);
|
||||
let h = g.as_ref().map_or(24.0, |g| g.size().y.max(24.0));
|
||||
let h = g.as_ref().map_or(ControlSize::Small.height(), |g| g.size().y.max(ControlSize::Small.height()));
|
||||
let (rect, mut resp) = ui.allocate_exact_size(Vec2::new(w, h), Sense::click());
|
||||
if resp.clicked() {
|
||||
*on = !*on;
|
||||
@@ -48,7 +49,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool, label: &str) -> Response {
|
||||
let sw = egui::Rect::from_min_size(egui::pos2(rect.left(), rect.top() + 3.0), Vec2::new(32.0, 18.0));
|
||||
ui.painter().rect(sw, 9.0, theme::mix(t.field, t.accent, how), Stroke::new(1.0, theme::mix(t.field_border, t.accent, how)), egui::StrokeKind::Inside);
|
||||
let knob = egui::pos2(egui::lerp(sw.left() + 9.0..=sw.right() - 9.0, how), sw.center().y);
|
||||
ui.painter().circle_filled(knob, 6.0, theme::mix(t.text_dim, Color32::WHITE, how));
|
||||
ui.painter().circle_filled(knob, 6.0, theme::mix(t.text_dim, t.on_accent, how));
|
||||
if let Some(g) = g {
|
||||
ui.painter().galley(egui::pos2(sw.right() + 10.0, rect.center().y - g.size().y / 2.0), g, t.text);
|
||||
}
|
||||
@@ -58,16 +59,104 @@ pub fn toggle(ui: &mut Ui, on: &mut bool, label: &str) -> Response {
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||
}
|
||||
|
||||
/// Every dropdown field: egui's combo box with our arrow, and a list whose rows are
|
||||
/// [`menu_item`]s sitting close together.
|
||||
pub fn dropdown(id_salt: impl egui::AsIdSalt) -> egui::ComboBox {
|
||||
egui::ComboBox::from_id_salt(id_salt).icon(combo_icon).popup_style(egui::style::StyleModifier::from(|s: &mut egui::Style| {
|
||||
s.spacing.item_spacing.y = theme::space::XXS;
|
||||
}))
|
||||
}
|
||||
|
||||
/// How long a dropdown's list takes to fade in.
|
||||
const POPUP_FADE: f64 = 0.12;
|
||||
|
||||
/// How visible the list `ui` belongs to is as it fades in. The fade starts again when the list
|
||||
/// wasn't drawn on the frame before (by frame, not by the clock: frames can be far apart).
|
||||
fn popup_fade(ui: &Ui) -> f32 {
|
||||
let (now, frame) = (ui.input(|i| i.time), ui.ctx().cumulative_frame_nr());
|
||||
let id = ui.id().with("popup-fade");
|
||||
let (since, seen) = ui.data(|d| d.get_temp::<(f64, u64)>(id)).unwrap_or((now, frame));
|
||||
let since = if frame.saturating_sub(seen) > 1 { now } else { since };
|
||||
ui.data_mut(|d| d.insert_temp(id, (since, frame)));
|
||||
let how = ((now - since) / POPUP_FADE).clamp(0.0, 1.0) as f32;
|
||||
if how < 1.0 {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
// Never invisible: the first frame already shows where the list is.
|
||||
0.35 + 0.65 * how
|
||||
}
|
||||
|
||||
/// One row of a dropdown's list or of a menu: a soft fill eases in under the pointer, and the chosen row has a
|
||||
/// tick at its end (so it doesn't rely on colour alone). `text` is shown as given.
|
||||
pub fn menu_item(ui: &mut Ui, selected: bool, text: impl Into<String>) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let text = text.into();
|
||||
ui.set_opacity(popup_fade(ui));
|
||||
// Rows sit close together, whatever list they are in.
|
||||
ui.spacing_mut().item_spacing.y = theme::space::XXS;
|
||||
let size = ControlSize::Medium;
|
||||
let galley = ui.painter().layout_no_wrap(text.clone(), egui::FontId::proportional(size.text()), t.text);
|
||||
let tick = size.icon() + theme::space::SM;
|
||||
let wanted = galley.size().x + theme::space::SM * 2.0 + tick;
|
||||
// As wide as the list, which is as wide as its widest row: while the list is being measured
|
||||
// a row asks only for what it needs, or a menu would open at its widest.
|
||||
let width = if ui.is_sizing_pass() { wanted } else { wanted.max(ui.available_width()) };
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(width, size.height()), Sense::click());
|
||||
let h = hover_t(ui, &resp);
|
||||
let fill = if resp.is_pointer_button_down_on() { t.pressed } else { theme::mix(Color32::TRANSPARENT, t.hover, h) };
|
||||
ui.painter().rect_filled(rect, t.radius_sm, fill);
|
||||
let ink = if selected { t.text } else { theme::mix(t.text_dim, t.text, h) };
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + theme::space::SM, rect.center().y - galley.size().y / 2.0), galley, ink);
|
||||
if selected {
|
||||
let at = egui::Rect::from_center_size(egui::pos2(rect.right() - theme::space::SM - size.icon() / 2.0, rect.center().y), Vec2::splat(size.icon()));
|
||||
icons::paint(ui, at, "check", size.icon(), t.accent_ink);
|
||||
}
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, selected, &text));
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||
}
|
||||
|
||||
/// One of a list of things to do with what is shown (a panel's actions): an icon and a label on
|
||||
/// a row as wide as the list, with a soft fill under the pointer. `danger` letters it in the
|
||||
/// danger colour, for the one that deletes.
|
||||
pub fn action_row(ui: &mut Ui, icon: &str, label: &str, danger: bool) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let size = ControlSize::Medium;
|
||||
let galley = ui.painter().layout_no_wrap(tr(label), egui::FontId::proportional(size.text()), t.text);
|
||||
let wanted = galley.size().x + size.icon() + theme::space::SM * 3.0;
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(wanted.max(ui.available_width()), size.height()), Sense::click());
|
||||
let h = hover_t(ui, &resp);
|
||||
let fill = if resp.is_pointer_button_down_on() { t.pressed } else { theme::mix(Color32::TRANSPARENT, t.hover, h) };
|
||||
ui.painter().rect_filled(rect, t.radius_sm, fill);
|
||||
let ink = if danger { t.danger } else { theme::mix(t.text_dim, t.text, h) };
|
||||
let at = egui::Rect::from_min_size(egui::pos2(rect.left() + theme::space::SM, rect.center().y - size.icon() / 2.0), Vec2::splat(size.icon()));
|
||||
icons::paint(ui, at, icon, size.icon(), if danger { t.danger } else { theme::mix(t.icon, t.text, h) });
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(at.right() + theme::space::SM, rect.center().y - galley.size().y / 2.0), galley, ink);
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tr(label)));
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||
}
|
||||
|
||||
/// A [`menu_item`] that sets `current` to `value` when picked. True when that changed it.
|
||||
pub fn menu_choice<V: PartialEq>(ui: &mut Ui, current: &mut V, value: V, text: impl Into<String>) -> bool {
|
||||
let on = *current == value;
|
||||
let picked = menu_item(ui, on, text).clicked() && !on;
|
||||
if picked {
|
||||
*current = value;
|
||||
}
|
||||
picked
|
||||
}
|
||||
|
||||
/// The dropdown arrow for every combo box: a Lucide chevron instead of egui's filled triangle.
|
||||
pub fn combo_icon(ui: &Ui, rect: egui::Rect, _visuals: &egui::style::WidgetVisuals, _open: bool) {
|
||||
icons::paint(ui, rect.expand(2.0), "chevron-down", 14.0, Tokens::get(ui.ctx()).icon);
|
||||
icons::paint(ui, rect.expand(2.0), "chevron-down", theme::icon::SM, Tokens::get(ui.ctx()).icon);
|
||||
}
|
||||
|
||||
/// The disclosure arrow for every collapsing section: a Lucide chevron.
|
||||
pub fn disclosure_icon(ui: &mut Ui, openness: f32, resp: &Response) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let r = egui::Rect::from_center_size(resp.rect.center(), Vec2::splat(12.0));
|
||||
icons::paint(ui, r, if openness > 0.5 { "chevron-down" } else { "chevron-right" }, 12.0, t.text_faint);
|
||||
icons::paint(ui, r, if openness > 0.5 { "chevron-down" } else { "chevron-right" }, theme::icon::XS, t.text_faint);
|
||||
}
|
||||
|
||||
/// Give a field without a visible label a name for screen readers (WCAG 4.1.2); egui doesn't
|
||||
@@ -89,7 +178,7 @@ pub fn suggestion(ui: &mut Ui, text: &str) -> Response {
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
t.radius,
|
||||
theme::mix(Color32::TRANSPARENT, t.hover, h),
|
||||
theme::mix(t.field, t.hover, h),
|
||||
Stroke::new(1.0, theme::mix(t.card_border, t.field_border, h)),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
@@ -114,11 +203,11 @@ pub fn choice_tile(ui: &mut Ui, size: Vec2, icon: &str, label: &str, blurb: &str
|
||||
let (fill, stroke) = if on {
|
||||
(t.accent_soft, Stroke::new(2.0, t.accent))
|
||||
} else {
|
||||
(theme::mix(Color32::TRANSPARENT, t.hover, h), Stroke::new(1.0, theme::mix(t.field_border, t.text_faint, h)))
|
||||
(theme::mix(t.field, t.hover, h), Stroke::new(1.0, theme::mix(t.card_border, t.field_border, h)))
|
||||
};
|
||||
ui.painter().rect(rect, t.radius, fill, stroke, egui::StrokeKind::Inside);
|
||||
let icon_rect = egui::Rect::from_center_size(egui::pos2(rect.left() + 28.0, rect.center().y), Vec2::splat(24.0));
|
||||
icons::paint(ui, icon_rect, icon, 22.0, if on { t.accent_ink } else { t.icon });
|
||||
icons::paint(ui, icon_rect, icon, theme::icon::XL, if on { t.accent_ink } else { t.icon });
|
||||
let top = egui::pos2(icon_rect.right() + 12.0, rect.center().y - text_h / 2.0);
|
||||
let title_h = g.size().y;
|
||||
ui.painter().galley(top, g, t.text);
|
||||
@@ -126,95 +215,191 @@ pub fn choice_tile(ui: &mut Ui, size: Vec2, icon: &str, label: &str, blurb: &str
|
||||
ui.painter().galley(top + Vec2::new(0.0, title_h + 3.0), s, t.text_dim);
|
||||
}
|
||||
if on {
|
||||
icons::paint(ui, egui::Rect::from_center_size(egui::pos2(rect.right() - 20.0, rect.center().y), Vec2::splat(18.0)), "check", 18.0, t.accent_ink);
|
||||
icons::paint(
|
||||
ui,
|
||||
egui::Rect::from_center_size(egui::pos2(rect.right() - 20.0, rect.center().y), Vec2::splat(18.0)),
|
||||
"check",
|
||||
theme::icon::LG,
|
||||
t.accent_ink,
|
||||
);
|
||||
}
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::RadioButton, true, on, tr(label)));
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||
}
|
||||
|
||||
/// A visible keyboard-focus ring around `rect` when `resp` has focus (2 px accent, outside).
|
||||
/// A visible keyboard-focus ring around `rect` when `resp` has focus: a hairline in the app
|
||||
/// colour on the control's edge and a soft 3 px halo outside it.
|
||||
pub fn focus_ring(ui: &Ui, resp: &Response, rect: egui::Rect) {
|
||||
if resp.has_focus() {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.painter().rect_stroke(rect.expand(2.0), t.radius + 2.0, Stroke::new(2.0, t.accent), egui::StrokeKind::Outside);
|
||||
ui.painter().rect_stroke(rect, t.radius, Stroke::new(3.0, t.accent_ink.gamma_multiply(0.45)), egui::StrokeKind::Outside);
|
||||
ui.painter().rect_stroke(rect, t.radius, Stroke::new(1.0, t.accent_ink), egui::StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
|
||||
/// How long a focus edge takes to fade in or out.
|
||||
pub const FOCUS_FADE: f32 = 0.12;
|
||||
|
||||
/// A text field with no box of its own (it sits in a bigger one that shows focus itself): the
|
||||
/// ring [`text_focus_ring`] draws would hug its bare text, so it gets none.
|
||||
pub fn frameless_field(resp: &Response) {
|
||||
resp.ctx.data_mut(|d| d.insert_temp(resp.id.with("frameless-field"), true));
|
||||
}
|
||||
|
||||
/// The focus edge of whichever text field is being typed in: the same hairline and halo as
|
||||
/// [`focus_ring`], faded in and out. Drawn once a frame, after the screens, because a field's
|
||||
/// own frame can't know it has focus.
|
||||
pub fn text_focus_ring(ctx: &egui::Context) {
|
||||
let key = egui::Id::new("text-focus-ring");
|
||||
let focused =
|
||||
ctx.memory(|m| m.focused()).filter(|id| ctx.text_edit_focused() && !ctx.data(|d| d.get_temp::<bool>(id.with("frameless-field")).unwrap_or(false)));
|
||||
// The field that had it last fades out.
|
||||
let Some(id) = focused.or_else(|| ctx.data(|d| d.get_temp::<egui::Id>(key))) else { return };
|
||||
let how = ctx.animate_bool_with_time(id.with("focus-ring"), focused == Some(id), FOCUS_FADE);
|
||||
match focused {
|
||||
Some(now) => {
|
||||
ctx.data_mut(|d| d.insert_temp(key, now));
|
||||
}
|
||||
None if how <= 0.0 => ctx.data_mut(|d| d.remove::<egui::Id>(key)),
|
||||
None => {}
|
||||
}
|
||||
let Some(resp) = ctx.read_response(id).filter(|_| how > 0.0) else { return };
|
||||
let t = Tokens::get(ctx);
|
||||
// Clipped to what the field's own layer shows of it (a field half scrolled out of a list).
|
||||
let painter = ctx.layer_painter(resp.layer_id).with_clip_rect(resp.interact_rect.expand(4.0));
|
||||
painter.rect_stroke(resp.rect, t.radius, Stroke::new(3.0, t.accent_ink.gamma_multiply(0.45 * how)), egui::StrokeKind::Outside);
|
||||
painter.rect_stroke(resp.rect, t.radius, Stroke::new(1.0, t.accent_ink.gamma_multiply(how)), egui::StrokeKind::Inside);
|
||||
}
|
||||
|
||||
/// A card frame: a soft rounded box with a hairline edge.
|
||||
pub fn card(t: &Tokens) -> Frame {
|
||||
Frame::new().fill(t.card).stroke(Stroke::new(1.0, t.card_border)).corner_radius(t.r_lg()).inner_margin(Margin::same(16))
|
||||
Frame::new().fill(t.card).stroke(Stroke::new(1.0, t.card_border)).corner_radius(t.r_lg()).inner_margin(theme::pad::CARD)
|
||||
}
|
||||
|
||||
/// A quieter, denser panel frame for the workbench.
|
||||
pub fn panel(t: &Tokens) -> Frame {
|
||||
Frame::new().fill(t.card).stroke(Stroke::new(1.0, t.card_border)).corner_radius(t.r()).inner_margin(Margin::same(10))
|
||||
Frame::new().fill(t.card).stroke(Stroke::new(1.0, t.card_border)).corner_radius(t.r()).inner_margin(theme::pad::PANEL)
|
||||
}
|
||||
|
||||
/// What a button is for, which decides its fill and ink.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ButtonKind {
|
||||
/// The main action of a screen or card: ink-filled (light on dark in the dark theme).
|
||||
Primary,
|
||||
/// Any other action: a card-coloured box with a soft edge.
|
||||
Secondary,
|
||||
/// An action that stays quiet until it's wanted: no box until the pointer is on it.
|
||||
Ghost,
|
||||
/// An action that deletes or can't be undone: filled in the danger colour.
|
||||
Danger,
|
||||
}
|
||||
|
||||
/// Every button in the app: one of four kinds, at one of the control sizes, with an optional icon.
|
||||
#[must_use = "put it in a ui with `ui.add(widget);`"]
|
||||
pub struct Button<'a> {
|
||||
kind: ButtonKind,
|
||||
size: ControlSize,
|
||||
icon: Option<&'a str>,
|
||||
label: &'a str,
|
||||
enabled: bool,
|
||||
wide: bool,
|
||||
}
|
||||
|
||||
impl<'a> Button<'a> {
|
||||
/// `label` is translated here.
|
||||
pub fn new(kind: ButtonKind, label: &'a str) -> Self {
|
||||
Self { kind, size: ControlSize::Medium, icon: None, label, enabled: true, wide: false }
|
||||
}
|
||||
|
||||
/// As wide as the room it has (the one action of a narrow panel).
|
||||
pub fn wide(mut self) -> Self {
|
||||
self.wide = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn icon(mut self, icon: Option<&'a str>) -> Self {
|
||||
self.icon = icon;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn size(mut self, size: ControlSize) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn enabled(mut self, enabled: bool) -> Self {
|
||||
self.enabled = enabled;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl egui::Widget for Button<'_> {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let Button { kind, size, icon, label, enabled, wide } = self;
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let galley = label_galley(ui, &tr(label), size.text(), t.text);
|
||||
let icon_w = if icon.is_some() { size.icon() + ICON_GAP } else { 0.0 };
|
||||
// Taller than its size only when the label is (a zoomed or fallback font).
|
||||
let wanted = Vec2::new(galley.size().x + icon_w + size.pad_x() * 2.0, (galley.size().y + theme::space::SM).max(size.height()));
|
||||
let wanted = if wide { Vec2::new(wanted.x.max(ui.available_width()), wanted.y) } else { wanted };
|
||||
let (rect, resp) = ui.allocate_exact_size(wanted, if enabled { Sense::click() } else { Sense::hover() });
|
||||
let h = if enabled { hover_t(ui, &resp) } else { 0.0 };
|
||||
let down = enabled && resp.is_pointer_button_down_on();
|
||||
let clear = Color32::TRANSPARENT;
|
||||
// Fill, edge, label, icon.
|
||||
let (fill, edge, fg, tint) = match kind {
|
||||
ButtonKind::Primary if !enabled => (t.pressed, clear, t.text_faint, t.text_faint),
|
||||
_ if !enabled => (clear, if kind == ButtonKind::Ghost { clear } else { t.card_border }, t.text_faint, t.text_faint),
|
||||
ButtonKind::Primary => (theme::mix(t.text, t.canvas, if down { 0.25 } else { 0.14 * h }), clear, t.canvas, t.canvas),
|
||||
ButtonKind::Secondary => {
|
||||
(if down { t.pressed } else { theme::mix(t.field, t.hover, h) }, theme::mix(t.card_border, t.field_border, h), t.text, t.icon)
|
||||
}
|
||||
ButtonKind::Ghost => {
|
||||
let ink = theme::mix(t.text_dim, t.text, h);
|
||||
(if down { t.pressed } else { theme::mix(clear, t.hover, h) }, clear, ink, ink)
|
||||
}
|
||||
ButtonKind::Danger => (theme::mix(t.danger, t.canvas, if down { 0.2 } else { 0.1 * h }), clear, t.canvas, t.canvas),
|
||||
};
|
||||
ui.painter().rect(rect, t.radius, fill, Stroke::new(1.0, edge), egui::StrokeKind::Inside);
|
||||
let mut x = (rect.center().x - (icon_w + galley.size().x) / 2.0).round();
|
||||
if let Some(i) = icon {
|
||||
icons::paint(ui, egui::Rect::from_min_size(egui::pos2(x, rect.center().y - size.icon() / 2.0), Vec2::splat(size.icon())), i, size.icon(), tint);
|
||||
x += icon_w;
|
||||
}
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(x, rect.center().y - galley.size().y / 2.0), galley, fg);
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, tr(label)));
|
||||
if enabled { resp.on_hover_cursor(egui::CursorIcon::PointingHand) } else { resp }
|
||||
}
|
||||
}
|
||||
|
||||
/// The gap between a button's icon and its label.
|
||||
const ICON_GAP: f32 = 6.0;
|
||||
|
||||
/// The main action: an ink-filled button (light on dark in the dark theme).
|
||||
pub fn primary(ui: &mut Ui, label: &str) -> Response {
|
||||
primary_icon(ui, None, label, true)
|
||||
}
|
||||
|
||||
pub fn primary_icon(ui: &mut Ui, icon: Option<&str>, label: &str, enabled: bool) -> Response {
|
||||
primary_sized(ui, icon, label, enabled, 32.0, 12.5)
|
||||
}
|
||||
|
||||
/// The main button at a given height and label size (Simple mode's Start is a big one).
|
||||
pub fn primary_sized(ui: &mut Ui, icon: Option<&str>, label: &str, enabled: bool, height: f32, text: f32) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let galley = label_galley(ui, &tr(label), text, t.canvas);
|
||||
let icon_w = if icon.is_some() { BUTTON_ICON_W } else { 0.0 };
|
||||
let pad = ui.spacing().button_padding;
|
||||
let size = Vec2::new(galley.size().x + icon_w + pad.x * 2.0 + 8.0 + (height - 32.0).max(0.0), (galley.size().y + pad.y * 2.0 + 8.0).max(height));
|
||||
let sense = if enabled { Sense::click() } else { Sense::hover() };
|
||||
let (rect, resp) = ui.allocate_exact_size(size, sense);
|
||||
let fill = if !enabled {
|
||||
t.pressed
|
||||
} else if resp.is_pointer_button_down_on() {
|
||||
theme::mix(t.text, t.canvas, 0.25)
|
||||
} else {
|
||||
theme::mix(t.text, t.canvas, 0.14 * hover_t(ui, &resp))
|
||||
};
|
||||
ui.painter().rect_filled(rect, t.radius, fill);
|
||||
let fg = if enabled { t.canvas } else { t.text_faint };
|
||||
button_content(ui, rect, icon, galley, fg, fg);
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, tr(label)));
|
||||
if enabled { resp.on_hover_cursor(egui::CursorIcon::PointingHand) } else { resp }
|
||||
ui.add(Button::new(ButtonKind::Primary, label).icon(icon).enabled(enabled))
|
||||
}
|
||||
|
||||
/// Secondary button: a card-coloured box with a soft edge and an optional icon.
|
||||
pub fn secondary(ui: &mut Ui, icon: Option<&str>, label: &str) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let galley = label_galley(ui, &tr(label), 12.0, t.text);
|
||||
let icon_w = if icon.is_some() { BUTTON_ICON_W } else { 0.0 };
|
||||
let pad = ui.spacing().button_padding;
|
||||
let size = Vec2::new(galley.size().x + icon_w + pad.x * 2.0 + 6.0, (galley.size().y + pad.y * 2.0 + 6.0).max(30.0));
|
||||
let (rect, resp) = ui.allocate_exact_size(size, Sense::click());
|
||||
let h = hover_t(ui, &resp);
|
||||
let fill = if resp.is_pointer_button_down_on() { t.pressed } else { theme::mix(t.card, t.hover, h) };
|
||||
let stroke = theme::mix(t.card_border, t.field_border, h);
|
||||
ui.painter().rect(rect, t.radius, fill, Stroke::new(1.0, stroke), egui::StrokeKind::Inside);
|
||||
button_content(ui, rect, icon, galley, t.text, t.icon);
|
||||
focus_ring(ui, &resp, rect);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tr(label)));
|
||||
resp.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||
ui.add(Button::new(ButtonKind::Secondary, label).icon(icon))
|
||||
}
|
||||
|
||||
/// A button's icon and label, centred together in `rect`.
|
||||
fn button_content(ui: &Ui, rect: egui::Rect, icon: Option<&str>, galley: std::sync::Arc<egui::Galley>, fg: Color32, icon_tint: Color32) {
|
||||
let icon_w = if icon.is_some() { BUTTON_ICON_W } else { 0.0 };
|
||||
let mut x = (rect.center().x - (icon_w + galley.size().x) / 2.0).round();
|
||||
if let Some(i) = icon {
|
||||
icons::paint(ui, egui::Rect::from_min_size(egui::pos2(x, rect.center().y - 8.0), Vec2::splat(16.0)), i, 15.0, icon_tint);
|
||||
x += icon_w;
|
||||
}
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(x, rect.center().y - galley.size().y / 2.0), galley, fg);
|
||||
/// A quiet button: no box until the pointer is on it.
|
||||
pub fn ghost(ui: &mut Ui, icon: Option<&str>, label: &str) -> Response {
|
||||
ui.add(Button::new(ButtonKind::Ghost, label).icon(icon))
|
||||
}
|
||||
|
||||
/// A button icon (16 px) and the gap after it.
|
||||
const BUTTON_ICON_W: f32 = 22.0;
|
||||
/// A button for something that deletes or can't be undone.
|
||||
pub fn danger(ui: &mut Ui, icon: Option<&str>, label: &str) -> Response {
|
||||
ui.add(Button::new(ButtonKind::Danger, label).icon(icon))
|
||||
}
|
||||
|
||||
/// A borderless text button in the accent colour.
|
||||
pub fn link(ui: &mut Ui, label: &str) -> Response {
|
||||
@@ -228,76 +413,96 @@ pub fn link(ui: &mut Ui, label: &str) -> Response {
|
||||
r
|
||||
}
|
||||
|
||||
/// A [`link`] at the size of the caption it sits in.
|
||||
pub fn caption_link(ui: &mut Ui, label: &str) -> Response {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_font_id = Some(egui::FontId::proportional(theme::CAPTION));
|
||||
link(ui, label)
|
||||
})
|
||||
.inner
|
||||
}
|
||||
|
||||
/// A segmented switch; the selected segment is a raised card on a sunken track. Returns the newly
|
||||
/// picked index when it changes.
|
||||
pub fn segmented(ui: &mut Ui, options: &[&str], selected: usize, height: f32) -> Option<usize> {
|
||||
segmented_sized(ui, options, selected, height, 12.0)
|
||||
pub fn segmented(ui: &mut Ui, options: &[&str], selected: usize, size: ControlSize) -> Option<usize> {
|
||||
segmented_scaled(ui, options, selected, size.height(), size.text(), 1.0)
|
||||
}
|
||||
|
||||
/// [`segmented`] with a given label size (in the [`label_galley`] style), for a bigger switch.
|
||||
pub fn segmented_sized(ui: &mut Ui, options: &[&str], selected: usize, height: f32, text: f32) -> Option<usize> {
|
||||
segmented_scaled(ui, options, selected, height, text, 1.0)
|
||||
}
|
||||
|
||||
/// [`segmented_sized`] with every size in it, padding too, multiplied by `scale` (the macOS
|
||||
/// title bar's, which keeps its size when the app zooms).
|
||||
/// [`segmented`] at a given height and label size, with every size in it, padding too, multiplied
|
||||
/// by `scale` (the macOS title bar's, which keeps its size when the app zooms).
|
||||
pub fn segmented_scaled(ui: &mut Ui, options: &[&str], selected: usize, height: f32, text: f32, scale: f32) -> Option<usize> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
// label_text adds a fixed 1.5 pt to the size it's given; scale that too.
|
||||
let label = (text + 1.5) * scale - 1.5;
|
||||
let (height, pad) = (height * scale, 2.0 * scale);
|
||||
let galleys: Vec<_> = options.iter().map(|o| label_galley(ui, &tr(o), label, t.text)).collect();
|
||||
let widths: Vec<f32> = galleys.iter().map(|g| g.size().x + (text * 2.0 + 2.0) * scale).collect();
|
||||
let (height, pad) = (height * scale, SEGMENT_INSET * scale);
|
||||
let galleys: Vec<_> = options.iter().map(|o| label_galley(ui, &tr(o), text * scale, t.text)).collect();
|
||||
let widths: Vec<f32> = galleys.iter().map(|g| g.size().x + segment_pad(text) * scale).collect();
|
||||
let total: f32 = widths.iter().sum::<f32>() + 2.0 * pad;
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(total, height), Sense::hover());
|
||||
ui.painter().rect(rect, t.radius, t.raised, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
|
||||
// A sunken track; the chosen segment is a lighter card on it.
|
||||
ui.painter().rect(rect, t.radius, t.canvas, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
|
||||
// The segments. One under the pointer only brightens its words: the card is what moves.
|
||||
let mut x = rect.left() + pad;
|
||||
let mut picked = None;
|
||||
for (i, (g, w)) in galleys.into_iter().zip(widths).enumerate() {
|
||||
let seg = egui::Rect::from_min_size(egui::pos2(x, rect.top() + pad), Vec2::new(w, height - 2.0 * pad));
|
||||
let resp = ui.interact(seg, ui.id().with(("seg", options.get(i).copied().unwrap_or_default())), Sense::click());
|
||||
let mut segments = Vec::with_capacity(options.len());
|
||||
for (i, w) in widths.iter().enumerate() {
|
||||
let seg = egui::Rect::from_min_size(egui::pos2(x, rect.top() + pad), Vec2::new(*w, height - 2.0 * pad));
|
||||
let name = options.get(i).copied().unwrap_or_default();
|
||||
let resp = ui.interact(seg, ui.id().with(("seg", name)), Sense::click());
|
||||
let on = i == selected;
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, on, tr(options.get(i).copied().unwrap_or_default())));
|
||||
if on {
|
||||
ui.painter().rect(seg, t.radius_sm, t.card, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
|
||||
} else {
|
||||
ui.painter().rect_filled(seg, t.radius_sm, theme::mix(Color32::TRANSPARENT, t.hover, hover_t(ui, &resp)));
|
||||
}
|
||||
let color = if on { t.text } else { t.text_dim };
|
||||
ui.painter().galley_with_override_text_color(seg.center() - g.size() / 2.0, g, color);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, on, tr(name)));
|
||||
segments.push((seg, resp));
|
||||
x += w;
|
||||
}
|
||||
// The card slides to the chosen segment (measured from the switch's own
|
||||
// left edge, so moving the whole switch doesn't set it off). Named by its options, not by
|
||||
// where it is drawn, so it keeps its place when the screen around it changes.
|
||||
let before: f32 = widths.iter().take(selected).sum();
|
||||
let slide = |part: &str, to: f32| ui.ctx().animate_value_with_time(egui::Id::new(("seg-slide", part, options)), to, SLIDE);
|
||||
let (card_x, card_w) = (slide("x", before), slide("w", widths.get(selected).copied().unwrap_or_default()));
|
||||
let card = egui::Rect::from_min_size(egui::pos2(rect.left() + pad + card_x, rect.top() + pad), Vec2::new(card_w, height - 2.0 * pad));
|
||||
ui.painter().rect(card, t.radius_sm, t.field, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
|
||||
let mut picked = None;
|
||||
for (i, ((seg, resp), g)) in segments.into_iter().zip(galleys).enumerate() {
|
||||
let on = i == selected;
|
||||
let ink = if on { t.text } else { theme::mix(t.text_dim, t.text, hover_t(ui, &resp)) };
|
||||
ui.painter().galley_with_override_text_color(seg.center() - g.size() / 2.0, g, ink);
|
||||
focus_ring(ui, &resp, seg);
|
||||
let resp = if on { resp } else { resp.on_hover_cursor(egui::CursorIcon::PointingHand) };
|
||||
if resp.clicked() && !on {
|
||||
picked = Some(i);
|
||||
}
|
||||
x += w;
|
||||
}
|
||||
picked
|
||||
}
|
||||
|
||||
fn segment_width(label: f32, text: f32) -> f32 {
|
||||
label + text * 2.0 + 2.0
|
||||
/// The room between the track's edge and the chosen segment's card.
|
||||
const SEGMENT_INSET: f32 = 4.0;
|
||||
|
||||
/// How long the chosen segment's card takes to slide to another segment.
|
||||
const SLIDE: f32 = 0.2;
|
||||
|
||||
/// The room around a segment's label, both sides together.
|
||||
fn segment_pad(text: f32) -> f32 {
|
||||
text * 2.0
|
||||
}
|
||||
|
||||
/// How wide [`segmented`] draws `options`, for a row that needs to know before drawing them.
|
||||
pub fn segmented_width(ui: &Ui, options: &[&str]) -> f32 {
|
||||
/// How wide [`segmented`] draws `options` at `size`, for a row that needs to know before drawing them.
|
||||
pub fn segmented_width(ui: &Ui, options: &[&str], size: ControlSize) -> f32 {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
options.iter().map(|o| segment_width(label_galley(ui, &tr(o), 12.0, t.text).size().x, 12.0)).sum::<f32>() + 4.0
|
||||
options.iter().map(|o| label_galley(ui, &tr(o), size.text(), t.text).size().x + segment_pad(size.text())).sum::<f32>() + 2.0 * SEGMENT_INSET
|
||||
}
|
||||
|
||||
/// A small status label on a tint.
|
||||
pub fn pill(ui: &mut Ui, text: &str, fg: Color32, bg: Color32) -> Response {
|
||||
pill_sized(ui, text, fg, bg, 11.0)
|
||||
pill_sized(ui, text, fg, bg, theme::CAPTION)
|
||||
}
|
||||
|
||||
/// [`pill`] with a given label size, its padding scaled to match.
|
||||
pub fn pill_sized(ui: &mut Ui, text: &str, fg: Color32, bg: Color32, text_size: f32) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let label = tr(text);
|
||||
let g = label_galley(ui, &label, text_size, fg);
|
||||
let size = Vec2::new(g.size().x + text_size * 14.0 / 11.0, g.size().y + text_size * 8.0 / 11.0);
|
||||
let size = Vec2::new(g.size().x + text_size * 18.0 / 11.0, g.size().y + text_size * 6.0 / 11.0);
|
||||
let (rect, resp) = ui.allocate_exact_size(size, Sense::hover());
|
||||
ui.painter().rect_filled(rect, t.r_sm(), bg);
|
||||
// A full pill, whatever its size.
|
||||
ui.painter().rect_filled(rect, rect.height() / 2.0, bg);
|
||||
ui.painter().galley_with_override_text_color(rect.center() - g.size() / 2.0, g, fg);
|
||||
// Painted text: say it to screen readers too.
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, &label));
|
||||
@@ -306,14 +511,13 @@ pub fn pill_sized(ui: &mut Ui, text: &str, fg: Color32, bg: Color32, text_size:
|
||||
|
||||
/// The "how sure are we" badge: a coloured dot and the plain label.
|
||||
pub fn confidence_badge(ui: &mut Ui, c: Option<Confidence>) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let col = confidence_color(c);
|
||||
let font = theme::medium(theme::CAPTION);
|
||||
let g = ui.painter().layout_no_wrap(tr(confidence_label(c)), font, col);
|
||||
let size = Vec2::new(g.size().x + 26.0, g.size().y + 7.0);
|
||||
let (rect, resp) = ui.allocate_exact_size(size, Sense::hover());
|
||||
let bg = Color32::from_rgba_unmultiplied(col.r(), col.g(), col.b(), 34);
|
||||
ui.painter().rect(rect, t.r_sm(), bg, Stroke::new(1.0, col.gamma_multiply(0.45)), egui::StrokeKind::Inside);
|
||||
let bg = col.gamma_multiply(0.13);
|
||||
ui.painter().rect(rect, rect.height() / 2.0, bg, Stroke::new(1.0, col.gamma_multiply(0.45)), egui::StrokeKind::Inside);
|
||||
ui.painter().circle_filled(egui::pos2(rect.left() + 10.0, rect.center().y), 3.5, col);
|
||||
ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + 18.0, rect.center().y - g.size().y / 2.0), g, col);
|
||||
let tip = match c {
|
||||
@@ -328,23 +532,46 @@ pub fn confidence_badge(ui: &mut Ui, c: Option<Confidence>) -> Response {
|
||||
/// A section caption in the label style, faint.
|
||||
pub fn caption(ui: &mut Ui, text: &str) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(theme::label_text(&tr(text), 12.0).color(t.text_faint));
|
||||
ui.label(theme::label_text(&tr(text), theme::LABEL).color(t.text_faint));
|
||||
}
|
||||
|
||||
/// A caption on the left and its value on the right, or the value on a line of its own when the
|
||||
/// two would overlap: a right-to-left layout doesn't make room for what's already on the row.
|
||||
pub fn stat_row(ui: &mut Ui, label: &str, value: &str) -> Response {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let text = RichText::new(value).font(theme::mono(theme::CODE)).color(t.text);
|
||||
let value_width =
|
||||
egui::WidgetText::from(text.clone()).into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::FontSelection::Default).size().x;
|
||||
let caption_width = label_galley(ui, &tr(label), theme::LABEL, t.text_faint).size().x;
|
||||
if caption_width + ui.spacing().item_spacing.x + value_width <= ui.available_width() {
|
||||
ui.horizontal(|ui| {
|
||||
caption(ui, label);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| ui.label(text));
|
||||
})
|
||||
.response
|
||||
} else {
|
||||
ui.vertical(|ui| {
|
||||
caption(ui, label);
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::Max), |ui| ui.label(text));
|
||||
})
|
||||
.response
|
||||
}
|
||||
}
|
||||
|
||||
/// A centred, calm empty state.
|
||||
pub fn empty_state(ui: &mut Ui, icon: &str, title: &str, body: &str) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(18.0);
|
||||
ui.add_space(theme::space::LG);
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::splat(44.0), Sense::hover());
|
||||
ui.painter().circle_filled(rect.center(), 22.0, t.raised);
|
||||
icons::paint(ui, rect, icon, 22.0, t.text_faint);
|
||||
ui.add_space(6.0);
|
||||
icons::paint(ui, rect, icon, theme::icon::XL, t.text_faint);
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(tr(title)).font(theme::medium(theme::SMALL)).color(t.text_dim));
|
||||
if !body.is_empty() {
|
||||
ui.label(RichText::new(tr(body)).color(t.text_faint).size(theme::CAPTION));
|
||||
}
|
||||
ui.add_space(12.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -361,7 +588,7 @@ pub fn big_card(ui: &mut Ui, size: Vec2, icon: &str, title: &str, blurb: &str, b
|
||||
ui.painter().rect(rect, t.radius_lg, fill, stroke, egui::StrokeKind::Inside);
|
||||
let icon_rect = egui::Rect::from_min_size(rect.min + Vec2::new(22.0, 22.0), Vec2::splat(52.0));
|
||||
ui.painter().rect_filled(icon_rect, t.radius, t.accent_soft);
|
||||
icons::paint(ui, icon_rect, icon, 28.0, t.accent_ink);
|
||||
icons::paint(ui, icon_rect, icon, theme::icon::XL, t.accent_ink);
|
||||
if let Some(b) = badge {
|
||||
let g = ui.painter().layout_no_wrap(tr(b), theme::medium(theme::TINY), t.text_dim);
|
||||
let br = egui::Rect::from_min_size(egui::pos2(rect.right() - g.size().x - 34.0, rect.top() + 22.0), g.size() + Vec2::new(16.0, 8.0));
|
||||
@@ -587,12 +814,12 @@ pub fn working_since(ui: &mut Ui, title: &str, detail: Option<&str>, began: Opti
|
||||
let secs = began.map_or((now - since) as u64, |b| b.elapsed().as_secs());
|
||||
let note = wait_note(secs, quiet);
|
||||
let sub = [detail.map(str::to_string), note].into_iter().flatten().collect::<Vec<_>>().join(" · ");
|
||||
let clock = RichText::new(crate::usage::duration_words(std::time::Duration::from_secs(secs))).font(theme::mono(12.5)).color(t.text_faint);
|
||||
let clock = RichText::new(crate::usage::duration_words(std::time::Duration::from_secs(secs))).font(theme::mono(theme::CODE)).color(t.text_faint);
|
||||
// The words wrap before the clock, never under it: a right-to-left layout doesn't make room
|
||||
// for what's already on the row.
|
||||
let clock_width =
|
||||
egui::WidgetText::from(clock.clone()).into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::FontSelection::Default).size().x;
|
||||
card(&t).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
||||
card(&t).inner_margin(theme::pad::ROW).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.horizontal(|ui| {
|
||||
let (r, _) = ui.allocate_exact_size(Vec2::splat(24.0), Sense::hover());
|
||||
@@ -602,12 +829,12 @@ pub fn working_since(ui: &mut Ui, title: &str, detail: Option<&str>, began: Opti
|
||||
let sweep = std::f32::consts::PI * (0.9 + 0.5 * (now * 1.7).sin() as f32);
|
||||
let arc = (0..=20).map(|i| c + radius * Vec2::angled(start + sweep * i as f32 / 20.0)).collect();
|
||||
ui.painter().add(egui::Shape::line(arc, Stroke::new(2.5, t.accent)));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_max_width((ui.available_width() - clock_width - ui.spacing().item_spacing.x).max(0.0));
|
||||
ui.label(RichText::new(tr(title)).font(theme::semibold(theme::BODY)).color(t.text));
|
||||
if !sub.is_empty() {
|
||||
ui.add(egui::Label::new(RichText::new(sub).color(t.text_dim).size(theme::SMALL)).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(sub).color(t.text_dim).size(theme::SMALL).line_height(Some(theme::leading(theme::SMALL)))).wrap());
|
||||
}
|
||||
});
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
@@ -615,7 +842,7 @@ pub fn working_since(ui: &mut Ui, title: &str, detail: Option<&str>, began: Opti
|
||||
});
|
||||
});
|
||||
// An indeterminate sweep along the bottom: movement even when nothing new has arrived.
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let (bar, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), 2.0), Sense::hover());
|
||||
sweep(ui.painter(), bar, now, t.separator, t.accent);
|
||||
});
|
||||
@@ -624,7 +851,7 @@ pub fn working_since(ui: &mut Ui, title: &str, detail: Option<&str>, began: Opti
|
||||
|
||||
/// The button that opens a failure's log; hovering shows where the log is. True when clicked.
|
||||
pub fn open_log_button(ui: &mut Ui, path: &std::path::Path) -> bool {
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
secondary(ui, None, "Open log").on_hover_text(path.display().to_string()).clicked()
|
||||
}
|
||||
|
||||
@@ -663,7 +890,7 @@ mod tests {
|
||||
});
|
||||
assert!(egui_spinner < Duration::from_millis(10), "egui's own asks for the next frame at once: {egui_spinner:?}");
|
||||
let ours = wait_after(true, &|ui| {
|
||||
ui.add(Spinner::new().size(16.0));
|
||||
ui.add(Spinner::new().size(theme::icon::MD));
|
||||
});
|
||||
assert!(paced(ours, FRAME), "ours waits for the animation's pace: {ours:?}");
|
||||
let background = wait_after(false, &|ui| drop(ui.add(Spinner::new())));
|
||||
|
||||
@@ -98,7 +98,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
egui::Panel::left("wb-rail-icons")
|
||||
.exact_size(48.0)
|
||||
.resizable(false)
|
||||
.frame(egui::Frame::new().fill(t.chrome).inner_margin(Margin::symmetric(6, 10)))
|
||||
.frame(egui::Frame::new().fill(t.chrome).inner_margin(theme::pad::TIGHT))
|
||||
.show(ui, |ui| rail_icons(app, ui));
|
||||
egui::Panel::left("wb-rail")
|
||||
.default_size(290.0)
|
||||
@@ -120,20 +120,17 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
|
||||
.show_collapsible(ui, &mut open, |ui| crate::guard_ui(ui, "bottom", |ui| bottom(app, ui)));
|
||||
app.state.bottom_open = open;
|
||||
if !app.state.bottom_open {
|
||||
egui::Panel::bottom("wb-bottom-closed").exact_size(30.0).frame(egui::Frame::new().fill(t.chrome).inner_margin(Margin::symmetric(10, 4))).show(
|
||||
ui,
|
||||
|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if icons::button(ui, "chevron-up", 22.0, false, "Show the console").clicked() {
|
||||
app.state.bottom_open = true;
|
||||
}
|
||||
status_line(app, ui);
|
||||
});
|
||||
},
|
||||
);
|
||||
egui::Panel::bottom("wb-bottom-closed").exact_size(30.0).frame(egui::Frame::new().fill(t.chrome).inner_margin(theme::pad::CHIP)).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if icons::button(ui, "chevron-up", theme::ControlSize::Small, false, "Show the console").clicked() {
|
||||
app.state.bottom_open = true;
|
||||
}
|
||||
status_line(app, ui);
|
||||
});
|
||||
});
|
||||
}
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame::new().fill(t.canvas).inner_margin(Margin::same(0)))
|
||||
.frame(egui::Frame::new().fill(t.canvas).inner_margin(Margin::ZERO))
|
||||
.show(ui, |ui| crate::guard_ui(ui, "centre", |ui| center(app, ui)));
|
||||
}
|
||||
|
||||
@@ -141,19 +138,19 @@ fn rail_icons(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.vertical_centered(|ui| {
|
||||
for k in RailKind::ALL {
|
||||
let on = app.state.rail == k;
|
||||
if icons::button(ui, k.icon(), 34.0, on, k.title()).clicked() && !on {
|
||||
if icons::button(ui, k.icon(), theme::ControlSize::Medium, on, k.title()).clicked() && !on {
|
||||
app.state.rail = k;
|
||||
app.state.rail_filter.clear();
|
||||
app.ensure_rail_loaded();
|
||||
}
|
||||
ui.add_space(2.0);
|
||||
ui.add_space(theme::space::XXS);
|
||||
}
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "search", 34.0, app.state.palette.open, "Command palette (Ctrl/⌘ K)").clicked() {
|
||||
if icons::button(ui, "search", theme::ControlSize::Medium, app.state.palette.open, "Command palette (Ctrl/⌘ K)").clicked() {
|
||||
app.state.palette.open = true;
|
||||
}
|
||||
// Projects and their builds; a dot when one needs an answer.
|
||||
let r = icons::button(ui, "hammer", 34.0, false, "Projects and builds");
|
||||
let r = icons::button(ui, "hammer", theme::ControlSize::Medium, false, "Projects and builds");
|
||||
if !app.asking.is_empty() {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.painter().circle_filled(r.rect.right_top() + egui::vec2(-7.0, 7.0), 4.5, t.warning);
|
||||
@@ -168,7 +165,7 @@ fn rail_icons(app: &mut CraftApp, ui: &mut Ui) {
|
||||
fn panel_title(ui: &mut Ui, title: &str, count: Option<usize>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(theme::label_text(&tr(title), 11.5).color(t.text));
|
||||
ui.label(theme::label_text(&tr(title), theme::LABEL).color(t.text));
|
||||
if let Some(n) = count {
|
||||
widgets::pill(ui, &n.to_string(), t.text_dim, t.raised);
|
||||
}
|
||||
@@ -198,12 +195,12 @@ fn rail_list(app: &mut CraftApp, ui: &mut Ui, kind: RailKind, fill: &Fill) {
|
||||
ui.horizontal(|ui| {
|
||||
panel_title(ui, kind.title(), matches!(fill, Fill::Ready(_) | Fill::Value(_)).then_some(all.len()));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "refresh-cw", 24.0, false, "Reload").clicked() {
|
||||
if icons::button(ui, "refresh-cw", theme::ControlSize::Small, false, "Reload").clicked() {
|
||||
app.load_rail(kind);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
widgets::named(
|
||||
ui.add(
|
||||
egui::TextEdit::singleline(&mut app.state.rail_filter)
|
||||
@@ -213,7 +210,7 @@ fn rail_list(app: &mut CraftApp, ui: &mut Ui, kind: RailKind, fill: &Fill) {
|
||||
),
|
||||
"Filter",
|
||||
);
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if app.view.active.is_none() {
|
||||
widgets::empty_state(ui, "folder-open", "Nothing open", "Open a file or drop one here.");
|
||||
ui.vertical_centered(|ui| {
|
||||
@@ -282,11 +279,11 @@ fn list_row(ui: &mut Ui, r: &Value, selected: bool, h: f32) -> bool {
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, selected, &name));
|
||||
let x = rect.left() + 8.0;
|
||||
if let Some(a) = &addr {
|
||||
let g = ui.painter().layout_no_wrap(a.clone(), theme::mono(11.0), if selected { t.accent_ink } else { t.text_faint });
|
||||
let g = ui.painter().layout_no_wrap(a.clone(), theme::mono(theme::TINY), if selected { t.accent_ink } else { t.text_faint });
|
||||
ui.painter().galley(egui::pos2(x, rect.top() + 3.0), g, t.text_faint);
|
||||
}
|
||||
let name_y = if addr.is_some() { rect.top() + 17.0 } else { rect.center().y - 8.0 };
|
||||
let name_g = ui.painter().layout_no_wrap(truncate(&name, 120), theme::mono(12.5), t.text);
|
||||
let name_g = ui.painter().layout_no_wrap(truncate(&name, 120), theme::mono(theme::CODE), t.text);
|
||||
let clip = rect.shrink2(Vec2::new(6.0, 0.0));
|
||||
ui.painter().with_clip_rect(clip).galley(egui::pos2(x, name_y), name_g, t.text);
|
||||
if let Some(d) = row_detail(r) {
|
||||
@@ -312,12 +309,12 @@ fn targets_list(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
panel_title(ui, "Targets", Some(app.view.targets.len()));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "plus", 24.0, false, "Open another target").clicked() {
|
||||
if icons::button(ui, "plus", theme::ControlSize::Small, false, "Open another target").clicked() {
|
||||
app.pick(Pick::OpenFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if app.view.targets.is_empty() {
|
||||
widgets::empty_state(ui, "layers", "No targets", "Open files, folders or apps; you can have several open at once.");
|
||||
return;
|
||||
@@ -333,7 +330,7 @@ fn targets_list(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
let ir = egui::Rect::from_min_size(rect.min + Vec2::new(8.0, 10.0), Vec2::splat(30.0));
|
||||
ui.painter().rect_filled(ir, t.radius_sm, t.raised);
|
||||
icons::paint(ui, ir, crate::kind_icon(tgt.kind), 16.0, if active { t.accent_ink } else { t.icon });
|
||||
icons::paint(ui, ir, crate::kind_icon(tgt.kind), theme::icon::MD, if active { t.accent_ink } else { t.icon });
|
||||
ui.painter().text(egui::pos2(ir.right() + 10.0, rect.top() + 8.0), egui::Align2::LEFT_TOP, &tgt.name, theme::medium(theme::SMALL), t.text);
|
||||
ui.painter().text(
|
||||
egui::pos2(ir.right() + 10.0, rect.top() + 27.0),
|
||||
@@ -359,10 +356,10 @@ fn tab_strip(ui: &mut Ui, tabs: &[(&str, &str)], selected: usize) -> Option<usiz
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let mut picked = None;
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
ui.spacing_mut().item_spacing.x = theme::space::XXS;
|
||||
for (i, (icon, title)) in tabs.iter().enumerate() {
|
||||
let on = i == selected;
|
||||
let g = widgets::label_galley(ui, &tr(title), 11.0, t.text);
|
||||
let g = widgets::label_galley(ui, &tr(title), theme::CAPTION, t.text);
|
||||
let w = g.size().x + if icon.is_empty() { 22.0 } else { 42.0 };
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(w, 32.0), egui::Sense::click());
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, on, tr(title)));
|
||||
@@ -397,7 +394,7 @@ fn tab_strip(ui: &mut Ui, tabs: &[(&str, &str)], selected: usize) -> Option<usiz
|
||||
|
||||
fn center(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
egui::Frame::new().fill(t.chrome).inner_margin(Margin::symmetric(8, 0)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.chrome).inner_margin(theme::pad::GUTTER).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
let tabs: Vec<(&str, &str)> = CenterTab::ALL.iter().map(|c| (c.icon(), c.title())).collect();
|
||||
let sel = CenterTab::ALL.iter().position(|c| *c == app.state.center).unwrap_or(0);
|
||||
@@ -411,7 +408,7 @@ fn center(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
ui.painter().hline(ui.max_rect().x_range(), ui.cursor().top(), egui::Stroke::new(1.0, t.separator));
|
||||
egui::Frame::new().inner_margin(Margin::same(14)).show(ui, |ui| {
|
||||
egui::Frame::new().inner_margin(theme::pad::CARD).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
if app.view.active.is_none() && app.state.center != CenterTab::Result {
|
||||
no_target(app, ui);
|
||||
@@ -444,7 +441,7 @@ fn no_target(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.pick(Pick::OpenFolder);
|
||||
}
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.label(RichText::new(tr("Tip: press Ctrl/⌘ K to run any tool.")).color(t.text_faint));
|
||||
});
|
||||
@@ -482,7 +479,7 @@ fn tool_view(app: &mut CraftApp, ui: &mut Ui, tab: CenterTab) {
|
||||
widgets::confidence_badge(ui, Some(e.confidence));
|
||||
ui.label(RichText::new(&e.summary).color(Tokens::get(ui.ctx()).text_dim));
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
render_result(ui, &e.result, tab);
|
||||
}
|
||||
Fill::Value(v) => render_result(ui, &v, tab),
|
||||
@@ -518,13 +515,16 @@ fn render_result(ui: &mut Ui, v: &Value, tab: CenterTab) {
|
||||
fn code_view(ui: &mut Ui, code: &str, t: &Tokens) {
|
||||
let lines: Vec<&str> = code.lines().collect();
|
||||
let row_h = 18.0;
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(Margin::same(8)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(theme::pad::TIGHT).show(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink([false, false]).show_rows(ui, row_h, lines.len(), |ui, range| {
|
||||
for i in range {
|
||||
let Some(line) = lines.get(i) else { continue };
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 12.0;
|
||||
ui.add_sized(Vec2::new(38.0, row_h), egui::Label::new(RichText::new(format!("{:>4}", i + 1)).font(theme::mono(12.0)).color(t.text_faint)));
|
||||
ui.spacing_mut().item_spacing.x = theme::space::MD;
|
||||
ui.add_sized(
|
||||
Vec2::new(38.0, row_h),
|
||||
egui::Label::new(RichText::new(format!("{:>4}", i + 1)).font(theme::mono(theme::CODE)).color(t.text_faint)),
|
||||
);
|
||||
ui.label(highlight(line, t));
|
||||
});
|
||||
}
|
||||
@@ -539,7 +539,7 @@ const KEYWORDS: &[&str] = &[
|
||||
|
||||
fn highlight(line: &str, t: &Tokens) -> egui::text::LayoutJob {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
let font = theme::mono(12.5);
|
||||
let font = theme::mono(theme::CODE);
|
||||
let comment = line.find("//").or_else(|| line.find(';').filter(|_| !line.trim_end().ends_with(';')));
|
||||
let (code, rest) = match comment {
|
||||
Some(i) => (line.get(..i).unwrap_or(line), line.get(i..).unwrap_or("")),
|
||||
@@ -599,7 +599,7 @@ fn table(ui: &mut Ui, rows: &[Value], t: &Tokens) {
|
||||
let row_h = 20.0;
|
||||
ui.horizontal(|ui| {
|
||||
for c in &cols {
|
||||
ui.add_sized(Vec2::new(150.0, 18.0), egui::Label::new(theme::label_text(c, 11.0).color(t.text_faint)));
|
||||
ui.add_sized(Vec2::new(150.0, 18.0), egui::Label::new(theme::label_text(c, theme::CAPTION).color(t.text_faint)));
|
||||
}
|
||||
});
|
||||
egui::ScrollArea::both().auto_shrink([false, false]).show_rows(ui, row_h, rows.len().min(MAX_ROWS), |ui, range| {
|
||||
@@ -611,7 +611,7 @@ fn table(ui: &mut Ui, rows: &[Value], t: &Tokens) {
|
||||
Value::Object(m) => m.get(c).map(|v| scalar(v).unwrap_or_else(|| v.to_string())).unwrap_or_default(),
|
||||
other => scalar(other).unwrap_or_default(),
|
||||
};
|
||||
ui.add_sized(Vec2::new(150.0, row_h), egui::Label::new(RichText::new(truncate(&v, 40)).font(theme::mono(12.0))).truncate());
|
||||
ui.add_sized(Vec2::new(150.0, row_h), egui::Label::new(RichText::new(truncate(&v, 40)).font(theme::mono(theme::CODE))).truncate());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -637,7 +637,7 @@ fn hex_view(app: &mut CraftApp, ui: &mut Ui) {
|
||||
egui::TextEdit::singleline(&mut goto)
|
||||
.hint_text(tr("Go to offset (0x…)"))
|
||||
.desired_width(150.0)
|
||||
.font(theme::mono(12.0))
|
||||
.font(theme::mono(theme::CODE))
|
||||
.frame(widgets::text_field_frame_compact(&t)),
|
||||
);
|
||||
if r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||
@@ -649,10 +649,10 @@ fn hex_view(app: &mut CraftApp, ui: &mut Ui) {
|
||||
});
|
||||
});
|
||||
ui.data_mut(|d| d.insert_temp(goto_id, goto));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
let rows = bytes.len().div_ceil(16);
|
||||
let row_h = 18.0;
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(Margin::same(8)).show(ui, |ui| {
|
||||
egui::Frame::new().fill(t.code_bg).corner_radius(t.r()).inner_margin(theme::pad::TIGHT).show(ui, |ui| {
|
||||
let mut area = egui::ScrollArea::both().auto_shrink([false, false]);
|
||||
if let Some(r) = scroll_to {
|
||||
area = area.vertical_scroll_offset(r as f32 * (row_h + ui.spacing().item_spacing.y));
|
||||
@@ -662,7 +662,7 @@ fn hex_view(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let start = row * 16;
|
||||
let Some(chunk) = bytes.get(start..(start + 16).min(bytes.len())) else { continue };
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
let f = theme::mono(12.5);
|
||||
let f = theme::mono(theme::CODE);
|
||||
job.append(&format!("{start:08x} "), 0.0, egui::TextFormat { font_id: f.clone(), color: t.text_faint, ..Default::default() });
|
||||
for (i, b) in chunk.iter().enumerate() {
|
||||
let col = if *b == 0 {
|
||||
@@ -717,7 +717,7 @@ fn result_view(app: &mut CraftApp, ui: &mut Ui) {
|
||||
fn evidence_view(ui: &mut Ui, e: &craft_anything_engine::evidence::Evidence, t: &Tokens) {
|
||||
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
|
||||
evidence_ui::proof_card(ui, e, true, false);
|
||||
ui.add_space(10.0);
|
||||
ui.add_space(theme::space::MD);
|
||||
if let Some(code) = code_text(&e.result) {
|
||||
code_view(ui, code, t);
|
||||
} else {
|
||||
@@ -736,7 +736,7 @@ fn right(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if let Some(i) = tab_strip(ui, &tabs, sel) {
|
||||
app.state.right = [RightTab::Inspector, RightTab::Evidence, RightTab::Unknowns].get(i).copied().unwrap_or_default();
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
match app.state.right {
|
||||
RightTab::Inspector => inspector(app, ui),
|
||||
RightTab::Evidence => ledger(app, ui),
|
||||
@@ -746,7 +746,7 @@ fn right(app: &mut CraftApp, ui: &mut Ui) {
|
||||
|
||||
fn kv(ui: &mut Ui, k: &str, v: &str, t: &Tokens) {
|
||||
ui.label(RichText::new(tr(k)).color(t.text_faint).size(theme::CAPTION));
|
||||
ui.add(egui::Label::new(RichText::new(v).font(theme::mono(12.0))).wrap());
|
||||
ui.add(egui::Label::new(RichText::new(v).font(theme::mono(theme::CODE))).wrap());
|
||||
ui.end_row();
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ fn inspector(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.set_width(ui.available_width());
|
||||
widgets::caption(ui, "Selection");
|
||||
ui.label(RichText::new(row_name(&sel).unwrap_or_else(|| "—".into())).font(theme::semibold(theme::BODY)));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
egui::Grid::new("sel-grid").num_columns(2).spacing([10.0, 4.0]).show(ui, |ui| {
|
||||
if let Value::Object(m) = &sel {
|
||||
for (k, v) in m.iter().take(30) {
|
||||
@@ -766,7 +766,7 @@ fn inspector(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
if widgets::secondary(ui, Some("message-square"), "Ask the agent about this").clicked() {
|
||||
let what = row_name(&sel).or_else(|| row_address(&sel)).unwrap_or_default();
|
||||
app.state.input = crate::i18n::trf("What does {what} do?", &[("what", &what)]);
|
||||
@@ -774,7 +774,7 @@ fn inspector(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.state.bottom_open = true;
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
}
|
||||
match app.view.active_target().cloned() {
|
||||
Some(tgt) => {
|
||||
@@ -782,11 +782,11 @@ fn inspector(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.set_width(ui.available_width());
|
||||
widgets::caption(ui, "Target");
|
||||
ui.horizontal(|ui| {
|
||||
icons::show(ui, crate::kind_icon(tgt.kind), 16.0, t.accent);
|
||||
icons::show(ui, crate::kind_icon(tgt.kind), theme::icon::MD, t.accent);
|
||||
ui.label(RichText::new(&tgt.name).font(theme::semibold(theme::SMALL)));
|
||||
});
|
||||
ui.label(RichText::new(tr(tgt.kind.plain())).color(t.text_dim));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
egui::Grid::new("tgt-grid").num_columns(2).spacing([10.0, 4.0]).show(ui, |ui| {
|
||||
kv(ui, "Kind", &tgt.kind.id(), &t);
|
||||
kv(ui, "Size", &crate::human_bytes(tgt.bytes.len()), &t);
|
||||
@@ -806,7 +806,7 @@ fn ledger(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
panel_title(ui, "Evidence ledger", Some(app.view.ledger_len));
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if app.view.ledger.is_empty() && app.view.findings.is_empty() {
|
||||
widgets::empty_state(ui, "shield-check", "No evidence yet", "Every finding is saved here with how sure we are.");
|
||||
return;
|
||||
@@ -816,8 +816,8 @@ fn ledger(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if !app.view.findings.is_empty() {
|
||||
panel_title(ui, "findings", Some(app.view.findings.len()));
|
||||
for finding in &app.view.findings {
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new(&finding.id).font(theme::mono(12.0)).color(t.accent));
|
||||
ui.add_space(theme::space::SM);
|
||||
ui.label(RichText::new(&finding.id).font(theme::mono(theme::CODE)).color(t.accent));
|
||||
ui.add(egui::Label::new(&finding.statement).wrap());
|
||||
ui.label(RichText::new(finding.confidence.plain_label()).color(t.text_dim).size(theme::CAPTION));
|
||||
for id in &finding.evidence_ids {
|
||||
@@ -833,7 +833,7 @@ fn ledger(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if evidence_ui::ledger_row(ui, e, selected) {
|
||||
pick = Some(e.id.clone());
|
||||
}
|
||||
ui.add_space(3.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
if app.view.ledger_len > app.view.ledger.len() {
|
||||
ui.label(RichText::new(crate::i18n::trf("… {n} older", &[("n", &(app.view.ledger_len - app.view.ledger.len()).to_string())])).color(t.text_faint));
|
||||
@@ -849,7 +849,7 @@ fn ledger(app: &mut CraftApp, ui: &mut Ui) {
|
||||
fn unknowns(app: &mut CraftApp, ui: &mut Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
panel_title(ui, "Open questions", Some(app.view.unknowns.len()));
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if app.view.unknowns.is_empty() {
|
||||
widgets::empty_state(ui, "circle-help", "No open questions", "Things we couldn't establish yet are listed here, with what would settle them.");
|
||||
return;
|
||||
@@ -874,7 +874,7 @@ fn unknowns(app: &mut CraftApp, ui: &mut Ui) {
|
||||
ui.label(RichText::new(r).color(t.success).size(theme::CAPTION));
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -904,14 +904,14 @@ fn bottom(app: &mut CraftApp, ui: &mut Ui) {
|
||||
app.state.bottom = [BottomTab::Agent, BottomTab::Jobs, BottomTab::Log].get(i).copied().unwrap_or_default();
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if icons::button(ui, "chevron-down", 24.0, false, "Hide the console").clicked() {
|
||||
if icons::button(ui, "chevron-down", theme::ControlSize::Small, false, "Hide the console").clicked() {
|
||||
app.state.bottom_open = false;
|
||||
}
|
||||
status_line(app, ui);
|
||||
});
|
||||
});
|
||||
ui.painter().hline(ui.max_rect().x_range(), ui.cursor().top(), egui::Stroke::new(1.0, t.separator));
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(theme::space::SM);
|
||||
match app.state.bottom {
|
||||
BottomTab::Agent => chat::conversation(app, ui, true),
|
||||
BottomTab::Jobs => jobs(app, ui),
|
||||
@@ -936,10 +936,10 @@ fn jobs(app: &mut CraftApp, ui: &mut Ui) {
|
||||
Some(Ok(())) => ("check", t.success),
|
||||
Some(Err(_)) => ("triangle-alert", t.danger),
|
||||
};
|
||||
icons::show(ui, icon, 14.0, col);
|
||||
icons::show(ui, icon, theme::icon::SM, col);
|
||||
ui.add_sized(Vec2::new(220.0, 18.0), egui::Label::new(RichText::new(tr(&j.title)).font(theme::medium(theme::CAPTION))).truncate());
|
||||
let secs = j.finished_at.unwrap_or_else(std::time::Instant::now).duration_since(j.started).as_secs_f32();
|
||||
ui.label(RichText::new(format!("{secs:.1}s")).font(theme::mono(11.5)).color(t.text_faint));
|
||||
ui.label(RichText::new(format!("{secs:.1}s")).font(theme::mono(theme::TINY)).color(t.text_faint));
|
||||
match &j.outcome {
|
||||
None => {
|
||||
let p = j.progress();
|
||||
@@ -947,7 +947,7 @@ fn jobs(app: &mut CraftApp, ui: &mut Ui) {
|
||||
if let Some(p) = p {
|
||||
ui.label(RichText::new(p.message).color(t.text_dim).size(theme::CAPTION));
|
||||
}
|
||||
if icons::button(ui, "x", 24.0, false, "Cancel").clicked() {
|
||||
if icons::button(ui, "x", theme::ControlSize::Small, false, "Cancel").clicked() {
|
||||
cancel = Some(j.id);
|
||||
}
|
||||
}
|
||||
@@ -958,7 +958,7 @@ fn jobs(app: &mut CraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
ui.add_space(theme::space::XS);
|
||||
if widgets::link(ui, "Clear finished").clicked() {
|
||||
clear = true;
|
||||
}
|
||||
@@ -978,8 +978,8 @@ fn log_view(app: &CraftApp, ui: &mut Ui) {
|
||||
for l in &app.log {
|
||||
let secs = start.map(|s| l.at.duration_since(s).as_secs_f32()).unwrap_or(0.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(format!("{secs:>8.2}")).font(theme::mono(11.5)).color(t.text_faint));
|
||||
ui.label(RichText::new(&l.text).font(theme::mono(11.5)).color(if l.error { t.danger } else { t.text_dim }));
|
||||
ui.label(RichText::new(format!("{secs:>8.2}")).font(theme::mono(theme::TINY)).color(t.text_faint));
|
||||
ui.label(RichText::new(&l.text).font(theme::mono(theme::TINY)).color(if l.error { t.danger } else { t.text_dim }));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1523,9 +1523,9 @@ Gaps found while using the app for real projects.
|
||||
switcher in every README (#831)
|
||||
- [x] A Thai README (`README.th.md`) translated from `README.md` and linked from the language
|
||||
switcher in every README
|
||||
- [ ] Vietnamese letters with stacked marks (ạ ả ấ ế ơ ư ữ…) aren't in the bundled DM Sans or egui's
|
||||
- [ ] Vietnamese letters with stacked marks (ạ ả ấ ế ơ ư ữ…) aren't in the bundled Figtree or egui's
|
||||
default fonts: without craft-fonts they show as boxes, and with it each such letter comes from
|
||||
Noto Sans CJK while the rest of the word is DM Sans. Bundle a DM Sans build that has the
|
||||
Noto Sans CJK while the rest of the word is Figtree. Bundle a build of the text font that has the
|
||||
Vietnamese set (with its OFL notice) so Tiếng Việt renders in one face
|
||||
- [x] A build told craft-fonts are required (`CRAFT_FONTS_REQUIRED=1`) finished with none
|
||||
embedded when `CRAFT_FONTS_DIR` was missing: the build script read the switch only when the
|
||||
@@ -1645,6 +1645,23 @@ Gaps found while using the app for real projects.
|
||||
a Rust project rewritten in Python is still checked with Cargo until the old manifest is
|
||||
moved out (#1837): record the stack from what was built for every toolchain, and check
|
||||
with that
|
||||
- [x] One design system for the desktop app: a typed scale (text sizes, gaps, padding, icon and
|
||||
control sizes) in `theme.rs`, one set of buttons (primary, secondary, ghost, danger),
|
||||
switches and fields in `widgets.rs`, and every screen moved onto them, so sizes and spacing
|
||||
stop differing from screen to screen; a test keeps literal sizes, paddings and colours out
|
||||
of the screens (`docs/design-system.md`). With it: Figtree for text; corners of 4, 6 and 8;
|
||||
fields and buttons a shade lighter than their card, with one soft edge; dropdowns, menus
|
||||
and the project's side panel as lists of rows; messages in the title bar; a sliding
|
||||
segmented switch; sharper small text and a wheel step of 100 points. Checked on every
|
||||
snapshot scene in both themes and in the app on Windows; not on macOS or Linux
|
||||
— claimed: bflatastic, branch refactor/ui-design-system
|
||||
- [ ] Design system, left for later: links come in two sizes (`widgets::link` follows the text
|
||||
around it); the title bar keeps its own control height (30, or 26 on macOS) instead of a
|
||||
`ControlSize`; frames with four different sides (prompt box, sidebar, workbench rails)
|
||||
still write their padding where it is used; the macOS disk image's background is still
|
||||
drawn in DM Sans and JetBrains Mono; dropdowns have no name for screen readers, only
|
||||
their value; fields and dropdowns have no 3:1 border at rest (WCAG 1.4.11), by choice,
|
||||
which wants a second look; a compact field is about a point taller than a button
|
||||
|
||||
### R2.10 Pinned builds
|
||||
Owner: maintainers · Status: in progress
|
||||
|
||||
@@ -293,7 +293,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie
|
||||
| Georgian UI | Georgian (`ka`) in Settings → General → Language; System picks it for a Georgian OS language. The catalog has the same keys as the other ones. Written with Claude Code from the meaning of each English string; terminology and doubtful strings decided by a native Georgian speaker (@devius). See [localisation](localization.md). | Catalog and locale tests, key-set comparison with the other catalogs, the isolated language-switch test, the craft-fonts glyph test with a Georgian line. Not checked: how the Georgian texts look in the running window (length, line breaks). |
|
||||
| Spanish UI | Spanish (`es`, informal "tú", Mexican vocabulary) in Settings → General → Language; System picks it for a Spanish OS language. The catalog has the same keys as the Chinese ones. Register and glossary chosen by a native speaker, the text drafted with AI assistance. Requests such as "Un juego de serpiente sencillo" or "Un sitio web para mi panadería" keep their project kind. See [localisation](localization.md). | Catalog and locale tests, key-set comparison with the Chinese catalogs, a kind-detection test. Not checked: how the Spanish texts look in the running window (length, line breaks). |
|
||||
| Italian UI | Italian (`it`, informal "tu") in Settings → General → Language; System picks it for an Italian OS language. The catalog has the same keys as the others. Drafted with an AI, not yet reviewed by a native speaker. Requests such as "Un semplice gioco del serpente" or "Un sito per …" keep their project kind. See [localisation](localization.md). | Placeholder and ellipsis check against the English keys, and a kind-detection test. Not checked: the running window (length, line breaks), a native-speaker review, or the full UI catalog test suite. |
|
||||
| Vietnamese UI | Vietnamese (`vi`, *Tiếng Việt*) in Settings → General → Language; System picks it for a Vietnamese OS language (`vi`, `vi-VN`). The catalog has the same keys as the Chinese ones. Drafted with an AI from the English source, not yet reviewed by a native speaker. Requests such as "Một trò chơi rắn săn mồi" or "Một trang web cho …" keep their project kind. Letters with stacked marks need craft-fonts (releases and CI have it); they come from Noto Sans CJK, not DM Sans. See [localisation](localization.md). | Catalog and locale tests, key-set comparison with the Chinese catalogs, the isolated language-switch test, a kind-detection test, `cargo xtask i18n-coverage` (0 missing); the craft-fonts script test with every Vietnamese letter, and a `--lang vi` Settings snapshot on macOS with the pinned craft-fonts; clippy, layers, locks and secrets are clean. Not checked: the `vi.tsv` wording by a native speaker, and the other screens in the running window (length, line breaks). |
|
||||
| Vietnamese UI | Vietnamese (`vi`, *Tiếng Việt*) in Settings → General → Language; System picks it for a Vietnamese OS language (`vi`, `vi-VN`). The catalog has the same keys as the Chinese ones. Drafted with an AI from the English source, not yet reviewed by a native speaker. Requests such as "Một trò chơi rắn săn mồi" or "Một trang web cho …" keep their project kind. Letters with stacked marks need craft-fonts (releases and CI have it); they come from Noto Sans CJK, not Figtree. See [localisation](localization.md). | Catalog and locale tests, key-set comparison with the Chinese catalogs, the isolated language-switch test, a kind-detection test, `cargo xtask i18n-coverage` (0 missing); the craft-fonts script test with every Vietnamese letter, and a `--lang vi` Settings snapshot on macOS with the pinned craft-fonts; clippy, layers, locks and secrets are clean. Not checked: the `vi.tsv` wording by a native speaker, and the other screens in the running window (length, line breaks). |
|
||||
| JVM method descriptor class names | Parameter and return types keep legal parentheses inside internal class names. | Class-file parser regression and an independent OpenJDK 17 MethodType check. |
|
||||
| DEX capped table alignment | Truncated class-data groups cannot invent following members, and catch-all addresses are read only after the complete typed-handler list. | Synthetic `dex_capped_table_boundaries` regressions (5 tests): Over-cap and exact-cap class members; oversized, truncated, empty and exact-cap typed-handler lists with real catch-all controls. [Format checks](https://github.com/Afloat16/claude-mem/actions/runs/42633003467/job/129213811327) and [compatibility gates](https://github.com/Afloat16/claude-mem/actions/runs/42642583301/job/129247271153) passed at `149f060b9959`. |
|
||||
| Java class usage | `java_class_users_find` includes the component class of multidimensional object arrays; primitive-array descriptors do not match an unrelated class with the same descriptor letter | Synthetic class files parsed by the built-in reader: one- and two-dimensional allocations, class names beginning with `L`, primitive arrays, hit limits and method filters; formats tests. This correction was not checked with javac output or a JVM |
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
# Design system
|
||||
|
||||
The desktop app draws every screen from one scale and one set of components, so sizes, buttons
|
||||
and gaps are the same everywhere. The scale lives in `crates/ui-egui/src/theme.rs`; the
|
||||
components live in `crates/ui-egui/src/widgets.rs` (icon buttons in `icons.rs`). Screens never
|
||||
write a size, a padding or a colour as a number: a test in `theme.rs`
|
||||
(`screens_take_sizes_and_colours_from_the_scale`) walks the source and fails when one does.
|
||||
|
||||
## The scale (`theme.rs`)
|
||||
|
||||
| What | Names | Values |
|
||||
| --- | --- | --- |
|
||||
| Headings (Figtree semibold, `theme::heading`) | `TITLE`, `SECTION`, `CARD` | 26, 18, 16 |
|
||||
| Text (Figtree regular, or medium through `theme::medium` / `label_text`) | `LEAD`, `BODY`, `SMALL`, `LABEL`, `CAPTION`, `TINY` | 17, 15, 14, 13, 12, 11 |
|
||||
| Code, paths and numbers (JetBrains Mono, `theme::mono`) | `CODE` | 12.5 |
|
||||
| A wrapped paragraph's line height | `theme::leading(size)` | 1.45 × the size |
|
||||
| Gaps (`ui.add_space`, item spacing) | `space::XXS` … `space::XXL` | 2, 4, 8, 12, 16, 24, 32 |
|
||||
| Padding inside frames | `pad::MENU`, `TIGHT`, `PANEL`, `CARD`, `ROOMY`, `ROW`, `BAR`, `CHIP`, `GUTTER`, `FIELD`, `FIELD_COMPACT` | built from the gaps |
|
||||
| Icons | `icon::XS` … `icon::XXL` | 12, 14, 16, 20, 24, 32 |
|
||||
| Corners | `Tokens::radius_sm`, `radius`, `radius_lg` | 4 (segments, rows of a list), 6 (controls, fields), 8 (cards, dialogs); status pills are fully round |
|
||||
| Colours | `Tokens` (`Tokens::get(ctx)`) | one set per theme; contrast is tested |
|
||||
|
||||
`TINY` is for the Advanced workbench's dense lists; everything else is 12 pt or more.
|
||||
|
||||
### Fonts
|
||||
|
||||
Text, labels and headings are Figtree, one variable font file set to three weights (400, 500,
|
||||
600). Code is JetBrains Mono. Both are in `assets/fonts` with their licences
|
||||
(`ATTRIBUTION.md`). Figtree covers Latin and extended Latin only; every other script comes from
|
||||
craft-fonts, which release and CI builds embed (`CRAFT_FONTS_DIR`, see
|
||||
[localisation](localization.md)). A local build without it shows those scripts as boxes.
|
||||
|
||||
### Control sizes
|
||||
|
||||
`ControlSize` ties a control's height, label size, side padding and icon size together, so two
|
||||
controls of one size always line up.
|
||||
|
||||
| Size | Height | Label | Icon | Used for |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `Small` | 24 | `LABEL` | 14 | toolbars, rows of a list, the workbench |
|
||||
| `Medium` (default) | 32 | `BODY` | 16 | buttons, switches, dropdowns and their rows, compact fields |
|
||||
| `Large` | 40 | `BODY` | 16 | a screen's main switch, full text fields |
|
||||
| `Hero` | 48 | `CARD` | 20 | the one action a screen is for (Start) |
|
||||
|
||||
A button's label, a dropdown's value, a row of its list and the text typed into a field are all
|
||||
`BODY`, the size of the text around them. egui's own controls (dropdowns, menu rows) are set up
|
||||
in `theme::apply` to match: `Medium` in Simple mode, `Small` in Advanced.
|
||||
|
||||
### Surfaces and edges
|
||||
|
||||
- The page is `canvas`, a card on it is `card`, and anything to type in or press is `field`: a
|
||||
shade lighter than the card (white on the paper card in the light theme), so it reads as
|
||||
something to use. `hover` and `pressed` are a step lighter again.
|
||||
- Every control has the same edge: `card_border` at rest, `field_border` under the pointer, the
|
||||
app colour while it is pressed, open or typed in. `field_border` is the 3:1 colour; at rest a
|
||||
field is told apart by its lighter fill and soft edge, not by a 3:1 border.
|
||||
- Keyboard focus is a hairline in `accent_ink` on the control's edge and a soft 3 px halo
|
||||
outside it (`focus_ring`). A text field gets the same, faded in and out
|
||||
(`text_focus_ring`, drawn once a frame for whichever field has focus).
|
||||
|
||||
## Components (`widgets.rs`)
|
||||
|
||||
| Need | Use |
|
||||
| --- | --- |
|
||||
| The main action of a screen or card | `primary`, `primary_icon` |
|
||||
| Any other action | `secondary` |
|
||||
| A quiet action (no box until hovered) | `ghost` |
|
||||
| Something that deletes or can't be undone | `danger` (filled in the danger colour) |
|
||||
| Another size, a disabled state, or the full width of a panel | `Button::new(kind, label).icon(..).size(..).enabled(..).wide()` |
|
||||
| An icon on its own | `icons::button(ui, name, ControlSize, selected, tooltip)` |
|
||||
| A list of things to do with what's shown (a panel's actions) | `action_row`, one per row, in a `card` with `pad::TIGHT` |
|
||||
| A link in text | `link`; inside a caption, `caption_link` |
|
||||
| One of a few choices | `segmented(ui, options, selected, ControlSize)`: the chosen segment's card slides to the one picked. Big choices with words: `choice_tile` |
|
||||
| One of many choices | `dropdown(id)` (egui's combo box, set up) with a `menu_item` or `menu_choice` per row |
|
||||
| A row of a menu | `menu_item` |
|
||||
| On/off | `toggle` |
|
||||
| A text field | `egui::TextEdit` with `.frame(text_field_frame(&t))` (`Large`) or `text_field_frame_compact` (`Medium`). One inside a bigger box that shows focus itself calls `frameless_field` |
|
||||
| A status word | `pill`; how sure we are: `confidence_badge` |
|
||||
| A box around content | `card` (screens), `panel` (workbench) |
|
||||
| A section's caption | `caption` |
|
||||
| A name and its value | `stat_row` |
|
||||
| Nothing to show yet | `empty_state` |
|
||||
| Work in progress | `Spinner`, `ProgressBar`, `working` (never egui's own: they redraw every frame) |
|
||||
|
||||
Every component paints its hover and pressed states with a short ease (`hover_t`), a focus ring,
|
||||
a disabled state where it has one, and names itself for screen readers. Labels are translated
|
||||
inside the component: pass the English key. A row of a list (`menu_item`) shows its text as
|
||||
given.
|
||||
|
||||
## Behaviour
|
||||
|
||||
- **Scrolling.** One notch of the wheel moves `theme::WHEEL_STEP` points (100) and eases there.
|
||||
Scroll bars are a slim thumb with no track that thickens under the pointer
|
||||
(`theme::scroll_style`); the thumb keeps 3:1 against every surface.
|
||||
- **Lists that open.** A dropdown's list and a menu fade in (`POPUP_FADE`), show about nine rows
|
||||
before they scroll, and are as wide as their widest row.
|
||||
- **Messages.** A message to the person (`CraftApp::toast`) shows as a compact card under the
|
||||
title bar, in the middle. The card lets clicks through to what is under it; only its close
|
||||
button takes one. A confirmation goes away by itself, and a new one takes the place of the
|
||||
one before it. Errors stay until dismissed.
|
||||
- **Text.** Glyphs sit on whole pixels (`subpixel_binning` is off), which keeps small text
|
||||
sharp on a display at 100 %.
|
||||
- **The window.** Without a native frame the app draws a 1 px edge in `card_border`. On Windows
|
||||
the top side is left to the line Windows draws itself.
|
||||
|
||||
## Rules
|
||||
|
||||
- A new size, gap or colour is a change to the scale, not a number in a screen. If nothing on
|
||||
the scale fits, the design probably wants one of the existing steps.
|
||||
- A size worked out from another (`body.size + 2.0`, a title bar size times its zoom) is fine.
|
||||
- Padding with four different sides (a prompt box that leaves room for its buttons) is written
|
||||
as `Margin { .. }` where it is used; even padding comes from `pad`.
|
||||
- A paragraph that wraps sets its line height with `theme::leading`; a single line doesn't.
|
||||
- Rows of a dropdown or a menu are `menu_item`s; don't use `ui.button` or `selectable_label`
|
||||
for them.
|
||||
- The title bar follows the window's chrome (and, on macOS, keeps its size when the app zooms),
|
||||
so it scales the same tokens instead of using `ControlSize`.
|
||||
- Check a change in both themes: `cargo run -p craft-anything-ui-egui --example snapshot -- --out-dir <dir>`
|
||||
renders every scene, and `--light` renders them in Studio Light. `--scale 1` shows what a
|
||||
display at 100 % shows. The README's pictures come from the same scenes (the example's header
|
||||
says which).
|
||||
@@ -17,6 +17,7 @@ place to add yours. Follow `AGENTS.md` (never crash, layers, external programs t
|
||||
| An external engine | `crates/engines/src/table.rs` | One `ExternalEngine` entry (exes, known paths, what it's for, install pins with SHA-256 checked against the publisher), plus a `tool_paths!` id in `settings.rs` if people can point at their own install. |
|
||||
| A front end for builds | anywhere above L5 | Hold a `rebuild::RunSet` (it queues past its limit) and `poll` it; test it with `RunSet::with_starter(StandIns::starter())`, whose runs report only what the test sends. |
|
||||
| A persisted file | its owner module | A version field and a migration step; see [file-formats.md](file-formats.md). |
|
||||
| A screen, a control or a size in the desktop app | `crates/ui-egui/src/` | Use the components in `widgets.rs` and the scale in `theme.rs`; a new size or colour goes into the scale, never into a screen. See [the design system](design-system.md). |
|
||||
| A UI language | `crates/ui-egui/src/i18n/` and `i18n.rs` | Add a TSV catalog and a language registry entry; preserve placeholders and run the catalog tests and `cargo xtask i18n-coverage`. See [localisation](localization.md) for scope and font setup. |
|
||||
|
||||
## Plugins: external MCP servers
|
||||
|
||||
|
Before Width: | Height: | Size: 311 KiB After Width: | Height: | Size: 322 KiB |
|
Before Width: | Height: | Size: 300 KiB After Width: | Height: | Size: 306 KiB |
|
Before Width: | Height: | Size: 354 KiB After Width: | Height: | Size: 382 KiB |
|
Before Width: | Height: | Size: 409 KiB After Width: | Height: | Size: 411 KiB |
@@ -167,9 +167,9 @@ cargo run -p craft-anything-ui-egui --example snapshot -- --lang zh-hant --only
|
||||
|
||||
Chinese, Korean and Georgian glyphs use the existing craft-fonts fallback, which release and CI builds
|
||||
Spanish and Estonian are Latin script and need no extra glyphs. Chinese and Korean glyphs use the existing craft-fonts fallback, which release and CI builds
|
||||
Vietnamese needs craft-fonts too: the bundled DM Sans and egui's default fonts lack the letters with
|
||||
Vietnamese needs craft-fonts too: the bundled Figtree and egui's default fonts lack the letters with
|
||||
stacked marks (ạ, ả, ấ, ế, ơ, ư, ữ…), so a build without craft-fonts shows them as boxes. With
|
||||
craft-fonts, Noto Sans CJK SC supplies those letters (a different face from the DM Sans around them);
|
||||
craft-fonts, Noto Sans CJK SC supplies those letters (a different face from the Figtree around them);
|
||||
the script test in `theme.rs` checks every one of them. Chinese and Korean glyphs use the existing craft-fonts fallback, which release and CI builds
|
||||
already include. Local builds must set `CRAFT_FONTS_DIR` to a craft-fonts checkout
|
||||
before compiling to get the same glyph coverage; with `CRAFT_FONTS_REQUIRED=1` set as well, a
|
||||
|
||||