Welcome to the PhotonUI quick start guide. If you want to learn how to build a UI using PhotonUI, you are in the right place.
Get PhotonUI
Standalone Version
To start using the standalone version of PhotonUI in your projects, you first need to download it:
or clone the git repository:
git clone git@github.com:wanadev/PhotonUI.git
All the files you need are in the dist
folder. You just have to import
photonui-base.css
(must be imported first),photonui-theme-particle.css
,and
photonui.js
(orphotonui.min.js
)
in your page:
1 | <!DOCTYPE html> |
NPM and Browserify
If you are using Browserify in your project, a NPM package is available. To install it, juste type:
1 | npm install --save photonui |
then, to use it in your project you just have to import PhotonUI:
1 | var photonui = require("photonui"); |
NOTE: do not forget to import CSS files in your HTML page:
1 | <link rel="stylesheet" href="./node_modules/photonui/dist/photonui-base.css" /> |
Using Your First Widgets
Some widgets, like photonui.Window
are “root widgets” ; that means they don’t need a parent to be displayed on the page. To use a root widget, you just have to instantiate its class with the desired parameters:
1 | var win = new photonui.Window({ |
The majority of the widgets are not “root widgets”, they need a parent to be displayed.
You can give them any DOM element as parent:
1 | // Create a button |
… or any PhotonUI widget that can contain other widgets (“container” and “layout” widgets):
1 | // Create a window |
Binding Events
Each PhotonUI Widget comes with a set of defined events (called wEvent
) to which you can attach one or more callbacks.
For example, the photonui.Button
widget has a click
wEvent that is fired each time the user clicks on the button:
1 | // Create a button |
Building More Complex UI Using Layouts
There are 5 main types of widgets in PhotonUI:
Interactive widgets: widgets used to get feedback from the user (e.g.
photonui.Button
,photonui.TextField
,…),Visual-Only widgets: only intended to be displayed, no interaction with the user (e.g.
photonui.FAIcon
,photonui.Label
,photonui.Separator
,…),Non-Visual widgets: widgets that do not display anything but that work behind the scene (e.g.
photonui.Translation
,photonui.FileManager
,photonui.MouseManager
,…),Container widgets: widgets, interactive or not, that can contain one child widget (e.g.
photonui.Window
,photonui.MenuItem
,…),and Layout widgets: widgets used to arrange other widgets in order to create a UI (e.g.
photonui.BoxLayout
,photonui.GridLayout
,…).
So if we want to create a window with two buttons inside, we will need to use a layout. The most basic and simple layout widget is photonui.BoxLayout
. Let’s use it to build our UI:
1 | // Create each widget of the UI |
One more thing
In the examples above, we “manually” built the UI by declaring several variables to store widgets and then assembling everything. There is a more efficient way to build your UI (called “declarative way”) that is used in most of the example of the PhotonUI documentation.
Let’s rewrite our last example (the window with two buttons) in the declarative way:
1 | new photonui.Window({ |
Here We Are
You are now ready to start using PhotonUI on your own project. :)