A Flexbox node for Roku's SceneGraph.
- Install
- Usage
- API
- Current Limitations
- Running the test project
- Questions and suggestions
- Contributing
With ropm
(tbd)
Grab our latest release from our Releases page and copy the contents of the components and source folders into the root of the equivalent folders in your application. Remember to update the import scripts if you copy them anywhere else.
<SGFlex
id="sgFlex"
direction="row"
justifyContent="spaceBetween"
alignItems="center"
width="1790"
height="596"
translation="[64, 101]"
>
<Rectangle width="170" height="170" color="0xA90F0F">
<Label text="0" />
</Rectangle>
<Rectangle width="170" height="170" color="0x2B9857">
<Label text="1" />
</Rectangle>
<Rectangle width="170" height="170" color="0x2B4A98">
<Label text="2" />
</Rectangle>
</SGFlex>m.sgFlex = CreateObject("roSGNode", "SGFlex")
' Consider that `flexify()` will be called for each of these assignments.
m.sgFlex.width = 1790
m.sgFlex.height = 596
m.sgFlex.direction = "row"
m.sgFlex.justifyContent = "spaceBetween"
m.sgFlex.alignItems = "center"
r1 = CreateObject("roSGNode", "Rectangle")
r1.width = 170
r1.height = 170
r2 = r1.clone()
r3 = r1.clone
m.sgFlex.appendChild(r1)
m.sgFlex.appendChild(r2)
m.sgFlex.appendChild(r3)
' Call flexify again due to limitation #1
m.sgFlex.callFunc("flexify")-
widthandheight: Dimensions of the flex container. If missing, they will be replaced by the accumulated width and height of the children. -
direction: The direction of the main axis.row(default)column
-
justifyContent: The flex alignment of the main axis.flexStart(default)flexEndcenterspaceBetweenspaceAroundspaceEvenly
-
alignItems:flexStart(default)flexEndcenter
-
flexifyOnce: A boolean value indicating if theSGFlexnode should only callflexify()once. If true, the node will ignore all the function calls toflexify()except the first one. -
flexify(): Call this function every time you want to re calculate and apply the children alignments.
-
The
SGFlexnode is not reactive to changes to its children. To update the layout you need to call theflexifyfunction. -
The
SGFlexnode assumes its children have their coordinate center at the top left. Otherwise they will not be properly aligned.- For example
LayoutGroupnodes with values other thanhorizAlignment="left"andvertAlignment="top"will not be laid out properly. Same forLabelnodes with values other thanhorizAlign="left"andvertAlign="top". - Consider replacing
LayoutGroupnodes withSGFlexnodes to aleviate this.
- For example
-
There are no flexbox-like capabilities for the children (e.g:
orderoralignSelf).
Grab the test-project.zip file from our latest release on the Releases page and sideload it into your Roku device following these instructions.
- Make sure you have the BrightScript Language extension installed.
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install RokuCommunity.brightscript
- Clone this repository
git clone https://github.com/haystacknews/sg-flex.git- Install the project dependencies (preferibly with Node
>=16.14.2and NPM>=8.5.0)
npm install- Go to Run and Debug on the Activity Bar and
Start debuggingwith the optionLaunch Test App.
The
preLaunchTaskmight take a bit to load because it copies the file structure of the test project into a separate folder and runsropm installevery time.
Hi! I'm Arturo Cuya, the main contributor of this project. If you have a question on how to use sg-flex or a suggesion on how to improve it, consider one of the following communication channels:
- Create an issue explaining your question or asking for a feature; or
- Ping me on the Roku Developers Slack
todo: explain this nicely
-
Remember to fork this repo and making a PR from yours into this instead of pulling this repo and doing modifications directly.
-
Use this node environment
"engines": {
"node": ">=16.14.2",
"npm": ">=8.5.0"
},-
Use BrighterScript
-
Switch between developing the component and the test project by changing the
rootDirinbsconfig.json -
Testing is done with
rocaandbrs, using a BrighterScript plugin located inbsconfig/pluginsto disable features not supported bybrs. Run the tests withnpm run test

