Split Surface and Window
This commit is contained in:
parent
dc86bd0373
commit
7f35256573
1 changed files with 35 additions and 47 deletions
|
|
@ -318,6 +318,7 @@ async fn run_instance<A, E, C>(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut states = HashMap::new();
|
let mut states = HashMap::new();
|
||||||
|
let mut surfaces = HashMap::new();
|
||||||
let mut interfaces = ManuallyDrop::new(HashMap::new());
|
let mut interfaces = ManuallyDrop::new(HashMap::new());
|
||||||
|
|
||||||
for (&id, window) in windows.keys().zip(windows.values()) {
|
for (&id, window) in windows.keys().zip(windows.values()) {
|
||||||
|
|
@ -342,20 +343,19 @@ async fn run_instance<A, E, C>(
|
||||||
id,
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_state: WindowState<A, C> = WindowState { surface, state };
|
let _ = states.insert(id, state);
|
||||||
|
let _ = surfaces.insert(id, surface);
|
||||||
let _ = states.insert(id, window_state);
|
|
||||||
let _ = interfaces.insert(id, user_interface);
|
let _ = interfaces.insert(id, user_interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// TODO(derezzedex)
|
// TODO(derezzedex)
|
||||||
let window_state = states.values().next().expect("No state found");
|
let state = states.values().next().expect("No state found");
|
||||||
|
|
||||||
run_command(
|
run_command(
|
||||||
&application,
|
&application,
|
||||||
&mut cache,
|
&mut cache,
|
||||||
&window_state.state,
|
state,
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
init_command,
|
init_command,
|
||||||
&mut runtime,
|
&mut runtime,
|
||||||
|
|
@ -396,7 +396,7 @@ async fn run_instance<A, E, C>(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let cursor_position =
|
let cursor_position =
|
||||||
states.get(&id).unwrap().state.cursor_position();
|
states.get(&id).unwrap().cursor_position();
|
||||||
let window = windows.get(&id).unwrap();
|
let window = windows.get(&id).unwrap();
|
||||||
|
|
||||||
if filtered.is_empty() && messages.is_empty() {
|
if filtered.is_empty() && messages.is_empty() {
|
||||||
|
|
@ -430,7 +430,7 @@ async fn run_instance<A, E, C>(
|
||||||
user_interface::State::Outdated,
|
user_interface::State::Outdated,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let state = &mut states.get_mut(&id).unwrap().state;
|
let state = &mut states.get_mut(&id).unwrap();
|
||||||
let pure_states: HashMap<_, _> =
|
let pure_states: HashMap<_, _> =
|
||||||
ManuallyDrop::into_inner(interfaces)
|
ManuallyDrop::into_inner(interfaces)
|
||||||
.drain()
|
.drain()
|
||||||
|
|
@ -481,7 +481,7 @@ async fn run_instance<A, E, C>(
|
||||||
debug.draw_started();
|
debug.draw_started();
|
||||||
let new_mouse_interaction = {
|
let new_mouse_interaction = {
|
||||||
let user_interface = interfaces.get_mut(&id).unwrap();
|
let user_interface = interfaces.get_mut(&id).unwrap();
|
||||||
let state = &states.get(&id).unwrap().state;
|
let state = states.get(&id).unwrap();
|
||||||
|
|
||||||
user_interface.draw(
|
user_interface.draw(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
|
|
@ -546,10 +546,8 @@ async fn run_instance<A, E, C>(
|
||||||
id,
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_state: WindowState<A, C> =
|
let _ = states.insert(id, state);
|
||||||
WindowState { surface, state };
|
let _ = surfaces.insert(id, surface);
|
||||||
|
|
||||||
let _ = states.insert(id, window_state);
|
|
||||||
let _ = interfaces.insert(id, user_interface);
|
let _ = interfaces.insert(id, user_interface);
|
||||||
let _ = window_ids.insert(window.id(), id);
|
let _ = window_ids.insert(window.id(), id);
|
||||||
let _ = windows.insert(id, window);
|
let _ = windows.insert(id, window);
|
||||||
|
|
@ -570,6 +568,9 @@ async fn run_instance<A, E, C>(
|
||||||
if windows.remove(&id).is_none() {
|
if windows.remove(&id).is_none() {
|
||||||
println!("Failed to remove from `windows`!")
|
println!("Failed to remove from `windows`!")
|
||||||
}
|
}
|
||||||
|
if surfaces.remove(&id).is_none() {
|
||||||
|
println!("Failed to remove from `surfaces`!")
|
||||||
|
}
|
||||||
|
|
||||||
if windows.is_empty() {
|
if windows.is_empty() {
|
||||||
break 'main;
|
break 'main;
|
||||||
|
|
@ -578,11 +579,15 @@ async fn run_instance<A, E, C>(
|
||||||
Event::NewWindow(_, _) => unreachable!(),
|
Event::NewWindow(_, _) => unreachable!(),
|
||||||
},
|
},
|
||||||
event::Event::RedrawRequested(id) => {
|
event::Event::RedrawRequested(id) => {
|
||||||
let window_state = window_ids
|
let state = window_ids
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|id| states.get_mut(id))
|
.and_then(|id| states.get_mut(id))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let physical_size = window_state.state.physical_size();
|
let surface = window_ids
|
||||||
|
.get(&id)
|
||||||
|
.and_then(|id| surfaces.get_mut(id))
|
||||||
|
.unwrap();
|
||||||
|
let physical_size = state.physical_size();
|
||||||
|
|
||||||
if physical_size.width == 0 || physical_size.height == 0 {
|
if physical_size.width == 0 || physical_size.height == 0 {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -590,13 +595,13 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
debug.render_started();
|
debug.render_started();
|
||||||
|
|
||||||
if window_state.state.viewport_changed() {
|
if state.viewport_changed() {
|
||||||
let mut user_interface = window_ids
|
let mut user_interface = window_ids
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|id| interfaces.remove(id))
|
.and_then(|id| interfaces.remove(id))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let logical_size = window_state.state.logical_size();
|
let logical_size = state.logical_size();
|
||||||
|
|
||||||
debug.layout_started();
|
debug.layout_started();
|
||||||
user_interface =
|
user_interface =
|
||||||
|
|
@ -605,7 +610,7 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
debug.draw_started();
|
debug.draw_started();
|
||||||
let new_mouse_interaction = {
|
let new_mouse_interaction = {
|
||||||
let state = &window_state.state;
|
let state = &state;
|
||||||
|
|
||||||
user_interface.draw(
|
user_interface.draw(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
|
|
@ -634,7 +639,7 @@ async fn run_instance<A, E, C>(
|
||||||
.insert(*window_ids.get(&id).unwrap(), user_interface);
|
.insert(*window_ids.get(&id).unwrap(), user_interface);
|
||||||
|
|
||||||
compositor.configure_surface(
|
compositor.configure_surface(
|
||||||
&mut window_state.surface,
|
surface,
|
||||||
physical_size.width,
|
physical_size.width,
|
||||||
physical_size.height,
|
physical_size.height,
|
||||||
);
|
);
|
||||||
|
|
@ -642,9 +647,9 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
match compositor.present(
|
match compositor.present(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
&mut window_state.surface,
|
surface,
|
||||||
window_state.state.viewport(),
|
state.viewport(),
|
||||||
window_state.state.background_color(),
|
state.background_color(),
|
||||||
&debug.overlay(),
|
&debug.overlay(),
|
||||||
) {
|
) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
|
|
@ -680,14 +685,11 @@ async fn run_instance<A, E, C>(
|
||||||
if let Some(window) =
|
if let Some(window) =
|
||||||
window_ids.get(&window_id).and_then(|id| windows.get(id))
|
window_ids.get(&window_id).and_then(|id| windows.get(id))
|
||||||
{
|
{
|
||||||
if let Some(window_state) = window_ids
|
if let Some(state) = window_ids
|
||||||
.get(&window_id)
|
.get(&window_id)
|
||||||
.and_then(|id| states.get_mut(id))
|
.and_then(|id| states.get_mut(id))
|
||||||
{
|
{
|
||||||
if requests_exit(
|
if requests_exit(&window_event, state.modifiers()) {
|
||||||
&window_event,
|
|
||||||
window_state.state.modifiers(),
|
|
||||||
) {
|
|
||||||
if let Some(id) =
|
if let Some(id) =
|
||||||
window_ids.get(&window_id).cloned()
|
window_ids.get(&window_id).cloned()
|
||||||
{
|
{
|
||||||
|
|
@ -696,16 +698,12 @@ async fn run_instance<A, E, C>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window_state.state.update(
|
state.update(window, &window_event, &mut debug);
|
||||||
window,
|
|
||||||
&window_event,
|
|
||||||
&mut debug,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(event) = conversion::window_event(
|
if let Some(event) = conversion::window_event(
|
||||||
&window_event,
|
&window_event,
|
||||||
window_state.state.scale_factor(),
|
state.scale_factor(),
|
||||||
window_state.state.modifiers(),
|
state.modifiers(),
|
||||||
) {
|
) {
|
||||||
events.push((
|
events.push((
|
||||||
window_ids.get(&window_id).cloned(),
|
window_ids.get(&window_id).cloned(),
|
||||||
|
|
@ -953,21 +951,12 @@ pub fn run_command<A, E>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WindowState<A, C>
|
/// TODO(derezzedex)
|
||||||
where
|
pub fn build_user_interfaces<'a, A>(
|
||||||
A: Application,
|
|
||||||
C: iced_graphics::window::Compositor<Renderer = A::Renderer>,
|
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
|
||||||
{
|
|
||||||
surface: <C as iced_graphics::window::Compositor>::Surface,
|
|
||||||
state: State<A>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_user_interfaces<'a, A, C>(
|
|
||||||
application: &'a A,
|
application: &'a A,
|
||||||
renderer: &mut A::Renderer,
|
renderer: &mut A::Renderer,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
states: &HashMap<window::Id, WindowState<A, C>>,
|
states: &HashMap<window::Id, State<A>>,
|
||||||
mut pure_states: HashMap<window::Id, user_interface::Cache>,
|
mut pure_states: HashMap<window::Id, user_interface::Cache>,
|
||||||
) -> HashMap<
|
) -> HashMap<
|
||||||
window::Id,
|
window::Id,
|
||||||
|
|
@ -979,13 +968,12 @@ fn build_user_interfaces<'a, A, C>(
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
C: iced_graphics::window::Compositor<Renderer = A::Renderer> + 'static,
|
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
let mut interfaces = HashMap::new();
|
let mut interfaces = HashMap::new();
|
||||||
|
|
||||||
for (id, pure_state) in pure_states.drain() {
|
for (id, pure_state) in pure_states.drain() {
|
||||||
let state = &states.get(&id).unwrap().state;
|
let state = &states.get(&id).unwrap();
|
||||||
|
|
||||||
let user_interface = build_user_interface(
|
let user_interface = build_user_interface(
|
||||||
application,
|
application,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue