ced/src/app/state/config.rs

69 lines
2.2 KiB
Rust
Raw Normal View History

2025-07-05 14:42:45 -04:00
use super::editor::TextEditor;
use crate::app::config::Config;
use crate::app::theme;
impl TextEditor {
pub fn from_config(config: Config) -> Self {
Self {
show_line_numbers: config.show_line_numbers,
word_wrap: config.word_wrap,
auto_hide_toolbar: config.auto_hide_toolbar,
2025-07-15 20:08:38 -04:00
hide_tab_bar: config.hide_tab_bar,
2025-07-05 14:42:45 -04:00
theme: config.theme,
line_side: config.line_side,
font_family: config.font_family,
font_size: config.font_size,
2025-07-22 21:42:31 -04:00
syntax_highlighting: config.syntax_highlighting,
..Default::default()
2025-07-05 14:42:45 -04:00
}
}
pub fn from_config_with_context(config: Config, cc: &eframe::CreationContext<'_>) -> Self {
let mut editor = Self::from_config(config);
theme::apply(editor.theme, &cc.egui_ctx);
cc.egui_ctx.options_mut(|o| o.zoom_with_keyboard = false);
2025-07-16 17:20:09 -04:00
let mut style = (*cc.egui_ctx.style()).to_owned();
2025-07-05 14:42:45 -04:00
style
.text_styles
.insert(egui::TextStyle::Body, egui::FontId::proportional(16.0));
style
.text_styles
.insert(egui::TextStyle::Button, egui::FontId::proportional(16.0));
style
.text_styles
.insert(egui::TextStyle::Heading, egui::FontId::proportional(22.0));
style
.text_styles
.insert(egui::TextStyle::Small, egui::FontId::proportional(14.0));
cc.egui_ctx.set_style(style);
editor.apply_font_settings(&cc.egui_ctx);
editor
}
pub fn get_config(&self) -> Config {
Config {
auto_hide_toolbar: self.auto_hide_toolbar,
show_line_numbers: self.show_line_numbers,
2025-07-15 20:08:38 -04:00
hide_tab_bar: self.hide_tab_bar,
2025-07-05 14:42:45 -04:00
word_wrap: self.word_wrap,
theme: self.theme,
line_side: self.line_side,
2025-07-16 17:20:09 -04:00
font_family: self.font_family.to_string(),
2025-07-05 14:42:45 -04:00
font_size: self.font_size,
2025-07-22 21:42:31 -04:00
syntax_highlighting: self.syntax_highlighting,
2025-07-05 14:42:45 -04:00
// vim_mode: self.vim_mode,
}
}
pub fn save_config(&self) {
let config = self.get_config();
if let Err(e) = config.save() {
2025-07-15 00:42:01 -04:00
eprintln!("Failed to save configuration: {e}");
2025-07-05 14:42:45 -04:00
}
}
}