Compare commits
7 Commits
87f0850fd5
...
3cf028fe16
Author | SHA1 | Date |
---|---|---|
~erin | 3cf028fe16 | |
~erin | e2b0b6b0f6 | |
~erin | aa336e60d4 | |
~erin | 5004b71b84 | |
~erin | 0d83071fd8 | |
~erin | 6616aeabdd | |
~erin | 11e7403caa |
|
@ -0,0 +1,6 @@
|
||||||
|
# clipboard api is still unstable, so web-sys requires the below flag to be passed for copy (ctrl + c) to work
|
||||||
|
# https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html
|
||||||
|
# check status at https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility
|
||||||
|
# we don't use `[build]` because of rust analyzer's build cache invalidation https://github.com/emilk/eframe_template/issues/93
|
||||||
|
[target.wasm32-unknown-unknown]
|
||||||
|
rustflags = ["--cfg=web_sys_unstable_apis"]
|
41
Cargo.toml
|
@ -1,8 +1,49 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fplanner"
|
name = "fplanner"
|
||||||
|
authors = ["Erin <contact@the-system.eu.org>"]
|
||||||
|
description = "Simple 2D floorplanning software"
|
||||||
|
repository = "https://git.lavender.software/erin/fplanner"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
egui = "0.21.0"
|
||||||
|
eframe = { version = "0.21.0", default-features = false, features = [
|
||||||
|
"accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies.
|
||||||
|
"default_fonts", # Embed the default egui fonts.
|
||||||
|
"wgpu", # Use the glow rendering backend. Alternative: "wgpu".
|
||||||
|
"persistence", # Enable restoring app state when restarting the app.
|
||||||
|
] }
|
||||||
|
|
||||||
|
# You only need serde if you want app persistence:
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
||||||
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
chrono-humanize = "0.2.2"
|
||||||
|
uuid = { version = "1.3.1", features = ["v4", "fast-rng", "js", "serde"] }
|
||||||
|
fake = "2.5"
|
||||||
|
serde-lexpr = "0.1.3"
|
||||||
|
rfd = "0.11"
|
||||||
|
|
||||||
|
# native:
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
tracing-subscriber = "0.3"
|
||||||
|
|
||||||
|
# web:
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
|
console_error_panic_hook = "0.1.6"
|
||||||
|
tracing-wasm = "0.2"
|
||||||
|
wasm-bindgen-futures = "0.4"
|
||||||
|
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 2 # fast and small wasm
|
||||||
|
|
||||||
|
# Optimize all dependencies even in debug builds:
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 2
|
||||||
|
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[build]
|
||||||
|
filehash = false
|
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 314 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 21 KiB |
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"name": "egui Template PWA",
|
||||||
|
"short_name": "egui-template-pwa",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "./icon-256.png",
|
||||||
|
"sizes": "256x256",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./maskable_icon_x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "any maskable"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./icon-1024.png",
|
||||||
|
"sizes": "1024x1024",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lang": "en-US",
|
||||||
|
"id": "/index.html",
|
||||||
|
"start_url": "./index.html",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "white",
|
||||||
|
"theme_color": "white"
|
||||||
|
}
|
After Width: | Height: | Size: 128 KiB |
|
@ -0,0 +1,25 @@
|
||||||
|
var cacheName = 'egui-template-pwa';
|
||||||
|
var filesToCache = [
|
||||||
|
'./',
|
||||||
|
'./index.html',
|
||||||
|
'./fplanner.js',
|
||||||
|
'./fplanner_bg.wasm',
|
||||||
|
];
|
||||||
|
|
||||||
|
/* Start the service worker and cache all of the app's content */
|
||||||
|
self.addEventListener('install', function (e) {
|
||||||
|
e.waitUntil(
|
||||||
|
caches.open(cacheName).then(function (cache) {
|
||||||
|
return cache.addAll(filesToCache);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Serve cached content when offline */
|
||||||
|
self.addEventListener('fetch', function (e) {
|
||||||
|
e.respondWith(
|
||||||
|
caches.match(e.request).then(function (response) {
|
||||||
|
return response || fetch(e.request);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# This scripts runs various CI-like checks in a convenient way.
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
cargo check --workspace --all-targets
|
||||||
|
cargo check --workspace --all-features --lib --target wasm32-unknown-unknown
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all
|
||||||
|
cargo test --workspace --all-targets --all-features
|
||||||
|
cargo test --workspace --doc
|
||||||
|
trunk build
|
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 314 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 21 KiB |
|
@ -0,0 +1,168 @@
|
||||||
|
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
|
||||||
|
<!-- Disable zooming: -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||||
|
|
||||||
|
|
||||||
|
<!-- change this to your project name -->
|
||||||
|
<title>fplanner</title>
|
||||||
|
|
||||||
|
<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
|
||||||
|
<script type="module">import init from '/fplanner.js';init('/fplanner_bg.wasm');</script>
|
||||||
|
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
|
||||||
|
<base href="/">
|
||||||
|
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="manifest" href="manifest.json">
|
||||||
|
<link rel="apple-touch-icon" href="icon_ios_touch_192.png">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
/* Remove touch delay: */
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
/* Light mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #909090;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
/* Dark mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #404040;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allow canvas to fill entire web page: */
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Position canvas in center-top: */
|
||||||
|
canvas {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, 0%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
color: #f0f0f0;
|
||||||
|
font-size: 24px;
|
||||||
|
font-family: Ubuntu-Light, Helvetica, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------- */
|
||||||
|
/* Loading animation from https://loading.io/css/ */
|
||||||
|
.lds-dual-ring {
|
||||||
|
display: inline-block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring:after {
|
||||||
|
content: " ";
|
||||||
|
display: block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 3px solid #fff;
|
||||||
|
border-color: #fff transparent #fff transparent;
|
||||||
|
animation: lds-dual-ring 1.2s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes lds-dual-ring {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<link rel="preload" href="/fplanner_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||||
|
<link rel="modulepreload" href="/fplanner.js"></head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- The WASM code will resize the canvas dynamically -->
|
||||||
|
<!-- the id is hardcoded in main.rs . so, make sure both match. -->
|
||||||
|
<canvas id="the_canvas_id"></canvas>
|
||||||
|
|
||||||
|
<!--Register Service Worker. this will cache the wasm / js scripts for offline use (for PWA functionality). -->
|
||||||
|
<!-- Force refresh (Ctrl + F5) to load the latest files instead of cached files -->
|
||||||
|
<script>
|
||||||
|
// We disable caching during development so that we always view the latest version.
|
||||||
|
if ('serviceWorker' in navigator && window.location.hash !== "#dev") {
|
||||||
|
window.addEventListener('load', function () {
|
||||||
|
navigator.serviceWorker.register('sw.js');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>(function () {
|
||||||
|
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
var url = protocol + '//' + window.location.host + '/_trunk/ws';
|
||||||
|
var poll_interval = 5000;
|
||||||
|
var reload_upon_connect = () => {
|
||||||
|
window.setTimeout(
|
||||||
|
() => {
|
||||||
|
// when we successfully reconnect, we'll force a
|
||||||
|
// reload (since we presumably lost connection to
|
||||||
|
// trunk due to it being killed, so it will have
|
||||||
|
// rebuilt on restart)
|
||||||
|
var ws = new WebSocket(url);
|
||||||
|
ws.onopen = () => window.location.reload();
|
||||||
|
ws.onclose = reload_upon_connect;
|
||||||
|
},
|
||||||
|
poll_interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
var ws = new WebSocket(url);
|
||||||
|
ws.onmessage = (ev) => {
|
||||||
|
const msg = JSON.parse(ev.data);
|
||||||
|
if (msg.reload) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onclose = reload_upon_connect;
|
||||||
|
})()
|
||||||
|
</script></body></html><!-- Powered by egui: https://github.com/emilk/egui/ -->
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"name": "egui Template PWA",
|
||||||
|
"short_name": "egui-template-pwa",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "./icon-256.png",
|
||||||
|
"sizes": "256x256",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./maskable_icon_x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "any maskable"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./icon-1024.png",
|
||||||
|
"sizes": "1024x1024",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lang": "en-US",
|
||||||
|
"id": "/index.html",
|
||||||
|
"start_url": "./index.html",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "white",
|
||||||
|
"theme_color": "white"
|
||||||
|
}
|
After Width: | Height: | Size: 128 KiB |
|
@ -0,0 +1,25 @@
|
||||||
|
var cacheName = 'egui-template-pwa';
|
||||||
|
var filesToCache = [
|
||||||
|
'./',
|
||||||
|
'./index.html',
|
||||||
|
'./fplanner.js',
|
||||||
|
'./fplanner_bg.wasm',
|
||||||
|
];
|
||||||
|
|
||||||
|
/* Start the service worker and cache all of the app's content */
|
||||||
|
self.addEventListener('install', function (e) {
|
||||||
|
e.waitUntil(
|
||||||
|
caches.open(cacheName).then(function (cache) {
|
||||||
|
return cache.addAll(filesToCache);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Serve cached content when offline */
|
||||||
|
self.addEventListener('fetch', function (e) {
|
||||||
|
e.respondWith(
|
||||||
|
caches.match(e.request).then(function (response) {
|
||||||
|
return response || fetch(e.request);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
|
@ -0,0 +1,140 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
|
||||||
|
<!-- Disable zooming: -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<!-- change this to your project name -->
|
||||||
|
<title>fplanner</title>
|
||||||
|
|
||||||
|
<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
|
||||||
|
<link data-trunk rel="rust" data-wasm-opt="2" />
|
||||||
|
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
|
||||||
|
<base data-trunk-public-url />
|
||||||
|
|
||||||
|
<link data-trunk rel="icon" href="assets/favicon.ico">
|
||||||
|
|
||||||
|
|
||||||
|
<link data-trunk rel="copy-file" href="assets/sw.js" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/manifest.json" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon-1024.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon-256.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon_ios_touch_192.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/maskable_icon_x512.png" />
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="manifest" href="manifest.json">
|
||||||
|
<link rel="apple-touch-icon" href="icon_ios_touch_192.png">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
/* Remove touch delay: */
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
/* Light mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #909090;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
/* Dark mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #404040;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allow canvas to fill entire web page: */
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Position canvas in center-top: */
|
||||||
|
canvas {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, 0%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
color: #f0f0f0;
|
||||||
|
font-size: 24px;
|
||||||
|
font-family: Ubuntu-Light, Helvetica, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------- */
|
||||||
|
/* Loading animation from https://loading.io/css/ */
|
||||||
|
.lds-dual-ring {
|
||||||
|
display: inline-block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring:after {
|
||||||
|
content: " ";
|
||||||
|
display: block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 3px solid #fff;
|
||||||
|
border-color: #fff transparent #fff transparent;
|
||||||
|
animation: lds-dual-ring 1.2s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes lds-dual-ring {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- The WASM code will resize the canvas dynamically -->
|
||||||
|
<!-- the id is hardcoded in main.rs . so, make sure both match. -->
|
||||||
|
<canvas id="the_canvas_id"></canvas>
|
||||||
|
|
||||||
|
<!--Register Service Worker. this will cache the wasm / js scripts for offline use (for PWA functionality). -->
|
||||||
|
<!-- Force refresh (Ctrl + F5) to load the latest files instead of cached files -->
|
||||||
|
<script>
|
||||||
|
// We disable caching during development so that we always view the latest version.
|
||||||
|
if ('serviceWorker' in navigator && window.location.hash !== "#dev") {
|
||||||
|
window.addEventListener('load', function () {
|
||||||
|
navigator.serviceWorker.register('sw.js');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<!-- Powered by egui: https://github.com/emilk/egui/ -->
|
|
@ -0,0 +1,322 @@
|
||||||
|
pub mod components;
|
||||||
|
pub mod draw;
|
||||||
|
mod structure;
|
||||||
|
|
||||||
|
use chrono::prelude::Utc;
|
||||||
|
use chrono_humanize::HumanTime;
|
||||||
|
use egui::{emath, Color32};
|
||||||
|
use egui::{pos2, Painter, Pos2, Rect, Shape};
|
||||||
|
use fake::{Fake, Faker};
|
||||||
|
use serde_lexpr::{from_str, print, to_string_custom};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
||||||
|
pub struct PlannerApp {
|
||||||
|
// Example stuff:
|
||||||
|
label: String,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
update_view: bool,
|
||||||
|
|
||||||
|
view_layers: Vec<structure::Layer>,
|
||||||
|
new_index: usize,
|
||||||
|
new_label: String,
|
||||||
|
save_path: Option<PathBuf>,
|
||||||
|
|
||||||
|
current_project: structure::Project,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PlannerApp {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
// Example stuff:
|
||||||
|
label: "Helllllo World!".to_owned(),
|
||||||
|
view_layers: vec![],
|
||||||
|
update_view: true,
|
||||||
|
new_index: 0,
|
||||||
|
new_label: String::default(),
|
||||||
|
save_path: None,
|
||||||
|
current_project: structure::Project::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlannerApp {
|
||||||
|
/// Called once before the first frame.
|
||||||
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
|
// This is also where you can customize the look and feel of egui using
|
||||||
|
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
|
||||||
|
|
||||||
|
// Load previous app state (if any).
|
||||||
|
// Note that you must enable the `persistence` feature for this to work.
|
||||||
|
if let Some(storage) = cc.storage {
|
||||||
|
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
||||||
|
}
|
||||||
|
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for PlannerApp {
|
||||||
|
/// Called by the frame work to save state before shutdown.
|
||||||
|
fn save(&mut self, storage: &mut dyn eframe::Storage) {
|
||||||
|
eframe::set_value(storage, eframe::APP_KEY, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called each time the UI needs repainting, which may be many times per second.
|
||||||
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
let Self {
|
||||||
|
label,
|
||||||
|
view_layers,
|
||||||
|
update_view,
|
||||||
|
new_index,
|
||||||
|
new_label,
|
||||||
|
save_path,
|
||||||
|
current_project,
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
// Examples of how to create different panels and windows.
|
||||||
|
// Pick whichever suits you.
|
||||||
|
// Tip: a good default choice is to just keep the `CentralPanel`.
|
||||||
|
// For inspiration and more examples, go to https://emilk.github.io/egui
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))] // no File->Quit on web pages!
|
||||||
|
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||||
|
// The top panel is often a good place for a menu bar:
|
||||||
|
egui::menu::bar(ui, |ui| {
|
||||||
|
ui.menu_button("File", |ui| {
|
||||||
|
if ui.button("Load").clicked() {
|
||||||
|
if let Some(path) = rfd::FileDialog::new()
|
||||||
|
.add_filter("plan", &["splan"])
|
||||||
|
.set_title("Load Plan")
|
||||||
|
.pick_file()
|
||||||
|
{
|
||||||
|
let read = std::fs::read_to_string(path.display().to_string()).unwrap();
|
||||||
|
println!("{}", &read);
|
||||||
|
let sexpr: structure::Project = from_str(&read).unwrap();
|
||||||
|
println!("{:?}", &sexpr);
|
||||||
|
*current_project = sexpr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ui.button("Save As").clicked() {
|
||||||
|
let options = print::Options::default();
|
||||||
|
let sexpr = to_string_custom(
|
||||||
|
¤t_project,
|
||||||
|
options
|
||||||
|
.with_keyword_syntax(print::KeywordSyntax::ColonPrefix)
|
||||||
|
.with_nil_syntax(print::NilSyntax::Token)
|
||||||
|
.with_bool_syntax(print::BoolSyntax::Token)
|
||||||
|
.with_vector_syntax(print::VectorSyntax::Octothorpe),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let Some(path) = rfd::FileDialog::new()
|
||||||
|
.add_filter("plan", &["splan"])
|
||||||
|
.set_file_name("untitled.splan")
|
||||||
|
.set_title("Save Plan")
|
||||||
|
.save_file()
|
||||||
|
{
|
||||||
|
println!("{}", &path.display().to_string());
|
||||||
|
std::fs::write(path.display().to_string(), sexpr).unwrap();
|
||||||
|
*save_path = Some(path.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ui.button("Quit").clicked() {
|
||||||
|
_frame.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::SidePanel::right("right_panel").show(ctx, |ui| {
|
||||||
|
ui.heading("Components");
|
||||||
|
|
||||||
|
for i in view_layers.clone() {
|
||||||
|
if i.visible {
|
||||||
|
for (id, comp) in &i.components {
|
||||||
|
ui.label(format!("{}: {}", &id.to_string(), &comp.label));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::SidePanel::left("side_panel").show(ctx, |ui| {
|
||||||
|
ui.heading("Project");
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Project Name: ");
|
||||||
|
ui.text_edit_singleline(&mut current_project.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.collapsing("Metadata", |ui| {
|
||||||
|
ui.label(current_project.id.to_string());
|
||||||
|
|
||||||
|
ui.label(format!(
|
||||||
|
"Created {}",
|
||||||
|
HumanTime::from(current_project.created)
|
||||||
|
));
|
||||||
|
|
||||||
|
match current_project.modified {
|
||||||
|
Some(d) => {
|
||||||
|
ui.label(format!("Modified {}", HumanTime::from(d)));
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Modify").clicked() {
|
||||||
|
current_project.modified = Some(Utc::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.collapsing("License", |ui| {
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
ui.radio_value(
|
||||||
|
&mut current_project.license,
|
||||||
|
structure::License::MIT,
|
||||||
|
"MIT",
|
||||||
|
);
|
||||||
|
ui.radio_value(
|
||||||
|
&mut current_project.license,
|
||||||
|
structure::License::GPL,
|
||||||
|
"GPL",
|
||||||
|
);
|
||||||
|
ui.radio_value(
|
||||||
|
&mut current_project.license,
|
||||||
|
structure::License::AGPL,
|
||||||
|
"AGPL",
|
||||||
|
);
|
||||||
|
ui.radio_value(
|
||||||
|
&mut current_project.license,
|
||||||
|
structure::License::CNPL,
|
||||||
|
"CNPLv7+",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.collapsing("Layers", |ui| {
|
||||||
|
ui.label("New Layer:");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Label: ");
|
||||||
|
ui.text_edit_singleline(new_label);
|
||||||
|
});
|
||||||
|
ui.add(egui::Slider::new(new_index, 0..=10).text("Z-Index"));
|
||||||
|
if ui.button("Create").clicked() {
|
||||||
|
let id = Uuid::new_v4();
|
||||||
|
let new_layer = structure::Layer {
|
||||||
|
zindex: new_index.clone(),
|
||||||
|
label: new_label.clone(),
|
||||||
|
visible: true,
|
||||||
|
components: HashMap::from([(
|
||||||
|
id.clone(),
|
||||||
|
components::Component {
|
||||||
|
id: id.clone(),
|
||||||
|
label: Faker.fake::<String>(),
|
||||||
|
description: Faker.fake::<String>(),
|
||||||
|
c_type: components::ComponentType::Door,
|
||||||
|
material: components::Material::Metal,
|
||||||
|
items: vec![],
|
||||||
|
},
|
||||||
|
)]),
|
||||||
|
};
|
||||||
|
current_project
|
||||||
|
.layers
|
||||||
|
.insert(new_index.clone(), new_layer.clone());
|
||||||
|
current_project.modified = Some(Utc::now());
|
||||||
|
*update_view = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if *update_view {
|
||||||
|
*view_layers = vec![];
|
||||||
|
for (index, layer) in ¤t_project.layers {
|
||||||
|
view_layers.push(layer.clone());
|
||||||
|
}
|
||||||
|
*update_view = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
for x in view_layers {
|
||||||
|
ui.checkbox(&mut x.visible, format!("{}: {}", &x.zindex, &x.label));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
|
ui.label("powered by ");
|
||||||
|
ui.hyperlink_to("egui", "https://github.com/emilk/egui");
|
||||||
|
ui.label(" and ");
|
||||||
|
ui.hyperlink_to(
|
||||||
|
"eframe",
|
||||||
|
"https://github.com/emilk/egui/tree/master/crates/eframe",
|
||||||
|
);
|
||||||
|
ui.label(".");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||||
|
let painter = Painter::new(
|
||||||
|
ui.ctx().clone(),
|
||||||
|
ui.layer_id(),
|
||||||
|
ui.available_rect_before_wrap(),
|
||||||
|
);
|
||||||
|
self.paint(&painter);
|
||||||
|
ui.expand_to_include_rect(painter.clip_rect());
|
||||||
|
|
||||||
|
// ui.heading("eframe template");
|
||||||
|
// ui.hyperlink("https://github.com/emilk/eframe_template");
|
||||||
|
// ui.add(egui::github_link_file!(
|
||||||
|
// "https://github.com/emilk/eframe_template/blob/master/",
|
||||||
|
// "Source code."
|
||||||
|
// ));
|
||||||
|
// egui::warn_if_debug_build(ui);
|
||||||
|
});
|
||||||
|
|
||||||
|
if false {
|
||||||
|
egui::Window::new("Window").show(ctx, |ui| {
|
||||||
|
ui.label("Windows can be moved by dragging them.");
|
||||||
|
ui.label("They are automatically sized based on contents.");
|
||||||
|
ui.label("You can turn on resizing and scrolling if you like.");
|
||||||
|
ui.label("You would normally choose either panels OR windows.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlannerApp {
|
||||||
|
fn paint(&mut self, painter: &Painter) {
|
||||||
|
let mut shapes: Vec<Shape> = Vec::new();
|
||||||
|
|
||||||
|
let rect = painter.clip_rect();
|
||||||
|
let to_screen = emath::RectTransform::from_to(
|
||||||
|
Rect::from_center_size(Pos2::ZERO, rect.square_proportions()),
|
||||||
|
rect,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut paint_line = |points: [Pos2; 2], color: Color32, width: f32| {
|
||||||
|
let line = [to_screen * points[0], to_screen * points[1]];
|
||||||
|
|
||||||
|
// culling
|
||||||
|
if rect.intersects(Rect::from_two_pos(line[0], line[1])) {
|
||||||
|
shapes.push(Shape::line_segment(line, (width, color)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
paint_line(
|
||||||
|
[pos2(0.0, 0.0), pos2(10.0, 10.0)],
|
||||||
|
Color32::from_additive_luminance(255),
|
||||||
|
20.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
painter.extend(shapes);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
use super::draw::DrawItem;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq)]
|
||||||
|
pub enum Unit {
|
||||||
|
Kilometer(f64),
|
||||||
|
Meter(f64),
|
||||||
|
Centimeter(f64),
|
||||||
|
Inch(f64),
|
||||||
|
Foot(f64),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
|
||||||
|
pub enum ComponentType {
|
||||||
|
Wall,
|
||||||
|
Door,
|
||||||
|
Window,
|
||||||
|
Floor,
|
||||||
|
Roof,
|
||||||
|
Furniture,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
|
||||||
|
pub enum Material {
|
||||||
|
Metal,
|
||||||
|
Wood,
|
||||||
|
Plastic,
|
||||||
|
Drywall,
|
||||||
|
Cement,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct Component {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub label: String,
|
||||||
|
pub description: String,
|
||||||
|
pub c_type: ComponentType,
|
||||||
|
pub material: Material,
|
||||||
|
pub items: Vec<DrawItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Component {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
label: String::default(),
|
||||||
|
description: String::default(),
|
||||||
|
c_type: ComponentType::Furniture,
|
||||||
|
material: Material::Wood,
|
||||||
|
items: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
|
||||||
|
pub struct Position(f64, f64, f64);
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone, Debug)]
|
||||||
|
pub enum Shape {
|
||||||
|
Circle(Position, f64), // Centre, Radius
|
||||||
|
Rectangle(Position, Position), // Top-left, Bottom-right
|
||||||
|
Triangle(Position, Position, Position), // 3 points
|
||||||
|
Line(Position, Position), // 2 points
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
use chrono::prelude::*;
|
||||||
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use super::components::Component;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Debug)]
|
||||||
|
pub enum License {
|
||||||
|
MIT,
|
||||||
|
GPL,
|
||||||
|
AGPL,
|
||||||
|
CNPL,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct Layer {
|
||||||
|
pub zindex: usize,
|
||||||
|
pub label: String,
|
||||||
|
pub visible: bool,
|
||||||
|
pub components: HashMap<Uuid, Component>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Layer {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
zindex: 0,
|
||||||
|
visible: true,
|
||||||
|
label: String::default(),
|
||||||
|
components: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
|
#[serde(default)] // if we add new fields, give them default values when deserializing old state
|
||||||
|
pub struct Project {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub created: DateTime<Utc>,
|
||||||
|
pub modified: Option<DateTime<Utc>>,
|
||||||
|
pub license: License,
|
||||||
|
pub layers: BTreeMap<usize, Layer>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Project {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
name: "".to_string(),
|
||||||
|
created: Utc::now(),
|
||||||
|
modified: None,
|
||||||
|
license: License::MIT,
|
||||||
|
layers: BTreeMap::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
|
|
||||||
|
mod app;
|
||||||
|
pub use app::PlannerApp;
|
39
src/main.rs
|
@ -1,3 +1,38 @@
|
||||||
fn main() {
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
println!("Hello, world!");
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||||
|
|
||||||
|
// When compiling natively:
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn main() -> eframe::Result<()> {
|
||||||
|
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
let native_options = eframe::NativeOptions::default();
|
||||||
|
eframe::run_native(
|
||||||
|
"fplanner",
|
||||||
|
native_options,
|
||||||
|
Box::new(|cc| Box::new(fplanner::PlannerApp::new(cc))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// when compiling to web using trunk.
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
fn main() {
|
||||||
|
// Make sure panics are logged using `console.error`.
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
// Redirect tracing to console.log and friends:
|
||||||
|
tracing_wasm::set_as_global_default();
|
||||||
|
|
||||||
|
let web_options = eframe::WebOptions::default();
|
||||||
|
|
||||||
|
wasm_bindgen_futures::spawn_local(async {
|
||||||
|
eframe::start_web(
|
||||||
|
"the_canvas_id", // hardcode it
|
||||||
|
web_options,
|
||||||
|
Box::new(|cc| Box::new(fplanner::PlannerApp::new(cc))),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("failed to start eframe");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
(
|
||||||
|
(id . "5d932ba0-8912-4e53-95b7-5152bab827ac")
|
||||||
|
(name . "Test Edit!")
|
||||||
|
(created . "2023-04-29T00:28:43.560471889Z")
|
||||||
|
(modified "2023-04-29T00:30:40.945891620Z")
|
||||||
|
(license . MIT)
|
||||||
|
(layers
|
||||||
|
(0
|
||||||
|
(zindex . 0)
|
||||||
|
(label . "Meow")
|
||||||
|
(visible . #f)
|
||||||
|
(components
|
||||||
|
("bbf8f70a-60c1-4859-924b-c360b897dc6c"
|
||||||
|
(id . "73e48d43-2ec4-4397-8289-54ddc87f9886")
|
||||||
|
(label . "sWzh9LGiSKrlQsRWoK")
|
||||||
|
(description . "Bq59shWXHCKhTH1")
|
||||||
|
(c_type . Door)
|
||||||
|
(material . Metal)
|
||||||
|
(items)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(2
|
||||||
|
(zindex . 2)
|
||||||
|
(label . ":O")
|
||||||
|
(visible . #t)
|
||||||
|
(components
|
||||||
|
("92e47d24-d69f-4b14-9d25-badb1ebe5f98"
|
||||||
|
(id . "7e82f1b1-5c88-4edd-805f-19f98e34c244")
|
||||||
|
(label . "s8so6MS711zAODf")
|
||||||
|
(description . "7tCDffx2dFFzIrT")
|
||||||
|
(c_type . Door)
|
||||||
|
(material . Metal)
|
||||||
|
(items)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(3
|
||||||
|
(zindex . 3)
|
||||||
|
(label . "Hello")
|
||||||
|
(visible . #t)
|
||||||
|
(components
|
||||||
|
("4774cddf-fba6-4008-a212-d1aff8b22cf9"
|
||||||
|
(id . "7d03467b-79bf-4e1f-8970-5be62c444842")
|
||||||
|
(label . "zEkXt7uOVBSb")
|
||||||
|
(description . "hi9js3X8dWaWZ")
|
||||||
|
(c_type . Door)
|
||||||
|
(material . Metal)
|
||||||
|
(items)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|