clean up ui and cross-compile config

This commit is contained in:
Matthew Ryan Dillon 2024-08-19 21:24:50 -04:00
parent 69d911ccb8
commit e1e67546aa
3 changed files with 44 additions and 18 deletions

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

View file

@ -6,5 +6,12 @@ edition = "2021"
[dependencies]
bevy = "0.14"
bevy_egui = "0.28"
# natord = "1.0"
vsort = "0.2"
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"

View file

@ -1,4 +1,5 @@
use bevy::{prelude::*, winit::WinitSettings};
#![windows_subsystem = "windows"]
use bevy::{prelude::*, window::PrimaryWindow, winit::WinitSettings};
use bevy_egui::{
egui::{self},
EguiContexts, EguiPlugin,
@ -30,11 +31,18 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_systems(Startup, set_window_title)
.add_systems(Update, ui_system)
.add_systems(Update, process_text)
.run();
}
fn set_window_title(mut window_query: Query<&mut Window, With<PrimaryWindow>>) {
if let Ok(mut window) = window_query.get_single_mut() {
window.title = "dsort".to_string();
}
}
fn process_text(input_text: Res<InputText>, mut output_text: ResMut<OutputText>) {
let mut arr = input_text.value.lines().collect::<Vec<_>>();
arr.sort_by(|&a, &b| vsort::compare(a, b));
@ -46,22 +54,31 @@ fn ui_system(
mut input_text: ResMut<InputText>,
mut output_text: ResMut<OutputText>,
) {
contexts.ctx_mut().set_visuals(egui::Visuals::light());
egui::CentralPanel::default().show(contexts.ctx_mut(), |ui| {
ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.label("input: ");
ui.add_sized(
[ui.available_width() / 2.0, ui.available_height()],
egui::TextEdit::multiline(&mut input_text.value),
);
});
ui.vertical(|ui| {
ui.label("output: ");
ui.add_sized(
[ui.available_width() / 2.0, ui.available_height()],
egui::TextEdit::multiline(&mut output_text.value),
);
});
});
let window_size = ui.available_size();
let height = window_size[1];
ui.with_layout(
egui::Layout::left_to_right(egui::Align::Center).with_cross_justify(true),
|ui| {
egui::ScrollArea::vertical()
.id_source("left")
.show(ui, |ui| {
ui.add_sized(
[ui.available_width() / 2., height],
egui::TextEdit::multiline(&mut input_text.value),
);
});
egui::ScrollArea::vertical()
.id_source("right")
.show(ui, |ui| {
ui.add_sized(
[ui.available_width(), height],
egui::TextEdit::multiline(&mut output_text.value),
);
});
},
);
});
}