Skip to content

Commit

Permalink
Merge pull request georgejecook#423 from georgejecook/feat/better-cle…
Browse files Browse the repository at this point in the history
…anup

Feat/better cleanup
  • Loading branch information
georgejecook authored Jun 5, 2024
2 parents c977cc9 + 8cab52b commit 8858fe0
Show file tree
Hide file tree
Showing 51 changed files with 2,909 additions and 761 deletions.
34 changes: 34 additions & 0 deletions .vscode/.maestro-templates/TemplateClass.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "pkg:/source/lib/BaseClass.bs"
namespace $NAMESPACE$
class $CLASSNAME$ extends gs.lib.BaseClass

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Public Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Initialization
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function new()
super("$CLASSNAME$")
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Public Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Overridden Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

end class
end namespace
26 changes: 26 additions & 0 deletions .vscode/.maestro-templates/TemplateClass.spec.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "pkg:/source/tests/BaseTestSuite.spec.bs"
import "pkg:/$SOURCE_PKG_PATH$.bs"


namespace tests
@suite("$CLASSNAME$ tests")
class $CLASSNAME$Tests extends tests.BaseTestSuite

private task

protected override function beforeEach()
super.beforeEach()
m.task = new $NAMESPACE$.$CLASSNAME$()
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("constructor")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("ensures dependencies are correctly set")
function _()
m.fail("implement me")
end function

end class
end namespace
120 changes: 120 additions & 0 deletions .vscode/.maestro-templates/TemplateCustomCell.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import "pkg:/source/roku_modules/maestro/ml/cells/BaseCell.brs"

namespace $NAMESPACE$

@observersWaitInitialize
@node("$CLASSNAME$", "ml_BaseCell")
class $CLASSNAME$ extends ml.BaseCell

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Public Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Views
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private poster as mc.types.node
private group as mc.types.node
private label as mc.types.node

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private styles as mc.types.assocarray
private scale = 1.0

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Overridden Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

protected override function createViews() as void
bundle = m.global.styleManager@.loadBundle("pkg:/source/list/cells/CustomSimpleCell.bundle")
m.styles = bundle.styles
m.createViewsFromStyleJson(bundle.views)
end function

protected override function onContentChange(content as mc.types.node)
m.label.text = asString(content.json.title)
m.poster.uri = asString(content.json.posterUrl)
m.label.visible = true
m.setScale(1, false)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private function toggleHighlighted(highlighted as boolean)
if highlighted
m.updateViewsWithStyleJson(m.styles.normal)
else
m.updateViewsWithStyleJson(m.styles.highlighted)
end if
end function

private function setScale(fraction as float, isGaining as boolean) as void
if isGaining
m.scale = mc.clamp((fraction + 0.9), 0.85, 1.1)
else
m.scale = mc.clamp((1 - fraction) + 0.3, 0.85, 1.1)
end if
m.group.scale = [m.scale, m.scale]
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Overridden Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

protected override function onShowWithContent(content as mc.types.node)
m.toggleHighlighted(true)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Lifecycle Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

protected override function onHide()
m.toggleHighlighted(true)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Cell Delegate Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private function onScrollingChange(isScrolling as boolean, isLong as boolean)
' ? "SC: isScrolling " ; " " ; isScrolling ; " IL " ; isLong
if not isScrolling
m.label.visible = true
end if
end function

private function onScrollingUpdate(startIndex as integer, currentIndex as integer)
' ? "SC: isScrolling UPDATE " ; " " ; startIndex ; " SI " ; currentIndex
textVisible = abs(startIndex - currentIndex) < 4
m.label.visible = textVisible
end function


private function onDidGainFocus(event as ml.ListEvent)
m.setScale(1, true)
m.toggleHighlighted(false)
end function

private function onDidLoseFocus(event as ml.ListEvent)
m.setScale(1, false)
m.toggleHighlighted(true)
end function

private function onGainingFocus(event as ml.ListEvent)
m.setScale(event.fraction, true)
m.toggleHighlighted(false)
end function

private function onLosingFocus(event as ml.ListEvent)
m.setScale(event.fraction, false)
m.toggleHighlighted(true)
end function
end class
end namespace
56 changes: 56 additions & 0 deletions .vscode/.maestro-templates/TemplateCustomCell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"views": [
{
"id": "backgroundRectangle",
"_type": "mv_Rectangle",
"size": [
1920,
1080
],
"color": "~theme.colors.black"
},
{
"id": "title",
"_type": "mv_Label",
"size": [
1080,
100
],
"translation": [
0,
400
],
"horizAlign": "left",
"vertAlign": "center",
"text": "This is a maestro view"
},
{
"id": "buttonsGroup",
"_type": "mv_ControlsGroup",
"_initializeAfterCreatingChildren": true,
"translation": [
96,
928
],
"itemSpacings": [
24
],
"layoutMode": "horiz",
"keyDirection": "horiz",
"_children": [
{
"id": "firstButton",
"_type": "mv_Button",
"styleKey": "buttons.primary",
"text": "Do something",
"autoSize": true,
"iconPosition": "",
"size": [
316,
88
]
}
]
}
]
}
45 changes: 45 additions & 0 deletions .vscode/.maestro-templates/TemplateCustomCell.spec.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "pkg:/source/rooibos/BaseTestSuite.bs"
import "pkg:/$SOURCE_PKG_PATH$.bs"

namespace tests
@suite("$CLASSNAME$ tests")
class $CLASSNAME$Tests extends rooibos.BaseTestSuite

private view

protected override function beforeEach()
super.beforeEach()
m.view = m.createNodeClass($NAMESPACE$.$CLASSNAME$)
m.createMockViews(m.view, "pkg:/$SOURCE_PKG_PATH$/$CLASSNAME$.json")
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("initialize")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("creates views")
function _()
m.expectCalled(m.view.createViews())
m.view.initialize()
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("createViews")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("creates views from bundle, and sets default view")
function _()
bundle = {
"id": "bundle"
"views": ["views"]
}
m.view.styleManager = { "id": "styleManager" }

m.expectCalled(m.view.styleManager@.loadBundle("pkg:/$SOURCE_PKG_PATH$/$CLASSNAME$.json"), bundle)
m.view.createViews()

m.assertEqual(m.view.focusedControl, m.view.focusedControl)
end function

end class
end namespace
98 changes: 98 additions & 0 deletions .vscode/.maestro-templates/TemplateCustomRow.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import "pkg:/source/roku_modules/maestro/ml/ListMixin.brs"
import "pkg:/source/roku_modules/maestro/ml/BaseRow.brs"
import "pkg:/source/roku_modules/maestro/ml/RowItemScroller.brs"
import "pkg:/source/roku_modules/maestro/ml/RowItemViewManager.brs"
import "pkg:/source/roku_modules/maestro/ml/ItemFocusManager.brs"

namespace $NAMESPACE$

@observersWaitInitialize
@node("$CLASSNAME$", "ml_BaseRow")
class $CLASSNAME$ extends ml.BaseRow

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Public Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Views
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private menu as mc.types.node
private titleLabel as mc.types.node

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Fields
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Initialization
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function new()
super("")
end function

protected override function initialize()
super.initialize()
m.createViews()
end function

private function createViews()
bundle = m.styleManager@.loadBundle("pkg:/$SOURCE_PKG_PATH$.json")
m.createViewsFromStyleJson(bundle.views, m.top)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Public Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Overridden Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

protected override function onContentUpdate(content as mc.types.node)
m.log.info("ROW CHANGE")
super.onContentUpdate(content)
m.titleLabel.text = asString(content.rowText)
m.observe(m.menu.selectedIndex, m.onMenuItemChange)
end function

public override function getFocusIndicatorConfig(cellInfo as ml.CellInfo, direction as integer, isFloatingFocus as boolean, isFromListScroll = false as boolean) as ml.FocusIndicatorConfig
return ml.createFocusIndicatorConfig(m.top, invalid, direction, -1, true)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Callbacks
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private function onMenuItemChange(index as integer)
m.log.info("selected tab item", index)
if index = 0
m.sendRowData({ offset: -1 })
else if index = 1
m.sendRowData({ offset: 1 })
end if
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Private Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Key Presses
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ Row Delegate Methods
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

private function onDidGainFocus(event as ml.ListEvent)
' ? "CR: onDidGainFocus " ; " " ; direction
if m.owner.isFocused or m.owner.isChildFocused
m.setFocus(m.menu)
end if
end function

end class
end namespace
Loading

0 comments on commit 8858fe0

Please sign in to comment.