78 lines
3.0 KiB
Rust
78 lines
3.0 KiB
Rust
//! Renders the settings view offscreen for visual inspection.
|
|
|
|
use notescraft_engine::{AppSettings, Connection, ConnectionKind};
|
|
use notescraft_ui_egui::{
|
|
settings_view::{self, SettingsCategory, SettingsView, ThemeInfo},
|
|
text::settings_view_categories as strings,
|
|
theme::Tokens,
|
|
};
|
|
|
|
struct SettingsExample {
|
|
tokens: Tokens,
|
|
view: SettingsView,
|
|
settings: AppSettings,
|
|
themes: Vec<ThemeInfo>,
|
|
fonts_ready: bool,
|
|
}
|
|
|
|
fn main() {
|
|
let Some(theme) = notescraft_themes::builtin("catppuccin-mocha") else {
|
|
eprintln!("missing built-in theme");
|
|
return;
|
|
};
|
|
let themes: Vec<ThemeInfo> = notescraft_themes::builtin_ids().iter().filter_map(|id| notescraft_themes::builtin(id)).map(ThemeInfo::from_theme).collect();
|
|
let mut view = SettingsView::default();
|
|
view.selected = SettingsCategory::AiAssistant;
|
|
let settings = if std::env::args().any(|argument| argument == "--connections-demo") { demo_settings() } else { AppSettings::default() };
|
|
let app = SettingsExample { tokens: Tokens::new(theme), view, settings, themes, fonts_ready: false };
|
|
let mut harness =
|
|
egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_pixels_per_point(1.0).with_max_steps(32).wgpu().build_ui_state(
|
|
|ui, state: &mut SettingsExample| {
|
|
if !state.fonts_ready {
|
|
egui_extras::install_image_loaders(ui.ctx());
|
|
notescraft_ui_egui::fonts::install(ui.ctx());
|
|
notescraft_ui_egui::style::apply(ui.ctx(), &state.tokens);
|
|
state.fonts_ready = true;
|
|
ui.ctx().request_repaint();
|
|
return;
|
|
}
|
|
let _ = settings_view::show_settings(ui, &state.tokens, &mut state.view, &state.settings, &state.themes);
|
|
},
|
|
app,
|
|
);
|
|
harness.run();
|
|
match harness.render() {
|
|
Ok(image) => {
|
|
if let Err(error) = image.save("/tmp/notescraft-settings-view.png") {
|
|
eprintln!("could not save settings screenshot: {error}");
|
|
}
|
|
}
|
|
Err(error) => eprintln!("could not render settings screenshot: {error}"),
|
|
}
|
|
}
|
|
|
|
fn demo_settings() -> AppSettings {
|
|
let mut settings = AppSettings::default();
|
|
settings.assistant.connections = vec![
|
|
Connection {
|
|
id: "codex".to_owned(),
|
|
name: strings::codex().to_owned(),
|
|
command: "codex-acp".to_owned(),
|
|
icon: "codex".to_owned(),
|
|
..Connection::default()
|
|
},
|
|
Connection {
|
|
id: "openai".to_owned(),
|
|
name: strings::openai().to_owned(),
|
|
kind: ConnectionKind::Openai,
|
|
base_url: "https://api.openai.com/v1".to_owned(),
|
|
model: "gpt-4.1-mini".to_owned(),
|
|
api_key_env: "OPENAI_API_KEY".to_owned(),
|
|
icon: "openai".to_owned(),
|
|
..Connection::default()
|
|
},
|
|
];
|
|
"codex".clone_into(&mut settings.assistant.active);
|
|
settings
|
|
}
|