Dev player rewrite (#883)
This commit is contained in:
1 parent
8c11272b92
commit
1ba454cdab
80 files changed
+8405
-921
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
' Trackbar track spans x=68..1212: right cluster right-aligns to 1212, center cluster centers on 640.
|
||||
const ROW_Y = 560
|
||||
const BUTTON_WIDTH = 42
|
||||
const BUTTON_SPACING = 20
|
||||
const SCREEN_CENTER_X = 640
|
||||
const TRACKBAR_RIGHT_X = 1212
|
||||
|
||||
function Init()
|
||||
' Focus order MUST match PlayerCoordinatorLogic.PlayerButton (playPause=0, minimize=1).
|
||||
m.buttons = [
|
||||
m.top.findNode("PlayPauseButton")
|
||||
m.top.findNode("MinimizeButton")
|
||||
]
|
||||
m.centerCluster = m.top.findNode("CenterCluster")
|
||||
m.rightCluster = m.top.findNode("RightCluster")
|
||||
LayoutClusters()
|
||||
m.top.buttonCount = m.buttons.Count() ' coordinator reads this to clamp focus
|
||||
|
||||
for each field in ["transportMode", "rowFocused", "focusedIndex", "playing"]
|
||||
m.top.ObserveField(field, FuncName(Repaint))
|
||||
end for
|
||||
m.top.ObserveField("nudge", FuncName(OnNudge))
|
||||
Repaint()
|
||||
end function
|
||||
|
||||
' Forward the nudge to the focused button (an out-of-range focusedIndex indexes to invalid -> no-op).
|
||||
function OnNudge() as void
|
||||
button = m.buttons[m.top.focusedIndex]
|
||||
if button <> invalid
|
||||
button.nudge = true
|
||||
end if
|
||||
end function
|
||||
|
||||
' Position the buttons inside each cluster and the clusters on screen, all from child count, so adding a
|
||||
' button auto-positions without hardcoded offsets.
|
||||
function LayoutClusters() as void
|
||||
LayoutButtons(m.centerCluster)
|
||||
LayoutButtons(m.rightCluster)
|
||||
m.centerCluster.translation = [SCREEN_CENTER_X - ClusterWidth(m.centerCluster) / 2, ROW_Y]
|
||||
m.rightCluster.translation = [TRACKBAR_RIGHT_X - ClusterWidth(m.rightCluster), ROW_Y]
|
||||
end function
|
||||
|
||||
function LayoutButtons(cluster as object) as void
|
||||
for i = 0 to cluster.getChildCount() - 1
|
||||
cluster.getChild(i).translation = [i * (BUTTON_WIDTH + BUTTON_SPACING), 0]
|
||||
end for
|
||||
end function
|
||||
|
||||
function ClusterWidth(cluster as object) as integer
|
||||
n = cluster.getChildCount()
|
||||
if n <= 0
|
||||
return 0
|
||||
end if
|
||||
return n * BUTTON_WIDTH + (n - 1) * BUTTON_SPACING
|
||||
end function
|
||||
|
||||
function Repaint() as void
|
||||
' Hide the row while a transport is active so it's out of the way during seeking. Chrome show/hide
|
||||
' fades the parent group, so visible=true with a hidden parent stays unpainted.
|
||||
m.top.visible = (m.top.transportMode = TransportController.Mode.Idle)
|
||||
|
||||
m.buttons[0].toggleState = not m.top.playing ' toggleState false = play icon, true = pause icon
|
||||
|
||||
for i = 0 to m.buttons.Count() - 1
|
||||
m.buttons[i].focused = m.top.rowFocused and i = m.top.focusedIndex
|
||||
end for
|
||||
end function
|
||||
@@ -0,0 +1,85 @@
|
||||
' ButtonRow @SGNode suite — instantiates just the row, sets its scalar input fields, and asserts the derived
|
||||
' visibility + the virtual-focus highlight on the child buttons (no coordinator, no Video node).
|
||||
|
||||
namespace Tests
|
||||
|
||||
@SGNode("ButtonRow")
|
||||
@suite
|
||||
class ButtonRowTests extends Rooibos.BaseTestSuite
|
||||
|
||||
protected override function beforeEach()
|
||||
m.top.transportMode = TransportController.Mode.Idle
|
||||
m.top.rowFocused = false
|
||||
m.top.focusedIndex = 0
|
||||
m.top.playing = true
|
||||
end function
|
||||
|
||||
@describe("visibility + layout")
|
||||
|
||||
@it("visible at idle (the chrome group's opacity fade does the chrome-gating)")
|
||||
function _()
|
||||
m.top.transportMode = TransportController.Mode.Idle
|
||||
m.assertTrue(m.top.visible)
|
||||
end function
|
||||
|
||||
@it("hidden during a transport (gets out of the way of seeking)")
|
||||
function _()
|
||||
m.top.transportMode = TransportController.Mode.Scrub
|
||||
m.assertFalse(m.top.visible)
|
||||
end function
|
||||
|
||||
@it("exposes its button count and auto-positions the clusters (centered + right-aligned)")
|
||||
function _()
|
||||
m.assertEqual(m.top.buttonCount, 2)
|
||||
' one 42px button per cluster: centered on 640 -> x=619; right-aligned to 1212 -> x=1170. Pins the
|
||||
' ClusterWidth math so a drift in BUTTON_WIDTH/itemSpacings can't silently de-center.
|
||||
m.assertEqual(m.top.findNode("CenterCluster").translation[0], 619.0)
|
||||
m.assertEqual(m.top.findNode("RightCluster").translation[0], 1170.0)
|
||||
end function
|
||||
|
||||
@describe("virtual-focus highlight")
|
||||
|
||||
@it("no button is focused until the row holds focus")
|
||||
function _()
|
||||
m.top.rowFocused = false
|
||||
m.assertFalse(m.top.findNode("PlayPauseButton").focused)
|
||||
m.assertFalse(m.top.findNode("MinimizeButton").focused)
|
||||
end function
|
||||
|
||||
@it("the focused button follows focusedIndex while the row holds focus")
|
||||
function _()
|
||||
m.top.rowFocused = true
|
||||
m.top.focusedIndex = 0
|
||||
m.assertTrue(m.top.findNode("PlayPauseButton").focused)
|
||||
m.assertFalse(m.top.findNode("MinimizeButton").focused)
|
||||
m.top.focusedIndex = 1
|
||||
m.assertFalse(m.top.findNode("PlayPauseButton").focused)
|
||||
m.assertTrue(m.top.findNode("MinimizeButton").focused)
|
||||
end function
|
||||
|
||||
@describe("nudge")
|
||||
|
||||
@it("nudge pulses the focused button's animation")
|
||||
function _()
|
||||
m.top.rowFocused = true
|
||||
m.top.focusedIndex = 1
|
||||
anim = m.top.findNode("MinimizeButton").findNode("nudgeAnim")
|
||||
anim.control = "stop"
|
||||
m.top.nudge = true
|
||||
m.assertEqual(anim.control, "start")
|
||||
end function
|
||||
|
||||
@describe("play/pause icon tracks the play state")
|
||||
|
||||
@it("shows the pause icon while playing, the play icon while paused")
|
||||
function _()
|
||||
' toggleState=false shows icon2 (pause); =true shows icon (play).
|
||||
m.top.playing = true
|
||||
m.assertFalse(m.top.findNode("PlayPauseButton").toggleState)
|
||||
m.top.playing = false
|
||||
m.assertTrue(m.top.findNode("PlayPauseButton").toggleState)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,37 @@
|
||||
<component name="ButtonRow" extends="Group">
|
||||
<!-- Virtual focus: the coordinator keeps real focus on the Video node and tells this row which button is
|
||||
highlighted (focusedIndex) and whether the row has focus (rowFocused). `visible` is gated on idle so the
|
||||
row rides the parent Chrome group's opacity fade instead of popping.
|
||||
|
||||
CenterCluster is centered on screen, RightCluster is right-aligned; each is a plain Group whose
|
||||
buttons + position are laid out in code from its child count. (Not a LayoutGroup: it re-aligns a child
|
||||
whenever its bounding rect changes, which pins the scale pulse's corner and makes it grow off-center.)
|
||||
|
||||
To add a button, do all four or focus/activation breaks:
|
||||
1. drop a VideoPlayerButton into a cluster (xml below);
|
||||
2. add it (in focus order) to m.buttons in ButtonRow.bs (buttonCount updates automatically);
|
||||
3. add a PlayerCoordinatorLogic.PlayerButton enum value (the index);
|
||||
4. add an `else if index = PlayerButton.x` case to ActivateButton in VideoPlayerDev.bs. -->
|
||||
<interface>
|
||||
<field id="transportMode" type="integer" value="0" />
|
||||
<field id="rowFocused" type="boolean" value="false" />
|
||||
<field id="focusedIndex" type="integer" value="0" />
|
||||
<field id="playing" type="boolean" value="true" /> <!-- selects the play vs pause icon -->
|
||||
<field id="buttonCount" type="integer" value="0" /> <!-- read-only: set in Init from m.buttons -->
|
||||
<!-- pulse the focused button's scale nudge (a Left/Right that couldn't move focus). -->
|
||||
<field id="nudge" type="boolean" alwaysNotify="true" />
|
||||
</interface>
|
||||
<children>
|
||||
<!-- play/pause, centered on screen (x=640). -->
|
||||
<Group id="CenterCluster">
|
||||
<VideoPlayerButton id="PlayPauseButton"
|
||||
iconUri="pkg:/images/icons/player/play.png"
|
||||
iconUri2="pkg:/images/icons/player/pause.png" />
|
||||
</Group>
|
||||
<!-- minimize, right-aligned to the trackbar's right edge (x=1212). -->
|
||||
<Group id="RightCluster">
|
||||
<VideoPlayerButton id="MinimizeButton"
|
||||
iconUri="pkg:/images/icons/player/minimize.png" />
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
Reference in new issue
Block a user