better init
This commit is contained in:
parent
4bdfce0ad1
commit
b0dd7b0004
1 changed files with 6 additions and 14 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -42,7 +42,6 @@ pub fn main() -> Result<(), iced_layershell::Error> {
|
|||
}
|
||||
|
||||
struct State {
|
||||
initialized: bool,
|
||||
current_message: String,
|
||||
history: Vec<History>,
|
||||
input_id: Id,
|
||||
|
|
@ -62,7 +61,6 @@ impl History {
|
|||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
initialized: false,
|
||||
current_message: String::new(),
|
||||
history: Vec::new(),
|
||||
input_id: Id::unique(),
|
||||
|
|
@ -83,27 +81,21 @@ fn namespace() -> String {
|
|||
String::from("Iced qalc claculator")
|
||||
}
|
||||
|
||||
fn subscription(state: &State) -> iced::Subscription<Message> {
|
||||
fn subscription(_state: &State) -> iced::Subscription<Message> {
|
||||
use iced::event;
|
||||
use iced::futures::stream;
|
||||
|
||||
let init = if !state.initialized {
|
||||
iced::Subscription::run_with("init", |_| stream::once(async { Message::Init }))
|
||||
} else {
|
||||
iced::Subscription::none()
|
||||
};
|
||||
|
||||
iced::Subscription::batch([init, event::listen().map(Message::IcedEvent)])
|
||||
iced::Subscription::batch([
|
||||
iced::Subscription::run_with("init", |_| stream::once(async { Message::Init })),
|
||||
event::listen().map(Message::IcedEvent),
|
||||
])
|
||||
}
|
||||
|
||||
fn update(state: &mut State, message: Message) -> Command<Message> {
|
||||
use iced::keyboard::{Event::KeyReleased, Key, key::Named};
|
||||
|
||||
match message {
|
||||
Message::Init => {
|
||||
state.initialized = true;
|
||||
operation::focus(state.input_id.clone())
|
||||
}
|
||||
Message::Init => operation::focus(state.input_id.clone()),
|
||||
Message::IcedEvent(event) => {
|
||||
if let Event::Keyboard(KeyReleased {
|
||||
key: Key::Named(Named::Escape),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue