feat: 添加 app/theme/ui/matrix/render 模块,重构 shader

This commit is contained in:
lennlouisgeek
2026-05-18 02:17:46 +08:00
parent e0fbbd46a6
commit aff9c2a75c
7 changed files with 947 additions and 576 deletions

114
src/theme.rs Normal file
View File

@@ -0,0 +1,114 @@
use eframe::egui;
#[derive(Clone, Copy)]
pub struct AppTheme {
pub bg: egui::Color32,
pub panel: egui::Color32,
pub panel_strong: egui::Color32,
pub panel_deep: egui::Color32,
pub border: egui::Color32,
pub border_soft: egui::Color32,
pub text: egui::Color32,
pub text_dim: egui::Color32,
pub accent: egui::Color32,
pub accent_hot: egui::Color32,
pub radius: u8,
}
pub const ENGINEERING_DARK: AppTheme = AppTheme {
bg: egui::Color32::from_rgb(27, 34, 44),
panel: egui::Color32::from_rgb(29, 40, 52),
panel_strong: egui::Color32::from_rgb(39, 51, 65),
panel_deep: egui::Color32::from_rgb(15, 21, 29),
border: egui::Color32::from_rgb(70, 87, 104),
border_soft: egui::Color32::from_rgb(48, 63, 78),
text: egui::Color32::from_rgb(224, 231, 238),
text_dim: egui::Color32::from_rgb(151, 166, 184),
accent: egui::Color32::from_rgb(255, 121, 47),
accent_hot: egui::Color32::from_rgb(255, 163, 82),
radius: 3,
};
pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
let mut visuals = egui::Visuals::dark();
visuals.override_text_color = Some(theme.text);
visuals.panel_fill = theme.bg;
visuals.window_fill = theme.panel;
visuals.window_stroke = egui::Stroke::new(1.0, theme.border);
visuals.extreme_bg_color = theme.panel_deep;
visuals.faint_bg_color = theme.panel_strong;
visuals.code_bg_color = theme.panel_deep;
visuals.warn_fg_color = theme.accent_hot;
visuals.error_fg_color = egui::Color32::from_rgb(255, 98, 82);
visuals.widgets.noninteractive.bg_fill = theme.panel_strong;
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0, theme.text_dim);
visuals.widgets.inactive.bg_fill = theme.panel_strong;
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
visuals.widgets.inactive.fg_stroke = egui::Stroke::new(1.0, theme.text);
visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(51, 66, 82);
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, theme.border);
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0, theme.text);
visuals.widgets.active.bg_fill = theme.accent;
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0, theme.accent_hot);
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
visuals.widgets.open.bg_fill = egui::Color32::from_rgb(45, 58, 72);
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0, theme.border);
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0, theme.text);
visuals.selection.bg_fill = theme.accent;
visuals.selection.stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
visuals.hyperlink_color = theme.accent_hot;
ctx.set_visuals(visuals);
let mut style = (*ctx.global_style()).clone();
style.spacing.item_spacing = egui::vec2(7.0, 5.0);
style.spacing.window_margin = egui::Margin::same(7);
style.visuals.window_corner_radius = egui::CornerRadius::same(theme.radius);
style.visuals.menu_corner_radius = egui::CornerRadius::same(2);
style.visuals.window_shadow = egui::epaint::Shadow {
offset: [0, 12],
blur: 24,
spread: 0,
color: egui::Color32::from_black_alpha(110),
};
ctx.set_global_style(style);
}
pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
let style = ctx.global_style();
egui::Frame::window(&style)
.fill(ENGINEERING_DARK.panel)
.stroke(egui::Stroke::new(1.0, ENGINEERING_DARK.border))
.corner_radius(egui::CornerRadius::same(ENGINEERING_DARK.radius))
.shadow(egui::epaint::Shadow {
offset: [0, 12],
blur: 26,
spread: 0,
color: egui::Color32::from_black_alpha(120),
})
}
pub fn group_frame() -> egui::Frame {
egui::Frame::new()
.fill(ENGINEERING_DARK.panel_deep)
.stroke(egui::Stroke::new(1.0, ENGINEERING_DARK.border_soft))
.corner_radius(egui::CornerRadius::same(2))
.inner_margin(egui::Margin::symmetric(6, 5))
}
pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
egui::Button::new(label)
.fill(ENGINEERING_DARK.panel_strong)
.stroke(egui::Stroke::new(1.0, ENGINEERING_DARK.border))
.corner_radius(egui::CornerRadius::same(2))
}
pub fn dim_text() -> egui::Color32 {
ENGINEERING_DARK.text_dim
}
pub fn accent_text() -> egui::Color32 {
ENGINEERING_DARK.accent_hot
}