diff options
| author | 2026-01-13 11:25:35 +0800 | |
|---|---|---|
| committer | 2026-01-13 11:25:35 +0800 | |
| commit | 68474e65c27323da62aad223cea7fb22356b0df6 (patch) | |
| tree | 3e6806cb3d1b0c2a0b6483fcd1768119620f9012 /src/ui/mod.rs | |
| parent | 431c117a55d06e45ef48305f67f71e6a2afb76fd (diff) | |
| download | DropOut-68474e65c27323da62aad223cea7fb22356b0df6.tar.gz DropOut-68474e65c27323da62aad223cea7fb22356b0df6.zip | |
feat: Added version control functionality and integrated Tokio and Reqwest to support asynchronous operations
Diffstat (limited to 'src/ui/mod.rs')
| -rw-r--r-- | src/ui/mod.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 778eeee..3ee1e6a 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,7 +1,12 @@ use gtk::prelude::*; use gtk::{Button, Window, WindowType}; +use tokio::sync::mpsc::Sender; -pub fn init() { +pub enum UiEvent { + StartGame, +} + +pub fn init(tx: Sender<UiEvent>) { if gtk::init().is_err() { println!("Failed to initialize GTK."); return; @@ -12,8 +17,13 @@ pub fn init() { window.set_default_size(350, 70); let button = Button::with_label("开始游戏"); - button.connect_clicked(|_| { + let tx_clone = tx.clone(); + button.connect_clicked(move |_| { println!("开始游戏按钮被点击"); + // Use blocking_send because we are in a synchronous callback + if let Err(e) = tx_clone.blocking_send(UiEvent::StartGame) { + eprintln!("Failed to send event: {}", e); + } }); window.add(&button); @@ -26,4 +36,4 @@ pub fn init() { window.show_all(); gtk::main(); -}
\ No newline at end of file +} |