Rename project structure with /core and /client

This commit is contained in:
Keavon Chambers
2021-03-27 02:26:55 -07:00
parent 18a8442b0e
commit 7bfb04a99a
64 changed files with 63 additions and 43 deletions
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "graphite-document-core"
version = "0.1.0"
authors = ["Graphite Authors <graphite@keavon.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+7
View File
@@ -0,0 +1,7 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "graphite-editor-core"
version = "0.1.0"
authors = ["Graphite Authors <graphite@keavon.com>"]
edition = "2018"
[dependencies]
log = "0.4"
+47
View File
@@ -0,0 +1,47 @@
use crate::EditorError;
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct Color {
red: f32,
green: f32,
blue: f32,
alpha: f32,
}
impl Color {
pub fn from_rgbaf32(red: f32, green: f32, blue: f32, alpha: f32) -> Result<Color, EditorError> {
let color = Color { red, green, blue, alpha };
if [red, green, blue, alpha].iter().any(|c| c.is_sign_negative() || !c.is_finite()) {
Err(color)?
}
Ok(color)
}
pub fn from_rgb8(red: u8, green: u8, blue: u8) -> Color {
Color::from_rgba8(red, green, blue, 255)
}
pub fn from_rgba8(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
let map = |int_color| int_color as f32 / 255.0;
Color {
red: map(red),
green: map(green),
blue: map(blue),
alpha: map(alpha),
}
}
pub fn r(&self) -> f32 {
self.red
}
pub fn g(&self) -> f32 {
self.green
}
pub fn b(&self) -> f32 {
self.blue
}
pub fn a(&self) -> f32 {
self.alpha
}
pub fn components(&self) -> (f32, f32, f32, f32) {
(self.red, self.green, self.blue, self.alpha)
}
}
+37
View File
@@ -0,0 +1,37 @@
use crate::Color;
use std::error::Error;
use std::fmt::{self, Display};
/// The error type used by the graphite editor.
#[derive(Clone, Debug)]
pub enum EditorError {
InvalidOperation(String),
Misc(String),
Color(String),
}
impl Display for EditorError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
EditorError::InvalidOperation(e) => write!(f, "Failed to execute operation: {}", e),
EditorError::Misc(e) => write!(f, "{}", e),
EditorError::Color(c) => write!(f, "Tried to construct an invalid color {:?}", c),
}
}
}
impl Error for EditorError {}
macro_rules! derive_from {
($type:ty, $kind:ident) => {
impl From<$type> for EditorError {
fn from(error: $type) -> Self {
EditorError::$kind(format!("{:?}", error))
}
}
};
}
derive_from!(&str, Misc);
derive_from!(String, Misc);
derive_from!(Color, Color);
+20
View File
@@ -0,0 +1,20 @@
mod color;
mod error;
mod scheduler;
pub mod tools;
pub mod workspace;
#[doc(inline)]
pub use error::EditorError;
#[doc(inline)]
pub use color::Color;
use tools::ToolState;
use workspace::Workspace;
// TODO: serialize with serde to save the current editor state
struct Editor {
tools: ToolState,
workspace: Workspace,
}
+1
View File
@@ -0,0 +1 @@
+42
View File
@@ -0,0 +1,42 @@
use crate::Color;
const TOOL_COUNT: usize = 10;
pub struct ToolState {
primary_color: Color,
secondary_color: Color,
active_tool: ToolType,
tool_settings: [ToolSettings; TOOL_COUNT],
}
impl ToolState {
pub fn select_tool(&mut self, tool: ToolType) {
self.active_tool = tool
}
}
#[repr(usize)]
pub enum ToolType {
Select = 0,
Crop = 1,
Navigate = 2,
Sample = 3,
Path = 4,
Pen = 5,
Line = 6,
Rectangle = 7,
Ellipse = 8,
Shape = 9,
// all discriminats must be strictly smaller than TOOL_COUNT!
}
pub enum ToolSettings {
Select { append_mode: SelectAppendMode },
}
pub enum SelectAppendMode {
New,
Add,
Subtract,
Intersect,
}
+34
View File
@@ -0,0 +1,34 @@
use crate::EditorError;
pub type PanelId = usize;
pub struct Workspace {
hovered_panel: PanelId,
root: PanelGroup,
}
impl Workspace {
// add panel / panel group
// delete panel / panel group
// move panel / panel group
// get_serialized_layout()
}
struct PanelGroup {
contents: Vec<Contents>,
layout_direction: LayoutDirection,
}
enum Contents {
PanelArea(PanelArea),
Group(PanelGroup),
}
struct PanelArea {
panels: Vec<PanelId>,
active: PanelId,
}
enum LayoutDirection {
Horizontal,
Vertical,
}
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "graphite-renderer-core"
version = "0.1.0"
authors = ["Graphite Authors <graphite@keavon.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+7
View File
@@ -0,0 +1,7 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}