-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The second example added, for widget button (in file button.rb). We now have two standalone examples; more will follow. Hopefully we will eventually cover the whole libui API with documented examples in the long run.
- Loading branch information
1 parent
66478f2
commit 4f167e4
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# ============================================================================ # | ||
# This example (button.rb) shall demonstrate the following functionality | ||
# (9 components), as well as their implementation-status in regards to | ||
# this file: | ||
# | ||
# :new_button # [DONE] | ||
# :button_on_clicked # [DONE] | ||
# :button_set_text # [DONE] | ||
# :button_text # [DONE] | ||
# | ||
# ============================================================================ # | ||
require 'libui' | ||
LibUI.init # Initialize LibUI. | ||
|
||
main_window = LibUI.new_window('button.rb', 400, 240, 1) | ||
|
||
hbox = LibUI.new_horizontal_box | ||
LibUI.box_set_padded(hbox, 1) | ||
|
||
_ = LibUI.new_button # Create a new button here. | ||
LibUI.box_append(hbox, _, 1) # Add the button here. | ||
LibUI.button_set_text(_, 'This is a generic text for the button.') | ||
|
||
puts 'The text for our button is as follows (obtained via LibUI.button_text():' | ||
puts | ||
puts " #{LibUI.button_text(_)}" | ||
puts | ||
|
||
callback_for_the_button = proc { | ||
puts 'I was clicked.' | ||
0 # This return value does not seem to be necessary, but we use it still, to show that one could use a return value here. | ||
} | ||
|
||
LibUI.button_on_clicked(_, callback_for_the_button) | ||
|
||
LibUI.window_set_child(main_window, hbox) | ||
LibUI.control_show(main_window) | ||
|
||
LibUI.window_on_closing(main_window) { | ||
LibUI.quit | ||
1 | ||
} | ||
|
||
LibUI.main | ||
LibUI.uninit |