libui_paradise 0.3.9 → 0.4.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +176 -155
- data/bin/libui_message +1 -1
- data/doc/README.gen +175 -85
- data/doc/todo/todo.md +9 -5
- data/lib/libui_paradise/autoinclude.rb +2 -1
- data/lib/libui_paradise/base/base.rb +17 -67
- data/lib/libui_paradise/base_module/base_module.rb +1514 -0
- data/lib/libui_paradise/colours/colours.rb +4 -4
- data/lib/libui_paradise/domain_specific_language/README.md +6 -0
- data/lib/libui_paradise/examples/complex/002_tabs_example.rb +1 -2
- data/lib/libui_paradise/examples/complex/003_open_file_button_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/006_coloured_boxes_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/007_slider_example.rb +10 -4
- data/lib/libui_paradise/examples/complex/008_radio_button_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/009_separator_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/010_table_example.rb +5 -9
- data/lib/libui_paradise/examples/complex/011_two_buttons_showing_how_to_enable_and_disable_them.rb +2 -1
- data/lib/libui_paradise/examples/complex/012_password_entry_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/013_form_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/014_text_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/015_text_view_example.rb +4 -4
- data/lib/libui_paradise/examples/complex/016_grid_example.rb +20 -11
- data/lib/libui_paradise/examples/complex/017_unicode_text_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/018_spinbutton_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/019_combo_box_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/020_checkbox_example.rb +5 -5
- data/lib/libui_paradise/examples/complex/021_font_example.rb +4 -3
- data/lib/libui_paradise/examples/complex/022_simple_notepad_example.rb +3 -3
- data/lib/libui_paradise/examples/complex/023_msg_box_error.rb +5 -5
- data/lib/libui_paradise/examples/complex/024_parse_config_file_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/025_colour_button.rb +1 -1
- data/lib/libui_paradise/examples/complex/026_basic_table_image.rb +5 -8
- data/lib/libui_paradise/examples/complex/027_basic_button_example.rb +3 -3
- data/lib/libui_paradise/examples/complex/028_try_for_automatic_button_press_event_after_a_delay.rb +4 -5
- data/lib/libui_paradise/examples/complex/029_progressbar_example.rb +4 -5
- data/lib/libui_paradise/examples/complex/030_entry_responds_to_comment_as_synonymous_to_the_enter_key_pressed_example.rb +5 -6
- data/lib/libui_paradise/examples/complex/031_notification_functionality_example.rb +3 -2
- data/lib/libui_paradise/examples/complex/032_simple_window_example.rb +2 -1
- data/lib/libui_paradise/examples/complex/033_daemonize_and_exit_after_delay_example.rb +3 -2
- data/lib/libui_paradise/examples/complex/034_bold_text_example.rb +115 -0
- data/lib/libui_paradise/examples/complex/035_parse_into_table_example.rb +109 -0
- data/lib/libui_paradise/examples/simple/001_open_file_example.rb +1 -1
- data/lib/libui_paradise/examples/simple/002_histogram_example.rb +6 -6
- data/lib/libui_paradise/examples/simple/003_fancy_text_example.rb +63 -35
- data/lib/libui_paradise/examples/simple/005_text_drawing_example.rb +3 -3
- data/lib/libui_paradise/examples/simple/007_control_gallery.rb +2 -1
- data/lib/libui_paradise/examples/simple/009_spectrum.rb +7 -1
- data/lib/libui_paradise/examples/simple/012_table_example.rb +5 -5
- data/lib/libui_paradise/examples/simple/013_scrolling_pane_example.rb +28 -0
- data/lib/libui_paradise/examples/simple/014_simple_entry_example.rb +30 -0
- data/lib/libui_paradise/examples/simple/015_slider_example.rb +32 -0
- data/lib/libui_paradise/fiddle/fiddle.rb +771 -636
- data/lib/libui_paradise/libui_classes/button.rb +31 -0
- data/lib/libui_paradise/libui_classes/entry.rb +35 -0
- data/lib/libui_paradise/libui_classes/grid.rb +14 -26
- data/lib/libui_paradise/libui_classes/hbox.rb +39 -0
- data/lib/libui_paradise/libui_classes/libui_classes.rb +9 -1630
- data/lib/libui_paradise/libui_classes/msg_box.rb +121 -0
- data/lib/libui_paradise/libui_classes/msg_box_error.rb +41 -0
- data/lib/libui_paradise/libui_classes/slider.rb +28 -0
- data/lib/libui_paradise/libui_classes/spinbox.rb +48 -0
- data/lib/libui_paradise/libui_classes/vbox.rb +38 -0
- data/lib/libui_paradise/project/project.rb +2 -1
- data/lib/libui_paradise/prototype/prototype.rb +8 -8
- data/lib/libui_paradise/requires/require_the_libui_classes.rb +2 -2
- data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +4 -2
- data/lib/libui_paradise/toplevel_methods/add_to_the_registered_widgets.rb +70 -0
- data/lib/libui_paradise/toplevel_methods/hash_fiddle_pointer_widgets.rb +37 -0
- data/lib/libui_paradise/{extensions → toplevel_methods}/toplevel_counters.rb +26 -1
- data/lib/libui_paradise/toplevel_methods/toplevel_methods.rb +792 -0
- data/lib/libui_paradise/version/version.rb +2 -2
- data/test/testing_generic_window.rb +2 -0
- metadata +22 -8
- data/doc/SNIPPETS.md +0 -65
- data/lib/libui_paradise/extensions/extensions.rb +0 -979
- data/lib/libui_paradise/libui_classes/box.rb +0 -157
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbe4ce296951afeee71f86f5247ff8b3f9b1d0606c37837748a62a6430baafec
|
4
|
+
data.tar.gz: 2edec366d003bd364608162a327473585794d7eb8836d9b35ba7547139d7877e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba3eeb6f909676b603d5ced9bda9561efe965a7935b8073e41a466288c13073f2bd5498831c67c90b4d5eb733325c62a7e573e018857013a8ac089de9f7a46a6
|
7
|
+
data.tar.gz: d44ea32762e050927fa36c6d6302f6ee224066ac117f6b429d89826d5e11b42df4de73aca810b9ad556b4e68aae52efc6730230ca57d0ca9b4ef03ecd1c13c2a
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![forthebadge](https://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/libui_paradise.svg)](https://badge.fury.io/rb/libui_paradise)
|
4
4
|
|
5
|
-
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">
|
5
|
+
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">28.12.2023</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">22:23:45</span> o'clock.
|
6
6
|
|
7
7
|
## The libui_paradise project
|
8
8
|
|
@@ -13,12 +13,12 @@ by me via **gimp** and ImageMagick - the rounded borders were
|
|
13
13
|
done via ImageMagick. You can re-use this image if you would like to,
|
14
14
|
including the colour-pattern, via a **CC BY 3.0** licence. See the following
|
15
15
|
link for that licence: https://creativecommons.org/licenses/by/3.0/. For
|
16
|
-
|
16
|
+
<b>cfdg</b> itself, have a look at: https://www.contextfreeart.org/gallery/)
|
17
17
|
|
18
|
-
The
|
18
|
+
The <b>libui_paradise project</b> aims to enhance the official (upstream)
|
19
19
|
ruby-libui bindings a little bit.
|
20
20
|
|
21
|
-
You can find the upstream ruby-libui bindings, maintained by
|
21
|
+
You can find the upstream ruby-libui bindings, maintained by <b>kojix2</b>,
|
22
22
|
here:
|
23
23
|
|
24
24
|
https://rubygems.org/gems/libui
|
@@ -154,7 +154,7 @@ around one day, that idea should be retained for other GUIs
|
|
154
154
|
in the future.
|
155
155
|
|
156
156
|
It's quite difficult to get GTK and ruby-gtk to work on
|
157
|
-
|
157
|
+
<b>windows</b> - I tried to compile it some weeks ago but I
|
158
158
|
ended up having "missing symbols" error messages afterwards.
|
159
159
|
I managed to get the hello-world.c example working, but the
|
160
160
|
more complicated examples did not work for me.
|
@@ -172,7 +172,7 @@ no binary bundles for ruby-gtk on windows anymore either. I
|
|
172
172
|
assume it is possible if you know msys2, and the windows
|
173
173
|
platform, but I am no expert on either, so ...)
|
174
174
|
|
175
|
-
|
175
|
+
<b>libui</b> is so much simpler to use on windows than GTK,
|
176
176
|
though - just do **gem install libui** and it'll work,
|
177
177
|
as-is. Literally. That's it. I tried it on my windows
|
178
178
|
laptop and it **does** indeed work. That convinced me
|
@@ -286,7 +286,8 @@ sense in this regard.
|
|
286
286
|
|
287
287
|
## How to add a margin in LibUI
|
288
288
|
|
289
|
-
Use
|
289
|
+
Use the following API if you wish to have your main window
|
290
|
+
use a margin:
|
290
291
|
|
291
292
|
LibUI.window_set_margined(MAIN_WINDOW, 1)
|
292
293
|
|
@@ -432,14 +433,19 @@ Or just:
|
|
432
433
|
|
433
434
|
Since as of 2022 I prefer the longer variant, e. g. **LibUI**init. The
|
434
435
|
old UI constant ("alias") will be retained, but new code added to the
|
435
|
-
libui_paradise gem will not use
|
436
|
-
|
437
|
-
|
436
|
+
libui_paradise gem will not use <b>UI</b> - instead the slightly longer
|
437
|
+
<b>LibUI</b> is used.
|
438
|
+
|
439
|
+
Note that since as of <b>December 2023</b>, whenever the libui_paradise
|
440
|
+
gem is required, <b>LibuiParadise.init</b> is automatically called,
|
441
|
+
which in turn invokes LibUI.init. The reason as to why this is
|
442
|
+
the new default is so that we can omit one line of code.
|
443
|
+
|
438
444
|
## Subclassing
|
439
445
|
|
440
446
|
Currently subclassing from LibUI elements does not work - I simply
|
441
|
-
have no idea how to "subclass" from a
|
442
|
-
have to build up a data structure that behaves like
|
447
|
+
have no idea how to "subclass" from a <b>Fiddle::Pointer</b>. Perhaps we
|
448
|
+
have to build up a data structure that behaves like <b>Fiddle::Pointer</b>
|
443
449
|
but also has methods that allow for a more direct 'OOP behaviour'. Has
|
444
450
|
anyone tried this yet? I am scared to try considering I already got
|
445
451
|
segfaults everywhere ...
|
@@ -456,8 +462,8 @@ The following API can be used to create a new scrolling area:
|
|
456
462
|
|
457
463
|
LibUI.new_scrolling_area
|
458
464
|
|
459
|
-
Scrolling areas
|
460
|
-
amount that can be scrolled is determined by the area's
|
465
|
+
<b>Scrolling areas</b> may contain horizontal and vertical scrollbars.
|
466
|
+
The amount that can be scrolled is determined by the area's
|
461
467
|
size, which is decided by the programmer (both when creating
|
462
468
|
the Area and by a call to SetSize). Only a portion of the
|
463
469
|
Area is visible at any time; drawing and mouse events are
|
@@ -465,9 +471,9 @@ automatically adjusted to match what portion is visible,
|
|
465
471
|
so you do not have to worry about scrolling in your
|
466
472
|
event handlers.
|
467
473
|
|
468
|
-
The method LibUI.new_scrolling_area() accepts three arguments
|
474
|
+
The method <b>LibUI.new_scrolling_area()</b> accepts <b>three arguments</b>.
|
469
475
|
The second and third are width and height, respectively
|
470
|
-
(as
|
476
|
+
(as <b>integers</b>).
|
471
477
|
|
472
478
|
The first argument is the area handle. It has the following
|
473
479
|
pointer types (struct):
|
@@ -497,6 +503,12 @@ The <b>handlerDraw() function</b> in C looks like this:
|
|
497
503
|
uiFreeFontButtonFont(&defaultFont);
|
498
504
|
}
|
499
505
|
|
506
|
+
This means that you will have to pass three arguments to
|
507
|
+
this method - all are mandatory. Failure to do so may yield an
|
508
|
+
error message, such as:
|
509
|
+
|
510
|
+
gems/libui-0.1.2.pre/lib/libui/ffi.rb:20:in `call': wrong number of arguments (given 0, expected 3) (ArgumentError)
|
511
|
+
|
500
512
|
The scrollable area may look like this:
|
501
513
|
|
502
514
|
<img src="https://raw.githubusercontent.com/msink/kotlin-libui/master/samples/hello/hello-windows.png">
|
@@ -521,6 +533,7 @@ label / ui_text widget.
|
|
521
533
|
To create a combo-box in vanilla libui, do this in plain ruby-libui:
|
522
534
|
|
523
535
|
alignment = LibUI.new_combobox # Here we actually create the combobox.
|
536
|
+
# Next, we show how to append to a combobox:
|
524
537
|
LibUI.combobox_append(alignment, 'Left')
|
525
538
|
LibUI.combobox_append(alignment, 'Center')
|
526
539
|
LibUI.combobox_append(alignment, 'Right')
|
@@ -552,11 +565,11 @@ For instance:
|
|
552
565
|
|
553
566
|
LibUI.combobox_set_selected(combobox, 0) # The first one will be active too.
|
554
567
|
|
555
|
-
To
|
568
|
+
To <b>query the currently selected value</b>, use:
|
556
569
|
|
557
570
|
LibUI.combobox_selected(pointer)
|
558
571
|
|
559
|
-
This is usually done via a
|
572
|
+
This is usually done via a <b>proc {}</b> object. See kojix2' examples.
|
560
573
|
|
561
574
|
In LibuiParadise a few custom methods were added, such as
|
562
575
|
**.ui_sync_connect()**. This method was added to connect a
|
@@ -582,11 +595,28 @@ To add content to an editable combobox youc an use:
|
|
582
595
|
|
583
596
|
LibUI.append() # .append() adds the named item to the end of the EditableCombobox.
|
584
597
|
|
585
|
-
|
598
|
+
A more concise example for populating a combobox may be
|
599
|
+
this one here:
|
600
|
+
|
601
|
+
combo_box = LibUI.combobox {
|
602
|
+
['combobox Item 1', 'combobox Item 2', 'combobox Item 3']
|
603
|
+
}
|
604
|
+
|
605
|
+
The <b>source code</b> to the combo-box in libui, at the least
|
586
606
|
for UNIX/Linux, can be seen here:
|
587
607
|
|
588
608
|
https://github.com/andlabs/libui/blob/master/unix/combobox.c
|
589
609
|
|
610
|
+
## How to add a libui-widget to the main window - how to designate a child widget:
|
611
|
+
|
612
|
+
LibUI.window_set_child(main_window, button) # Both these widgets have to be created first, of course.
|
613
|
+
|
614
|
+
## LibUI.control_show
|
615
|
+
|
616
|
+
No clue what this does so far.
|
617
|
+
|
618
|
+
LibUI.control_show(main_window)
|
619
|
+
|
590
620
|
## Error messages and ui_error_message
|
591
621
|
|
592
622
|
In LibUI respectively ruby-libui you can display error messages
|
@@ -612,7 +642,7 @@ just a stub though - we may have to research this with better examples.
|
|
612
642
|
|
613
643
|
## Checkboxes in Libui-ng
|
614
644
|
|
615
|
-
A simple checkbox example in
|
645
|
+
A simple checkbox example in <b>plain</b> ruby-libui follows:
|
616
646
|
|
617
647
|
checkbox = LibUI.checkbox('Checkbox')
|
618
648
|
checkbox_toggle_callback = proc { |pointer|
|
@@ -629,8 +659,8 @@ This may look like so on Linux:
|
|
629
659
|
|
630
660
|
<img src="https://i.imgur.com/d7qWalZ.png" style="margin-left: 2em; padding: 4px; border: 1px solid black;">
|
631
661
|
|
632
|
-
To set such a checkbox to the checked-state (that is, as if
|
633
|
-
user clicked on it), use the following method, if you use the
|
662
|
+
To set such a checkbox to the <b>checked-state</b> (that is, as if
|
663
|
+
the user clicked on it), use the following method, if you use the
|
634
664
|
libui_paradise gem:
|
635
665
|
|
636
666
|
checkbox.set_checked(1)
|
@@ -639,8 +669,8 @@ To query its state use:
|
|
639
669
|
|
640
670
|
checked = LibUI.checkbox_checked(pointer) == 1
|
641
671
|
|
642
|
-
To <b>query</b> whether a checkbox is
|
643
|
-
following:
|
672
|
+
To <b>query</b> whether a checkbox is <b>active</b>, use code such as
|
673
|
+
the following:
|
644
674
|
|
645
675
|
checkbox.is_active?
|
646
676
|
checkbox.active?
|
@@ -649,7 +679,7 @@ This depends on the modifications to Fiddler::Pointer, so
|
|
649
679
|
be wary when you use this - there be dragons (perhaps). Most
|
650
680
|
of these modifications are based on **.object_id**, which is
|
651
681
|
registered in a main, toplevel Hash in the
|
652
|
-
|
682
|
+
<b>libui_paradise project</b>. Not very elegant, but simple, and
|
653
683
|
it works (for the most part).
|
654
684
|
|
655
685
|
The toggle-event for a checkbox can be triggered via:
|
@@ -661,23 +691,23 @@ The toggle-event for a checkbox can be triggered via:
|
|
661
691
|
0
|
662
692
|
}
|
663
693
|
|
664
|
-
To respond to on-toggled events
|
694
|
+
To respond to <b>on-toggled events</b>, do use:
|
665
695
|
|
666
696
|
LibUI.checkbox_on_toggled(checkbox, checkbox_toggle_callback, nil)
|
667
697
|
|
668
698
|
## Adding a widget into another widget
|
669
699
|
|
670
|
-
I chose the following
|
700
|
+
I chose the following <b>API</b> for this:
|
671
701
|
|
672
702
|
box1.add(box2, 1)
|
673
703
|
|
674
|
-
Note that this is "cheating" a bit because the method
|
675
|
-
on
|
676
|
-
also seems to work to some extent. Which is amazing ... :-)
|
704
|
+
Note that this is "cheating" a bit because the method <b>.add()</b> is
|
705
|
+
defined on <b>Fiddle::Pointer</b>. That's scary! Segfaults coming your
|
706
|
+
way. But it also seems to work to some extent. Which is amazing ... :-)
|
677
707
|
|
678
708
|
In ruby-gtk it is quite common to use **.add()**. While **.pack_start()**
|
679
709
|
and **.pack_end()** are available in ruby-gtk as well, I think .add() is
|
680
|
-
the simpler name. We just
|
710
|
+
the simpler name. We just <b>add a widget to another widget</b> - job done.
|
681
711
|
|
682
712
|
(I may also use << as alias to .add() and while << is great, remember
|
683
713
|
that it can not easily be used all the time, e. g. box1 << box2 <<
|
@@ -745,8 +775,8 @@ If you use the libui_paradise gem, you can use this:
|
|
745
775
|
|
746
776
|
## Adding a horizontal separator or a vertical separator
|
747
777
|
|
748
|
-
The method
|
749
|
-
first create) a horizontal separator
|
778
|
+
The method <b>LibUI.new_horizontal_separator</b> can be used to add (or
|
779
|
+
rather first create) <b>a horizontal separator</b>.
|
750
780
|
|
751
781
|
You can then add it via .add() or << if you use the libui_paradise
|
752
782
|
project. Alternatively you can use the toplevel method provided by
|
@@ -795,6 +825,10 @@ not necessarily recommending this be done, but **if** you ever have
|
|
795
825
|
such a use case then you can use it - which is another reason why
|
796
826
|
I added this screenshot, so that I don't forget. :)
|
797
827
|
|
828
|
+
The toplevel method <b>LibuiParadise.horizontal_separator()</b>
|
829
|
+
has also been added; it is simply a wrapper towards
|
830
|
+
<b>LibUI.new_horizontal_separator()</b>.
|
831
|
+
|
798
832
|
## Padding elements in LibUI
|
799
833
|
|
800
834
|
The general API for setting padding to a container in LibUI
|
@@ -878,24 +912,38 @@ hand. Only the raw filename will be used, so if you
|
|
878
912
|
have a file at **/tmp/foo/bar.rb** then the title
|
879
913
|
of the window will be **bar.rb**.
|
880
914
|
|
881
|
-
##
|
915
|
+
## Entries in libui (libui-entry)
|
882
916
|
|
883
|
-
|
917
|
+
Let's first show how an <b>entry</b> in libui may look like:
|
884
918
|
|
885
919
|
<img src="https://raw.githubusercontent.com/parro-it/libui-node/master/docs/media/UiEntry.png" style="margin-left:1em">
|
886
920
|
|
887
|
-
Such an entry can be set to be
|
921
|
+
Such an entry can be set to be <b>read only</b> (readOnly: Boolean, aka true or false).
|
922
|
+
This means that it can not be changed by the user; it is then only used to
|
923
|
+
display some content.
|
888
924
|
|
889
|
-
The upstream C code for libui-entry, for
|
925
|
+
The upstream C code for libui-entry, for <b>unix/</b>, can be seen here:
|
890
926
|
|
891
927
|
https://github.com/andlabs/libui/blob/master/unix/entry.c
|
892
928
|
|
929
|
+
To create a new libui-entry, in raw libui-code, use this method:
|
930
|
+
|
931
|
+
LibUI.new_entry
|
932
|
+
entry = LibUI.new_entry # or better, this variant
|
933
|
+
|
893
934
|
In ruby, for the LibUI namespace, you can set text on an entry
|
894
935
|
by calling <b>LibUI.entry_set_text()</b>, such as shown in
|
895
936
|
the following example:
|
896
937
|
|
897
938
|
LibUI.entry_set_text(entry, 'Please enter your feelings')
|
898
939
|
|
940
|
+
If you use the libui_paradise gem, a modification in Fiddle
|
941
|
+
is to allow the method calls called .is_read_only and its
|
942
|
+
alias name, .readonly. This can be called on the entry,
|
943
|
+
such as:
|
944
|
+
|
945
|
+
entry.readonly
|
946
|
+
|
899
947
|
## Borderless windows and fullscreen windows
|
900
948
|
|
901
949
|
A window that is **borderless: true** will not show any title or
|
@@ -905,6 +953,14 @@ To set the main window to full screen (occupy the whole monitor) do:
|
|
905
953
|
|
906
954
|
LibUI.window_set_fullscreen(main_window, 1)
|
907
955
|
|
956
|
+
## How to add a new main window:
|
957
|
+
# width, height, hasMenubar
|
958
|
+
main_window = LibUI.new_window('hello world', 300, 200, 1)
|
959
|
+
|
960
|
+
The source code for this method can be seen here:
|
961
|
+
|
962
|
+
https://raw.githubusercontent.com/libui-ng/libui-ng/master/unix/window.c
|
963
|
+
|
908
964
|
## Spinbutton / Spinbox
|
909
965
|
|
910
966
|
You can use the following API for a spinbox:
|
@@ -959,29 +1015,30 @@ In libui the general API for this is:
|
|
959
1015
|
|
960
1016
|
## Control Gallery
|
961
1017
|
|
962
|
-
Here is an image, from kotlin-libui
|
1018
|
+
Here is an image, from <b>kotlin-libui</b>, how this may look on windows:
|
963
1019
|
|
964
1020
|
<img src="https://raw.githubusercontent.com/msink/kotlin-libui/master/samples/controlgallery/controlgallery-windows7.png" style="margin-left: 2em">
|
965
1021
|
|
966
1022
|
## LibUI.new_button() - how to work with buttons in LibUI in general
|
967
1023
|
|
968
|
-
<b>LibUI.new_button</b> allows us to create a new button via
|
969
|
-
LibUI.
|
1024
|
+
<b>LibUI.new_button</b> allows us to create a new button, via
|
1025
|
+
the LibUI gem maintained by kojix2.
|
970
1026
|
|
971
|
-
Examples for this:
|
1027
|
+
Examples for this, syntax-wise, follow:
|
972
1028
|
|
973
1029
|
button1 = LibUI.new_button('Text')
|
974
1030
|
button2 = LibUI.new_button('▶')
|
975
1031
|
button3 = LibUI.new_button('■') # You can use Unicode / Emojis here just fine.
|
1032
|
+
button3 = LibUI.new_button('♥') # This also gives you a way to do simple GUI elements, thanks to Unicode / Emoji.
|
976
1033
|
|
977
|
-
Now, we need to "tell" this button what to do when it is clicked
|
978
|
-
This is done via
|
1034
|
+
Now, we need to "<i>tell</i>" this button what to do when it is clicked
|
1035
|
+
by the user. This is done via the method <b>LibUI.button_on_clicked()</b>.
|
979
1036
|
|
980
|
-
|
1037
|
+
Usage example:
|
981
1038
|
|
982
|
-
LibUI.button_on_clicked(button)
|
983
|
-
LibUI.msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
|
984
|
-
|
1039
|
+
LibUI.button_on_clicked(button) {
|
1040
|
+
LibUI.msg_box(MAIN_WINDOW, 'Information', 'You clicked the button') # Show a message-box upon clicking this button.
|
1041
|
+
}
|
985
1042
|
|
986
1043
|
## Enabling / Disabling buttons in libui
|
987
1044
|
|
@@ -1127,86 +1184,6 @@ to be simpler for the time being. I may plan to change a lot more one day,
|
|
1127
1184
|
if I ever manage to find out how to simulate proper subclasses via
|
1128
1185
|
Fiddle::Pointer ... :)
|
1129
1186
|
|
1130
|
-
--------------------------------------------------------------------------------
|
1131
|
-
## SNIPPETS.md
|
1132
|
-
|
1133
|
-
Next, the content of the file called **SNIPPETS.md** will be shown. Note
|
1134
|
-
that this file will eventually be integreated into this file, and then
|
1135
|
-
subsequently removed one day.
|
1136
|
-
|
1137
|
-
|
1138
|
-
<pre>
|
1139
|
-
# How to add a new main window:
|
1140
|
-
# width, height, hasMenubar
|
1141
|
-
main_window = UI.new_window('hello world', 300, 200, 1)
|
1142
|
-
|
1143
|
-
Source code:
|
1144
|
-
|
1145
|
-
https://raw.githubusercontent.com/andlabs/libui/master/unix/window.c
|
1146
|
-
|
1147
|
-
# How to add a libui-widget to the main window / Designate a child widget:
|
1148
|
-
|
1149
|
-
UI.window_set_child(main_window, button)
|
1150
|
-
|
1151
|
-
# Act on closing-event (on quit tag):
|
1152
|
-
|
1153
|
-
UI.window_on_closing(main_window) {
|
1154
|
-
puts 'Bye Bye'
|
1155
|
-
UI.control_destroy(main_window)
|
1156
|
-
UI.quit
|
1157
|
-
0
|
1158
|
-
}
|
1159
|
-
# Or simpler:
|
1160
|
-
close_properly(main_window)
|
1161
|
-
|
1162
|
-
# Add the window to the main UI:
|
1163
|
-
|
1164
|
-
UI.control_show(main_window)
|
1165
|
-
main_window.show_the_controls # Or use this one here.
|
1166
|
-
|
1167
|
-
# And the control:
|
1168
|
-
|
1169
|
-
UI.control_show(main_window)
|
1170
|
-
|
1171
|
-
# Using a text-entry (ui entry tag):
|
1172
|
-
|
1173
|
-
text_entry = UI.new_entry
|
1174
|
-
UI.entry_set_text(text_entry, 'Please enter your feelings')
|
1175
|
-
UI.entry_on_changed(text_entry, text_changed_callback, nil)
|
1176
|
-
|
1177
|
-
# To set this on a "multiline entry", aka spanning several
|
1178
|
-
# rows, do use:
|
1179
|
-
UI.multiline_entry_set_text(entry1, 'Yo there')
|
1180
|
-
ui_text_view # an alias used in libui_paradise
|
1181
|
-
|
1182
|
-
text1 = UI.entry_text(entry1) # Obtain text. You may have to call .to_s on it, to guarantee the String.
|
1183
|
-
UI.multiline_entry_text # Obtain the text from a multiline entry.
|
1184
|
-
|
1185
|
-
# Create a combobox (combo tag, combobox tag):
|
1186
|
-
|
1187
|
-
combobox_selected_callback = proc { |ptr|
|
1188
|
-
puts "New combobox selection: #{UI.combobox_selected(ptr)}"
|
1189
|
-
}
|
1190
|
-
cbox = UI.new_combobox
|
1191
|
-
UI.combobox_append(cbox, 'combobox Item 1')
|
1192
|
-
UI.combobox_append(cbox, 'combobox Item 2')
|
1193
|
-
UI.combobox_append(cbox, 'combobox Item 3')
|
1194
|
-
UI.box_append(inner, cbox, 0)
|
1195
|
-
UI.combobox_on_selected(cbox, combobox_selected_callback, nil)
|
1196
|
-
|
1197
|
-
# Or more concise:
|
1198
|
-
combo_box = LibUI.combobox {
|
1199
|
-
['combobox Item 1', 'combobox Item 2', 'combobox Item 3']
|
1200
|
-
}
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
</pre>
|
1206
|
-
|
1207
|
-
|
1208
|
-
--------------------------------------------------------------------------------
|
1209
|
-
|
1210
1187
|
## Advantages and Disadvantages of the libui project
|
1211
1188
|
|
1212
1189
|
It would be unfair to only selectively name advantages but not talk about
|
@@ -1214,29 +1191,31 @@ disadvantages, so this subsection will show some limitations, trade-offs,
|
|
1214
1191
|
constraints and opportunities. This is not complete, but it may become
|
1215
1192
|
somewhat more complete over time. Stay tuned.
|
1216
1193
|
|
1217
|
-
(a) Advantages:
|
1194
|
+
(a) Advantages of LibUI:
|
1218
1195
|
|
1219
|
-
- Works on windows out-of-the-box after
|
1196
|
+
- Works on the windows platform, out-of-the-box, after the libui-gem has been installed.
|
1220
1197
|
- Is super-simple to use compared to other toolkits, including ruby-gtk.
|
1221
|
-
- Super-simple to build up a prototype for a GUI, buttons that work,
|
1222
|
-
|
1223
|
-
IMO.
|
1198
|
+
- Super-simple to build up a prototype for a GUI, buttons that work, spin-boxes, text-views
|
1199
|
+
and so forth. Faster than any other toolkit, IMO.
|
1224
1200
|
- Works cross-platform.
|
1225
1201
|
|
1226
|
-
(b) Disadvantage:
|
1202
|
+
(b) Disadvantage of LibUI:
|
1227
1203
|
|
1228
1204
|
- Limited ability to control the layout and size of widgets.
|
1229
|
-
- May look like utter crap ... :-)
|
1230
|
-
- Some functionality is missing, such as a scrolled-window for every widget
|
1205
|
+
- May look like utter crap on some platforms ... :-)
|
1206
|
+
- Some functionality is flat-out missing, such as a scrolled-window for every widget
|
1207
|
+
or tooltips for every widget.
|
1231
1208
|
- No way to use different fonts in the same application and choosing a font
|
1232
1209
|
is needlessly complicated. (This may not be completely correct, though -
|
1233
|
-
the glimmer-dsl-libui has
|
1210
|
+
the glimmer-dsl-libui has examples that seem to work. But if you ask me
|
1234
1211
|
right now in 2021 how this works via a standalone example then I can
|
1235
1212
|
happily tell you I have absolutely no idea. Which brings me to the
|
1236
|
-
next problem...)
|
1237
|
-
- Lack of documentation. This part is REALLY annoying
|
1213
|
+
next problem ...)
|
1214
|
+
- Lack of documentation overall. This part is REALLY annoying, because there
|
1215
|
+
are only few users, so asking others about documentation when there is nobody
|
1216
|
+
else using it, plan sucks ...
|
1238
1217
|
|
1239
|
-
Some more disadvantages relate to Fiddle::Pointer
|
1218
|
+
Some more disadvantages relate to <b>Fiddle::Pointer</b>. You kind of need to
|
1240
1219
|
know C fairly well as well as the GC in ruby, in order to understand
|
1241
1220
|
what is going on. Since I don't, I hit a dead end, kind of.
|
1242
1221
|
|
@@ -1244,6 +1223,10 @@ This is so far in September 2021. Let's see what the future brings.
|
|
1244
1223
|
Perhaps other toolkits will learn from libui and implement the good
|
1245
1224
|
parts for **their own** widget set.
|
1246
1225
|
|
1226
|
+
Update in December 2023: things improved a bit, so the above is not
|
1227
|
+
100% correct anymore. In particular libui-ng may receive some more
|
1228
|
+
usability-centric updates in the next months.
|
1229
|
+
|
1247
1230
|
## LibuiParadise.parse_this_config_file()
|
1248
1231
|
|
1249
1232
|
This method can be used to parse a .config file. This file should
|
@@ -1293,17 +1276,21 @@ You can also use something like '95%' as input. In that case the
|
|
1293
1276
|
desired value will be calculated depending on the max-resolution
|
1294
1277
|
of the current display. This presently only works on **linux**; if
|
1295
1278
|
someone knows how to make this work on windows and Mac OSX let
|
1296
|
-
me know. (On these systems
|
1297
|
-
value of 1024 for width and 800 for height
|
1279
|
+
me know. (On these two systems the method will instead default
|
1280
|
+
to a hardcoded value of 1024 for width and 800 for height; these
|
1281
|
+
values, I think, are probably fairly safe, to also support older
|
1282
|
+
laptops. Evidently for smartphone devices this won't work, so
|
1283
|
+
if anyone has an idea how to handle this differently let me
|
1284
|
+
know).
|
1298
1285
|
|
1299
1286
|
The following example shows how to use a percentage value:
|
1300
1287
|
|
1301
|
-
set_height('80%')
|
1288
|
+
set_height('80%') # 80% of the max-height.
|
1302
1289
|
|
1303
1290
|
## Coloured Text
|
1304
1291
|
|
1305
1292
|
At this point I only show how this may look on Win7, re-using
|
1306
|
-
the picture the
|
1293
|
+
the picture the <b>kotlin-libui developers</b> made available:
|
1307
1294
|
|
1308
1295
|
<img src="https://raw.githubusercontent.com/msink/kotlin-libui/master/samples/drawtext/drawtext-windows7.png" style="margin-left: 2em">
|
1309
1296
|
|
@@ -1610,8 +1597,8 @@ Available "**new**"-widgets in LibUI:
|
|
1610
1597
|
LibUI.new_weight_attribute
|
1611
1598
|
LibUI.new_form # this is a form
|
1612
1599
|
LibUI.new_size_attribute
|
1613
|
-
LibUI.new_window
|
1614
|
-
LibUI.new_slider # this is a slider
|
1600
|
+
LibUI.new_window # this will create a new window, such as a gtk-window on linux
|
1601
|
+
LibUI.new_slider # this is a slider, allowing the user to set a value via a small GUI-handle
|
1615
1602
|
|
1616
1603
|
## A search entry in LibUI
|
1617
1604
|
|
@@ -1640,9 +1627,18 @@ Example for this:
|
|
1640
1627
|
|
1641
1628
|
## How to to build a menu-interface (menu tag):
|
1642
1629
|
|
1630
|
+
Building a menu in libui is possible by using the method
|
1631
|
+
<b>LibUI.new_menu()</b>.
|
1632
|
+
|
1633
|
+
A more complete example follows:
|
1634
|
+
|
1643
1635
|
help_menu = LibUI.new_menu('Help')
|
1644
1636
|
version_item = LibUI.menu_append_item(help_menu, 'Version')
|
1645
1637
|
|
1638
|
+
On IceWM this may look like this:
|
1639
|
+
|
1640
|
+
<img src="https://i.imgur.com/1rWYcZM.png" style="margin: 1em">
|
1641
|
+
|
1646
1642
|
## Creating a new drawing area in LibUI
|
1647
1643
|
|
1648
1644
|
The following code should suffice:
|
@@ -1684,6 +1680,19 @@ This may look like so on Linux:
|
|
1684
1680
|
|
1685
1681
|
<img src="https://i.imgur.com/GVKPMS7.png" style="margin-left: 3em">
|
1686
1682
|
|
1683
|
+
In raw-libui you instantiate a new slider in this way:
|
1684
|
+
|
1685
|
+
slider = LibUI.new_slider(0, 10)
|
1686
|
+
|
1687
|
+
The two values here, 0 and 10, specify start and end position.
|
1688
|
+
|
1689
|
+
Note that you can also use the block-form rather than use
|
1690
|
+
a proc-callback. Example for this:
|
1691
|
+
|
1692
|
+
LibUI.slider_on_changed(slider1) {|widget|
|
1693
|
+
puts 'The value of the slider was changed.'
|
1694
|
+
}
|
1695
|
+
|
1687
1696
|
## Create a new tabbed notebook:
|
1688
1697
|
|
1689
1698
|
ui_tabs
|
@@ -1878,6 +1887,7 @@ may be helpful.
|
|
1878
1887
|
The API for creating a new grid in libui is quite complex and
|
1879
1888
|
hard to remember:
|
1880
1889
|
|
1890
|
+
# gtk-widget, left, top, xspan, yspan, hexpand, halign, vexpand, valign
|
1881
1891
|
LibUI.grid_append(grid, entry1, 0, 0, 2, 1, 0, 0, 1, 0)
|
1882
1892
|
LibUI.grid_append(grid, text('Yo2'), 1, 0, 1, 1, 0, 0, 1, 0) # text() can be used if you use the libui_paradise gem
|
1883
1893
|
|
@@ -1908,10 +1918,12 @@ The documentation for Go has this signature:
|
|
1908
1918
|
|
1909
1919
|
Append adds the given control to the Grid, at the given coordinate.
|
1910
1920
|
|
1911
|
-
|
1912
|
-
into the grid, so the numbers that follow afterwards are the ones
|
1913
|
-
that are important.
|
1914
|
-
|
1921
|
+
The element called <b>uiControl c</b> refers to the widget that is to be embedded
|
1922
|
+
into the grid-widget, so the numbers that follow afterwards are the ones
|
1923
|
+
that are important.
|
1924
|
+
|
1925
|
+
Let's have a look at these numbers, based on the above API call, and only
|
1926
|
+
list these again, without the <b>()</b> this time, to simplify reading:
|
1915
1927
|
|
1916
1928
|
# left, top, xspan, yspan, hexpand, halign, vexpand, valign
|
1917
1929
|
# 0, 0, 2, 1, 0, 0, 1, 0
|
@@ -1980,12 +1992,13 @@ Usage example for the new API:
|
|
1980
1992
|
{ left: 2, top: 3, xspan: 3, yspan: 3, hexpand: 0, halign: 0, vexpand: 0, valign: 0 }
|
1981
1993
|
)
|
1982
1994
|
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1995
|
+
This again requires more argument, but on the plus side it allows you complete
|
1996
|
+
control over each positional argument.
|
1997
|
+
|
1998
|
+
In the closing days of <b>August 2022</b> I went on to improve the above. Three
|
1999
|
+
new methods were "added" to grid (actually Fiddle::Pointer, but hopefully one
|
2000
|
+
day I can find out how to work on a grid directly in libui; right now I seem
|
2001
|
+
to only have to work with raw pointers, which confuses me).
|
1989
2002
|
|
1990
2003
|
These three methods are:
|
1991
2004
|
|
@@ -2118,6 +2131,14 @@ following simplified method call instead:
|
|
2118
2131
|
"https://github.com/kojix2/libui\n Version #{VERSION}"
|
2119
2132
|
)
|
2120
2133
|
|
2134
|
+
## LibUI.attributed_string_len()
|
2135
|
+
|
2136
|
+
The method LibUI.attributed_string_len() will return an Integer value.
|
2137
|
+
|
2138
|
+
A usage example follows:
|
2139
|
+
|
2140
|
+
start_position = LibUI.attributed_string_len(self)
|
2141
|
+
|
2121
2142
|
## How to create an .exe file on Windows via libui
|
2122
2143
|
|
2123
2144
|
First check: https://github.com/larsch/ocra/
|
data/bin/libui_message
CHANGED