Git Product home page Git Product logo

uielements-slim's Introduction

UIElements-Slim

Create Unity UIElements UXML files using the Slim template engine. Works great alongside UIElements-Sass.

Why

XML is a pain to write and looks messy. Slim removes the bloat and adds features like variables, functions, loops.

Here is iteration over an array of strings:

UXML
    Foldout class='column'
        - ['elephant', 'zebra', 'lion', 'giraffe'].each do |animal|
            - elementName = 'row-' << animal
            Box name=elementName
                - imagePath = 'Resources.Load(' << animal << 'Image)'
                Image image=imagePath class='animal-image'
                Label text=animal class='animal-label'
                - buttonText = 'Choose the ' << animal
                Button text=buttonText

It compiles to the following UXML:

<?xml version="1.0" encoding="utf-8"?>
<UXML xmlns:xsi="http:/www.w3.org/2001/XMLSchema-instance"
      xmlns="UnityEngine.UIElements"
      xsi:noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd"
      xsi:schemaLocation="UnityEngine.UIElements ../UIElementsSchema/UnityEngine.UIElements.xsd">
  <Foldout class="column">
    <Box name="row-elephant">
      <Image class="animal-image" image="Resources.Load(elephantImage)"></Image>
      <Label class="animal-label" text="elephant"></Label>
      <Button text="Choose the elephant"></Button>
    </Box>
    <Box name="row-zebra">
      <Image class="animal-image" image="Resources.Load(zebraImage)"></Image>
      <Label class="animal-label" text="zebra"></Label>
      <Button text="Choose the zebra"></Button>
    </Box>
    <Box name="row-lion">
      <Image class="animal-image" image="Resources.Load(lionImage)"></Image>
      <Label class="animal-label" text="lion"></Label>
      <Button text="Choose the lion"></Button>
    </Box>
    <Box name="row-giraffe">
      <Image class="animal-image" image="Resources.Load(giraffeImage)"></Image>
      <Label class="animal-label" text="giraffe"></Label>
      <Button text="Choose the giraffe"></Button>
    </Box>
  </Foldout>
</UXML>

You can learn more about it's features here.

Usage

This is just a proof-of-concept so your mileage may vary, but I've tested it on Windows and since it only consists of one script that calls to the command line, I don't see why it wouldn't work everywhere.

UIElements-Slim assumes you have a working ruby installation with the slim gem. You can do this like so:

On Windows: choco install ruby then gem install slim.

Mac: brew install ruby then gem install slim.

Ubuntu: sudo apt-get install ruby then gem install slim.

Then you can clone this repo, add it as a submodule, or download the zip and extract it into your Unity project.

Every time a '.slim' file is added or updated, the script will run the slim compiler and output a '.uxml' file in the same directory.

To-do

  • It would be great if this didn't depend on a ruby installation and the command line...Unity uses nodejs for some of its processes so if I can figure out how to hook into this somehow perhaps the Slm project based on node can be used instead.

uielements-slim's People

Contributors

eidetic-av avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.