Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

ba0f3/uibuilder.nim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uibuilder.nim

UI Builder for @nim-lang/ui using Glade

Checkout examples

Usage

you must have Glade installed in order to build UI and create *.glade files

$ nimble install uibuilder

UIBuilder contains a library for load glade file and construct UI on-the-fly, another part - uibuilder binary - which generates a Nim module from glade file.

Construct UI at compile-time

This method is prefered:

  • Glade file compiled into AST at compile-time
  • No more glade files in your distribution package
  • Output module wont depends on UIBuilder
  • Binary size reduced 50%
import ui, ospaths, uibuilderpkg/codegen

const path = joinPath(staticExec("pwd"), "test.glade")

init()
build(path)
mainLoop()

Load Glade on run-ime file

import ui, uibuilder

var builder = newBuilder()
builder.load("ui.glade")
builder.run()

Generate Nim module (WIP)

the uibuilder command will generates a Nim module which can run standalone or importable. the generated module will not requires uibuilder, it just need ui module

Note: only widgets have id are exported

$ uibuilder examples/basic_controls.glade
Nim code saved at: examples/basic_controls.nim
Run command bellow to see the result:

# nim c -r examples/basic_controls.nim

Showcases:

Widgets

Almost widgets are same as GTK Widgets, but there are some widgets need a small hack in order to work

Group

UI Builder converts GtkFrame into a Group, it will finds nested GtkLabel and make it as Group's title

RadioButtons

In Glade, you must cover a group of GtkRadioButtons with a GtkBox, the box must have a style class named radiobuttons

Tab

Tab uses GtkNotebook, tab's container must be a GtkBox

MultilineEntry

Just add a GtkTextView widget to make a MultilineEntry, you also can pre-define text for it w/ GtkTextBuffer

Menu

libui requires to init Menu first, before creating main Window, so it better make a GtkMenuBar separated

Slider

Slider uses GtkScale You can defined ajustment for Slider and SpinBox with GtkAdjustment

examples

Todos

  • Better event handling
  • Code generator for static layout
  • Support QT Designer layout file