Add some basic keyboard dialog functionality

This commit is contained in:
Nick Bisby 2019-02-18 16:44:17 -06:00
parent d74e801d41
commit 2d708b9dd9
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
4 changed files with 121 additions and 30 deletions

View File

@ -3,4 +3,91 @@ sub init()
m.top.backgroundURI = ""
m.top.setFocus(true)
m.focused_options = [
m.top.findNode("host"),
m.top.findNode("port")
]
m.focused_index = 0
m.focused_item = m.focused_options[m.focused_index]
focus_node(m.focused_item)
end sub
function onKeyEvent(key as String, press as Boolean) as Boolean
if press then
if (key = "OK") then
show_dialog(m.focused_item.id)
return true
else if (key = "up") then
' Already at the top, ignore
if m.focused_index = 0 then
return true
end if
unfocus_node(m.focused_item)
m.focused_index = m.focused_index - 1
m.focused_item = m.focused_options[m.focused_index]
focus_node(m.focused_item)
return true
else if (key = "down") then
' Already at the bottom, ignore
if m.focused_index = (m.focused_options.count() - 1) then
return true
end if
unfocus_node(m.focused_item)
m.focused_index = m.focused_index + 1
m.focused_item = m.focused_options[m.focused_index]
focus_node(m.focused_item)
return true
end if
end if
return false
end function
sub focus_node(node)
node.textColor = "#ffffff"
node.hintTextColor = "#999999"
end sub
sub unfocus_node(node)
node.textColor = "#777777"
node.hintTextColor = "#555555"
end sub
function onDialogButton()
d = m.top.dialog
button_text = d.buttons[d.buttonSelected]
if button_text = "OK"
' TODO - pick right field
m.focused_item.text = d.text
dismiss_dialog()
return true
else if button_text = "Cancel"
dismiss_dialog()
return false
end if
end function
sub show_dialog(title as String)
dialog = createObject("roSGNode", "KeyboardDialog")
dialog.title = "Enter the " + m.focused_item.id
dialog.buttons = ["OK", "Cancel"]
if m.focused_item.text <> "" then
dialog.text = m.focused_item.text
end if
m.top.dialog = dialog
dialog.observeField("buttonSelected", "onDialogButton")
end sub
sub dismiss_dialog()
m.top.dialog.close = true
end sub

View File

@ -1,21 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="ServerSelection" extends="Scene">
<children>
<Rectangle
id="theRect"
color="#000b35"
width="1920"
height="1080"
opacity=".6"
translation="[0,0]" />
<label text="Connect to Server" translation="[150, 150]" />
<LayoutGroup layoutDirection="vert" itemSpacings="20" translation="[150, 200]">
<LayoutGroup layoutDirection="horiz" itemSpacings="20">
<Label text="Host:" />
<TextEditBox
id="host"
hintText="127.0.0.1 or https://example.com"
hintTextColor="#555555"
textColor="#777777"
width="500"
/>
</LayoutGroup>
<LayoutGroup layoutDirection="horiz" itemSpacings="20">
<Label text="Port:" />
<TextEditBox
id="port"
hintText="8096 or blank"
hintTextColor="#555555"
textColor="#777777"
width="500"
/>
</LayoutGroup>
<Button
id="submit_btn"
text="Submit"
/>
</LayoutGroup>
</children>
<interface>
<field id="hostname" type="string" />
<field id="port" type="string" />
<field id="hostname" type="string" alias="host.text" />
<field id="port" type="string" alias="port.text" />
</interface>
<script type="text/brightscript" uri="pkg:/components/ServerSelect.brs"/>
<script type="text/brightscript" uri="pkg:/components/ServerScene.brs"/>
</component>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="ServerSelection" extends="Scene">
<children>
<label text="Connect to Server" translation="[150, 150]" />
<LayoutGroup layoutDirection="vert" itemSpacings="20" translation="[150, 200]">
<Label text="Host:" />
<Label text="Port:" />
</LayoutGroup>
</children>
<interface>
<field id="hostname" type="string" />
<field id="port" type="string" />
</interface>
<script type="text/brightscript" uri="pkg:/components/ServerScene.brs"/>
</component>

View File

@ -31,7 +31,7 @@ sub Main()
'librow.GetRowListContent()
print 1 + "halt"
print 1 + "halt" ' Mixed types stops the debugger
while(true)
msg = wait(0, m.port)