Coder Social home page Coder Social logo

iu's Introduction

Control gallery

IU

UI framework based on the Fusion/libui.cr library, with custom elements from watzon/cru.

Motivation

Currently avaliable Crystal UI frameworks are either not maintained anymore or the documentation is scarce and a single error might cause a developer to lose motivation, which is why I decided to build IU on top of the LibUI framework which is a multi-platform powerful UI toolkit.

Build status

Build Status

Features

Widgets

  • Horizontal box, Vertical box, Checkbox, Combobox, Editable combobox.
  • Button, Font button, Color button, Radio button.
  • Datetime picker, Progress bar, Slider, Spinbox.
  • Text entry, Multiline text entry.
  • Form, Grid, Group, Table, Tab, Separator.
  • Image, Label.
  • Window, Menubar, Area.
  • Many more.

Platforms

  • Mac OSX
  • Linux
  • Windows (Once crystal will be available on Windows)

Code example

require "iu"

module Example
  include Iu::Components

  # Ability to reuse components extracted to other classes.
  class MyComponent < Iu::ReusableComponent
    def initialize(@id : Int32); end

    def render : Iu::Component
      Group
        .new(title: "MyComponent", margined: true)
        .adopt(
          VerticalBox
            .new(padded: true)
            .adopt(
              Label.new(text: "Hello, World ##{@id}!"),
              stretchy: true
            )
            .adopt(
              Button.new(text: "Click Me!"),
              stretchy: true
            )
        )
    end
  end

  # :nodoc:
  class Application < Iu::Application
    def initialize_component
      window =
        Window.new(
          title: "Example",
          width: 800,
          height: 600,
          menu_bar: false
        )
      
      window.margined = true

      window
        .adopt(
          HorizontalBox
            .new(padded: true)
            .adopt(
              MyComponent.new(1),
              stretchy: true
            )
            .adopt(
              MyComponent.new(2),
              stretchy: true
            )
            .adopt(
              MyComponent.new(3),
              stretchy: true
            )
        )

      window.closing.on do
        exit(0)
      end
      
      window.show
    end
  end
end

app = Example::Application.new

app.should_quit.on do
  exit(0)
end

app.start

Installation

  1. Follow the instructions for installation laid out in andlabs/libui.
  2. Copy the compiled files from step 1 (i.e. files in build/out) to /usr/lib for OSX and Linux users.
  3. Go to your shard.yml file, and enter this in:
dependencies:
  iu:
    github: grkek/iu
  1. Run shards install.

iu's People

Contributors

grkek avatar videotoaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

iu's Issues

Standalone image example?

Could a standalone image example be added to demonstrate the view-image functionality?

I know it is possible because ruby libui does it. Would be nice to have copy/paste-able code
in crystal as-is to just modify it a little bit for already existing images.

Crash when Area component callback accesses instance variable

A class inherits Iu::Components::Area and implements on_* callback, will crash program when its instance access instance variables:

class MyArea < Iu::Components::Area
    def initialize(width = nil, height = width)
      @blah = "blah"
      super(width, height)
    end

    def on_draw(params : UI::AreaDrawParams)
       puts @blah
    end

    def on_mouse_event(mouse_event : UI::AreaMouseEvent);end
    def on_mouse_crossed(left : Bool);end
    def on_drag_broken;end
    def on_key_event(key_event : UI::AreaKeyEvent);end
end

I'm not familiar with Crystal. I think the reason is that the callback function passed to the libui C library forms a closure. The Iu shard wraps libui, a new member "data" is added to the AreaHandler structure to store pointers to an area objects. This allows libui to call back the on_* method implemented by the MyArea class, I'm not sure if this is the scenario described in Crystal document. After testing, this bug can be solved in this way:

@@on_mouse_event_cb = Proc(UI::AreaHandler*, UI::Area*, UI::AreaMouseEvent*, Nil).new { |h, a, e|
        # h.value.data.as(Area*).value.on_mouse_event(e.value).as(Nil)
        ::Box(Area).unbox(h.value.data).on_mouse_event(e.value).as(Nil)
}
# @handler.data = self.as(Void*)
@handler.data = ::Box.box(self)

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.