Skip to content

Commit 4e418bb

Browse files
committed
Fix device pixel ratio being tied to the document by moving it from overlays to portfolio
1 parent fff0a53 commit 4e418bb

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct DocumentMessageData<'a> {
4242
pub executor: &'a mut NodeGraphExecutor,
4343
pub current_tool: &'a ToolType,
4444
pub preferences: &'a PreferencesMessageHandler,
45+
pub device_pixel_ratio: f64,
4546
}
4647

4748
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
@@ -173,6 +174,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
173174
executor,
174175
current_tool,
175176
preferences,
177+
device_pixel_ratio,
176178
} = data;
177179

178180
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
@@ -197,7 +199,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
197199
}
198200
DocumentMessage::Overlays(message) => {
199201
let overlays_visible = self.overlays_visible;
200-
self.overlays_message_handler.process_message(message, responses, OverlaysMessageData { overlays_visible, ipp });
202+
self.overlays_message_handler.process_message(
203+
message,
204+
responses,
205+
OverlaysMessageData {
206+
overlays_visible,
207+
ipp,
208+
device_pixel_ratio,
209+
},
210+
);
201211
}
202212
DocumentMessage::PropertiesPanel(message) => {
203213
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {

editor/src/messages/portfolio/document/overlays/overlays_message.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::messages::prelude::*;
55
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
66
pub enum OverlaysMessage {
77
Draw,
8-
SetDevicePixelRatio { ratio: f64 },
98
// Serde functionality isn't used but is required by the message system macros
109
AddProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),
1110
RemoveProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),

editor/src/messages/portfolio/document/overlays/overlays_message_handler.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ use crate::messages::prelude::*;
44
pub struct OverlaysMessageData<'a> {
55
pub overlays_visible: bool,
66
pub ipp: &'a InputPreprocessorMessageHandler,
7+
pub device_pixel_ratio: f64,
78
}
89

910
#[derive(Debug, Clone, Default)]
1011
pub struct OverlaysMessageHandler {
1112
pub overlay_providers: HashSet<OverlayProvider>,
1213
canvas: Option<web_sys::HtmlCanvasElement>,
1314
context: Option<web_sys::CanvasRenderingContext2d>,
14-
device_pixel_ratio: Option<f64>,
1515
}
1616

1717
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
1818
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
19-
let OverlaysMessageData { overlays_visible, ipp } = data;
19+
let OverlaysMessageData {
20+
overlays_visible,
21+
ipp,
22+
device_pixel_ratio,
23+
} = data;
2024

2125
match message {
2226
#[cfg(target_arch = "wasm32")]
@@ -41,8 +45,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
4145

4246
let size = ipp.viewport_bounds.size().as_uvec2();
4347

44-
let device_pixel_ratio = self.device_pixel_ratio.unwrap_or(1.);
45-
4648
let [a, b, c, d, e, f] = DAffine2::from_scale(DVec2::splat(device_pixel_ratio)).to_cols_array();
4749
let _ = context.set_transform(a, b, c, d, e, f);
4850
context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
@@ -70,10 +72,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
7072
self.canvas, self.context
7173
);
7274
}
73-
OverlaysMessage::SetDevicePixelRatio { ratio } => {
74-
self.device_pixel_ratio = Some(ratio);
75-
responses.add(OverlaysMessage::Draw);
76-
}
7775
OverlaysMessage::AddProvider(message) => {
7876
self.overlay_providers.insert(message);
7977
}

editor/src/messages/portfolio/portfolio_message.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub enum PortfolioMessage {
105105
SetActivePanel {
106106
panel: PanelType,
107107
},
108+
SetDevicePixelRatio {
109+
ratio: f64,
110+
},
108111
SelectDocument {
109112
document_id: DocumentId,
110113
},

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct PortfolioMessageHandler {
5050
pub selection_mode: SelectionMode,
5151
/// The spreadsheet UI allows for instance data to be previewed.
5252
pub spreadsheet: SpreadsheetMessageHandler,
53+
device_pixel_ratio: Option<f64>,
5354
}
5455

5556
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
@@ -103,6 +104,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
103104
executor: &mut self.executor,
104105
current_tool,
105106
preferences,
107+
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
106108
};
107109
document.process_message(message, responses, document_inputs)
108110
}
@@ -119,6 +121,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
119121
executor: &mut self.executor,
120122
current_tool,
121123
preferences,
124+
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
122125
};
123126
document.process_message(message, responses, document_inputs)
124127
}
@@ -1008,6 +1011,10 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
10081011
self.active_panel = panel;
10091012
responses.add(DocumentMessage::SetActivePanel { active_panel: self.active_panel });
10101013
}
1014+
PortfolioMessage::SetDevicePixelRatio { ratio } => {
1015+
self.device_pixel_ratio = Some(ratio);
1016+
responses.add(OverlaysMessage::Draw);
1017+
}
10111018
PortfolioMessage::SelectDocument { document_id } => {
10121019
// Auto-save the document we are leaving
10131020
let mut node_graph_open = false;

frontend/wasm/src/editor_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl EditorHandle {
352352
/// Inform the overlays system of the current device pixel ratio
353353
#[wasm_bindgen(js_name = setDevicePixelRatio)]
354354
pub fn set_device_pixel_ratio(&self, ratio: f64) {
355-
let message = OverlaysMessage::SetDevicePixelRatio { ratio };
355+
let message = PortfolioMessage::SetDevicePixelRatio { ratio };
356356
self.dispatch(message);
357357
}
358358

0 commit comments

Comments
 (0)