State & Plans of GUI development with Crystal

It is not his responsibility to create the bindings but I always can ask him about some technicalities if needed. :smiley:

It is free but not open source.

2 Likes

Yeah but the free tier is limited to dynamic libraries provided by the vendor. If you want to provide statically linked distributables where you only need to download a single file, you need to buy a license.

Just checked out your rendering engine, and its awesome! I have no idea how to make a GUI library, and have really wanted one for crystal. I used Hedron (libui wrapper) for a while, but libui is terrible.

Right, it make sense, this part was overlooked by me.

Sad day, sciter looks awesome

I am using the Gambas GUI environment as a sort of GUI server via scripting or via TCP sockets. Gambas supports both GTK/QT in an event driven way.
-Accessing Gambas (GUI)objects and properties by their Name from Crystal works fine.
-Forwarding GUI events to Crystal as plain text is also working fine.
-Gambas has a RAD GUI designer, which is drag and drop like in Visual Basic.

Demo App in cystal using Gambas(GTK,QT) for RAD GUI design.

require "socket"
GUI_SERVER="localhost"
GUI_PORT=9090

class GuiClient
  property send_time = true
  @client = TCPSocket.new    #define var
  def connect
    @client = TCPSocket.new(GUI_SERVER,GUI_PORT)
  rescue err
    puts err.message  
    exit
  end-

def send (object,value)
    puts "send(object,value)"     
    @client << object + "," + value + "\n"  #send to GUI_SERVER
    sleep 0.1    
end

def send (object)
  puts "send(object)"     
  @client << object + "\n"  #send to GUI_SERVER
  sleep 0.1
end

def disconnect
  @client.close
end  

def receive  #handle events
  
spawn do  
        loop do    
            event = @client.gets
            puts event
            case event 
            when "Button1_clicked"  #stop button
              @send_time=false
            when "Button2_clicked"  #continue button
              @send_time=true
            when "Button3_clicked"  #clear textarea button
              send "textarea1.text",""    
            when "Button4_clicked"  #upcase textarea.text
              send "Textarea1.text" #request this value from gui elemen
              response = @client.gets
              puts "Response: ",response
              send "Textarea1.text",(response.not_nil! + "\n").upcase  #do upcase on string in textarea1
            when "Button5_clicked"  #upcase textarea.text
              send "Textarea1.text" #request this value from gui element
              response = @client.gets
              puts "Response: ",response
              send "Textarea1.text",(response.not_nil! + "\n").downcase  #do downcase on string in textarea1
            when "FMain_closed"     #Appilcation Window closed by user
            exit
            else  
            end  
        end
    end
  end
end  
#start the gambas gui server demo app
spawn do; system("~/src_gambas/gui_server/gui_server.gambas"); end
sleep 1   #give some time for startup
mygui = GuiClient.new
mygui.connect 
mygui.receive
mygui.send "textlabel1.text","crystal + gambas = crybas"
mygui.send "button1.text","stop"
mygui.send "button2.text","continue"
#mygui.send "button3.enabled","0"  #disable a button
mygui.send "button3.text","clear texrarea"
mygui.send "button4.text","do Text.upcase"
mygui.send "button5.text","do Text.downcase"
#send key,value pairs for GUI Objects based on GTK or QT 
mygui.send "FMain.Text","Crybas"   #set title of Application
mygui.send "Textarea1.Text","hello-textarea"

loop do   #Error writing to socket: Broken pipe when server closes
       mygui.send "Textbox1.Text",Time.local.to_s if mygui.send_time # display time in the gui
       sleep 1
    end   

sleep
6 Likes

Very nice. So, if you want to share this app, you need a runtime dependency on this library?

Package Dependencies for deploying this crybas example:
On Debian based distros:
gambas3-runtime
gambas3-gb-net
gambas3-gb-gtk
gambas3-gb-form
gambas3-gb-image

If you want to redesign/design a gui you need to install this package:
gambas3 - Complete visual development environment for Gambas
There is an issue with pre-built packages at least for Ubuntu 20.04. If Gambas is missing some components on startup you need to build the environment for your Linux installation from sources. Gambas3 is open source GPLv2+.
http://gambaswiki.org/wiki/install?nh

If you need a GUI for your bash scripts:

1 Like

Does anyone know more details about what Nikola Motors uses?

Are they binding directly to Chromium maybe?

As I understood it from the article, Crystal is providing a plain old webapp that they probably just launch in a fullscreen chromless browser

We’re essentially following the Electron paradigm, but we use Crystal instead of node.js to generate all the APIs and HTML.

4 Likes

Last week I got some constraint based UI elements working. It still has a ways to go, but the foundation is there. The code is a complete mess, but you can run the specs to see some blocks in the window https://github.com/neutrinog/gui-crystal.

This is very rough experimental code, so don’t expect to be impressed. Just wanted to share that I have constraint based positioning of UI elements working.

I plan to abstract away the low level constraints and probably steal some ideas from css, and maybe even (eventually) attempt implementing a flex box layout.

4 Likes

Anyone know how hard it would be to create a skia binding? With skia, we could create a flutter-like framework in crystal.

Well, it looks like C++, is there a C API? With that it’s not any harder than any other binding, if you have to create it first, then that’s that additionally. Either way the binding sounds like the relatively easy task in that kind of endeavor :P

1 Like

Looks like still there is no stable C API.
Other bindings in Rust, Go, .Net, Python don’t look trivial & use some extra tools like binding generators. Maybe Crystal bindgen could help here?
An alternative could be Cairo library although seems like its development/usage is declining (LibreOffice is also migrating to Skia on v7).

This is a really interesting approach. Thinking out of the box.

That makes me sad. Oh well. I’m no expert but I’ve heard Cairo is slowing being phased out of most projects. With skia looking like its on the upturn & backed by google, I figured that should be the go to.

Just found on Reddit that there are new bindings for the DearImGUI inmediate-mode-ui library here

Hey everyone! I had to take a long break from GUI stuff but I was able to tinker a little bit and have something handy to share.

Here’s a tiny shard for building layouts in 100% pure crystal (including dependencies) https://github.com/da1nerd/layout.cr. It’s still pretty simple but you can already build some pretty complex layouts. Eventually I want to provide similar functionality to css flexbox.

Keep in mind this does not do any GUI magic. This is just calculating the layout. The next step will to use this shard to build a UI toolkit that can actually draw things to the screen.

P.S. if you play with it and run into any errors from Kiwi::Solver please file a bug so I can continue to improve the constraint library.

1 Like