Skip to content

Commit

Permalink
Merge pull request #402 from georgejecook/controls-group-selectedIndex
Browse files Browse the repository at this point in the history
set selected for passed index control
  • Loading branch information
georgejecook authored Jun 28, 2023
2 parents 4da62e0 + 06c9b4c commit dec41a0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src-ml-test-app/source/debug-screens/ButtonScreen.bs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class ButtonScreen extends mv.BaseScreen
return true
end function

private function onKeyPressOptions() as boolean
m.log.info("options pressed")
m.focusedControl@.setSelectedIndex(m.focusedControl.focusedIndex)
return true
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Lifecycle
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
12 changes: 5 additions & 7 deletions src-ml-test-app/source/debug-screens/ButtonScreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@
"$extends": "mv.Button.default",
"normal.backgroundPoster.blendColor": "~colors.general.light-red",
"focused.backgroundPoster.blendColor": "~colors.general.red",
"selected.backgroundPoster.blendColor": "~colors.general.red",
"normal.label.color": "~colors.general.black",
"focused.label.color": "~colors.general.white",
"selected.label.color": "~colors.general.white"
"selected.label.color": "~colors.general.white",
"selected.backgroundPoster.blendColor": "#33dd33"
},
"blue": {
"$extends": "mv.Button.default",
Expand All @@ -285,15 +285,13 @@
},
"round_white": {
"$extends": "mv.Button.default",
"normal.backgroundPoster.uri": "pkg:/images/backgrounds/background-round-solid-$$RES$$.9.png",
"focused.backgroundPoster.uri": "pkg:/images/backgrounds/background-round-solid-$$RES$$.9.png",
"normal.backgroundPoster.blendColor": "~colors.general.white",
"normal.label.fontKey": "Medium,24",
"focused.backgroundPoster.blendColor": "~colors.general.grey",
"normal.label.color": "~colors.general.black",
"focused.label.color": "~colors.general.white",
"focused.label.fontKey": "MediumBold,24",
"selected.label.color": "~colors.general.black",
"selected.label.color": "~colors.general.red",
"selected.label.fontKey": "MediumBold,32",
"selected.backgroundPoster.blendColor": "#33dd33",
"normal.label.translation": [10, 0],
"normal.iconPoster.translation": [10, 0]
},
Expand Down
1 change: 0 additions & 1 deletion src/source/core/Core.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ namespace tests
m.assertEqual(value, node2)
end function

@only
@it("gets indexed child nodes ")
function _()
a = {
Expand Down
8 changes: 4 additions & 4 deletions src/source/core/Request.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,15 @@ namespace tests
@describe("logAsCurl")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@ignore("fixme- this used to work")
@it("logs the request in Curl format")
@params("post", "url4", "", "{d1:1,d2:2}", "curl -X POST -d {d1:1,d2:2} url4")
@params("post", "url4", "", "{d1:1,d2:2}", "curl -X POST -d '{d1:1,d2:2}' url4")
@params("delete", "url", invalid, invalid, "curl -X DELETE url")
@params("get", "url", invalid, "id=1", "curl -X GET -d id=1 url")
@params("put", "url4", { h1: "h1", h2: "h2" }, "{d1:1,d2:2}", "curl -X PUT -H'h1:h1' -H'h2:h2' -d {d1:1,d2:2} url4")
@params("get", "url", invalid, "id=1", "curl -X GET -d 'id=1' url")
@params("put", "url4", { h1: "h1", h2: "h2" }, "{d1:1,d2:2}", "curl -X PUT -H'h1:h1' -H'h2:h2' -d '{d1:1,d2:2}' url4")

function _(method, url, headers, data, expected)
m.request.isLogAsCurlEnabled = true

m.expectCalled(m.request.log.info(expected))

m.request.logAsCurl(method, url, headers, data)
Expand Down
7 changes: 7 additions & 0 deletions src/source/view/controls/ControlsGroup.bs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ namespace mv.controls
return m._focusedControl
end function

function setSelectedIndex(index as integer)
control = m.visibleChildren[index]
if control <> invalid and control.isDisabled <> true
control.isSelected = true
end if
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Callbacks
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
24 changes: 24 additions & 0 deletions src/source/view/controls/ControlsGroup.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,29 @@ namespace tests
m.assertEqual(m.control.getIsFocusedControl(control), isSameNode)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("setSelectedIndex")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("doesn't do anything if index is out of bounds")
@params(-1)
@params(1)
@params(2)
function _(index)
control = { "id": "c1" }
m.control.visibleChildren = [control]
m.control.setSelectedIndex(index)
end function

@it("sets isSelected to true on the selected control if control is found in original children and not disabled")
@params(false, true)
@params(true, false)
function _(disabled, expected)
control = { "id": "c1", isSelected: false, isDisabled: disabled }
m.control.visibleChildren = [control]
m.control.setSelectedIndex(0)
m.assertEqual(control.isSelected, expected)
end function

end class
end namespace

0 comments on commit dec41a0

Please sign in to comment.