Fidgit

Fidgit is a GUI framework built on Gosu and Chingu

Description

The API is inspired by Shoes, but since Shoes is very simplistic, the level of functionality is based around FXRuby and other GUI APIs. Fidgit was originally developed as a part of the Sidney game, but as it got more complex, it was obvious it would be useful to separate them.

WARNING: THIS PROJECT IS IN EARLY ALPHA DEVELOPMENT AND THE API IS LIABLE TO CONTINUOUS CHANGE AND IT IS QUITE UNSTABLE!

Read the Yard documentation at rubydoc.info

Aim

Fidgit aims to be a toolkit which will provide the building blocks to quickly create a GUI either for a GUI-based game or for options screens and menus within a regular Gosu game.

License

MIT (see COPYING.txt)

Requirements

Example

# examples/readme_example.rb
require 'fidgit'

class MyGame < Chingu::Window
  def initialize
    super(640, 480, false)

    # To use the Fidgit features, a Fidgit::GuiState must be active.
    push_game_state MyGuiState
  end
end

class MyGuiState < Fidgit::GuiState
  def initialize
    super

    # Create a vertically packed section, centred in the window.
    vertical align: :center do
      # Create a label with a dark green background.
      my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)

      # Create a button that, when clicked, changes the label.
      button("Goodbye", align_h: :center, tip: "Press me and be done with it!") do
        my_label.text = "Goodbye cruel world!"
      end
    end
  end
end

MyGame.new.show

API

As well as a cursor and tool-tips that are managed by the GuiState for you, there are several elements you can use inside your GuiState.

Elements are best added by using simple methods (listed below). Most of these method accept a block, some offering access to public methods of the element and others being default event handlers.

The GuiState itself only accepts #vertical/#horizontal/#grid, but any packer or group accepts any other element method.

GuiState methods

Container methods

Arrangement managers

Fidgit uses automatic packers to manage layout.

Elements

Elements can be placed inside a packer or group.

Groupable elements

These should be placed within a group (directly or indirectly) and only one of them will be selected. The group manages which one is selected.

Compound elements

These elements contain items, which can easily be added from within a block passed to them. One can subscribe to the :changed event, which is usually easier than managing each item separately.

Alternative GUI frameworks

There are two other GUI tool-kits that work with Gosu:

Remember that if you primarily want a GUI for your GUI application, not just a GUI in your Gosu game, consider using a dedicated GUI tool-kit, such as Shoes or wxruby-ruby19