Bundle Graphite using Tauri (#873)

* Setup tauri component for graphite editor

Integrate graphite into tauri app

Split interpreted-executor out of graph-craft

* Add gpu execution node

* General Cleanup
This commit is contained in:
TrueDoctor
2022-12-07 12:49:34 +01:00
committed by Keavon Chambers
parent 52cc770a1e
commit 7d8f94462a
109 changed files with 5661 additions and 544 deletions
@@ -4,7 +4,6 @@ use crate::messages::prelude::*;
pub use graphene::DocumentResponse;
use bitflags::bitflags;
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
@@ -51,7 +50,7 @@ bitflags! {
// (although we ignore the shift key, so the user doesn't have to press `Ctrl Shift +` on a US keyboard), even if the keyboard layout
// is for a different locale where the `+` key is somewhere entirely different, shifted or not. This would then also work for numpad `+`.
#[impl_message(Message, InputMapperMessage, KeyDown)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum Key {
// Writing system keys
Digit0,
@@ -210,18 +209,6 @@ pub enum Key {
NumKeys,
}
impl Serialize for Key {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let key = format!("{:?}", self);
let label = self.to_string();
let mut state = serializer.serialize_struct("KeyWithLabel", 2)?;
state.serialize_field("key", &key)?;
state.serialize_field("label", &label)?;
state.end()
}
}
impl fmt::Display for Key {
// TODO: Relevant key labels should be localized when we get around to implementing localization/internationalization
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
@@ -308,6 +295,35 @@ impl fmt::Display for Key {
}
}
impl From<Key> for LayoutKey {
fn from(key: Key) -> Self {
Self {
key: format!("{:?}", key),
label: key.to_string(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct LayoutKey {
key: String,
label: String,
}
/*
impl Serialize for Key {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let key = format!("{:?}", self.0);
let label = self.0.to_string();
assert_eq!(serde_json::to_string(Key::KeyEscape), {"key": KeyEscape, "label": "Esc"});
let mut state = serializer.serialize_struct("KeyWithLabel", 2)?;
state.serialize_field("key", &key)?;
state.serialize_field("label", &label)?;
state.end()
}
}*/
pub const NUMBER_OF_KEYS: usize = Key::NumKeys as usize;
/// Only `Key`s that exist on a physical keyboard should be used.
@@ -342,6 +358,22 @@ impl fmt::Display for KeysGroup {
}
}
impl From<KeysGroup> for String {
fn from(keys: KeysGroup) -> Self {
let layout_keys: LayoutKeysGroup = keys.into();
serde_json::to_string(&layout_keys).expect("Failed to serialize KeysGroup")
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct LayoutKeysGroup(Vec<LayoutKey>);
impl From<KeysGroup> for LayoutKeysGroup {
fn from(keys_group: KeysGroup) -> Self {
Self(keys_group.0.into_iter().map(|key| key.into()).collect())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MouseMotion {
None,
@@ -1,4 +1,4 @@
use super::input_keyboard::{all_required_modifiers_pressed, KeysGroup};
use super::input_keyboard::{all_required_modifiers_pressed, KeysGroup, LayoutKeysGroup};
use crate::messages::input_mapper::default_mapping::default_mapping;
use crate::messages::input_mapper::utility_types::input_keyboard::{KeyStates, NUMBER_OF_KEYS};
use crate::messages::prelude::*;
@@ -81,24 +81,27 @@ pub struct MappingEntry {
pub enum ActionKeys {
Action(MessageDiscriminant),
#[serde(rename = "keys")]
Keys(KeysGroup),
Keys(LayoutKeysGroup),
}
impl ActionKeys {
pub fn to_keys(&mut self, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Vec<KeysGroup>) {
pub fn to_keys(&mut self, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Vec<KeysGroup>) -> String {
match self {
ActionKeys::Action(action) => {
if let Some(keys) = action_input_mapping(action).get_mut(0) {
let mut taken_keys = KeysGroup::default();
std::mem::swap(keys, &mut taken_keys);
*self = ActionKeys::Keys(taken_keys);
let description = taken_keys.to_string();
*self = ActionKeys::Keys(taken_keys.into());
description
} else {
*self = ActionKeys::Keys(KeysGroup::default());
*self = ActionKeys::Keys(KeysGroup::default().into());
String::new()
}
}
ActionKeys::Keys(keys) => {
warn!("Calling `.to_keys()` on a `ActionKeys::Keys` is a mistake/bug. Keys are: {:?}.", keys);
String::new()
}
}
}