Skip to content

Commit

Permalink
chore: try set viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent ba8084b commit 5265fa2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions iced_layershell/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) enum LayerShellActions<INFO: Clone> {
RedrawAll,
RedrawWindow(LayerId), // maybe one day it is useful, but now useless
NewMenu((IcedNewPopupSettings, INFO)),
SingleLayerViewportDestintion { width: i32, height: i32 },
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down
17 changes: 12 additions & 5 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ where
LayerShellActions::RedrawWindow(index) => {
ev.append_return_data(ReturnData::RedrawIndexRequest(index));
}
LayerShellActions::SingleLayerViewportDestintion { width, height } => {
ev.main_window().try_set_viewport_destination(width, height);
}
_ => {}
}
def_returndata
Expand Down Expand Up @@ -374,10 +377,14 @@ async fn run_instance<A, E, C>(
fractal_scale,
} => {
state.update_view_port(width, height, fractal_scale);
let ps = state.physical_size();
let width = ps.width;
let height = ps.height;
//state.update_view_port(width, height);
let physical_size = state.physical_size();
let width = physical_size.width;
let height = physical_size.height;
let logical_size = state.logical_size();
custom_actions.push(LayerShellActions::SingleLayerViewportDestintion {
width: logical_size.width.ceil() as i32,
height: logical_size.height.ceil() as i32,
});
debug.layout_started();
user_interface =
ManuallyDrop::new(ManuallyDrop::into_inner(user_interface).relayout(
Expand Down Expand Up @@ -470,7 +477,7 @@ async fn run_instance<A, E, C>(
}
}
IcedLayerEvent::Window(event) => {
state.update(&event);
state.update(&event, &mut custom_actions);

if let Some(event) =
conversion::window_event(&event, state.scale_factor(), state.modifiers())
Expand Down
8 changes: 7 additions & 1 deletion iced_layershell/src/application/state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::actions::LayerShellActions;
use crate::application::Application;
use crate::{Appearance, DefaultStyle};
use iced_core::{mouse as IcedMouse, Color, Point, Size};
Expand Down Expand Up @@ -101,7 +102,7 @@ where
.unwrap_or(IcedMouse::Cursor::Unavailable)
}

pub fn update(&mut self, event: &WindowEvent) {
pub fn update(&mut self, event: &WindowEvent, custom_actions: &mut Vec<LayerShellActions<()>>) {
match event {
WindowEvent::CursorLeft => {
self.mouse_position = None;
Expand All @@ -121,6 +122,11 @@ where

self.viewport_version = self.viewport_version.wrapping_add(1);
self.window_scale_factor = *scale_float;
let logical_size = self.logical_size();
custom_actions.push(LayerShellActions::SingleLayerViewportDestintion {
width: logical_size.width.ceil() as i32,
height: logical_size.height.ceil() as i32,
});
}
_ => {}
}
Expand Down

0 comments on commit 5265fa2

Please sign in to comment.