-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/dial-cast-poc
- Loading branch information
Showing
9 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
playlet-lib/src/components/Screens/SettingsScreen/NumberControl.bs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
44 changes: 44 additions & 0 deletions
44
playlet-lib/src/components/Screens/SettingsScreen/NumberControl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
2 changes: 1 addition & 1 deletion
2
playlet-lib/src/components/Screens/SettingsScreen/SettingCategory.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
playlet-lib/src/components/Services/Preferences/Preferences.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
playlet-web/src/lib/Screens/Settings/SettingControls/NumberControl.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script lang="ts"> | ||
import { PlayletApi } from "lib/Api/PlayletApi"; | ||
import { userPreferencesStore } from "lib/Stores"; | ||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"]; | ||
export let displayText: string = ""; | ||
export let key: string = ""; | ||
export let description: string = ""; | ||
export let level: number = 0; | ||
export let min: number = -999999; | ||
export let max: number = 999999; | ||
let value; | ||
userPreferencesStore.subscribe((userPreferences) => { | ||
value = userPreferences[key]; | ||
}); | ||
async function handleChange() { | ||
if (key !== "") { | ||
await PlayletApi.saveUserPreference(key, value); | ||
} | ||
} | ||
</script> | ||
|
||
<div class="form-control m-5"> | ||
<label class="label p-0 cursor-pointer"> | ||
<div class="label-text {textSizes[level]}">{displayText}</div> | ||
<div class="join mt-2 mb-2"> | ||
<button | ||
class="join-item btn btn-sm btn-primary" | ||
on:click={() => { | ||
value = Math.max(min, value - 1); | ||
handleChange(); | ||
}} | ||
> | ||
- | ||
</button> | ||
<input | ||
class="join-item input input-bordered input-sm" | ||
type="number" | ||
name={key} | ||
{min} | ||
{max} | ||
bind:value | ||
on:change={handleChange} | ||
/> | ||
<button | ||
class="join-item btn btn-sm btn-primary" | ||
on:click={() => { | ||
value = Math.min(max, value + 1); | ||
handleChange(); | ||
}} | ||
> | ||
+ | ||
</button> | ||
</div> | ||
</label> | ||
<div class="text-xs text-gray-500">{@html description}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters