Git Product home page Git Product logo

uibuilder.nim's Introduction

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

uibuilder.nim's People

Contributors

ba0f3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

uibuilder.nim's Issues

Error when attempting to compile

This is an exciting project! I know you just started, and it's a prototype, but I thought I'd report this anyway. When I run nim c uibuilder.nim It fails with this message:

uibuilder.nim(30, 30) Error: type mismatch: got <Builder, XmlNode>
but expected one of: 
proc build(builder: Builder; node: XmlNode; parent: var Widget)
  first type mismatch at position: 3
  required type: var Widget

expression: build(builder, child)

failed to compile on Windows with Mingw64

nimble install uibuilder

... CC: debug
        ... Hint:  [Link]
        ... C:\Users\LOVLJIDY\nimcache\uibuilder_r\win_alloc.cpp.obj:alloc.cpp:(.text+0x30): undefined reference to `std::ios_base::ios_base()'
        ... C:\Users\LOVLJIDY\nimcache\uibuilder_r\win_alloc.cpp.obj:alloc.cpp:(.text+0xc8): undefined reference to `std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'
        ... C:\Users\USER\nimcache\uibuilder_r\win_alloc.cpp.obj:alloc.cpp:(.text+0x126): undefined reference to `std::locale::locale()'
        ... C:\Users\USER\nimcache\uibuilder_r\win_alloc.cpp.obj:alloc.cpp:(.text+0x171): undefined reference to `std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'

and so many errors

Err: "cannot evaluate at compile time: state"

Hi @ba0f3

I just got an issue on the nimblegui due to an error while compiling. Are you going for an update of uibuilder anytime soon?

/nim/nim_nimble_gui/nimblegui.nim(7, 6) template/generic instantiation of `build` from here
/.choosenim/toolchains/nim-1.0.4/lib/pure/random.nim(593, 3) Error: cannot evaluate at compile time: state

Install fail with XML error

When I run "nimble install" it fails with:
Error: Build failed for package: uibuilder

Further down are the details:

$HOME/.nimble/pkgs/xml-#devel/xml.nim(170, 24) Error: usage of 'isNil' is a user-defined error

I'm using latest head of nim compiler (0.18.1) and recent nimble too.

SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Amazing progress on this!

After pulling latest changes from the last 2 days, I now get this error when attempting to run the basic_controls example program:

$ ./basic_controls
Traceback (most recent call last)
basic_controls.nim(4)    basic_controls
uibuilder.nim(293)       load
uibuilder.nim(142)       parseXml
uibuilder.nim(142)       parseXml
uibuilder.nim(142)       parseXml
uibuilder.nim(142)       parseXml
uibuilder.nim(125)       parseXml
system.nim(1529)         add
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

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.