-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on adding window UI to tombstone
- Loading branch information
1 parent
7a6cfb9
commit 544712b
Showing
5 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use ghast::state::{Emulator, Message}; | ||
use iced::{Element, Subscription, Task}; | ||
use tokio::sync::broadcast::Receiver; | ||
use tokio_stream::{wrappers::BroadcastStream, StreamExt}; | ||
|
||
pub struct WindowState { | ||
gb: Arc<Mutex<Emulator>>, | ||
inbound: Receiver<Message>, | ||
} | ||
|
||
impl WindowState { | ||
pub fn new(gb: Arc<Mutex<Emulator>>, inbound: Receiver<Message>) -> Self { | ||
Self { gb, inbound } | ||
} | ||
|
||
pub fn run(self) { | ||
std::thread::spawn(move || { | ||
iced::application( | ||
"Specters - Tombstone GBC Debugger", | ||
WindowState::update, | ||
WindowState::view, | ||
) | ||
.subscription(WindowState::subscription) | ||
.run_with(move || (self, Task::none())) | ||
}); | ||
} | ||
|
||
fn update(&mut self, msg: Message) { | ||
self.gb.lock().unwrap().update(msg) | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
self.gb.lock().unwrap().view_owned() | ||
} | ||
|
||
fn subscription(&self) -> Subscription<Message> { | ||
let sub = self.gb.lock().unwrap().subscription(); | ||
let recv = BroadcastStream::new(self.inbound.resubscribe()).map(Result::unwrap); | ||
Subscription::batch([sub, Subscription::run_with_id(0, recv)]) | ||
} | ||
} |