Skip to content
New issue

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

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

Already on GitHub? # to your account

callback for UI.timer #33

Closed
kojix2 opened this issue Oct 3, 2021 · 6 comments
Closed

callback for UI.timer #33

kojix2 opened this issue Oct 3, 2021 · 6 comments

Comments

@kojix2
Copy link
Owner

kojix2 commented Oct 3, 2021

You can't write this way.

UI.timer(1000) do
  puts "hello"
  0
end
can't modify frozen Integer: 1000 (FrozenError)

Cannot add callbacks as instance variables to 1000. (This is necessary to avoid garbage collection.)

You can write it this way.

c = Fiddle::Closure::BlockCaller.new(4, [0]) { puts "hello"; 0}
UI.timer(1000, c)

However, the first way of writing is better.

@kojix2
Copy link
Owner Author

kojix2 commented Oct 3, 2021

An easy way to solve this problem is to override UI#timer.
But before doing that, it would be better to check other callbacks used in libui.
There may be other functions that cause the same problem.

@AndyObtiva
Copy link
Collaborator

I just added support for timer and queue_main block syntax to Glimmer DSL for LibUI today (0.2.0)

Here are examples using it:

https://github.com/AndyObtiva/glimmer-dsl-libui/#timer

https://github.com/AndyObtiva/glimmer-dsl-libui/#color-the-circles

The implementation includes some extra convenience options like specifying repeat option as a finite integer or disabling repetition after one run (currently at the bottom of this file):

https://github.com/AndyObtiva/glimmer-dsl-libui/blob/master/lib/glimmer/libui.rb

So, your implementation in LibUI is more than good enough at the binding layer to enable Glimmer’s code at the higher DSL layer. I don’t think you have to worry about it.

@kojix2
Copy link
Owner Author

kojix2 commented Oct 5, 2021

Amazing!
You work so fast, I can't keep up with you at all.
Well, I'll take my time.

@kojix2
Copy link
Owner Author

kojix2 commented Oct 16, 2021

  • uiQueueMain
  • uiOnShouldQuit

@kojix2 kojix2 closed this as completed in ff18a79 Nov 18, 2021
@kojix2
Copy link
Owner Author

kojix2 commented Nov 18, 2021

Maybe I could have solved this issue, but I haven't tested it enough, so I'll wait and see.

@AndyObtiva
Copy link
Collaborator

AndyObtiva commented Nov 18, 2021

Given the Layered Architecture of Glimmer DSL for LibUI, I think we have the following layers from top to bottom, and each is performing its function sufficiently, so I wouldn't worry:

  • DSL (Domain Specific Language) layer for desktop application developers to build GUI with the simplest declarative hierarchical object-oriented syntax possible.
  • Binding layer for mapping C functions to Ruby to make LibUI available in the Ruby programming language.
  • Implementation layer for implementing libui in C on top of each operating system's windowing system.
  • Windowing layer, which varies per operating system (Cocoa on Mac, Win32 on Windows, and GTK on Linux).
  • CPU architecture layer, which varier per CPU hardware (e.g. x86_64 vs Aarch64).

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

No branches or pull requests

2 participants