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

reuse observer functions for @debounced callback handlers #367

Open
georgejecook opened this issue May 3, 2023 · 0 comments
Open

reuse observer functions for @debounced callback handlers #367

georgejecook opened this issue May 3, 2023 · 0 comments

Comments

@georgejecook
Copy link
Owner

georgejecook commented May 3, 2023

THIS IS BETTER

function m_wireUpObservers()
m.top.observeField("styleKey", "on_styleKey")
m.top.observeField("text", "on_text")
m.top.observeField("size", "on_size")
for each field in ["isDisabled", "showBackground", "textStyle", "focusedTextStyle", "footprintTextStyle", "disabledTextStyle", "backgroundUri", "focusedBackgroundUri", "footprintBackgroundUri", "backgroundColor", "focusedBackgroundColor", "footprintBackgroundColor", "textOffset", "textSize", "backgroundPosterSize", "backgroundPosterOffset", "disabledBackgroundColor", "focusState", "textAlign", "iconStyle", "iconUri"
]
m.top.observeField(field, "on_disabledBackgroundColor")
end for
m.top.observeField("__debugM", "on___debugM")
end function

THAN






function init()
    m.top.selected = false
    m.top.enabled = true
    m.top.styleKey = "controls.Button.normal"
    m.top.text = invalid
    m.top.size = [
        120
        60
    ]
    m.top.isDisabled = false
    m.top.showBackground = true
    m.top.textStyle = {
        fontKey: "Medium,30"
        color: "#000000"
    }
    m.top.focusedTextStyle = {
        fontKey: "MediumBold,30"
        color: "#000000"
    }
    m.top.footprintTextStyle = {
        fontKey: "MediumBold,30"
        color: "#000000"
    }
    m.top.disabledTextStyle = {
        fontKey: "Medium,30"
        color: "#aaaaaa"
    }
    m.top.backgroundUri = "pkg:/images/controls/button-bg.9.png"
    m.top.focusedBackgroundUri = ""
    m.top.footprintBackgroundUri = ""
    m.top.backgroundColor = "#aaaaaa"
    m.top.focusedBackgroundColor = "#ffffff"
    m.top.footprintBackgroundColor = "#ffffff"
    m.top.textOffset = [
        0
        0
    ]
    m.top.textSize = [
        0
        0
    ]
    m.top.backgroundPosterSize = [
        0
        0
    ]
    m.top.backgroundPosterOffset = [
        0
        0
    ]
    m.top.disabledBackgroundColor = "#ffffff"
    m.top.focusState = "none"
    m.top.textAlign = {
        horizAlign: "center"
        vertAlign: "center"
    }
    m.top.iconStyle = invalid
    m.top.iconUri = invalid
    m.top.isHandlingSelection = true
    m.top.isUsingFootprint = false
    m.top.__debugM = invalid
    m.top.state = invalid
    instance = __nba_controls_Button_builder()
    instance.delete("top")
    instance.delete("global")
    top = m.top
    m.append(instance)
    m.__isVMCreated = true
    m.new()
    m.top = top
    m_wireUpObservers()
    m.pendingCallbacks = {}
end function

function on_styleKey(event)
    m.onStyleKeyChange(event.getData())
end function

function on_text(event)
    addCallback("redraw")
end function

function on_size(event)
    addCallback("redraw")
end function

function on_isDisabled(event)
    addCallback("redraw")
end function

function on_showBackground(event)
    addCallback("redraw")
end function

function on_textStyle(event)
    addCallback("redraw")
end function

function on_focusedTextStyle(event)
    addCallback("redraw")
end function

function on_footprintTextStyle(event)
    addCallback("redraw")
end function

function on_disabledTextStyle(event)
    addCallback("redraw")
end function

function on_backgroundUri(event)
    addCallback("redraw")
end function

function on_focusedBackgroundUri(event)
    addCallback("redraw")
end function

function on_footprintBackgroundUri(event)
    addCallback("redraw")
end function

function on_backgroundColor(event)
    addCallback("redraw")
end function

function on_focusedBackgroundColor(event)
    addCallback("redraw")
end function

function on_footprintBackgroundColor(event)
    addCallback("redraw")
end function

function on_textOffset(event)
    addCallback("redraw")
end function

function on_textSize(event)
    addCallback("redraw")
end function

function on_backgroundPosterSize(event)
    addCallback("redraw")
end function

function on_backgroundPosterOffset(event)
    addCallback("redraw")
end function

function on_disabledBackgroundColor(event)
    addCallback("redraw")
end function

function on_focusState(event)
    m.redraw()
end function

function on_textAlign(event)
    m.redraw()
end function

function on_iconStyle(event)
    m.redraw()
end function

function on_iconUri(event)
    m.redraw()
end function

function on___debugM(event)
    m.onDebugMChange()
end function

function m_wireUpObservers()
    m.top.observeField("styleKey", "on_styleKey")
    m.top.observeField("text", "on_text")
    m.top.observeField("size", "on_size")
    m.top.observeField("isDisabled", "on_isDisabled")
    m.top.observeField("showBackground", "on_showBackground")
    m.top.observeField("textStyle", "on_textStyle")
    m.top.observeField("focusedTextStyle", "on_focusedTextStyle")
    m.top.observeField("footprintTextStyle", "on_footprintTextStyle")
    m.top.observeField("disabledTextStyle", "on_disabledTextStyle")
    m.top.observeField("backgroundUri", "on_backgroundUri")
    m.top.observeField("focusedBackgroundUri", "on_focusedBackgroundUri")
    m.top.observeField("footprintBackgroundUri", "on_footprintBackgroundUri")
    m.top.observeField("backgroundColor", "on_backgroundColor")
    m.top.observeField("focusedBackgroundColor", "on_focusedBackgroundColor")
    m.top.observeField("footprintBackgroundColor", "on_footprintBackgroundColor")
    m.top.observeField("textOffset", "on_textOffset")
    m.top.observeField("textSize", "on_textSize")
    m.top.observeField("backgroundPosterSize", "on_backgroundPosterSize")
    m.top.observeField("backgroundPosterOffset", "on_backgroundPosterOffset")
    m.top.observeField("disabledBackgroundColor", "on_disabledBackgroundColor")
    m.top.observeField("focusState", "on_focusState")
    m.top.observeField("textAlign", "on_textAlign")
    m.top.observeField("iconStyle", "on_iconStyle")
    m.top.observeField("iconUri", "on_iconUri")
    m.top.observeField("__debugM", "on___debugM")
end function

function addCallback(funcName)
    m.pendingCallbacks[funcName] = true
    if (m.pendingCallbacks.count() = 1)
        mc_tasks_observeNodeField(m.global.tick, "fire", onTick, "none", true)
    end if
end function

function onTick()
    for each funcName in m.pendingCallbacks
        m[funcName]()
    end for
    m.pendingCallbacks = {}
end function

function __m_setTopField(field, value)
    if m.top.doesExist(field)
        m.top[field] = value
    end if
    return value
end function

function onStyleKeyChange(key = invalid)
    return m.onStyleKeyChange(key)
end function

function onKeyPressOK(dummy = invalid)
    return m.onKeyPressOK()
end function

function onDebugMChange(dummy = invalid)
    return m.onDebugMChange()
end function

function onSyncMChange(dummy = invalid)
    return m.onSyncMChange()
end function

function getInstance(name = invalid, path = invalid, defaultValue = invalid)
    return m.getInstance(name, path, defaultValue)
end function

function _apply(funcName = invalid, args = invalid, warnIfNoFunction = true)
    return m._apply(funcName, args, warnIfNoFunction)
end function'//# sourceMappingURL=./nba_Button.bs.map`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant