Engine prototype #13

Merged
glen merged 133 commits from engine-proto into main 2024-10-21 03:18:48 +00:00
Showing only changes of commit 5ea32ac53c - Show all commits

View File

@ -57,8 +57,9 @@ mutable struct ConstructionViewer
#control-panel > div { #control-panel > div {
margin-top: 5px; margin-top: 5px;
padding: 2px; padding: 4px;
border-radius: 5px; border-radius: 5px;
border: solid;
font-family: monospace; font-family: monospace;
} }
""") """)
@ -81,13 +82,13 @@ mutable struct ConstructionViewer
// declare handles for the controls // declare handles for the controls
var controlPanel; var controlPanel;
var visControls; var visToggles;
// create scene function // create scene function
function scene() { function scene() {
commands = []; commands = [];
for (let n = 0; n < elements.length; ++n) { for (let n = 0; n < elements.length; ++n) {
if (visControls[n].checked) { if (visToggles[n].checked) {
commands.push(palette[n], elements[n]); commands.push(palette[n], elements[n]);
} }
} }
@ -142,38 +143,30 @@ function display!(viewer::ConstructionViewer, elements::Matrix)
palette_packed = [RGB24(c).color for c in palette] palette_packed = [RGB24(c).color for c in palette]
@js viewer.win palette = $palette_packed @js viewer.win palette = $palette_packed
# generate visibility controls # create visibility toggles
@js viewer.win begin @js viewer.win begin
controlPanel.replaceChildren() controlPanel.replaceChildren()
visControls = [] visToggles = []
end end
for n in 1:size(elements, 2) for (elt, c) in zip(eachcol(elements), palette)
index_str = string(n) vec_str = join(map(t -> @sprintf("%.3f", t), elt), ", ")
vec_str = join(map(t -> @sprintf("%.3f", t), elements[:, n]), ", ") color_str = "#$(hex(c))"
style_str = "background-color: #$(hex(palette[n]));" style_str = "background-color: $color_str; border-color: $color_str;"
println(style_str)
@js viewer.win begin @js viewer.win begin
# create container @var toggle = document.createElement(:div)
@var container = document.createElement(:div) toggle.setAttribute(:style, $style_str)
container.setAttribute(:style, $style_str) toggle.checked = true
toggle.addEventListener(
# create checkbox "click",
@var checkbox = document.createElement(:input) () -> begin
checkbox.setAttribute(:type, "checkbox") toggle.checked = !toggle.checked
checkbox.setAttribute(:id, $index_str) toggle.style.backgroundColor = toggle.checked ? $color_str : "inherit";
checkbox.setAttribute(:checked, "true") updateView()
checkbox.addEventListener(:input, updateView) end
visControls.push(checkbox) )
container.appendChild(checkbox) toggle.appendChild(document.createTextNode($vec_str))
visToggles.push(toggle);
# create label controlPanel.appendChild(toggle);
@var label = document.createElement(:label);
label.setAttribute(:for, $index_str)
label.appendChild(document.createTextNode($vec_str))
container.appendChild(label)
# add the control to the control panel
controlPanel.appendChild(container)
end end
end end