generated from ElnuDev/rust-project
Compare commits
No commits in common. "0e5bd5ad946f7c490e6e2ea411ed0d6dcd25e0b7" and "a9724a4636b417c5a2ea75318b6744cd340abb68" have entirely different histories.
0e5bd5ad94
...
a9724a4636
5 changed files with 42 additions and 143 deletions
60
demo/Cargo.lock
generated
60
demo/Cargo.lock
generated
|
@ -682,17 +682,6 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "egui-sfml"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2c29f2eb88bc1c2043f5cb807173b643d4241502d97c955880ffc86ca9fb21dc"
|
|
||||||
dependencies = [
|
|
||||||
"egui",
|
|
||||||
"glu-sys",
|
|
||||||
"sfml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui-winit"
|
name = "egui-winit"
|
||||||
version = "0.21.1"
|
version = "0.21.1"
|
||||||
|
@ -982,15 +971,6 @@ dependencies = [
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glu-sys"
|
|
||||||
version = "0.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b96e6aab9cc22fe28d706c0efb380f1825d660a27ccf9a26591fb327905cc3f3"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glutin"
|
name = "glutin"
|
||||||
version = "0.30.8"
|
version = "0.30.8"
|
||||||
|
@ -1211,15 +1191,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "link-cplusplus"
|
|
||||||
version = "1.0.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.3.8"
|
version = "0.3.8"
|
||||||
|
@ -1398,15 +1369,6 @@ dependencies = [
|
||||||
"minimal-lexical",
|
"minimal-lexical",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_enum"
|
name = "num_enum"
|
||||||
version = "0.5.11"
|
version = "0.5.11"
|
||||||
|
@ -1774,10 +1736,8 @@ name = "renrs-gui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui-sfml",
|
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"renrs",
|
"renrs",
|
||||||
"sfml",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1871,20 +1831,6 @@ dependencies = [
|
||||||
"syn 2.0.16",
|
"syn 2.0.16",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sfml"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cc90f712d9a93d8db54e53281dbb6dbb29e443abcc83e185df4bbe60ba6e8311"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cc",
|
|
||||||
"link-cplusplus",
|
|
||||||
"num-traits",
|
|
||||||
"once_cell",
|
|
||||||
"widestring",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha1"
|
name = "sha1"
|
||||||
version = "0.10.5"
|
version = "0.10.5"
|
||||||
|
@ -2438,12 +2384,6 @@ dependencies = [
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "widestring"
|
|
||||||
version = "1.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
renrs_gui::run("demo.rpy".into());
|
renrs_gui::run("demo.rpy".into()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,5 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = "0.21.3"
|
eframe = "0.21.3"
|
||||||
egui-sfml = "0.4.0"
|
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
renrs = { path = "../renrs" }
|
renrs = { path = "../renrs" }
|
||||||
sfml = "0.20.0"
|
|
||||||
|
|
|
@ -3,22 +3,23 @@ use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
use egui::*;
|
||||||
use renrs::{State, Command};
|
use renrs::{State, Command};
|
||||||
|
|
||||||
use sfml::{
|
pub fn run(file: PathBuf) -> Result<(), eframe::Error> {
|
||||||
graphics::{Color, RenderTarget, RenderWindow, RectangleShape, Transformable},
|
|
||||||
system::Vector2f,
|
|
||||||
window::{Event, mouse, Key, Style},
|
|
||||||
};
|
|
||||||
use egui_sfml::SfEgui;
|
|
||||||
|
|
||||||
const WIDTH: f32 = 800.0;
|
|
||||||
const HEIGHT: f32 = 600.0;
|
|
||||||
|
|
||||||
pub fn run(file: PathBuf) {
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let mut app = App::from_state(State::from_file(file));
|
let options = eframe::NativeOptions {
|
||||||
app.run();
|
initial_window_size: Some(egui::vec2(640.0, 480.0)),
|
||||||
|
resizable: false, // prevent i3 from automatically resizing
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
eframe::run_native(
|
||||||
|
"renrs-gui",
|
||||||
|
options,
|
||||||
|
Box::new(|_cc| Box::new(
|
||||||
|
App::from_state(State::from_file(file))
|
||||||
|
)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
|
@ -40,13 +41,13 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next(&mut self) {
|
fn next(&mut self, ctx: &Context) {
|
||||||
if let Some(Command::Say { name, text }) = self.state.next_command() {
|
if let Some(Command::Say { name, text }) = self.state.next_command() {
|
||||||
self.text = match name {
|
self.text = match name {
|
||||||
Some(name) => format!("{name}: {text}"),
|
Some(name) => format!("{name}: {text}"),
|
||||||
None => text,
|
None => text,
|
||||||
};
|
};
|
||||||
self.start_typing();
|
self.start_typing(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ impl App {
|
||||||
*self.typing_done.lock().unwrap() = true;
|
*self.typing_done.lock().unwrap() = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_typing(&mut self) {
|
fn start_typing(&mut self, ctx: &Context) {
|
||||||
// Kill previous typing thread if exists
|
// Kill previous typing thread if exists
|
||||||
self.kill_typing();
|
self.kill_typing();
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ impl App {
|
||||||
*self.typing_done.lock().unwrap() = false;
|
*self.typing_done.lock().unwrap() = false;
|
||||||
|
|
||||||
// Set up references to be passed into thread
|
// Set up references to be passed into thread
|
||||||
|
let ctx = ctx.clone();
|
||||||
let kill = {
|
let kill = {
|
||||||
let kill = Arc::new(Mutex::new(false));
|
let kill = Arc::new(Mutex::new(false));
|
||||||
self.typing_kill = Some(kill.clone());
|
self.typing_kill = Some(kill.clone());
|
||||||
|
@ -86,6 +88,7 @@ impl App {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*chars.lock().unwrap() = i;
|
*chars.lock().unwrap() = i;
|
||||||
|
ctx.request_repaint();
|
||||||
thread::sleep(Duration::from_millis(50));
|
thread::sleep(Duration::from_millis(50));
|
||||||
complete = true;
|
complete = true;
|
||||||
}
|
}
|
||||||
|
@ -95,72 +98,31 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_interaction(&mut self) {
|
fn handle_interaction(&mut self, ctx: &Context) {
|
||||||
if *self.typing_done.lock().unwrap() {
|
if *self.typing_done.lock().unwrap() {
|
||||||
self.next();
|
self.next(ctx);
|
||||||
} else {
|
} else {
|
||||||
self.interrupt_typing();
|
self.interrupt_typing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&mut self) {
|
|
||||||
let mut window = RenderWindow::new(
|
|
||||||
(WIDTH as u32, HEIGHT as u32),
|
|
||||||
"renrs-gui",
|
|
||||||
Style::CLOSE,
|
|
||||||
&Default::default(),
|
|
||||||
);
|
|
||||||
let mut sfegui = SfEgui::new(&window);
|
|
||||||
window.set_vertical_sync_enabled(true);
|
|
||||||
|
|
||||||
const SIZE: f32 = 64.0;
|
|
||||||
let mut velocity = Vector2f::new(4.0, 4.0);
|
|
||||||
let mut shape = RectangleShape::with_size(Vector2f::new(SIZE, SIZE));
|
|
||||||
shape.set_position(Vector2f::new(SIZE, SIZE));
|
|
||||||
|
|
||||||
while window.is_open() {
|
|
||||||
while let Some(event) = window.poll_event() {
|
|
||||||
match event {
|
|
||||||
Event::Closed | Event::KeyPressed { code: Key::Escape, .. } => return,
|
|
||||||
Event::MouseButtonPressed { button: mouse::Button::Left, .. } | Event::KeyPressed { code: Key::Space, .. } => self.handle_interaction(),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
use egui::*;
|
|
||||||
sfegui
|
|
||||||
.do_frame(|ctx| {
|
|
||||||
egui::CentralPanel::default()
|
|
||||||
.frame(Frame {
|
|
||||||
inner_margin: Margin::same(32.0),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.show(ctx, |ui| {
|
|
||||||
if ctx.input(|i|
|
|
||||||
i.key_pressed(Key::Space)
|
|
||||||
|| i.pointer.button_clicked(PointerButton::Primary)
|
|
||||||
) {
|
|
||||||
self.handle_interaction();
|
|
||||||
}
|
|
||||||
ui.with_layout(egui::Layout::left_to_right(Align::Max), |ui| ui.heading(&self.text[0..*self.chars.lock().unwrap()]));
|
|
||||||
});
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Vector2f { x, y } = shape.position();
|
|
||||||
if x >= WIDTH - SIZE || x < 0.0 {
|
|
||||||
velocity.x *= -1.0;
|
|
||||||
}
|
|
||||||
if y >= HEIGHT - SIZE || y < 0.0 {
|
|
||||||
velocity.y *= -1.0;
|
|
||||||
}
|
|
||||||
shape.set_position(Vector2f::new(x + velocity.x, y + velocity.y));
|
|
||||||
|
|
||||||
window.clear(Color::BLACK);
|
|
||||||
window.draw(&shape);
|
|
||||||
sfegui.draw(&mut window, None);
|
|
||||||
window.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl eframe::App for App {
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
egui::CentralPanel::default()
|
||||||
|
.frame(Frame {
|
||||||
|
fill: Color32::BLACK,
|
||||||
|
inner_margin: Margin::same(32.0),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
if ctx.input(|i|
|
||||||
|
i.key_pressed(Key::Space)
|
||||||
|
|| i.pointer.button_clicked(PointerButton::Primary)
|
||||||
|
) {
|
||||||
|
self.handle_interaction(ctx);
|
||||||
|
}
|
||||||
|
ui.with_layout(egui::Layout::left_to_right(Align::Max), |ui| ui.heading(&self.text[0..*self.chars.lock().unwrap()]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ mkShell {
|
||||||
libXrandr
|
libXrandr
|
||||||
libXi
|
libXi
|
||||||
pkg-config
|
pkg-config
|
||||||
sfml
|
|
||||||
] ++ [
|
] ++ [
|
||||||
#python3
|
#python3
|
||||||
libGL
|
libGL
|
||||||
|
|
Loading…
Add table
Reference in a new issue