Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #20

Merged
merged 8 commits into from
Jan 8, 2021
Merged

Beta #20

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
redo ui buttons when object state changes
  • Loading branch information
sjbrown committed Jan 5, 2021
commit 0105a033ae77ce7ece6e97f8d6afedc991255d77
6 changes: 6 additions & 0 deletions src/svg/v1/tray_explode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const ui = {
let boundHandler = (evt) => {
userlog.add({ user: myClientId, title: title, event: evt, el: svgEl })
menuItem.handler.bind(svgEl)(evt)
ui.updateButtons() // state-changes due to handler affect disabled state
}
eventHandlers[menuItem.eventName] = boundHandler
if (menuItem.otherEvents) {
Expand Down Expand Up @@ -364,20 +365,20 @@ const ui = {
})
ui.setHeaderText('Select dice by clicking on them; roll by double-clicking; zoom with Ctrl-wheel')

function addNewButton(title) {
function addNewButton(title, uiLabel) {
let btn = template.content.firstElementChild.cloneNode(true)
btn.id = 'button-' + title
btn.dataset.eventTitle = title
btn.innerText = title
btn.innerText = uiLabel
btn.classList.add('cloned-button')
buttons[title] = {
btn: btn,
clickFns: [],
}
}
function attachButton(title, svgNode, handler, applicableFn) {
function attachButton(title, uiLabel, svgNode, handler, applicableFn) {
if (buttons[title] === undefined) {
addNewButton(title)
addNewButton(title, uiLabel)
}
if (!applicableFn(svgNode)) {
buttons[title].btn.disabled = 'disabled'
Expand All @@ -396,7 +397,14 @@ const ui = {

Object.keys(actionMenu).map((title) => {
let handler = allHandlers[actionMenu[title].eventName]
attachButton(title, focusedSVG, handler, actionMenu[title].applicable)
let uiLabel = (
actionMenu[title].uiLabel
?
actionMenu[title].uiLabel(focusedSVG)
:
title
)
attachButton(title, uiLabel, focusedSVG, handler, actionMenu[title].applicable)
})

ui.updateQuickButton(focusedSVG)
Expand All @@ -407,9 +415,9 @@ const ui = {
let handler = allHandlers[actionMenu[title].eventName]

if (i === 1) { // the first one sets up the 'buttons' object
attachButton(title, focusedSVG, handler, actionMenu[title].applicable)
attachButton(title, title, focusedSVG, handler, actionMenu[title].applicable)
} else if (title in buttons) {
attachButton(title, focusedSVG, handler, actionMenu[title].applicable)
attachButton(title, title, focusedSVG, handler, actionMenu[title].applicable)
}
})
// Remove any 'verbs' that don't pertain to ALL focused nodes
Expand All @@ -425,6 +433,7 @@ const ui = {
if (focusedNodes.length > 0 && selectBoxes.length > 0) {
let sBoxNode = selectBoxes[0]
attachButton(
'Delete',
'Delete',
sBoxNode,
(evt) => {
Expand Down