Skip to content

Instantly share code, notes, and snippets.

@vaiorabbit
Created December 10, 2022 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaiorabbit/0da026e80d208c6419e95fed688942e3 to your computer and use it in GitHub Desktop.
Save vaiorabbit/0da026e80d208c6419e95fed688942e3 to your computer and use it in GitHub Desktop.
require 'ffi'
module UI
extend FFI::Library
class InitOptions < FFI::Struct
layout(
:Size, :size_t
)
end
@@libuing_import_done = false
def self.load_lib(libpath = Dir.pwd + '/libui.dll')
ffi_lib_flags :now, :global
ffi_lib libpath
import_symbols() unless @@libuing_import_done
end
def self.import_symbols()
callback :WindowOnClosingCallback, [:pointer, :pointer], :int
attach_function :Init, :uiInit, [:pointer], :pointer
attach_function :Uninit, :uiUninit, [], :void
attach_function :NewWindow, :uiNewWindow, [:pointer, :int, :int, :int], :pointer
attach_function :Main, :uiMain, [], :void
attach_function :ControlShow, :uiControlShow, [:pointer], :void
attach_function :WindowOnClosing, :uiWindowOnClosing, [:pointer, :WindowOnClosingCallback, :pointer], :void
attach_function :Quit, :uiQuit, [], :void
attach_function :NewLabel, :uiNewLabel, [:pointer], :pointer
attach_function :WindowSetChild, :uiWindowSetChild, [:pointer, :pointer], :void
@@libuing_import_done = true
end
end
require_relative 'libuing'
onClosing = Proc.new do |sender, sender_data|
puts 'Closing ...'
UI.Quit()
return 1
end
if __FILE__ == $PROGRAM_NAME
UI.load_lib()
init_opts = UI::InitOptions.new
UI.Init(init_opts)
w = UI.NewWindow('Hello', 200, 50, 0)
UI.WindowOnClosing(w, onClosing, nil)
l = UI.NewLabel('World')
UI.WindowSetChild(w, l)
UI.ControlShow(w)
UI.Main()
UI.Uninit()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment