Skip to content

Commit c71ef03

Browse files
committed
Scale thin strokes to maintain a minimum selection tolerance
1 parent 07fbcd4 commit c71ef03

85 files changed

Lines changed: 607 additions & 993 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.branding

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
https://github.com/Keavon/graphite-branded-assets/archive/8cd7cf811d36228a2eb7ce741adc3c745632a6e7.tar.gz
2-
17a7cd32dda4afd893c65e1fb6757f1ecf760702217f647d1c680db8d92643ef
1+
https://github.com/Keavon/graphite-branded-assets/archive/f44aa2f362ae4fed8d634878b817a1d3948a7dcb.tar.gz
2+
dffe2b483e491979ef57c320d61446ada5400ef73ff26582976631d9c36efefc

desktop/src/app.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rand::Rng;
12
use rfd::AsyncFileDialog;
23
use std::fs;
34
use std::path::PathBuf;
@@ -16,7 +17,7 @@ use crate::event::{AppEvent, AppEventScheduler};
1617
use crate::persist::PersistentData;
1718
use crate::render::{RenderError, RenderState};
1819
use crate::window::Window;
19-
use crate::wrapper::messages::{DesktopFrontendMessage, DesktopWrapperMessage, InputMessage, MouseKeys, MouseState, Platform};
20+
use crate::wrapper::messages::{DesktopFrontendMessage, DesktopWrapperMessage, InputMessage, MouseKeys, MouseState};
2021
use crate::wrapper::{DesktopWrapper, NodeGraphExecutionResult, WgpuContext, serialize_frontend_messages};
2122

2223
pub(crate) struct App {
@@ -78,6 +79,8 @@ impl App {
7879
let mut persistent_data = PersistentData::default();
7980
persistent_data.load_from_disk();
8081

82+
let desktop_wrapper = DesktopWrapper::new(rand::rng().random());
83+
8184
Self {
8285
render_state: None,
8386
wgpu_context,
@@ -91,7 +94,7 @@ impl App {
9194
ui_scale: 1.,
9295
app_event_receiver,
9396
app_event_scheduler,
94-
desktop_wrapper: DesktopWrapper::new(),
97+
desktop_wrapper,
9598
last_ui_update: Instant::now(),
9699
cef_context,
97100
cef_schedule: Some(Instant::now()),
@@ -478,14 +481,6 @@ impl ApplicationHandler for App {
478481
self.resize();
479482

480483
self.desktop_wrapper.init(self.wgpu_context.clone());
481-
482-
#[cfg(target_os = "windows")]
483-
let platform = Platform::Windows;
484-
#[cfg(target_os = "macos")]
485-
let platform = Platform::Mac;
486-
#[cfg(target_os = "linux")]
487-
let platform = Platform::Linux;
488-
self.dispatch_desktop_wrapper_message(DesktopWrapperMessage::UpdatePlatform(platform));
489484
}
490485

491486
fn proxy_wake_up(&mut self, event_loop: &dyn ActiveEventLoop) {

desktop/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn start() {
6666
}
6767
};
6868

69+
// Must be called before event loop initialization or native window integrations will break
6970
App::init();
7071

7172
let wgpu_context = futures::executor::block_on(gpu_context::create_wgpu_context());
@@ -78,9 +79,9 @@ pub fn start() {
7879

7980
let cef_handler = cef::CefHandler::new(wgpu_context.clone(), app_event_scheduler.clone(), cef_view_info_receiver);
8081
let cef_context = match cef_context_builder.initialize(cef_handler, cli.disable_ui_acceleration) {
81-
Ok(c) => {
82+
Ok(context) => {
8283
tracing::info!("CEF initialized successfully");
83-
c
84+
context
8485
}
8586
Err(cef::InitError::AlreadyRunning) => {
8687
tracing::error!("Another instance is already running, Exiting.");

desktop/wrapper/src/handle_desktop_wrapper_message.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use graphene_std::Color;
22
use graphene_std::raster::Image;
3-
use graphite_editor::messages::app_window::app_window_message_handler::AppWindowPlatform;
43
use graphite_editor::messages::clipboard::utility_types::ClipboardContentRaw;
54
use graphite_editor::messages::prelude::*;
65

76
use super::DesktopWrapperMessageDispatcher;
8-
use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessage, OpenFileDialogContext, Platform, SaveFileDialogContext};
7+
use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessage, OpenFileDialogContext, SaveFileDialogContext};
98

109
pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: DesktopWrapperMessage) {
1110
match message {
@@ -111,15 +110,6 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
111110
dispatcher.queue_editor_message(message);
112111
}
113112
DesktopWrapperMessage::PollNodeGraphEvaluation => dispatcher.poll_node_graph_evaluation(),
114-
DesktopWrapperMessage::UpdatePlatform(platform) => {
115-
let platform = match platform {
116-
Platform::Windows => AppWindowPlatform::Windows,
117-
Platform::Mac => AppWindowPlatform::Mac,
118-
Platform::Linux => AppWindowPlatform::Linux,
119-
};
120-
let message = AppWindowMessage::UpdatePlatform { platform };
121-
dispatcher.queue_editor_message(message);
122-
}
123113
DesktopWrapperMessage::UpdateMaximized { maximized } => {
124114
let message = FrontendMessage::UpdateMaximized { maximized };
125115
dispatcher.queue_editor_message(message);

desktop/wrapper/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use graph_craft::wasm_application_io::WasmApplicationIo;
2-
use graphite_editor::application::Editor;
2+
use graphite_editor::application::{Editor, Environment, Host, Platform};
33
use graphite_editor::messages::prelude::{FrontendMessage, Message};
44

55
// TODO: Remove usage of this reexport in desktop create and remove this line
@@ -27,8 +27,18 @@ pub struct DesktopWrapper {
2727
}
2828

2929
impl DesktopWrapper {
30-
pub fn new() -> Self {
31-
Self { editor: Editor::new() }
30+
pub fn new(uuid_random_seed: u64) -> Self {
31+
#[cfg(target_os = "windows")]
32+
let host = Host::Windows;
33+
#[cfg(target_os = "macos")]
34+
let host = Host::Mac;
35+
#[cfg(target_os = "linux")]
36+
let host = Host::Linux;
37+
let env = Environment { platform: Platform::Desktop, host };
38+
39+
Self {
40+
editor: Editor::new(env, uuid_random_seed),
41+
}
3242
}
3343

3444
pub fn init(&self, wgpu_context: WgpuContext) {
@@ -51,12 +61,6 @@ impl DesktopWrapper {
5161
}
5262
}
5363

54-
impl Default for DesktopWrapper {
55-
fn default() -> Self {
56-
Self::new()
57-
}
58-
}
59-
6064
pub enum NodeGraphExecutionResult {
6165
HasRun(Option<wgpu::Texture>),
6266
NotRun,

desktop/wrapper/src/messages.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub enum DesktopWrapperMessage {
109109
content: Vec<u8>,
110110
},
111111
PollNodeGraphEvaluation,
112-
UpdatePlatform(Platform),
113112
UpdateMaximized {
114113
maximized: bool,
115114
},
@@ -163,12 +162,6 @@ pub enum SaveFileDialogContext {
163162
File { content: Vec<u8> },
164163
}
165164

166-
pub enum Platform {
167-
Windows,
168-
Mac,
169-
Linux,
170-
}
171-
172165
pub enum MenuItem {
173166
Action {
174167
id: String,

editor/src/application.rs

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
use crate::dispatcher::Dispatcher;
22
use crate::messages::prelude::*;
33
pub use graphene_std::uuid::*;
4+
use std::sync::OnceLock;
45

5-
// TODO: serialize with serde to save the current editor state
66
pub struct Editor {
77
pub dispatcher: Dispatcher,
88
}
99

1010
impl Editor {
11-
/// Construct the editor.
12-
/// Remember to provide a random seed with `editor::set_uuid_seed(seed)` before any editors can be used.
13-
pub fn new() -> Self {
11+
pub fn new(environment: Environment, uuid_random_seed: u64) -> Self {
12+
ENVIRONMENT.set(environment).expect("Editor shoud only be initialized once");
13+
graphene_std::uuid::set_uuid_seed(uuid_random_seed);
14+
1415
Self { dispatcher: Dispatcher::new() }
1516
}
1617

1718
#[cfg(test)]
1819
pub(crate) fn new_local_executor() -> (Self, crate::node_graph_executor::NodeRuntime) {
20+
let _ = ENVIRONMENT.set(*Editor::environment());
21+
graphene_std::uuid::set_uuid_seed(0);
22+
1923
let (runtime, executor) = crate::node_graph_executor::NodeGraphExecutor::new_with_local_runtime();
20-
let dispatcher = Dispatcher::with_executor(executor);
21-
(Self { dispatcher }, runtime)
24+
let editor = Self {
25+
dispatcher: Dispatcher::with_executor(executor),
26+
};
27+
28+
(editor, runtime)
2229
}
2330

2431
pub fn handle_message<T: Into<Message>>(&mut self, message: T) -> Vec<FrontendMessage> {
@@ -32,9 +39,53 @@ impl Editor {
3239
}
3340
}
3441

35-
impl Default for Editor {
36-
fn default() -> Self {
37-
Self::new()
42+
static ENVIRONMENT: OnceLock<Environment> = OnceLock::new();
43+
impl Editor {
44+
#[cfg(not(test))]
45+
pub fn environment() -> &'static Environment {
46+
ENVIRONMENT.get().expect("Editor environment accessed before initialization")
47+
}
48+
49+
#[cfg(test)]
50+
pub fn environment() -> &'static Environment {
51+
&Environment {
52+
platform: Platform::Desktop,
53+
host: Host::Linux,
54+
}
55+
}
56+
}
57+
58+
#[derive(Clone, Copy, Debug)]
59+
pub struct Environment {
60+
pub platform: Platform,
61+
pub host: Host,
62+
}
63+
#[derive(Clone, Copy, Debug)]
64+
pub enum Platform {
65+
Desktop,
66+
Web,
67+
}
68+
#[derive(Clone, Copy, Debug)]
69+
pub enum Host {
70+
Windows,
71+
Mac,
72+
Linux,
73+
}
74+
impl Environment {
75+
pub fn is_desktop(&self) -> bool {
76+
matches!(self.platform, Platform::Desktop)
77+
}
78+
pub fn is_web(&self) -> bool {
79+
matches!(self.platform, Platform::Web)
80+
}
81+
pub fn is_windows(&self) -> bool {
82+
matches!(self.host, Host::Windows)
83+
}
84+
pub fn is_mac(&self) -> bool {
85+
matches!(self.host, Host::Mac)
86+
}
87+
pub fn is_linux(&self) -> bool {
88+
matches!(self.host, Host::Linux)
3889
}
3990
}
4091

editor/src/dispatcher.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ pub struct DispatcherMessageHandlers {
2323
debug_message_handler: DebugMessageHandler,
2424
defer_message_handler: DeferMessageHandler,
2525
dialog_message_handler: DialogMessageHandler,
26-
globals_message_handler: GlobalsMessageHandler,
2726
input_preprocessor_message_handler: InputPreprocessorMessageHandler,
2827
key_mapping_message_handler: KeyMappingMessageHandler,
2928
layout_message_handler: LayoutMessageHandler,
3029
menu_bar_message_handler: MenuBarMessageHandler,
31-
pub portfolio_message_handler: PortfolioMessageHandler,
30+
pub(crate) portfolio_message_handler: PortfolioMessageHandler,
3231
preferences_message_handler: PreferencesMessageHandler,
3332
tool_message_handler: ToolMessageHandler,
3433
viewport_message_handler: ViewportMessageHandler,
@@ -192,17 +191,11 @@ impl Dispatcher {
192191
self.responses.push(message);
193192
}
194193
}
195-
Message::Globals(message) => {
196-
self.message_handlers.globals_message_handler.process_message(message, &mut queue, ());
197-
}
198194
Message::InputPreprocessor(message) => {
199-
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
200-
201195
self.message_handlers.input_preprocessor_message_handler.process_message(
202196
message,
203197
&mut queue,
204198
InputPreprocessorMessageContext {
205-
keyboard_platform,
206199
viewport: &self.message_handlers.viewport_message_handler,
207200
},
208201
);

editor/src/messages/app_window/app_window_message.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use crate::messages::prelude::*;
22

3-
use super::app_window_message_handler::AppWindowPlatform;
4-
53
#[impl_message(Message, AppWindow)]
64
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
75
pub enum AppWindowMessage {
8-
UpdatePlatform { platform: AppWindowPlatform },
96
PointerLock,
107
PointerLockMove { x: f64, y: f64 },
118
Close,

editor/src/messages/app_window/app_window_message_handler.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
use crate::messages::app_window::AppWindowMessage;
1+
use crate::application::{Environment, Platform};
22
use crate::messages::prelude::*;
3+
use crate::{application::Host, messages::app_window::AppWindowMessage};
34
use graphite_proc_macros::{ExtractField, message_handler_data};
45

56
#[derive(Debug, Clone, Default, ExtractField)]
6-
pub struct AppWindowMessageHandler {
7-
platform: AppWindowPlatform,
8-
}
7+
pub struct AppWindowMessageHandler {}
98

109
#[message_handler_data]
1110
impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler {
1211
fn process_message(&mut self, message: AppWindowMessage, responses: &mut std::collections::VecDeque<Message>, _: ()) {
1312
match message {
14-
AppWindowMessage::UpdatePlatform { platform } => {
15-
self.platform = platform;
16-
responses.add(FrontendMessage::UpdatePlatform { platform: self.platform });
17-
}
1813
AppWindowMessage::PointerLock => {
1914
responses.add(FrontendMessage::WindowPointerLock);
2015
}
@@ -66,3 +61,14 @@ pub enum AppWindowPlatform {
6661
Mac,
6762
Linux,
6863
}
64+
65+
impl From<&Environment> for AppWindowPlatform {
66+
fn from(environment: &Environment) -> Self {
67+
match (environment.platform, environment.host) {
68+
(Platform::Web, _) => AppWindowPlatform::Web,
69+
(Platform::Desktop, Host::Linux) => AppWindowPlatform::Linux,
70+
(Platform::Desktop, Host::Mac) => AppWindowPlatform::Mac,
71+
(Platform::Desktop, Host::Windows) => AppWindowPlatform::Windows,
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)