Skip to content

Commit 737c569

Browse files
committed
implement path
1 parent 603d3db commit 737c569

File tree

9 files changed

+62
-38
lines changed

9 files changed

+62
-38
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ panic = "abort"
1313
eframe = { version = "0.28.1", default-features = false, features = ["glow", "default_fonts"] }
1414
serde = { version = "1.0", features = ["derive"] }
1515
indexmap = "2.5.0"
16+
rfd = "0.14.1"

src/app.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ pub struct GodotSconsGUI {
77
state: AppState,
88
}
99

10-
#[derive(Debug, Default)]
10+
#[derive(Debug)]
1111
pub enum AppState {
12-
#[default] Start,
12+
Start(StartState),
1313
Clone(CloneState),
1414
Setup(SetupState),
1515
Build(BuildState),
1616
}
1717

18+
1819
impl AppState {
1920
pub fn start() -> Self {
20-
AppState::Start
21+
AppState::Start(Default::default())
2122
}
2223
pub fn clone() -> Self {
2324
AppState::Clone(Default::default())
@@ -30,6 +31,12 @@ impl AppState {
3031
}
3132
}
3233

34+
impl Default for AppState {
35+
fn default() -> Self {
36+
Self::Start(Default::default())
37+
}
38+
}
39+
3340

3441
impl GodotSconsGUI {
3542
pub fn new(cc: &eframe::CreationContext) -> Self {
@@ -60,14 +67,14 @@ impl eframe::App for GodotSconsGUI {
6067
}
6168

6269
let new_state = match &mut self.state {
63-
AppState::Start => start::show(ctx),
70+
AppState::Start(state) => start::show(state, ctx),
6471
AppState::Clone(state) => clone::show(state, ctx),
6572
AppState::Setup(state) => setup::show(state, ctx),
6673
AppState::Build(state) => build::show(state, ctx),
6774
};
6875

6976
if let Some(s) = new_state {
70-
println!("Transitioning to {s:?}");
77+
#[cfg(debug_assertions)] println!("Transitioning to {s:?}");
7178
self.state = s;
7279
}
7380
}

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
mod app;
44
mod options;
5-
mod states;
65
mod views;
76

87
use eframe::egui;

src/states.rs

Whitespace-only changes.

src/views.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pub mod build;
66
pub use build::BuildState;
77
pub use clone::CloneState;
88
pub use setup::SetupState;
9+
pub use start::StartState;
910

1011
use crate::app::AppState;
1112
use eframe::egui;
12-
use egui::{Align, Button, Color32, Context, Frame, Layout, Stroke, TextEdit, Vec2};
13+
use egui::{Align, Button, Color32, Context, Frame, Label, Layout, Stroke, TextEdit, Vec2};
1314
use egui::{CentralPanel, ScrollArea, TopBottomPanel};

src/views/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use super::*;
22

33
#[derive(Debug, Default)]
4-
pub struct BuildState {}
4+
pub struct BuildState {
5+
pub path: String,
6+
}
57

68
pub fn show(state: &mut BuildState, ctx: &Context) -> Option<AppState> {
79
CentralPanel::default().show(ctx, |_ui| {});

src/views/clone.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::mpsc::Receiver;
44

55
#[derive(Debug, Default)]
66
pub struct CloneState {
7+
pub path: String,
78
pub rx: Option<Receiver<i32>>,
89
pub status: Option<i32>,
910
}
@@ -21,6 +22,7 @@ pub fn show(state: &mut CloneState, ctx: &egui::Context) -> Option<AppState> {
2122
let (tx, rx) = std::sync::mpsc::channel::<i32>();
2223
state.rx = Some(rx);
2324

25+
let path = state.path.clone();
2426
std::thread::spawn(move || {
2527
let status = Command::new("git")
2628
.args([
@@ -31,7 +33,7 @@ pub fn show(state: &mut CloneState, ctx: &egui::Context) -> Option<AppState> {
3133
"4.3-stable",
3234
"https://github.com/godotengine/godot",
3335
])
34-
.current_dir("D:/Godot/test")
36+
.current_dir(path)
3537
.status()
3638
.unwrap()
3739
.code()
@@ -62,7 +64,7 @@ pub fn show(state: &mut CloneState, ctx: &egui::Context) -> Option<AppState> {
6264

6365
let btn = Button::new("Continue ➡");
6466
if ui.add_sized(Vec2::new(100., 40.), btn).clicked() {
65-
return Some(AppState::setup());
67+
return Some(AppState::Setup(SetupState { path: state.path.clone(), ..Default::default()}));
6668
}
6769
} else {
6870
ui.add_space(10.);

src/views/setup.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::*;
22
use crate::{OptionDetail, Options};
3-
use eframe::egui::Label;
43
use std::collections::HashMap;
54
use std::process::Command;
65
use std::sync::mpsc::{channel, Receiver};
@@ -18,6 +17,7 @@ pub enum SetupScreen {
1817

1918
#[derive(Debug, Default)]
2019
pub struct SetupState {
20+
pub path: String,
2121
pub changes: Changes,
2222
pub cmd: String,
2323
pub screen: SetupScreen,
@@ -27,55 +27,53 @@ impl SetupState {
2727
fn compute_command(&mut self) {
2828
let mut cmd = String::from("scons");
2929
for (k, v) in &self.changes {
30-
cmd += &format!(" {k}={v}");
30+
cmd += &format!(" {k}={}", v.replace(' ', "_"));
3131
}
3232
self.cmd = cmd;
3333
}
3434
}
3535

3636
pub fn show(state: &mut SetupState, ctx: &Context) -> Option<AppState> {
37-
//state.compute_command();
3837
TopBottomPanel::bottom("cmd")
3938
.max_height(150.)
4039
.resizable(true)
4140
.show(ctx, |ui| {
4241
ScrollArea::vertical().show(ui, |ui| {
4342
ui.add_space(6.);
4443

45-
Frame::default()
46-
.inner_margin(6.)
47-
.rounding(6.)
48-
.fill(Color32::from_rgb(22, 22, 22))
49-
.stroke(Stroke::new(2., Color32::from_rgb(15, 15, 15)))
50-
.show(ui, |ui| {
51-
//ui.allocate_space(Vec2::new(ui.available_width(), 0.));
52-
53-
let text = egui::RichText::new(&state.cmd).monospace();
54-
let label = Label::new(text);
55-
ui.add_sized(Vec2::new(ui.available_width() - ui.spacing().item_spacing.x - 40., f32::INFINITY), label);
56-
57-
if ui.add_sized(Vec2::new(ui.available_width(), f32::INFINITY), Button::new("📋")).clicked() {
58-
ui.ctx().copy_text(state.cmd.clone());
59-
}
44+
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
45+
if ui.button("📋 Copy").clicked() {
46+
ui.ctx().copy_text(state.cmd.clone());
47+
}
48+
Frame::default()
49+
.inner_margin(6.)
50+
.rounding(6.)
51+
.fill(Color32::from_rgb(22, 22, 22))
52+
.stroke(Stroke::new(2., Color32::from_rgb(15, 15, 15)))
53+
.show(ui, |ui| {
54+
let text = egui::RichText::new(&state.cmd).monospace();
55+
ui.add_sized(ui.available_size(), Label::new(text));
56+
});
57+
});
6058

61-
});
6259
});
63-
ui.allocate_space(Vec2::new(0., ui.available_height()));
6460
});
6561
CentralPanel::default().show(ctx, |ui| {
6662
ScrollArea::vertical()
6763
.auto_shrink(false)
6864
.show(ui, |ui| {
65+
ui.label(&state.path);
6966
match &state.screen {
7067
SetupScreen::Start => {
7168
let btn = Button::new("Load compilation options");
7269
if ui.add_sized(Vec2::new(200., 30.), btn).clicked() {
7370
let (tx, rx) = channel();
74-
71+
72+
let path = state.path.clone() + "/godot";
7573
spawn(move || {
7674
let output = Command::new("scons")
7775
.arg("--help")
78-
.current_dir("D:/Godot/test/godot")
76+
.current_dir(path)
7977
.output()
8078
.unwrap();
8179

src/views/start.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
use super::*;
22

3-
pub fn show(ctx: &Context) -> Option<AppState> {
3+
#[derive(Debug, Default)]
4+
pub struct StartState {
5+
pub path: Option<String>,
6+
}
7+
8+
pub fn show(state: &mut StartState, ctx: &Context) -> Option<AppState> {
49
CentralPanel::default()
510
.show(ctx, |ui| {
11+
let btn_size = Vec2::new(180., 80.);
612
ui.vertical_centered(|ui| {
7-
let btn = Button::new("➕ Create");
8-
if ui.add_sized(Vec2::new(180., 80.), btn).clicked() {
9-
Some(AppState::clone())
10-
} else {
11-
None
13+
if ui.add_sized(btn_size, Button::new("📁 Choose Directory")).clicked() {
14+
if let Some(path) = rfd::FileDialog::new().pick_folder() {
15+
state.path = Some(path.display().to_string());
16+
}
1217
}
18+
19+
ui.add_enabled_ui(state.path.is_some(), |ui| {
20+
ui.add_space(8.);
21+
22+
return if ui.add_sized(btn_size, Button::new("➕ Create")).clicked() {
23+
let path = state.path.as_ref().unwrap().to_owned();
24+
Some(AppState::Clone(CloneState { path, ..Default::default() }))
25+
} else { None }
26+
}).inner
1327
})
1428
}).inner.inner
1529
}

0 commit comments

Comments
 (0)