https://github.com/feathersui/feathersui-xml
Experimental Haxe macros for creating Feathers UI components from markup, similar to MXML from Adobe Flex
https://github.com/feathersui/feathersui-xml
cross-platform feathers-ui frontend gui haxe mxml openfl ui user-interface xml
Last synced: 7 months ago
JSON representation
Experimental Haxe macros for creating Feathers UI components from markup, similar to MXML from Adobe Flex
- Host: GitHub
- URL: https://github.com/feathersui/feathersui-xml
- Owner: feathersui
- License: other
- Created: 2020-02-28T21:39:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T22:21:26.000Z (over 1 year ago)
- Last Synced: 2024-03-26T09:05:39.277Z (about 1 year ago)
- Topics: cross-platform, feathers-ui, frontend, gui, haxe, mxml, openfl, ui, user-interface, xml
- Language: Haxe
- Homepage:
- Size: 99.6 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# XML Components for Feathers UI
An **experimental** library containing [Haxe macros](https://haxe.org/manual/macro.html) to create [Feathers UI](https://feathersui.com/) components at compile-time using markup.
This markup is inspired by MXML, which is an XML dialect designed for creating user interfaces with Apache Flex (originally developed at Macromedia and Adobe).
## Installation
This library is not yet available on Haxelib, so you'll need to install it from Github.
```sh
haxelib git feathersui-xml https://github.com/feathersui/feathersui-xml.git
```## Usage
The `XmlComponent` class contains some macro functions, like `withMarkup()` and `withFile()`, that may be used to create custom components from markup.
By default, the `XmlComponent` class doesn't know anything about Feathers UI. It is meant to be a generic library that can be used with other UI component frameworks too. To add Feathers UI components to the set of available tags, a special build macro must be added to the project.
You can add it in your _project.xml_ file:
```xml
```
Or you can add it as a build macro to your application class:
```haxe
import feathers.core.Application;@:build(com.feathersui.xml.FeathersUICoreNamespace.setup())
class Main extends Application {
public function new() {
super();
}
}
```Be sure to import the `XmlComponent` class to use the methods demonstrated below.
```haxe
import com.feathersui.xml.XmlComponent;
```### `withMarkup()`
Calling the `XmlComponent.withMarkup()` macro generates a Haxe class from inline markup (or from a string), and then it returns a new instance.
```haxe
var instance = XmlComponent.withMarkup(
'
'
);
container.addChild(instance);
instance.okButton.addEventListener(TriggerEvent.TRIGGER, (event) -> {
trace("triggered the OK button");
});
```### `withFile()`
Calling the `XmlComponent.withFile()` macro works similarly to `withMarkup()`, but the XML is loaded from a separate file. Relative paths are resolved from the folder containing the _.hx_ file where the macro is used.
```haxe
var instance = XmlComponent.withFile("path/to/file.xml");
```## Haxe primitive types
A subset of core Haxe types may be used in markup by defining the following namespace:
```
xmlns:hx="http://ns.haxe.org/4/xml"
```### `Bool`
The value must be `true` or `false`, and it is case-sensitive.
```xml
true
```### `Float`
A float may be a positive or negative numeric value which may have a decimal portion.
```xml
123.4
```### `Int`
An integer may be a positive or negative numeric value, and it must not have a decimal portion. Validated by `Std.parseInt()`.
```xml
-456
```### `String`
A sequence of characters.
```xml
Hello World
```If the string value would make the XML invalid, wrap it with CDATA.
```xml
that is not valid XML]]>
```### `Dynamic`
An anonymous structure. Properties may be set using XML attributes, child elements, or a combination of both.
```xml
Matt Murdock
```
### `Any`
An anonymous structure. Properties may be set using XML attributes, child elements, or a combination of both.
```xml
Danny Rand
```
### `Array`
An collection of items, which are added as child elements.
```xml
```
## Tips & Tricks
When using [haxe-formatter](https://github.com/HaxeCheckstyle/haxe-formatter), you may want to disable formatting for sections of _.hx_ files that contain embedded markup.
```haxe
var instance = XmlComponent.withMarkup(
// @formatter:off
'
'
// @formatter:on
);
```