Number control (#282)
This commit is contained in:
1 parent
f3aeb58b38
commit
74082f406a
9 files changed
+203
-5
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/MathUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [10]
|
||||
|
||||
m.minusButton = m.top.findNode("MinusButton")
|
||||
m.numberButton = m.top.findNode("NumberButton")
|
||||
m.plusButton = m.top.findNode("PlusButton")
|
||||
|
||||
m.minusButton.observeFieldScoped("buttonSelected", FuncName(OnMinusSelected))
|
||||
m.plusButton.observeFieldScoped("buttonSelected", FuncName(OnPlusSelected))
|
||||
|
||||
SetNavigation(m.minusButton, "right", m.numberButton)
|
||||
SetNavigation(m.numberButton, "left", m.minusButton)
|
||||
SetNavigation(m.numberButton, "right", m.plusButton)
|
||||
SetNavigation(m.plusButton, "left", m.numberButton)
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
if m.preferences <> invalid and m.key <> invalid
|
||||
m.preferences.unobserveFieldScoped(m.key)
|
||||
end if
|
||||
|
||||
m.preferences = preferences
|
||||
m.key = key
|
||||
|
||||
if preferences <> invalid and key <> invalid
|
||||
preferences.observeFieldScoped(key, FuncName(OnPreferenceChange))
|
||||
OnPreferenceChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPreferenceChange()
|
||||
m.top.value = MathUtils.Max(MathUtils.Min(m.preferences[m.key], m.top.max), m.top.min)
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
m.numberButton.text = `${m.top.value}`
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.numberButton, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnMinusSelected()
|
||||
m.top.value = MathUtils.Max(m.top.value - 1, m.top.min)
|
||||
end function
|
||||
|
||||
function OnPlusSelected()
|
||||
m.top.value = MathUtils.Min(m.top.value + 1, m.top.max)
|
||||
end function
|
||||
@@ -0,0 +1,44 @@
|
||||
<component name="NumberControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="min" type="integer" value="-999999" />
|
||||
<field id="max" type="integer" value="999999" />
|
||||
<field id="value" type="integer" onChange="OnValueChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<LayoutGroup layoutDirection="horiz">
|
||||
<Button
|
||||
id="MinusButton"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
minWidth="64"
|
||||
maxWidth="64"
|
||||
showFocusFootprint="true"
|
||||
text="-" />
|
||||
<Button
|
||||
id="NumberButton"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
minWidth="150"
|
||||
showFocusFootprint="true"
|
||||
text="0" />
|
||||
<Button
|
||||
id="PlusButton"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
minWidth="64"
|
||||
maxWidth="64"
|
||||
showFocusFootprint="true"
|
||||
text="+" />
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
</component>
|
||||
@@ -1,6 +1,6 @@
|
||||
<component name="SettingCategory" extends="Button">
|
||||
<interface>
|
||||
<field id="padding" type="integer" value="10" onChange="Resize" />
|
||||
<field id="padding" type="integer" value="15" onChange="Resize" />
|
||||
<field id="minimumWidth" type="integer" value="280" onChange="Resize" />
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" onChange="Resize" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" onChange="Resize" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Navigation/ScrollTo.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
@@ -9,9 +10,9 @@ function Init()
|
||||
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
|
||||
m.viewport = {
|
||||
x: 150
|
||||
y: 96
|
||||
y: 50
|
||||
width: 1920
|
||||
height: 550
|
||||
height: 620
|
||||
}
|
||||
end function
|
||||
|
||||
@@ -126,6 +127,8 @@ function CreateControl(item as object, container as object, startX as integer, s
|
||||
control = CreateRadioControl(item, container)
|
||||
else if item.type = "string"
|
||||
control = CreateStringControl(item, container)
|
||||
else if item.type = "number"
|
||||
control = CreateNumberComponent(item, container)
|
||||
else if item.rokuComponent <> invalid
|
||||
control = CreateRokuComponent(item, container)
|
||||
end if
|
||||
@@ -169,6 +172,19 @@ function CreateStringControl(item as object, container as object) as object
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateNumberComponent(item as object, container as object) as object
|
||||
node = container.createChild("NumberControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
if IsInt(item.min)
|
||||
node.min = item.min
|
||||
end if
|
||||
if IsInt(item.max)
|
||||
node.max = item.max
|
||||
end if
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateRokuComponent(item as object, container as object) as object
|
||||
node = container.createChild(item.rokuComponent)
|
||||
if node.hasField("displayText")
|
||||
|
||||
@@ -5,6 +5,7 @@ function Init()
|
||||
m.typeMapping = {
|
||||
"boolean": "boolean"
|
||||
"string": "string"
|
||||
"number": "integer"
|
||||
"radio": "string"
|
||||
"array": "array"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<component name="Preferences" extends="Node">
|
||||
<interface>
|
||||
<!--
|
||||
The version of the preferences model. This is used to determine if the
|
||||
user prefs saved need to be migrated. If the version is less than the
|
||||
current version, a migration is needed.
|
||||
-->
|
||||
<field id="__version" type="integer" value="1" />
|
||||
<field id="prefsModel" type="array" />
|
||||
<field id="preferenceFields" type="assocarray" />
|
||||
|
||||
Reference in new issue
Block a user