Cargo fix

This commit is contained in:
Bingus 2023-02-20 12:34:04 -08:00
parent 9565b477ca
commit bd58d5fe25
No known key found for this signature in database
GPG key ID: 5F84D2AA40A9F170
4 changed files with 187 additions and 169 deletions

View file

@ -47,7 +47,7 @@ chrome-trace = [
"iced_glow?/tracing", "iced_glow?/tracing",
] ]
# Enables experimental multi-window support # Enables experimental multi-window support
multi_window = ["iced_winit/multi_window", "iced_glutin/multi_window"] multi_window = ["iced_winit/multi_window", "iced_glutin?/multi_window"]
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }

View file

@ -7,7 +7,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
iced = { path = "../..", features = ["debug", "multi_window"] } iced = { path = "../..", features = ["debug", "multi_window", "tokio"] }
env_logger = "0.10.0" env_logger = "0.10.0"
iced_native = { path = "../../native" } iced_native = { path = "../../native" }
iced_lazy = { path = "../../lazy" } iced_lazy = { path = "../../lazy" }

View file

@ -1,5 +1,5 @@
use iced::alignment::{self, Alignment}; use iced::alignment::{self, Alignment};
use iced::executor; use iced::{executor, time};
use iced::keyboard; use iced::keyboard;
use iced::multi_window::Application; use iced::multi_window::Application;
use iced::theme::{self, Theme}; use iced::theme::{self, Theme};
@ -15,6 +15,7 @@ use iced_native::{event, subscription, Event};
use iced_native::widget::scrollable::{Properties, RelativeOffset}; use iced_native::widget::scrollable::{Properties, RelativeOffset};
use iced_native::window::Id; use iced_native::window::Id;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::{Duration, Instant};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
env_logger::init(); env_logger::init();
@ -25,6 +26,7 @@ pub fn main() -> iced::Result {
struct Example { struct Example {
windows: HashMap<window::Id, Window>, windows: HashMap<window::Id, Window>,
panes_created: usize, panes_created: usize,
count: usize,
_focused: window::Id, _focused: window::Id,
} }
@ -39,6 +41,7 @@ struct Window {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Message { enum Message {
Window(window::Id, WindowMessage), Window(window::Id, WindowMessage),
CountIncremented(Instant),
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -80,6 +83,7 @@ impl Application for Example {
Example { Example {
windows: HashMap::from([(window::Id::MAIN, window)]), windows: HashMap::from([(window::Id::MAIN, window)]),
panes_created: 1, panes_created: 1,
count: 0,
_focused: window::Id::MAIN, _focused: window::Id::MAIN,
}, },
Command::none(), Command::none(),
@ -94,8 +98,8 @@ impl Application for Example {
} }
fn update(&mut self, message: Message) -> Command<Message> { fn update(&mut self, message: Message) -> Command<Message> {
let Message::Window(id, message) = message;
match message { match message {
Message::Window(id, message) => match message {
WindowMessage::SnapToggle => { WindowMessage::SnapToggle => {
let window = self.windows.get_mut(&id).unwrap(); let window = self.windows.get_mut(&id).unwrap();
@ -251,12 +255,17 @@ impl Application for Example {
} }
} }
} }
},
Message::CountIncremented(_) => {
self.count += 1;
}
} }
Command::none() Command::none()
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
Subscription::batch(vec![
subscription::events_with(|event, status| { subscription::events_with(|event, status| {
if let event::Status::Captured = status { if let event::Status::Captured = status {
return None; return None;
@ -273,7 +282,9 @@ impl Application for Example {
} // TODO(derezzedex) } // TODO(derezzedex)
_ => None, _ => None,
} }
}) }),
time::every(Duration::from_secs(1)).map(Message::CountIncremented),
])
} }
fn view(&self, window_id: window::Id) -> Element<Message> { fn view(&self, window_id: window::Id) -> Element<Message> {
@ -335,6 +346,7 @@ impl Application for Example {
view_content( view_content(
id, id,
pane.scrollable_id.clone(), pane.scrollable_id.clone(),
self.count,
total_panes, total_panes,
pane.is_pinned, pane.is_pinned,
size, size,
@ -453,6 +465,7 @@ impl Pane {
fn view_content<'a>( fn view_content<'a>(
pane: pane_grid::Pane, pane: pane_grid::Pane,
scrollable_id: scrollable::Id, scrollable_id: scrollable::Id,
count: usize,
total_panes: usize, total_panes: usize,
is_pinned: bool, is_pinned: bool,
size: Size, size: Size,
@ -493,6 +506,7 @@ fn view_content<'a>(
let content = column![ let content = column![
text(format!("{}x{}", size.width, size.height)).size(24), text(format!("{}x{}", size.width, size.height)).size(24),
controls, controls,
text(format!("{count}")).size(48),
] ]
.width(Length::Fill) .width(Length::Fill)
.height(800) .height(800)

View file

@ -416,6 +416,7 @@ async fn run_instance<A, E, C>(
} }
event::Event::MainEventsCleared => { event::Event::MainEventsCleared => {
for id in states.keys().copied().collect::<Vec<_>>() { for id in states.keys().copied().collect::<Vec<_>>() {
// Partition events into only events for this window
let (filtered, remaining): (Vec<_>, Vec<_>) = let (filtered, remaining): (Vec<_>, Vec<_>) =
events.iter().cloned().partition( events.iter().cloned().partition(
|(window_id, _event): &( |(window_id, _event): &(
@ -426,7 +427,9 @@ async fn run_instance<A, E, C>(
}, },
); );
// Only retain events which have not been processed for next iteration
events.retain(|el| remaining.contains(el)); events.retain(|el| remaining.contains(el));
let window_events: Vec<_> = filtered let window_events: Vec<_> = filtered
.into_iter() .into_iter()
.map(|(_id, event)| event) .map(|(_id, event)| event)
@ -439,8 +442,8 @@ async fn run_instance<A, E, C>(
continue; continue;
} }
// Process winit events for window
debug.event_processing_started(); debug.event_processing_started();
let cursor_position = let cursor_position =
states.get(&id).unwrap().cursor_position(); states.get(&id).unwrap().cursor_position();
@ -455,15 +458,16 @@ async fn run_instance<A, E, C>(
) )
}; };
debug.event_processing_finished();
for event in for event in
window_events.into_iter().zip(statuses.into_iter()) window_events.into_iter().zip(statuses.into_iter())
{ {
runtime.broadcast(event); runtime.broadcast(event);
} }
debug.event_processing_finished();
// TODO(derezzedex): Should we redraw every window? We can't know what changed. // Update application with app message(s)
// Note: without tying an app message to a window ID, we must redraw all windows
// as we cannot know what changed without some kind of damage tracking.
if !messages.is_empty() if !messages.is_empty()
|| matches!( || matches!(
interface_state, interface_state,
@ -498,7 +502,7 @@ async fn run_instance<A, E, C>(
|| compositor.fetch_information(), || compositor.fetch_information(),
); );
// Update window // synchronize window state with application state.
states.get_mut(&id).unwrap().synchronize( states.get_mut(&id).unwrap().synchronize(
&application, &application,
id, id,
@ -564,6 +568,7 @@ async fn run_instance<A, E, C>(
for window in windows.values() { for window in windows.values() {
window.request_redraw(); window.request_redraw();
}
runtime.broadcast(( runtime.broadcast((
redraw_event.clone(), redraw_event.clone(),
@ -588,7 +593,6 @@ async fn run_instance<A, E, C>(
redraw_pending = false; redraw_pending = false;
} }
} }
}
event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(
event::MacOS::ReceivedUrl(url), event::MacOS::ReceivedUrl(url),
)) => { )) => {