Skip to content

Commit

Permalink
Sample: custom-layout-group-item-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Jul 29, 2023
1 parent a799ce0 commit 8edf03f
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ jobs:
haxelib run openfl build html5
haxelib run openfl build flash
haxelib run openfl build hl
- name: Build samples/custom-layout-group-item-renderer
working-directory: samples/custom-layout-group-item-renderer
run: |
haxelib run openfl build neko
haxelib run openfl build html5
haxelib run openfl build flash
haxelib run openfl build hl
- name: Build samples/custom-programmatic-skin
working-directory: samples/custom-programmatic-skin
run: |
Expand Down Expand Up @@ -275,6 +282,10 @@ jobs:
working-directory: samples/components-explorer
run: |
haxelib run openfl build air
- name: Build samples/custom-layout-group-item-renderer
working-directory: samples/custom-layout-group-item-renderer
run: |
haxelib run openfl build air
- name: Build samples/custom-programmatic-skin
working-directory: samples/custom-programmatic-skin
run: |
Expand Down
34 changes: 34 additions & 0 deletions samples/custom-layout-group-item-renderer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Feathers UI Custom LayoutGroupItemRenderer

This [Feathers UI](https://feathersui.com/) example demonstrates how to create a custom item renderer for [`ListView`](https://feathersui.com/learn/haxe-openfl/list-view/) or other [data containers](https://feathersui.com/learn/haxe-openfl/layouts-and-containers/#data-containers) using the [`LayoutGroupItemRenderer](https://feathersui.com/learn/haxe-openfl/layout-group-item-renderer) component.

## Live demo

A build of the [_custom-layout-group-item-renderer_ sample](https://feathersui.com/samples/haxe-openfl/custom-layout-group-item-renderer/) is hosted on the Feathers UI website, and it may be viewed in any modern web browser.

## Run locally

This project includes an [_project.xml_](https://lime.software/docs/project-files/xml-format/) file that configures all options for [OpenFL](https://openfl.org/). This file makes it easy to build from the command line, and many IDEs can parse this file to configure a Haxe project to use OpenFL.

### Prerequisites

- [Install Haxe 4.0.0 or newer](https://haxe.org/download/)
- [Install Feathers UI from Haxelib](https://feathersui.com/learn/haxe-openfl/installation/)

### Command Line

Run the [**openfl**](https://www.openfl.org/learn/haxelib/docs/tools/) tool in your terminal:

```sh
haxelib run openfl test html5
```

In addition to `html5`, other supported targets include `windows`, `mac`, `linux`, `android`, and `ios`. See [Lime Command Line Tools: Basic Commands](https://lime.software/docs/command-line-tools/basic-commands/) for complete details about the available commands.

### Editors and IDEs

Check out the following tutorials for creating Feathers UI projects in popular development environments:

- [HaxeDevelop](https://feathersui.com/learn/haxe-openfl/haxedevelop/)
- [Moonshine IDE](https://feathersui.com/learn/haxe-openfl/moonshine-ide/)
- [Visual Studio Code](https://feathersui.com/learn/haxe-openfl/visual-studio-code/)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions samples/custom-layout-group-item-renderer/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<meta title="LayoutGroup Item Renderer" package="com.feathersui.samples.CustomLayoutGroupItemRenderer" version="1.0.0" company="Bowler Hat LLC"/>
<meta title="Custom LayoutGroupItemRenderer with ListView — Feathers UI Samples" if="html5"/>
<app main="Main" file="CustomLayoutGroupItemRenderer"/>

<window allow-high-dpi="true"/>
<window fps="60"/>
<window fps="0" if="html5"/>
<window background="#F8F8F8"/>

<source path="src"/>

<haxelib name="openfl"/>
<haxelib name="actuate"/>
<haxelib name="feathersui"/>

<haxedef name="feathersui_theme_manage_stage_color"/>

<assets path="assets/img/haxe.png"/>
<assets path="assets/img/lime.png"/>
<assets path="assets/img/openfl.png"/>
<assets path="assets/img/feathersui.png"/>

<icon path="assets/icons/feathersui-icon.svg"/>
</project>
73 changes: 73 additions & 0 deletions samples/custom-layout-group-item-renderer/src/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import feathers.controls.Application;
import feathers.controls.AssetLoader;
import feathers.controls.Label;
import feathers.controls.ListView;
import feathers.controls.dataRenderers.LayoutGroupItemRenderer;
import feathers.data.ArrayCollection;
import feathers.data.ListViewItemState;
import feathers.layout.AnchorLayout;
import feathers.layout.AnchorLayoutData;
import feathers.layout.TiledRowsLayout;
import feathers.layout.VerticalLayout;
import feathers.utils.DisplayObjectRecycler;

class Main extends Application {
public function new() {
super();

this.layout = new AnchorLayout();

this.listView = new ListView();
this.listView.dataProvider = new ArrayCollection([
new ListItem("Haxe", "assets/img/haxe.png"),
new ListItem("Lime", "assets/img/lime.png"),
new ListItem("OpenFL", "assets/img/openfl.png"),
new ListItem("Feathers UI", "assets/img/feathersui.png"),
]);
this.listView.itemToText = (item:ListItem) -> {
return item.name;
};
this.listView.layout = new TiledRowsLayout();
this.listView.itemRendererRecycler = DisplayObjectRecycler.withFunction(() -> {
var itemRenderer = new LayoutGroupItemRenderer();
var layout = new VerticalLayout();
layout.gap = 5;
layout.setPadding(5);
layout.horizontalAlign = CENTER;
layout.verticalAlign = MIDDLE;
itemRenderer.layout = layout;

var iconLoader = new AssetLoader();
iconLoader.name = "loader";
iconLoader.width = 75.0;
iconLoader.height = 75.0;
itemRenderer.addChild(iconLoader);
var titleLabel = new Label();
titleLabel.name = "title";
itemRenderer.addChild(titleLabel);
return itemRenderer;
}, (itemRenderer:LayoutGroupItemRenderer, state:ListViewItemState) -> {
var iconLoader = cast(itemRenderer.getChildByName("loader"), AssetLoader);
var titleLabel = cast(itemRenderer.getChildByName("title"), Label);

var data = cast(state.data, ListItem);

iconLoader.source = data.icon;
titleLabel.text = state.text;
});
this.listView.layoutData = AnchorLayoutData.fill();
this.addChild(this.listView);
}

private var listView:ListView;
}

class ListItem {
public function new(name:String, icon:String) {
this.name = name;
this.icon = icon;
}

public var name:String;
public var icon:String;
}
2 changes: 2 additions & 0 deletions samples/website-samples.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
--next
-cmd haxelib run openfl build components-explorer/project.xml html5 -final -clean --haxedef=feathersui.com
--next
-cmd haxelib run openfl build custom-layout-group-item-renderer/project.xml html5 -final -clean --haxedef=feathersui.com
--next
-cmd haxelib run openfl build custom-programmatic-skin/project.xml html5 -final -clean --haxedef=feathersui.com
--next
-cmd haxelib run openfl build custom-programmatic-skin-with-states/project.xml html5 -final -clean --haxedef=feathersui.com
Expand Down

0 comments on commit 8edf03f

Please sign in to comment.