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:
0HyperCube
2021-04-21 22:25:06 +01:00
committed by Keavon Chambers
parent 2849b99b59
commit 46c9ef02ca
26 changed files with 689 additions and 407 deletions

View File

@@ -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 {