2025-07-05 14:42:45 -04:00
|
|
|
use crate::app::TextEditor;
|
|
|
|
|
use eframe::egui;
|
|
|
|
|
|
|
|
|
|
pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
|
|
|
|
|
let visuals = &ctx.style().visuals;
|
|
|
|
|
let screen_rect = ctx.screen_rect();
|
|
|
|
|
let window_width = (screen_rect.width() * 0.6).min(400.0).max(300.0);
|
|
|
|
|
let window_height = (screen_rect.height() * 0.7).min(500.0).max(250.0);
|
|
|
|
|
let max_size = egui::Vec2::new(window_width, window_height);
|
|
|
|
|
|
|
|
|
|
egui::Window::new("Preferences")
|
|
|
|
|
.collapsible(false)
|
|
|
|
|
.resizable(false)
|
|
|
|
|
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
|
|
|
|
|
.default_open(true)
|
|
|
|
|
.max_size(max_size)
|
2025-07-16 13:27:31 -04:00
|
|
|
.fade_in(true)
|
|
|
|
|
.fade_out(true)
|
2025-07-05 14:42:45 -04:00
|
|
|
.frame(egui::Frame {
|
|
|
|
|
fill: visuals.window_fill,
|
|
|
|
|
stroke: visuals.window_stroke,
|
|
|
|
|
corner_radius: egui::CornerRadius::same(8),
|
|
|
|
|
shadow: visuals.window_shadow,
|
|
|
|
|
inner_margin: egui::Margin::same(16),
|
|
|
|
|
outer_margin: egui::Margin::same(0),
|
|
|
|
|
})
|
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
|
ui.heading("Font Settings");
|
|
|
|
|
ui.add_space(8.0);
|
|
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.label("Font Family:");
|
|
|
|
|
ui.add_space(5.0);
|
|
|
|
|
|
|
|
|
|
let mut changed = false;
|
|
|
|
|
egui::ComboBox::from_id_salt("font_family")
|
|
|
|
|
.selected_text(&app.font_family)
|
|
|
|
|
.show_ui(ui, |ui| {
|
|
|
|
|
if ui
|
|
|
|
|
.selectable_value(
|
|
|
|
|
&mut app.font_family,
|
|
|
|
|
"Proportional".to_string(),
|
|
|
|
|
"Proportional",
|
|
|
|
|
)
|
|
|
|
|
.clicked()
|
|
|
|
|
{
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
if ui
|
|
|
|
|
.selectable_value(
|
|
|
|
|
&mut app.font_family,
|
|
|
|
|
"Monospace".to_string(),
|
|
|
|
|
"Monospace",
|
|
|
|
|
)
|
|
|
|
|
.clicked()
|
|
|
|
|
{
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if changed {
|
2025-07-15 09:53:45 -04:00
|
|
|
app.apply_font_settings_with_ui(ctx, ui);
|
2025-07-05 14:42:45 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.add_space(8.0);
|
|
|
|
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
ui.label("Font Size:");
|
|
|
|
|
ui.add_space(5.0);
|
|
|
|
|
|
|
|
|
|
if app.font_size_input.is_none() {
|
|
|
|
|
app.font_size_input = Some(app.font_size.to_string());
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-15 11:07:41 -04:00
|
|
|
let mut font_size_text = app
|
|
|
|
|
.font_size_input
|
|
|
|
|
.as_ref()
|
|
|
|
|
.unwrap_or(&"14".to_string())
|
2025-07-16 17:20:09 -04:00
|
|
|
.to_owned();
|
2025-07-05 14:42:45 -04:00
|
|
|
let response = ui.add(
|
|
|
|
|
egui::TextEdit::singleline(&mut font_size_text)
|
|
|
|
|
.desired_width(50.0)
|
|
|
|
|
.hint_text("14")
|
|
|
|
|
.id(egui::Id::new("font_size_input")),
|
|
|
|
|
);
|
|
|
|
|
|
2025-07-16 17:20:09 -04:00
|
|
|
app.font_size_input = Some(font_size_text.to_owned());
|
2025-07-05 14:42:45 -04:00
|
|
|
|
|
|
|
|
if response.clicked() {
|
|
|
|
|
response.request_focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.label("px");
|
|
|
|
|
|
|
|
|
|
if response.lost_focus() {
|
|
|
|
|
if let Ok(new_size) = font_size_text.parse::<f32>() {
|
|
|
|
|
let clamped_size = new_size.clamp(8.0, 32.0);
|
|
|
|
|
if (app.font_size - clamped_size).abs() > 0.1 {
|
|
|
|
|
app.font_size = clamped_size;
|
2025-07-15 09:53:45 -04:00
|
|
|
app.apply_font_settings_with_ui(ctx, ui);
|
2025-07-05 14:42:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
app.font_size_input = None;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.add_space(12.0);
|
|
|
|
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
ui.add_space(8.0);
|
|
|
|
|
ui.label("Preview:");
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
|
|
|
|
|
egui::ScrollArea::vertical()
|
|
|
|
|
.max_height(150.0)
|
|
|
|
|
.show(ui, |ui| {
|
|
|
|
|
egui::Frame::new()
|
|
|
|
|
.fill(visuals.code_bg_color)
|
|
|
|
|
.stroke(visuals.widgets.noninteractive.bg_stroke)
|
|
|
|
|
.inner_margin(egui::Margin::same(8))
|
|
|
|
|
.show(ui, |ui| {
|
|
|
|
|
let preview_font = egui::FontId::new(
|
|
|
|
|
app.font_size,
|
|
|
|
|
match app.font_family.as_str() {
|
|
|
|
|
"Monospace" => egui::FontFamily::Monospace,
|
|
|
|
|
_ => egui::FontFamily::Proportional,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
ui.label(
|
2025-07-15 11:07:41 -04:00
|
|
|
egui::RichText::new(
|
|
|
|
|
"The quick brown fox jumps over the lazy dog.",
|
|
|
|
|
)
|
2025-07-16 17:20:09 -04:00
|
|
|
.font(preview_font.to_owned()),
|
2025-07-05 14:42:45 -04:00
|
|
|
);
|
|
|
|
|
ui.label(
|
|
|
|
|
egui::RichText::new("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
2025-07-16 17:20:09 -04:00
|
|
|
.font(preview_font.to_owned()),
|
2025-07-05 14:42:45 -04:00
|
|
|
);
|
|
|
|
|
ui.label(
|
|
|
|
|
egui::RichText::new("abcdefghijklmnopqrstuvwxyz")
|
2025-07-16 17:20:09 -04:00
|
|
|
.font(preview_font.to_owned()),
|
2025-07-05 14:42:45 -04:00
|
|
|
);
|
2025-07-15 11:07:41 -04:00
|
|
|
ui.label(
|
2025-07-16 17:34:11 -04:00
|
|
|
egui::RichText::new("1234567890 !@#$%^&*()")
|
|
|
|
|
.font(preview_font.to_owned()),
|
2025-07-15 11:07:41 -04:00
|
|
|
);
|
2025-07-05 14:42:45 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.add_space(12.0);
|
|
|
|
|
|
|
|
|
|
if ui.button("Close").clicked() {
|
|
|
|
|
app.show_preferences = false;
|
|
|
|
|
app.font_size_input = None;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|