feat: 添加 app/theme/ui/matrix/render 模块,重构 shader
This commit is contained in:
116
src/ui.rs
Normal file
116
src/ui.rs
Normal file
@@ -0,0 +1,116 @@
|
||||
use eframe::egui;
|
||||
|
||||
use crate::theme::{accent_text, dim_text, group_frame, panel_frame, tag_button};
|
||||
|
||||
pub struct FloatingPanelState {
|
||||
pub visible: bool,
|
||||
default_pos: egui::Pos2,
|
||||
tag_pos: egui::Pos2,
|
||||
}
|
||||
|
||||
impl FloatingPanelState {
|
||||
pub fn new(default_pos: [f32; 2], tag_pos: [f32; 2]) -> Self {
|
||||
Self {
|
||||
visible: true,
|
||||
default_pos: egui::pos2(default_pos[0], default_pos[1]),
|
||||
tag_pos: egui::pos2(tag_pos[0], tag_pos[1]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_scene_panel(ctx: &egui::Context, panel: &mut FloatingPanelState) {
|
||||
draw_floating_panel(ctx, panel, "Scene", "scene_panel", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.colored_label(dim_text(), "View");
|
||||
let _ = ui.selectable_label(true, "Clusters");
|
||||
let _ = ui.selectable_label(false, "Triangles");
|
||||
});
|
||||
ui.separator();
|
||||
group_frame().show(ui, |ui| {
|
||||
ui.label("Models / materials / lights");
|
||||
ui.label("target tasks 64");
|
||||
ui.label("slack cache 100.0%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn draw_config_panel(ctx: &egui::Context, panel: &mut FloatingPanelState) {
|
||||
draw_floating_panel(ctx, panel, "Config", "config_panel", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Shader");
|
||||
let _ = ui.selectable_label(true, "Clusters");
|
||||
let _ = ui.selectable_label(false, "wireframe");
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Grid");
|
||||
ui.label("x 32");
|
||||
ui.label("z 32");
|
||||
ui.label("side 1.000");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn draw_stats_panel(ctx: &egui::Context, panel: &mut FloatingPanelState) {
|
||||
draw_floating_panel(ctx, panel, "Stats", "stats_panel", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.colored_label(accent_text(), "0.030");
|
||||
ui.label("81m:51s");
|
||||
});
|
||||
ui.separator();
|
||||
group_frame().show(ui, |ui| {
|
||||
ui.label("FPS / GPU info");
|
||||
ui.label("bounds 589.0us");
|
||||
ui.label("clusters 12.8ms");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_floating_panel(
|
||||
ctx: &egui::Context,
|
||||
panel: &mut FloatingPanelState,
|
||||
title: &'static str,
|
||||
id: &'static str,
|
||||
add_contents: impl FnOnce(&mut egui::Ui),
|
||||
) {
|
||||
if panel.visible {
|
||||
let mut open = true;
|
||||
let mut hide_requested = false;
|
||||
|
||||
egui::Window::new(title)
|
||||
.id(egui::Id::new(id))
|
||||
.open(&mut open)
|
||||
.default_pos(panel.default_pos)
|
||||
.title_bar(false)
|
||||
.resizable(true)
|
||||
.frame(panel_frame(ctx))
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.add(tag_button("Hide")).clicked() {
|
||||
hide_requested = true;
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
ui.colored_label(dim_text(), title);
|
||||
});
|
||||
ui.separator();
|
||||
add_contents(ui);
|
||||
});
|
||||
|
||||
panel.visible = open && !hide_requested;
|
||||
} else {
|
||||
let response = egui::Area::new(egui::Id::new(format!("{id}_tag")))
|
||||
.current_pos(panel.tag_pos)
|
||||
.movable(true)
|
||||
.order(egui::Order::Foreground)
|
||||
.show(ctx, |ui| {
|
||||
ui.set_min_width(86.0);
|
||||
if ui
|
||||
.add(tag_button(format!("▸ {title}")).min_size(egui::vec2(86.0, 22.0)))
|
||||
.clicked()
|
||||
{
|
||||
panel.visible = true;
|
||||
}
|
||||
});
|
||||
|
||||
panel.tag_pos = response.response.rect.min;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user