-
Notifications
You must be signed in to change notification settings - Fork 10
Description
This code on the Mac shows one area only (note the two disabled lines in the middle of the code).
require 'libui'
UI = LibUI
UI.init
handler = UI::FFI::AreaHandler.malloc
handler.to_ptr.free = Fiddle::RUBY_FREE
area = UI.new_area(handler)
brush = UI::FFI::DrawBrush.malloc
brush.to_ptr.free = Fiddle::RUBY_FREE
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
path = UI.draw_new_path(0)
UI.draw_path_add_rectangle(path, 0, 0, 100, 100)
UI.draw_path_end(path)
brush.Type = 0
brush.R = 0.4
brush.G = 0.4
brush.B = 0.8
brush.A = 1.0
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
UI.draw_free_path(path)
end
handler.Draw = handler_draw_event
handler.MouseEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.MouseCrossed = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.DragBroken = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.KeyEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
box = UI.new_vertical_box
UI.box_set_padded(box, 1)
UI.box_append(box, area, 1)
handler2 = UI::FFI::AreaHandler.malloc
handler2.to_ptr.free = Fiddle::RUBY_FREE
area2 = UI.new_area(handler2)
brush2 = UI::FFI::DrawBrush.malloc
brush2.to_ptr.free = Fiddle::RUBY_FREE
handler_draw_event2 = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
path = UI.draw_new_path(0)
UI.draw_path_add_rectangle(path, 0, 0, 100, 100)
UI.draw_path_end(path)
brush.Type = 0
brush.R = 0.4
brush.G = 0.4
brush.B = 0.8
brush.A = 1.0
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
UI.draw_free_path(path)
end
handler2.Draw = handler_draw_event2
handler2.MouseEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler2.MouseCrossed = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler2.DragBroken = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler2.KeyEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
box2 = UI.new_vertical_box
UI.box_set_padded(box2, 1)
UI.box_append(box2, area2, 1)
# NOTE: Enable these two lines and area2 will show up
# entry = UI.new_entry
# UI.box_append(box2, entry, 1)
grid = UI.new_grid
UI.grid_append(grid, box, 0, 0, 1, 1, 0, 0, 0, 0)
UI.grid_append(grid, box2, 0, 1, 1, 1, 0, 0, 0, 0)
main_window = UI.new_window('Basic Area', 400, 400, 1)
UI.window_set_margined(main_window, 1)
UI.window_set_child(main_window, grid)
UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
end
UI.control_show(main_window)
UI.main
UI.quitWhen enabling the two disabled lines, which add a control underneath the vertical box containing the second area, suddenly it shows up.
Not sure if this is an issue in LibUI (Ruby) or libui (C), so reporting...
BTW, I discovered this issue while building the GUI for Befunge98's Ruby implementation. You can see a screenshot of the Glimmer DSL for LibUI implementation at the bottom of the project README (gui branch under my fork). It basically constructs a grid of many area controls, capturing keyboard and mouse input from them and maintaining focus with a light gray color for the selected cell. At first, I tried building it with grid, but I encountered the issue above. I rewrote it using vertical_box and horizontal_boxs, and it worked!
LibUI is awesome!

