Cura

A component toolkit for creating user interfaces.

Cura can be used to create:

  • Command-line interfaces (CLI).
  • Text-based user interfaces (TUI).
  • Graphical user interfaces (GUI).
  • Read-Eval-Print-Loops (REPL).
  • Extensions or functionality in current applications.

Cura is:

  • Portable
  • * No dependencies on external libraries or gems, besides adapters.
  • * Does not use any IO or system-specific methods.
  • * Can be used on any Ruby implementation, including MRuby (embeddable).
  • Adaptable
  • * Adapters exist for implementation and platform specific windowing, drawing, and terminal printing libraries.
  • * Easily create adapters for any external library to implement a custom view tree for any application.

Cura provides:

  • Command system
  • * Simple routing DSL.
  • * Class based commands.
  • * Windows and *NIX style option parsing (optional, for use outside of CLI environments).
  • * Usable in CLI, TUI, GUI, REPL, or any environment.
  • Component system
  • * View tree hierarchy.
  • * Box model layouts.
  • * CCML, a XML user interface markup language for defining view trees
  • Event system
  • * Dispatch event loop.
  • * Middleware for modifying or translating events.
  • * Defining events on any Ruby object.
  • * Propagation using both the capturing and the bubbling models and ability to stop propagation.
  • Adapter system

Note: Strikethrough means not yet implemented (wait for 0.1.0)

Install

Bundler: gem 'cura'

RubyGems: gem install cura

Adapters

Ruby

Used for its libraries.

Text-based User Interface (TUI)

Graphical User Interface (GUI)

MRuby

Used for its compilability and portability.

Text-based User Interface (TUI)

Graphical User Interface (GUI)

JRuby

Used for compilability, speed, and libraries.
Ruby FFI based adapters should also work in JRuby.

Text-based User Interface (TUI)

Graphical User Interface (GUI)

Usage

require 'cura'

# Define our window

class MainWindow < Cura::Window

  def initialize
    super

    @label = Cura::Label.new(
      text: 'Hello, world!',
      bold: true,
      underline: true,
      alignment: { horizontal: :center },
      margin: 10,
      border: { size: 1, color: Cura::Color.red },
      padding: 3
    )

    add_child( @label ) # Will mixin any adapter methods for Label
  end

end

# Define our application and add our window

class Application < Cura::Application

  def initialize
    super

    @window = MainWindow.new

    add_window( @window )

    @window.show # Note that in TUIs, only one window can be shown at once.
  end

end

# Require any adapters

require 'cura-adapter-termbox'
require 'cura-adapter-termbox-ffi'
require 'cura-adapter-curses'
require 'cura-adapter-sdl'
require 'cura-adapter-sdl-ffi'
require 'cura-adapter-opengl'
require 'cura-adapter-opengl-ffi'
require 'cura-adapter-gosu'

# Choose adapter

adapter_names = Cura::Adapter.all.collect(&:name)
adapter = loop do
  puts "Choose one or type 'exit': #{ adapter_names.join(', ') }"
  print '> '

  answer = gets.downcase.strip

  exit if answer == 'exit'
  retry unless adapter_names.include?( answer.to_sym )
end

# Run application with adapter

Application.run( adapter: adapter )

Copyright © 2015 Ryan Scott Lewis [email protected].

The MIT License (MIT) - See LICENSE for further details.