mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
Add colors in Rust (#78)
* 🎨 Add colors in Rust * 🌿 Use an option for the properties and #[repr(C)] * ❌ Remove WASM dependency on document. * 😎 Wrap Fill and stroke in a style struct. * 📦 Use crate::Color * Merge Add transactions for temporary modifications to the document * Run cargo fmt * Color without a 'U'
This commit is contained in:
committed by
Keavon Chambers
parent
2849b99b59
commit
46c9ef02ca
@@ -322,13 +322,14 @@ export default defineComponent({
|
||||
}
|
||||
todo(toolIndex);
|
||||
},
|
||||
async updatePrimaryColor(c: { r: number; g: number; b: number; a: number }) {
|
||||
const { update_primary_color, Color } = await wasm;
|
||||
update_primary_color(new Color(c.r, c.g, c.b, c.a));
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
registerResponseHandler(ResponseType.UpdateCanvas, (responseData) => {
|
||||
this.viewportSvg = responseData
|
||||
.split("\n")
|
||||
.map((shape, i) => shape.replace("#fff", `#${Math.floor(Math.abs(Math.sin(i + 1)) * 16777215).toString(16)}`))
|
||||
.join("\n");
|
||||
this.viewportSvg = responseData;
|
||||
});
|
||||
registerResponseHandler(ResponseType.SetActiveTool, (responseData) => {
|
||||
this.activeTool = responseData;
|
||||
@@ -336,6 +337,9 @@ export default defineComponent({
|
||||
|
||||
window.addEventListener("keyup", (e: KeyboardEvent) => this.keyUp(e));
|
||||
window.addEventListener("keydown", (e: KeyboardEvent) => this.keyDown(e));
|
||||
|
||||
// TODO: Implement actuall UI for chosing colors (this is completly temporary)
|
||||
this.updatePrimaryColor({ r: 0.29, g: 0.52, b: 0.29, a: 0.6 });
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
@@ -12,8 +12,8 @@ impl Color {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Result<Color, JsValue> {
|
||||
match InnerColor::from_rgbaf32(red, green, blue, alpha) {
|
||||
Ok(v) => Ok(Self(v)),
|
||||
Err(e) => Err(Error::new(&e.to_string()).into()),
|
||||
Some(v) => Ok(Self(v)),
|
||||
None => Err(Error::new("invalid color").into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user