mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
Use target family insted of target arch (#2975)
* Replace cfg target_arch wasm32 with target_family wasm * Fix warnings in test builds from previous pr
This commit is contained in:
@@ -13,7 +13,7 @@ use graphene_std::raster::Image;
|
||||
use graphene_std::raster::color::Color;
|
||||
use graphene_std::text::{Font, TextAlign};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
|
||||
#[impl_message(Message, Frontend)]
|
||||
@@ -322,7 +322,7 @@ pub enum FrontendMessage {
|
||||
UpdateViewportHolePunch {
|
||||
active: bool,
|
||||
},
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
RenderOverlays(
|
||||
#[serde(skip, default = "OverlayContext::default")]
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
|
||||
@@ -591,7 +591,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||
description: Cow::Borrowed("Creates a new canvas object."),
|
||||
properties: None,
|
||||
},
|
||||
#[cfg(all(feature = "gpu", target_arch = "wasm32"))]
|
||||
#[cfg(all(feature = "gpu", target_family = "wasm"))]
|
||||
DocumentNodeDefinition {
|
||||
identifier: "Rasterize",
|
||||
category: "Raster",
|
||||
|
||||
@@ -2,7 +2,7 @@ pub mod grid_overlays;
|
||||
mod overlays_message;
|
||||
mod overlays_message_handler;
|
||||
pub mod utility_functions;
|
||||
#[cfg_attr(not(target_arch = "wasm32"), path = "utility_types_vello.rs")]
|
||||
#[cfg_attr(not(target_family = "wasm"), path = "utility_types_vello.rs")]
|
||||
pub mod utility_types;
|
||||
|
||||
#[doc(inline)]
|
||||
|
||||
@@ -11,20 +11,24 @@ pub struct OverlaysMessageContext<'a> {
|
||||
#[derive(Debug, Clone, Default, ExtractField)]
|
||||
pub struct OverlaysMessageHandler {
|
||||
pub overlay_providers: HashSet<OverlayProvider>,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(target_family = "wasm")]
|
||||
canvas: Option<web_sys::HtmlCanvasElement>,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(target_family = "wasm")]
|
||||
context: Option<web_sys::CanvasRenderingContext2d>,
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMessageHandler {
|
||||
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, context: OverlaysMessageContext) {
|
||||
let OverlaysMessageContext { visibility_settings, ipp, .. } = context;
|
||||
let device_pixel_ratio = context.device_pixel_ratio;
|
||||
let OverlaysMessageContext {
|
||||
visibility_settings,
|
||||
ipp,
|
||||
device_pixel_ratio,
|
||||
..
|
||||
} = context;
|
||||
|
||||
match message {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(target_family = "wasm")]
|
||||
OverlaysMessage::Draw => {
|
||||
use super::utility_functions::overlay_canvas_element;
|
||||
use super::utility_types::OverlayContext;
|
||||
@@ -68,11 +72,10 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMes
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
OverlaysMessage::Draw => {}
|
||||
#[cfg(all(not(target_arch = "wasm32"), not(test)))]
|
||||
#[cfg(all(not(target_family = "wasm"), not(test)))]
|
||||
OverlaysMessage::Draw => {
|
||||
use super::utility_types::OverlayContext;
|
||||
|
||||
let size = ipp.viewport_bounds.size();
|
||||
|
||||
let overlay_context = OverlayContext::new(size, device_pixel_ratio, visibility_settings);
|
||||
@@ -86,6 +89,13 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMes
|
||||
}
|
||||
responses.add(FrontendMessage::RenderOverlays(overlay_context));
|
||||
}
|
||||
#[cfg(all(not(target_family = "wasm"), test))]
|
||||
OverlaysMessage::Draw => {
|
||||
// Removes unused warnings in test builds
|
||||
drop(responses);
|
||||
drop(context);
|
||||
drop(super::utility_types::OverlayContext::new(ipp.viewport_bounds.size(), device_pixel_ratio, visibility_settings));
|
||||
}
|
||||
OverlaysMessage::AddProvider(message) => {
|
||||
self.overlay_providers.insert(message);
|
||||
}
|
||||
|
||||
@@ -1424,13 +1424,13 @@ impl NodeNetworkInterface {
|
||||
.any(|id| id == potentially_upstream_node)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
fn text_width(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<f64> {
|
||||
warn!("Failed to find width of {node_id:#?} in network_path {network_path:?} due to non-wasm arch");
|
||||
Some(0.)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(target_family = "wasm")]
|
||||
fn text_width(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<f64> {
|
||||
let document = web_sys::window().unwrap().document().unwrap();
|
||||
let div = match document.create_element("div") {
|
||||
|
||||
@@ -962,7 +962,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
responses.add(FrontendMessage::UpdateOpenDocumentsList { open_documents });
|
||||
}
|
||||
PortfolioMessage::UpdateVelloPreference => {
|
||||
let active = if cfg!(target_arch = "wasm32") { false } else { preferences.use_vello };
|
||||
let active = if cfg!(target_family = "wasm") { false } else { preferences.use_vello };
|
||||
responses.add(FrontendMessage::UpdateViewportHolePunch { active });
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
self.persistent_data.use_vello = preferences.use_vello;
|
||||
|
||||
@@ -134,9 +134,9 @@ impl NodeRuntime {
|
||||
pub async fn run(&mut self) -> Option<ImageTexture> {
|
||||
if self.editor_api.application_io.is_none() {
|
||||
self.editor_api = WasmEditorApi {
|
||||
#[cfg(all(not(test), target_arch = "wasm32"))]
|
||||
#[cfg(all(not(test), target_family = "wasm"))]
|
||||
application_io: Some(WasmApplicationIo::new().await.into()),
|
||||
#[cfg(any(test, not(target_arch = "wasm32")))]
|
||||
#[cfg(any(test, not(target_family = "wasm")))]
|
||||
application_io: Some(WasmApplicationIo::new_offscreen().await.into()),
|
||||
font_cache: self.editor_api.font_cache.clone(),
|
||||
node_graph_message_sender: Box::new(self.sender.clone()),
|
||||
|
||||
Reference in New Issue
Block a user