Compare commits

..

No commits in common. "f69e490d076b4b6e69ddf6ee433dc3129fab9098" and "9f2699e2c8d1d2d7cd248a37b21d5cec7753f9b4" have entirely different histories.

6 changed files with 40 additions and 70 deletions

View File

@ -18,7 +18,7 @@
import MainMenu from "./components/MainMenu.vue"; import MainMenu from "./components/MainMenu.vue";
import CanvasBoard from "./components/CanvasBoard.vue"; import CanvasBoard from "./components/CanvasBoard.vue";
import MenuReset from "./components/MenuReset.vue"; import MenuReset from "./components/MenuReset.vue";
import { mapState, mapWritableState, mapActions } from "pinia"; import { mapWritableState, mapActions } from "pinia";
import { globalStore } from "./stores/index.js"; import { globalStore } from "./stores/index.js";
export default { export default {
@ -30,12 +30,15 @@
}, },
data() { data() {
return { return {
mainMenu: false,
windowWidth: window.innerWidth, windowWidth: window.innerWidth,
}; };
}, },
computed: { computed: {
...mapState(globalStore, ["mainMenu", "activeSubMenu"]), ...mapWritableState(globalStore, {
...mapWritableState(globalStore, ["canvasWidth", "canvasHeight"]), canvasWidth: "canvasWidth",
canvasHeight: "canvasHeight",
}),
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
@ -46,13 +49,9 @@
window.removeEventListener("resize", this.onResize); window.removeEventListener("resize", this.onResize);
}, },
methods: { methods: {
...mapActions(globalStore, [ ...mapActions(globalStore, ["setBoardWidth", "setBoardHeight"]),
"setBoardWidth",
"setBoardHeight",
"setMainMenu",
]),
toggleMainMenu() { toggleMainMenu() {
this.setMainMenu(!this.mainMenu); this.mainMenu = !this.mainMenu;
}, },
onResize() { onResize() {
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -1,9 +1,9 @@
<template> <template>
<div id="main-menu"> <div id="main-menu">
<MenuGeneralOptions /> <MenuGeneralOptions :active="active" @update-active="updateActive" />
<MenuCellProperties /> <MenuCellProperties :active="active" @update-active="updateActive" />
<MenuElementaryCA /> <MenuElementaryCA :active="active" @update-active="updateActive" />
<Menu2dCA /> <Menu2dCA :active="active" @update-active="updateActive" />
</div> </div>
</template> </template>
@ -20,6 +20,21 @@
MenuElementaryCA, MenuElementaryCA,
Menu2dCA, Menu2dCA,
}, },
data() {
return {
active: "",
};
},
methods: {
// set the opened submenu. If already active, reset it so it can close
updateActive(menu) {
if (menu === this.active) {
this.active = "";
} else {
this.active = menu;
}
},
},
}; };
</script> </script>
@ -28,6 +43,7 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 100%; width: 100%;
flex: 1; flex: 1;
} }

View File

@ -38,7 +38,7 @@
import { globalStore } from "../stores/index.js"; import { globalStore } from "../stores/index.js";
import MenuRow from "./MenuRow.vue"; import MenuRow from "./MenuRow.vue";
export default { export default {
name: "MenuCellProperties", name: "MainMenu",
components: { components: {
MenuRow, MenuRow,
}, },

View File

@ -1,14 +1,6 @@
<template> <template>
<MenuRow row-title="Elementary Automaton"> <MenuRow row-title="Elementary Automaton">
<form> <form>
<div class="form-field">
<input
type="button"
name="start"
value="start"
@click="toggleDraw1d()"
/>
</div>
<div class="form-field"> <div class="form-field">
<label> <label>
Initial state presets Initial state presets
@ -70,6 +62,9 @@
</label> </label>
</div> </div>
</form> </form>
<div class="form-field">
<input type="button" name="start" value="start" @click="toggleDraw1d()" />
</div>
</MenuRow> </MenuRow>
</template> </template>

View File

@ -1,17 +1,15 @@
<template> <template>
<div class="menu-row"> <div class="menu-row">
<h2 :id="rowTitle" @click.stop="storeActiveSubMenu"> <h2 :id="rowTitle" @click="$emit('update-active', rowTitle)">
{{ rowTitle }} {{ rowTitle }}
</h2> </h2>
<div v-if="isActive" ref="content" class="menu-row-content"> <div v-if="isActive" class="menu-row-content">
<slot /> <slot />
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapActions, mapState } from "pinia";
import { globalStore } from "../stores/index.js";
export default { export default {
name: "MenuRow", name: "MenuRow",
props: { props: {
@ -19,38 +17,15 @@
type: String, type: String,
default: "", default: "",
}, },
active: {
type: String,
default: "",
}, },
},
emits: ["update-active"],
computed: { computed: {
...mapState(globalStore, ["activeSubMenu"]),
isActive() { isActive() {
return this.rowTitle == this.activeSubMenu; return this.rowTitle == this.active;
},
},
beforeUnmount() {
window.removeEventListener("click", this.onWindowClick);
},
methods: {
...mapActions(globalStore, ["setActiveSubMenu", "toggleMainMenu"]),
onKeyDown: function (event) {
// escape
if (event.keyCode == 27) {
this.setActiveSubMenu("");
}
},
storeActiveSubMenu() {
window.addEventListener("click", this.onWindowClick);
this.setActiveSubMenu(this.rowTitle);
},
// hides submenu when click is detected outside from it
onWindowClick(event) {
const form = this.$refs.content;
if (form != null) {
if (!form.contains(event.target)) {
this.setActiveSubMenu("");
this.setMainMenu(false);
}
return;
}
}, },
}, },
}; };

View File

@ -34,8 +34,6 @@ export const globalStore = defineStore("globalStore", {
draw2dLast: false, draw2dLast: false,
reset: false, reset: false,
canDraw: true, canDraw: true,
mainMenu: false,
activeSubMenu: "",
}; };
}, },
actions: { actions: {
@ -48,20 +46,14 @@ export const globalStore = defineStore("globalStore", {
); );
}, },
toggleDraw1d() { toggleDraw1d() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.draw1d = true; this.draw1d = true;
}, },
toggleDraw2d() { toggleDraw2d() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.toggleStop(); this.toggleStop();
this.canDraw = true; this.canDraw = true;
this.draw2d = true; this.draw2d = true;
}, },
toggleDraw2dLast() { toggleDraw2dLast() {
this.setActiveSubMenu("");
this.setMainMenu(false);
this.toggleStop(); this.toggleStop();
this.canDraw = true; this.canDraw = true;
this.draw2dLast = true; this.draw2dLast = true;
@ -76,12 +68,5 @@ export const globalStore = defineStore("globalStore", {
this.draw2dLast = false; this.draw2dLast = false;
this.canDraw = false; this.canDraw = false;
}, },
setActiveSubMenu(data) {
if (this.activeSubMenu == data) this.activeSubMenu = "";
else this.activeSubMenu = data;
},
setMainMenu(data) {
this.mainMenu = data;
},
}, },
}); });