Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more than one area underneath a grid makes only the first area show up (Mac) #38

Open
AndyObtiva opened this issue Oct 18, 2021 · 2 comments

Comments

@AndyObtiva
Copy link
Collaborator

AndyObtiva commented Oct 18, 2021

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.quit

Screen Shot 2021-10-18 at 5 17 49 PM

When enabling the two disabled lines, which add a control underneath the vertical box containing the second area, suddenly it shows up.

Screen Shot 2021-10-18 at 5 19 49 PM

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!

@kojix2
Copy link
Owner

kojix2 commented Oct 31, 2021

Thanks for the report.
I actually had a chance to touch the Mac and confirmed that I can reproduce the problem.
But it may be difficult to determine the cause...

@AndyObtiva
Copy link
Collaborator Author

One thing I didn't mention before was that I originally tried the code without having intermediate vertical boxes between the grid and areas, and the same issue occured. I later added the vertical boxes as intermediaries hoping that would resolve the issue, but the issue persisted.

Thanks for confirming. I wonder if this needs to be reported to the C libui project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants