handle enum selections
This commit is contained in:
parent
380a4a00d9
commit
cd1902bf1b
35
src/main.js
35
src/main.js
|
|
@ -32,6 +32,11 @@ let tools = {
|
||||||
type: "number",
|
type: "number",
|
||||||
// default: 5,
|
// default: 5,
|
||||||
label: "Line Width"
|
label: "Line Width"
|
||||||
|
},
|
||||||
|
"simplifyMode": {
|
||||||
|
type: "enum",
|
||||||
|
options: ["corners", "smooth"], // "auto"],
|
||||||
|
label: "Line Mode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -60,6 +65,7 @@ let context = {
|
||||||
"#FF00FF",
|
"#FF00FF",
|
||||||
],
|
],
|
||||||
lineWidth: 5,
|
lineWidth: 5,
|
||||||
|
simplifyMode: "smooth",
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
|
|
@ -282,7 +288,7 @@ function stage() {
|
||||||
if (context.activeShape) {
|
if (context.activeShape) {
|
||||||
let midpoint = {x: (mouse.x+context.lastMouse.x)/2, y: (mouse.y+context.lastMouse.y)/2}
|
let midpoint = {x: (mouse.x+context.lastMouse.x)/2, y: (mouse.y+context.lastMouse.y)/2}
|
||||||
context.activeShape.addCurve(new Curve(midpoint.x, midpoint.y, midpoint.x, midpoint.y, mouse.x, mouse.y))
|
context.activeShape.addCurve(new Curve(midpoint.x, midpoint.y, midpoint.x, midpoint.y, mouse.x, mouse.y))
|
||||||
context.activeShape.simplify()
|
context.activeShape.simplify(context.simplifyMode)
|
||||||
context.activeShape = undefined
|
context.activeShape = undefined
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -390,14 +396,41 @@ function infopanel() {
|
||||||
span = document.createElement("span")
|
span = document.createElement("span")
|
||||||
span.className = "infopanel-label"
|
span.className = "infopanel-label"
|
||||||
span.innerText = prop.label
|
span.innerText = prop.label
|
||||||
|
switch (prop.type) {
|
||||||
|
case "number":
|
||||||
input = document.createElement("input")
|
input = document.createElement("input")
|
||||||
input.className = "infopanel-input"
|
input.className = "infopanel-input"
|
||||||
|
input.type = "number"
|
||||||
input.value = getProperty(context, property)
|
input.value = getProperty(context, property)
|
||||||
|
break;
|
||||||
|
case "enum":
|
||||||
|
input = document.createElement("select")
|
||||||
|
input.className = "infopanel-input"
|
||||||
|
let optionEl;
|
||||||
|
for (let option of prop.options) {
|
||||||
|
optionEl = document.createElement("option")
|
||||||
|
optionEl.value = option
|
||||||
|
optionEl.innerText = option
|
||||||
|
input.appendChild(optionEl)
|
||||||
|
}
|
||||||
|
input.value = getProperty(context, property)
|
||||||
|
break;
|
||||||
|
}
|
||||||
input.addEventListener("input", () => {
|
input.addEventListener("input", () => {
|
||||||
console.log(input.value)
|
console.log(input.value)
|
||||||
|
switch (prop.type) {
|
||||||
|
case "number":
|
||||||
if (!isNaN(input.value) && input.value > 0) {
|
if (!isNaN(input.value) && input.value > 0) {
|
||||||
setProperty(context, property, input.value)
|
setProperty(context, property, input.value)
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case "enum":
|
||||||
|
if (prop.options.indexOf(input.value) >= 0) {
|
||||||
|
// console.log(input.value)
|
||||||
|
setProperty(context, property, input.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
label.appendChild(span)
|
label.appendChild(span)
|
||||||
label.appendChild(input)
|
label.appendChild(input)
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ button {
|
||||||
background-color: #0f0f0f;
|
background-color: #0f0f0f;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
contain: size;
|
||||||
}
|
}
|
||||||
.horizontal-grid {
|
.horizontal-grid {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue