1
0

Experiment with GUI binary

This commit is contained in:
Jeff 2023-08-30 17:21:30 -04:00
parent 6c1dbeb009
commit ca7051d24d
3 changed files with 1050 additions and 32 deletions

1001
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -39,3 +39,7 @@ egui_extras = "0.22.0"
rustyline = { version = "12.0.0", features = ["with-file-history", "derive"] } rustyline = { version = "12.0.0", features = ["with-file-history", "derive"] }
ansi_term = "0.12.1" ansi_term = "0.12.1"
iced = "0.10.0" iced = "0.10.0"
egui = "0.22.0"
eframe = "0.22.0"
env_logger = "0.10.0"
once_cell = "1.18.0"

View File

@ -1,50 +1,71 @@
use iced::widget::{button, column, text}; use dust_lib::eval;
use iced::{Alignment, Element, Sandbox, Settings}; use iced::widget::{button, column, container, scrollable, text, text_input};
use iced::{executor, Alignment, Application, Command, Element, Sandbox, Settings, Theme};
use once_cell::sync::Lazy;
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
Counter::run(Settings::default()) DustGui::run(Settings::default())
} }
struct Counter { struct DustGui {
value: i32, text_buffer: String,
results: Vec<String>,
} }
#[derive(Debug, Clone, Copy)] impl Application for DustGui {
enum Message { type Executor = executor::Default;
IncrementPressed,
DecrementPressed,
}
impl Sandbox for Counter {
type Message = Message; type Message = Message;
fn new() -> Self { type Theme = Theme;
Self { value: 0 }
type Flags = ();
fn new(flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
(
DustGui {
text_buffer: String::new(),
results: Vec::new(),
},
Command::none(),
)
} }
fn title(&self) -> String { fn title(&self) -> String {
String::from("Counter - Iced") "Dust".to_string()
} }
fn update(&mut self, message: Message) { fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> {
match message { match message {
Message::IncrementPressed => { Message::TextInput(input) => {
self.value += 1; self.text_buffer = input;
Command::none()
} }
Message::DecrementPressed => { Message::Evaluate => {
self.value -= 1; let eval_result = eval(&self.text_buffer);
Command::batch(vec![])
} }
} }
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
column![ let input = text_input("What needs to be done?", &self.text_buffer)
button("Increment").on_press(Message::IncrementPressed), .id(INPUT_ID.clone())
text(self.value).size(50), .on_input(Message::TextInput)
button("Decrement").on_press(Message::DecrementPressed) .on_submit(Message::Evaluate)
] .padding(15)
.padding(20) .size(30);
.align_items(Alignment::Center)
.into() scrollable(container(column![input])).into()
} }
} }
#[derive(Debug, Clone)]
enum Message {
TextInput(String),
Evaluate,
}