Comments (8)
I am re-opening this issue because I encountered it too, but only on Linux.
I reported it at the c libui project, but they were not able to reproduce it there, so it must be a Ruby libui binding issue:
libui-ng/libui-ng#205
If I try to run this example (which simply duplicates the code of basic window twice), it runs on the Mac, but it fails to launch a window twice on Ubuntu Linux 22:
require 'libui'
UI = LibUI
puts 'Run 1'
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
end
UI.main
UI.quit
puts 'Run 2'
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
end
UI.main
UI.quit
It was reported to me by 2 users:
This is an important feature to have to be able to conditionally open and close windows within the same application. It is useful for example in IRB or girb
(Glimmer IRB).
A fix would be highly appreciated.
from libui.
I am a bit confused about this issue.
However, I still think that calling UI.quit
twice is causing problems.
Cody's C code translated into Ruby's LibUI looks like this Here
libui-ng/libui-ng#205 (comment)
require "libui"
UI = LibUI
UI.init
# Create a new window
w = UI.new_window("hello world", 300, 30, 0)
UI.window_on_closing(w) { UI.quit; 1}
l = UI.new_label("Hello, World!")
UI.window_set_child(w, l)
UI.control_show(w)
UI.main
w = UI.new_window("hello world", 300, 30, 0)
UI.window_on_closing(w) { UI.quit; 1}
l = UI.new_label("Hello, World!")
UI.window_set_child(w, l)
UI.control_show(w)
UI.main
UI.uninit
uiQuit
is called only once in each window, and uiUninit
is called last instead of uiQuit
.
Probably, this is the correct way to use libui(-ng).
So, the way I have been writing UI.quit
at the end is not the correct way to write libui, or at least not the recommended way.
I started writing the LibUI samples based on the old Ruby binding using FFI created by jamescook, and you see the same usage here. This should also be written with reference to other libraries, and while it is one popular way of writing, I don't think it is the correct way.
I think this is the biggest point of this issue, but there could be other problems as well...
from libui.
I am planning to make a change in all the examples of LibUI.
Instead of calling uiQuit()
twice, I intend to use uiInit()
and uiUninit()
to align with the C examples of libui. However, it should be noted that in LibUI, the UI.init function has been customized. The uiInitOptions structure is not protected and may be subject to garbage collection (GC). While there have been no known issues caused by this so far, it is necessary to understand the actual role of uiInitOptions
before making any changes.
from libui.
Hi, I experimented with using LibUI.uninit
in order to start a window multiple times.
I encountered an issue when using a menu/quit-menu-item on the Mac.
LibUI code (attempts to start an app 3 times):
#!/usr/bin/ruby
require 'libui'
UI = LibUI
UI.init
menu = UI.new_menu('File')
UI.menu_append_quit_item(menu)
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit
If you do not think this is an issue in the LibUI Ruby binding, yet an issue with the libui-ng C library, please confirm to me and I will report the issue at libui-ng.
from libui.
Hi. @rubyFeedback
Thank you for your Feedback.
Sorry, I forgot about this problem for so long. When I first saw it, I thought it looked difficult and forgot about it.
Today I noticed this issue left behind.
I am only connecting the C libui to the Ruby language interface and do not have a deep understanding of libui. I'm sure everyone has already noticed that I'm not that familiar with the C language. But even if I didn't know much about it, there are things I could figure out by looking at the code. My guess is that it is due to calling UI.quit
twice.
You say that's not true?
Indeed UI.quit
is called twice, once in the block of the window_on_closing
method, and then once in the last line of initialize
method.
Although libui looks like one library, it is actually a collection of three different libraries that behave in a similar way. For Unix, for macOS, and for Windows. Let's take a look at the Unix code. uiQuit is here.
void uiQuit(void)
{
gdk_threads_add_idle(quit, NULL);
}
Here the quit
function is added to the thread. The quit
function waits for the end of main
.
Since you called UI.quit
twice, there are two callbacks waiting for main
to exit. But actually main
has only been called once. So there is one callback remaining. This may be causing the problem. If you delete the last line of UI.quit
, it works as expected.
Button.new
Button.new
Button.new
...
Sorry if my explanation above is wrong. Read the libui code and find out for yourself. If you can read Ruby, you can read C.
If you think you can't read C, it's just a self-suggestion.
But in any case, if you're going to create a Window more than once, I'd suggest you delete the UI.quit on the last line.
Best regards
from libui.
Hi @AndyObtiva
I ran your code on Ubuntu and the latest libui-ng, no error occurred.
If menus do not work properly in previous versions, this may be related to the following problem. Once a Menu was set, flags such as menusFinalized
were set and UI.uninit
did not restore the flags. This bug seems to have been fixed 4 months ago.
git clone https://github.com/kojix2/LibUI
cd LibUI
rm -f vendor/libui.*
# Download latest libui-ng binary
bundle exec rake vendor:kojix2:auto
# Or you can compile from source code
bundle exec rake vendor:libui-ng:build
bundle exec ruby three_times_window.rb
I will check the behavior on Mac tomorrow.
from libui.
Updated:
Just confirmed that it works on M2 Mac mini.
But we need to release a LibUI gem with the latest libui-ng binaries to get a real solution...
from libui.
Thank you for the update. I actually tested Linux from my side, and I didn't have the problem on Linux when using uninit. However, I do have the problem on MacOS as reported already.
I look forward to you making a new release with the latest libui-ng binaries to resolve the issue on the Mac.
from libui.
Related Issues (20)
- libui-ng HOT 8
- ARM64/AARCH64 Support HOT 26
- Exe wont start (Fiddle::DLError) Windows 11 Notebook HOT 14
- Glimmer DSL for LibUI Wins Fukuoka Ruby 2022 Special Award HOT 1
- libui-ng - "beta" ffi for it, for "early testing"? HOT 6
- Warning message when running LibUI::FFI.uiInit on Mac HOT 2
- Example for Parent and Child Windows HOT 8
- [Question] Field Edit sign restriction visible in GUI? HOT 1
- libui-ng related methods: how to use it? HOT 1
- Organising on https://github.com/kojix2 ? HOT 3
- Custom toplevel methods: aiming to enhance LibUI HOT 2
- Two things about libui-ng: one is a build failure with "rake"; the other is a suggestion HOT 2
- Table Selection API HOT 12
- Question: Why choose `fiddle` rather than `ffi`? HOT 4
- Two duplicate lines, I think, at: https://github.com/kojix2/LibUI/blob/main/examples/draw_text.rb#L92 HOT 3
- Optimize performance of area draw methods HOT 3
- Version 0.0.13.pre x86-mingw32 does not work HOT 3
- Table example: HOT 4
- `LibUI.draw_text_layout_extents` always returns 0 values
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libui.