Skip to content

Commit a3dc90a

Browse files
committed
feat: 在底部面板中添加终端
1 parent 67b68ed commit a3dc90a

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

crates/project_graph/src/app.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
fonts::{ic, setup_custom_fonts},
77
settings::Settings,
88
settings_window::SettingsWindow,
9-
stage::Stage,
9+
stage::{
10+
Stage,
11+
structs::{Entity, Text},
12+
},
1013
themes::apply_custom_theme,
1114
};
1215

@@ -16,7 +19,7 @@ pub struct MyApp {
1619
show_about: bool,
1720
settings_window: SettingsWindow,
1821

19-
test_input: String,
22+
terminal_input: String,
2023

2124
#[cfg(android)]
2225
last_ime_active: bool,
@@ -38,7 +41,7 @@ impl MyApp {
3841
show_about: true,
3942
settings_window: SettingsWindow::new(),
4043

41-
test_input: String::new(),
44+
terminal_input: String::new(),
4245

4346
#[cfg(android)]
4447
last_ime_active: false,
@@ -126,6 +129,20 @@ impl eframe::App for MyApp {
126129
.show(ctx, |ui| {
127130
ui.heading("Terminal");
128131
ui.separator();
132+
ui.text_edit_multiline(&mut self.terminal_input);
133+
if ui.button("execute").clicked() {
134+
match knus::parse::<Vec<Text>>("terminal_input.kdl", &self.terminal_input) {
135+
Ok(doc) => {
136+
for entity in doc {
137+
self.stage.context.add(entity.into());
138+
}
139+
}
140+
Err(e) => {
141+
log::error!("{:?}", miette::Report::new(e));
142+
}
143+
}
144+
self.terminal_input.clear();
145+
}
129146
});
130147

131148
egui::CentralPanel::default().show(ctx, |ui| {
@@ -141,9 +158,6 @@ impl eframe::App for MyApp {
141158
ui.label("这是 Project Graph 3.0 的雏形,基于 Rust 和 egui 构建,性能和内存占用将会得到显著提升");
142159
ui.label("目前处于早期开发阶段,功能还非常基础,但未来会逐步完善");
143160
ui.separator();
144-
ui.label("测试输入框");
145-
ui.text_edit_multiline(&mut self.test_input);
146-
ui.separator();
147161
ui.columns(2, |columns| {
148162
columns[0].add(egui::Image::new(egui::include_image!(
149163
"../assets/icon.png"

crates/project_graph/src/stage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use crate::stage::render_context::RenderContext;
1313
/// egui 和画布之间的桥梁
1414
/// 负责坐标系转换、事件处理等
1515
pub struct Stage {
16-
camera: Camera,
17-
context: StageContext,
16+
pub camera: Camera,
17+
pub context: StageContext,
1818
}
1919

2020
impl Stage {
2121
pub fn new() -> Self {
2222
Stage {
2323
camera: Camera::new(),
24-
context: StageContext::random(),
24+
context: StageContext::new(),
2525
}
2626
}
2727

crates/project_graph/src/stage/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use egui::Pos2;
44
use nanoid::nanoid;
55

6-
use crate::stage::structs::{Entity, Text};
6+
use crate::stage::structs::{Entity, EntityTrait, Text};
77

88
pub struct StageContext {
99
entities: HashMap<String, Entity>,
@@ -38,4 +38,8 @@ impl StageContext {
3838
pub fn entities(&self) -> &HashMap<String, Entity> {
3939
&self.entities
4040
}
41+
42+
pub fn add(&mut self, entity: Entity) {
43+
self.entities.insert(entity.id().to_string(), entity);
44+
}
4145
}

0 commit comments

Comments
 (0)