glimmer-dsl-libui 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +279 -282
- data/VERSION +1 -1
- data/examples/cpu_percentage.rb +36 -0
- data/examples/snake2.rb +97 -0
- data/examples/tic_tac_toe.rb +1 -0
- data/examples/tic_tac_toe2.rb +84 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3bdea12bc1f9ff1798491a5637c598e0e1e9448d8cb3e5e2cd194b77ad8d95a
|
4
|
+
data.tar.gz: f704324045b58a3372d5ffe7893642fa953ac5f00edded4171b96272ec0c792b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 671a20f2ea32891bb02a8c0167ca6ae4018f2a012168358311e5fd2f978e72c505452374cec6cf287eee5ada148b332fc641e4eb396e731e19b64d58c69406d8
|
7
|
+
data.tar.gz: c6f60d658ed413eca1c69fde9423916457c77718d206000428733e232be506ab4631b57b66489b476c41e0b7c994dca42d59422da8cedfc273a688418d8a3988
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.4.10
|
4
|
+
|
5
|
+
- examples/cpu_percentage.rb
|
6
|
+
- Bring back non-data-binding versions of examples/snake.rb and examples/tic_tac_toe.rb for educational purposes
|
7
|
+
|
3
8
|
## 0.4.9
|
4
9
|
|
5
10
|
- Support unidirectional data-binding on all control properties that support bidirectional data-binding
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.4.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.4.10
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -267,6 +267,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
267
267
|
- [Button Counter](#button-counter)
|
268
268
|
- [Color The Circles](#color-the-circles)
|
269
269
|
- [Control Gallery](#control-gallery)
|
270
|
+
- [CPU Percentage](#cpu-percentage)
|
270
271
|
- [Custom Draw Text](#custom-draw-text)
|
271
272
|
- [Dynamic Area](#dynamic-area)
|
272
273
|
- [Editable Column Table](#editable-column-table)
|
@@ -373,7 +374,7 @@ gem install glimmer-dsl-libui
|
|
373
374
|
Or install via Bundler `Gemfile`:
|
374
375
|
|
375
376
|
```ruby
|
376
|
-
gem 'glimmer-dsl-libui', '~> 0.4.
|
377
|
+
gem 'glimmer-dsl-libui', '~> 0.4.10'
|
377
378
|
```
|
378
379
|
|
379
380
|
Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
|
@@ -627,11 +628,11 @@ class FormTable
|
|
627
628
|
|
628
629
|
def initialize
|
629
630
|
@data = [
|
630
|
-
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'
|
631
|
-
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'
|
632
|
-
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'
|
633
|
-
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'
|
634
|
-
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'
|
631
|
+
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'],
|
632
|
+
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'],
|
633
|
+
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'],
|
634
|
+
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'],
|
635
|
+
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'],
|
635
636
|
]
|
636
637
|
end
|
637
638
|
|
@@ -1398,7 +1399,7 @@ Data-binding supports utilizing the [MVP (Model View Presenter)](https://en.wiki
|
|
1398
1399
|
- `search_entry`: `text`
|
1399
1400
|
- `slider`: `value`
|
1400
1401
|
- `spinbox`: `value`
|
1401
|
-
- `table`: `cell_rows` (explicit data-binding using `<=>` and [implicit data-binding](#table-api) by assigning value directly)
|
1402
|
+
- `table`: `cell_rows` (explicit data-binding by using `<=>` and [implicit data-binding](#table-api) by assigning value directly)
|
1402
1403
|
- `time_picker`: `time`
|
1403
1404
|
|
1404
1405
|
Example of bidirectional data-binding:
|
@@ -1494,268 +1495,7 @@ Learn more from data-binding usage in [Login](#login) (4 data-binding versions),
|
|
1494
1495
|
### Original API
|
1495
1496
|
|
1496
1497
|
Here are all the lower-level [LibUI](https://github.com/kojix2/LibUI) API methods utilized by [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui):
|
1497
|
-
|
1498
|
-
- `area_begin_user_window_move`
|
1499
|
-
- `area_begin_user_window_resize`
|
1500
|
-
- `area_queue_redraw_all`
|
1501
|
-
- `area_scroll_to`
|
1502
|
-
- `area_set_size`
|
1503
|
-
- `attribute_color`
|
1504
|
-
- `attribute_family`
|
1505
|
-
- `attribute_features`
|
1506
|
-
- `attribute_get_type`
|
1507
|
-
- `attribute_italic`
|
1508
|
-
- `attribute_size`
|
1509
|
-
- `attribute_stretch`
|
1510
|
-
- `attribute_underline`
|
1511
|
-
- `attribute_underline_color`
|
1512
|
-
- `attribute_weight`
|
1513
|
-
- `attributed_string_append_unattributed`
|
1514
|
-
- `attributed_string_byte_index_to_grapheme`
|
1515
|
-
- `attributed_string_delete`
|
1516
|
-
- `attributed_string_for_each_attribute`
|
1517
|
-
- `attributed_string_grapheme_to_byte_index`
|
1518
|
-
- `attributed_string_insert_at_unattributed`
|
1519
|
-
- `attributed_string_len`
|
1520
|
-
- `attributed_string_num_graphemes`
|
1521
|
-
- `attributed_string_set_attribute`
|
1522
|
-
- `attributed_string_string`
|
1523
|
-
- `box_append`
|
1524
|
-
- `box_delete`
|
1525
|
-
- `box_padded`
|
1526
|
-
- `box_set_padded`
|
1527
|
-
- `button_on_clicked`
|
1528
|
-
- `button_set_text`
|
1529
|
-
- `button_text`
|
1530
|
-
- `checkbox_checked`
|
1531
|
-
- `checkbox_on_toggled`
|
1532
|
-
- `checkbox_set_checked`
|
1533
|
-
- `checkbox_set_text`
|
1534
|
-
- `checkbox_text`
|
1535
|
-
- `color_button_color`
|
1536
|
-
- `color_button_on_changed`
|
1537
|
-
- `color_button_set_color`
|
1538
|
-
- `combobox_append`
|
1539
|
-
- `combobox_on_selected`
|
1540
|
-
- `combobox_selected`
|
1541
|
-
- `combobox_set_selected`
|
1542
|
-
- `control_destroy`
|
1543
|
-
- `control_disable`
|
1544
|
-
- `control_enable`
|
1545
|
-
- `control_enabled`
|
1546
|
-
- `control_enabled_to_user`
|
1547
|
-
- `control_handle`
|
1548
|
-
- `control_hide`
|
1549
|
-
- `control_parent`
|
1550
|
-
- `control_set_parent`
|
1551
|
-
- `control_show`
|
1552
|
-
- `control_toplevel`
|
1553
|
-
- `control_verify_set_parent`
|
1554
|
-
- `control_visible`
|
1555
|
-
- `date_time_picker_on_changed`
|
1556
|
-
- `date_time_picker_set_time`
|
1557
|
-
- `date_time_picker_time`
|
1558
|
-
- `draw_clip`
|
1559
|
-
- `draw_fill`
|
1560
|
-
- `draw_free_path`
|
1561
|
-
- `draw_free_text_layout`
|
1562
|
-
- `draw_matrix_invert`
|
1563
|
-
- `draw_matrix_invertible`
|
1564
|
-
- `draw_matrix_multiply`
|
1565
|
-
- `draw_matrix_rotate`
|
1566
|
-
- `draw_matrix_scale`
|
1567
|
-
- `draw_matrix_set_identity`
|
1568
|
-
- `draw_matrix_skew`
|
1569
|
-
- `draw_matrix_transform_point`
|
1570
|
-
- `draw_matrix_transform_size`
|
1571
|
-
- `draw_matrix_translate`
|
1572
|
-
- `draw_new_path`
|
1573
|
-
- `draw_new_text_layout`
|
1574
|
-
- `draw_path_add_rectangle`
|
1575
|
-
- `draw_path_arc_to`
|
1576
|
-
- `draw_path_bezier_to`
|
1577
|
-
- `draw_path_close_figure`
|
1578
|
-
- `draw_path_end`
|
1579
|
-
- `draw_path_line_to`
|
1580
|
-
- `draw_path_new_figure`
|
1581
|
-
- `draw_path_new_figure_with_arc`
|
1582
|
-
- `draw_restore`
|
1583
|
-
- `draw_save`
|
1584
|
-
- `draw_stroke`
|
1585
|
-
- `draw_text`
|
1586
|
-
- `draw_text_layout_extents`
|
1587
|
-
- `draw_transform`
|
1588
|
-
- `editable_combobox_append`
|
1589
|
-
- `editable_combobox_on_changed`
|
1590
|
-
- `editable_combobox_set_text`
|
1591
|
-
- `editable_combobox_text`
|
1592
|
-
- `entry_on_changed`
|
1593
|
-
- `entry_read_only`
|
1594
|
-
- `entry_set_read_only`
|
1595
|
-
- `entry_set_text`
|
1596
|
-
- `entry_text`
|
1597
|
-
- `ffi_lib`
|
1598
|
-
- `ffi_lib=`
|
1599
|
-
- `font_button_font`
|
1600
|
-
- `font_button_on_changed`
|
1601
|
-
- `form_append`
|
1602
|
-
- `form_delete`
|
1603
|
-
- `form_padded`
|
1604
|
-
- `form_set_padded`
|
1605
|
-
- `free_attribute`
|
1606
|
-
- `free_attributed_string`
|
1607
|
-
- `free_control`
|
1608
|
-
- `free_font_button_font`
|
1609
|
-
- `free_image`
|
1610
|
-
- `free_init_error`
|
1611
|
-
- `free_open_type_features`
|
1612
|
-
- `free_table_model`
|
1613
|
-
- `free_table_value`
|
1614
|
-
- `free_text`
|
1615
|
-
- `grid_append`
|
1616
|
-
- `grid_insert_at`
|
1617
|
-
- `grid_padded`
|
1618
|
-
- `grid_set_padded`
|
1619
|
-
- `group_margined`
|
1620
|
-
- `group_set_child`
|
1621
|
-
- `group_set_margined`
|
1622
|
-
- `group_set_title`
|
1623
|
-
- `group_title`
|
1624
|
-
- `image_append`
|
1625
|
-
- `init`
|
1626
|
-
- `label_set_text`
|
1627
|
-
- `label_text`
|
1628
|
-
- `main`
|
1629
|
-
- `main_step`
|
1630
|
-
- `main_steps`
|
1631
|
-
- `menu_append_about_item`
|
1632
|
-
- `menu_append_check_item`
|
1633
|
-
- `menu_append_item`
|
1634
|
-
- `menu_append_preferences_item`
|
1635
|
-
- `menu_append_quit_item`
|
1636
|
-
- `menu_append_separator`
|
1637
|
-
- `menu_item_checked`
|
1638
|
-
- `menu_item_disable`
|
1639
|
-
- `menu_item_enable`
|
1640
|
-
- `menu_item_on_clicked`
|
1641
|
-
- `menu_item_set_checked`
|
1642
|
-
- `msg_box`
|
1643
|
-
- `msg_box_error`
|
1644
|
-
- `multiline_entry_append`
|
1645
|
-
- `multiline_entry_on_changed`
|
1646
|
-
- `multiline_entry_read_only`
|
1647
|
-
- `multiline_entry_set_read_only`
|
1648
|
-
- `multiline_entry_set_text`
|
1649
|
-
- `multiline_entry_text`
|
1650
|
-
- `new_area`
|
1651
|
-
- `new_attributed_string`
|
1652
|
-
- `new_background_attribute`
|
1653
|
-
- `new_button`
|
1654
|
-
- `new_checkbox`
|
1655
|
-
- `new_color_attribute`
|
1656
|
-
- `new_color_button`
|
1657
|
-
- `new_combobox`
|
1658
|
-
- `new_date_picker`
|
1659
|
-
- `new_date_time_picker`
|
1660
|
-
- `new_editable_combobox`
|
1661
|
-
- `new_entry`
|
1662
|
-
- `new_family_attribute`
|
1663
|
-
- `new_features_attribute`
|
1664
|
-
- `new_font_button`
|
1665
|
-
- `new_form`
|
1666
|
-
- `new_grid`
|
1667
|
-
- `new_group`
|
1668
|
-
- `new_horizontal_box`
|
1669
|
-
- `new_horizontal_separator`
|
1670
|
-
- `new_image`
|
1671
|
-
- `new_italic_attribute`
|
1672
|
-
- `new_label`
|
1673
|
-
- `new_menu`
|
1674
|
-
- `new_multiline_entry`
|
1675
|
-
- `new_non_wrapping_multiline_entry`
|
1676
|
-
- `new_open_type_features`
|
1677
|
-
- `new_password_entry`
|
1678
|
-
- `new_progress_bar`
|
1679
|
-
- `new_radio_buttons`
|
1680
|
-
- `new_scrolling_area`
|
1681
|
-
- `new_search_entry`
|
1682
|
-
- `new_size_attribute`
|
1683
|
-
- `new_slider`
|
1684
|
-
- `new_spinbox`
|
1685
|
-
- `new_stretch_attribute`
|
1686
|
-
- `new_tab`
|
1687
|
-
- `new_table`
|
1688
|
-
- `new_table_model`
|
1689
|
-
- `new_table_value_color`
|
1690
|
-
- `new_table_value_image`
|
1691
|
-
- `new_table_value_int`
|
1692
|
-
- `new_table_value_string`
|
1693
|
-
- `new_time_picker`
|
1694
|
-
- `new_underline_attribute`
|
1695
|
-
- `new_underline_color_attribute`
|
1696
|
-
- `new_vertical_box`
|
1697
|
-
- `new_vertical_separator`
|
1698
|
-
- `new_weight_attribute`
|
1699
|
-
- `new_window`
|
1700
|
-
- `on_should_quit`
|
1701
|
-
- `open_file`
|
1702
|
-
- `open_type_features_add`
|
1703
|
-
- `open_type_features_clone`
|
1704
|
-
- `open_type_features_for_each`
|
1705
|
-
- `open_type_features_get`
|
1706
|
-
- `open_type_features_remove`
|
1707
|
-
- `progress_bar_set_value`
|
1708
|
-
- `progress_bar_value`
|
1709
|
-
- `queue_main`
|
1710
|
-
- `quit`
|
1711
|
-
- `radio_buttons_append`
|
1712
|
-
- `radio_buttons_on_selected`
|
1713
|
-
- `radio_buttons_selected`
|
1714
|
-
- `radio_buttons_set_selected`
|
1715
|
-
- `save_file`
|
1716
|
-
- `slider_on_changed`
|
1717
|
-
- `slider_set_value`
|
1718
|
-
- `slider_value`
|
1719
|
-
- `spinbox_on_changed`
|
1720
|
-
- `spinbox_set_value`
|
1721
|
-
- `spinbox_value`
|
1722
|
-
- `tab_append`
|
1723
|
-
- `tab_delete`
|
1724
|
-
- `tab_insert_at`
|
1725
|
-
- `tab_margined`
|
1726
|
-
- `tab_num_pages`
|
1727
|
-
- `tab_set_margined`
|
1728
|
-
- `table_append_button_column`
|
1729
|
-
- `table_append_checkbox_column`
|
1730
|
-
- `table_append_checkbox_text_column`
|
1731
|
-
- `table_append_image_column`
|
1732
|
-
- `table_append_image_text_column`
|
1733
|
-
- `table_append_progress_bar_column`
|
1734
|
-
- `table_append_text_column`
|
1735
|
-
- `table_model_row_changed`
|
1736
|
-
- `table_model_row_deleted`
|
1737
|
-
- `table_model_row_inserted`
|
1738
|
-
- `table_value_color`
|
1739
|
-
- `table_value_get_type`
|
1740
|
-
- `table_value_image`
|
1741
|
-
- `table_value_int`
|
1742
|
-
- `table_value_string`
|
1743
|
-
- `timer`
|
1744
|
-
- `uninit`
|
1745
|
-
- `user_bug_cannot_set_parent_on_toplevel`
|
1746
|
-
- `window_borderless`
|
1747
|
-
- `window_content_size`
|
1748
|
-
- `window_fullscreen`
|
1749
|
-
- `window_margined`
|
1750
|
-
- `window_on_closing`
|
1751
|
-
- `window_on_content_size_changed`
|
1752
|
-
- `window_set_borderless`
|
1753
|
-
- `window_set_child`
|
1754
|
-
- `window_set_content_size`
|
1755
|
-
- `window_set_fullscreen`
|
1756
|
-
- `window_set_margined`
|
1757
|
-
- `window_set_title`
|
1758
|
-
- `window_title`
|
1498
|
+
`alloc_control`, `append_features`, `area_begin_user_window_move`, `area_begin_user_window_resize`, `area_queue_redraw_all`, `area_scroll_to`, `area_set_size`, `attribute_color`, `attribute_family`, `attribute_features`, `attribute_get_type`, `attribute_italic`, `attribute_size`, `attribute_stretch`, `attribute_underline`, `attribute_underline_color`, `attribute_weight`, `attributed_string_append_unattributed`, `attributed_string_byte_index_to_grapheme`, `attributed_string_delete`, `attributed_string_for_each_attribute`, `attributed_string_grapheme_to_byte_index`, `attributed_string_insert_at_unattributed`, `attributed_string_len`, `attributed_string_num_graphemes`, `attributed_string_set_attribute`, `attributed_string_string`, `box_append`, `box_delete`, `box_padded`, `box_set_padded`, `button_on_clicked`, `button_set_text`, `button_text`, `checkbox_checked`, `checkbox_on_toggled`, `checkbox_set_checked`, `checkbox_set_text`, `checkbox_text`, `color_button_color`, `color_button_on_changed`, `color_button_set_color`, `combobox_append`, `combobox_on_selected`, `combobox_selected`, `combobox_set_selected`, `control_destroy`, `control_disable`, `control_enable`, `control_enabled`, `control_enabled_to_user`, `control_handle`, `control_hide`, `control_parent`, `control_set_parent`, `control_show`, `control_toplevel`, `control_verify_set_parent`, `control_visible`, `date_time_picker_on_changed`, `date_time_picker_set_time`, `date_time_picker_time`, `draw_clip`, `draw_fill`, `draw_free_path`, `draw_free_text_layout`, `draw_matrix_invert`, `draw_matrix_invertible`, `draw_matrix_multiply`, `draw_matrix_rotate`, `draw_matrix_scale`, `draw_matrix_set_identity`, `draw_matrix_skew`, `draw_matrix_transform_point`, `draw_matrix_transform_size`, `draw_matrix_translate`, `draw_new_path`, `draw_new_text_layout`, `draw_path_add_rectangle`, `draw_path_arc_to`, `draw_path_bezier_to`, `draw_path_close_figure`, `draw_path_end`, `draw_path_line_to`, `draw_path_new_figure`, `draw_path_new_figure_with_arc`, `draw_restore`, `draw_save`, `draw_stroke`, `draw_text`, `draw_text_layout_extents`, `draw_transform`, `editable_combobox_append`, `editable_combobox_on_changed`, `editable_combobox_set_text`, `editable_combobox_text`, `entry_on_changed`, `entry_read_only`, `entry_set_read_only`, `entry_set_text`, `entry_text`, `ffi_lib`, `ffi_lib=`, `font_button_font`, `font_button_on_changed`, `form_append`, `form_delete`, `form_padded`, `form_set_padded`, `free_attribute`, `free_attributed_string`, `free_control`, `free_font_button_font`, `free_image`, `free_init_error`, `free_open_type_features`, `free_table_model`, `free_table_value`, `free_text`, `grid_append`, `grid_insert_at`, `grid_padded`, `grid_set_padded`, `group_margined`, `group_set_child`, `group_set_margined`, `group_set_title`, `group_title`, `image_append`, `init`, `label_set_text`, `label_text`, `main`, `main_step`, `main_steps`, `menu_append_about_item`, `menu_append_check_item`, `menu_append_item`, `menu_append_preferences_item`, `menu_append_quit_item`, `menu_append_separator`, `menu_item_checked`, `menu_item_disable`, `menu_item_enable`, `menu_item_on_clicked`, `menu_item_set_checked`, `msg_box`, `msg_box_error`, `multiline_entry_append`, `multiline_entry_on_changed`, `multiline_entry_read_only`, `multiline_entry_set_read_only`, `multiline_entry_set_text`, `multiline_entry_text`, `new_area`, `new_attributed_string`, `new_background_attribute`, `new_button`, `new_checkbox`, `new_color_attribute`, `new_color_button`, `new_combobox`, `new_date_picker`, `new_date_time_picker`, `new_editable_combobox`, `new_entry`, `new_family_attribute`, `new_features_attribute`, `new_font_button`, `new_form`, `new_grid`, `new_group`, `new_horizontal_box`, `new_horizontal_separator`, `new_image`, `new_italic_attribute`, `new_label`, `new_menu`, `new_multiline_entry`, `new_non_wrapping_multiline_entry`, `new_open_type_features`, `new_password_entry`, `new_progress_bar`, `new_radio_buttons`, `new_scrolling_area`, `new_search_entry`, `new_size_attribute`, `new_slider`, `new_spinbox`, `new_stretch_attribute`, `new_tab`, `new_table`, `new_table_model`, `new_table_value_color`, `new_table_value_image`, `new_table_value_int`, `new_table_value_string`, `new_time_picker`, `new_underline_attribute`, `new_underline_color_attribute`, `new_vertical_box`, `new_vertical_separator`, `new_weight_attribute`, `new_window`, `on_should_quit`, `open_file`, `open_type_features_add`, `open_type_features_clone`, `open_type_features_for_each`, `open_type_features_get`, `open_type_features_remove`, `progress_bar_set_value`, `progress_bar_value`, `queue_main`, `quit`, `radio_buttons_append`, `radio_buttons_on_selected`, `radio_buttons_selected`, `radio_buttons_set_selected`, `save_file`, `slider_on_changed`, `slider_set_value`, `slider_value`, `spinbox_on_changed`, `spinbox_set_value`, `spinbox_value`, `tab_append`, `tab_delete`, `tab_insert_at`, `tab_margined`, `tab_num_pages`, `tab_set_margined`, `table_append_button_column`, `table_append_checkbox_column`, `table_append_checkbox_text_column`, `table_append_image_column`, `table_append_image_text_column`, `table_append_progress_bar_column`, `table_append_text_column`, `table_model_row_changed`, `table_model_row_deleted`, `table_model_row_inserted`, `table_value_color`, `table_value_get_type`, `table_value_image`, `table_value_int`, `table_value_string`, `timer`, `uninit`, `user_bug_cannot_set_parent_on_toplevel`, `window_borderless`, `window_content_size`, `window_fullscreen`, `window_margined`, `window_on_closing`, `window_on_content_size_changed`, `window_set_borderless`, `window_set_child`, `window_set_content_size`, `window_set_fullscreen`, `window_set_margined`, `window_set_title`, `window_title`
|
1759
1499
|
|
1760
1500
|
To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui):
|
1761
1501
|
- Check out [LibUI ffi.rb](https://github.com/kojix2/LibUI/blob/main/lib/libui/ffi.rb)
|
@@ -5748,6 +5488,71 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
|
|
5748
5488
|
MAIN_WINDOW.show
|
5749
5489
|
```
|
5750
5490
|
|
5491
|
+
#### CPU Percentage
|
5492
|
+
|
5493
|
+
This example shows CPU usage percentage second by second.
|
5494
|
+
|
5495
|
+
Note that it is highly dependent on low-level OS terminal commands, so if anything changes in their output formatting, the code could break. Please report any issues you might encounter.
|
5496
|
+
|
5497
|
+
[examples/cpu_percentage.rb](examples/cpu_percentage.rb)
|
5498
|
+
|
5499
|
+
Run with this command from the root of the project if you cloned the project:
|
5500
|
+
|
5501
|
+
```
|
5502
|
+
ruby -r './lib/glimmer-dsl-libui' examples/cpu_percentage.rb
|
5503
|
+
```
|
5504
|
+
|
5505
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
5506
|
+
|
5507
|
+
```
|
5508
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/cpu_percentage'"
|
5509
|
+
```
|
5510
|
+
|
5511
|
+
Mac | Windows | Linux
|
5512
|
+
----|---------|------
|
5513
|
+
![glimmer-dsl-libui-mac-cpu-percentage.png](images/glimmer-dsl-libui-mac-cpu-percentage.png) | ![glimmer-dsl-libui-windows-cpu-percentage.png](images/glimmer-dsl-libui-windows-cpu-percentage.png) | ![glimmer-dsl-libui-linux-cpu-percentage.png](images/glimmer-dsl-libui-linux-cpu-percentage.png)
|
5514
|
+
|
5515
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
5516
|
+
|
5517
|
+
```ruby
|
5518
|
+
require 'glimmer-dsl-libui'
|
5519
|
+
require 'bigdecimal'
|
5520
|
+
|
5521
|
+
include Glimmer
|
5522
|
+
|
5523
|
+
data = [
|
5524
|
+
['CPU', '0%', 0],
|
5525
|
+
]
|
5526
|
+
|
5527
|
+
Glimmer::LibUI.timer(1) do
|
5528
|
+
cpu_percentage_value = nil
|
5529
|
+
if OS.windows?
|
5530
|
+
cpu_percentage_raw_value = `wmic cpu get loadpercentage`
|
5531
|
+
cpu_percentage_value = cpu_percentage_raw_value.split("\n")[2].to_i
|
5532
|
+
elsif OS.mac?
|
5533
|
+
cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
|
5534
|
+
elsif OS.linux?
|
5535
|
+
stats = `top -n 1`
|
5536
|
+
idle_percentage = stats.split("\n")[2].match(/ni,.* (.*) .*id/)[1]
|
5537
|
+
cpu_percentage_value = (BigDecimal(100) - BigDecimal(idle_percentage)).to_i
|
5538
|
+
end
|
5539
|
+
data[0][1] = "#{cpu_percentage_value}%"
|
5540
|
+
data[0][2] = cpu_percentage_value
|
5541
|
+
end
|
5542
|
+
|
5543
|
+
window('CPU Percentage', 400, 200) {
|
5544
|
+
vertical_box {
|
5545
|
+
table {
|
5546
|
+
text_column('Name')
|
5547
|
+
text_column('Value')
|
5548
|
+
progress_bar_column('Percentage')
|
5549
|
+
|
5550
|
+
cell_rows data # implicit data-binding
|
5551
|
+
}
|
5552
|
+
}
|
5553
|
+
}.show
|
5554
|
+
```
|
5555
|
+
|
5751
5556
|
#### Custom Draw Text
|
5752
5557
|
|
5753
5558
|
[examples/custom_draw_text.rb](examples/custom_draw_text.rb)
|
@@ -6509,11 +6314,11 @@ class FormTable
|
|
6509
6314
|
|
6510
6315
|
def initialize
|
6511
6316
|
@data = [
|
6512
|
-
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'
|
6513
|
-
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'
|
6514
|
-
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'
|
6515
|
-
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'
|
6516
|
-
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'
|
6317
|
+
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'],
|
6318
|
+
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'],
|
6319
|
+
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'],
|
6320
|
+
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'],
|
6321
|
+
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'],
|
6517
6322
|
]
|
6518
6323
|
end
|
6519
6324
|
|
@@ -6618,11 +6423,11 @@ require 'glimmer-dsl-libui'
|
|
6618
6423
|
include Glimmer
|
6619
6424
|
|
6620
6425
|
data = [
|
6621
|
-
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'
|
6622
|
-
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'
|
6623
|
-
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'
|
6624
|
-
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'
|
6625
|
-
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'
|
6426
|
+
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO'],
|
6427
|
+
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA'],
|
6428
|
+
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL'],
|
6429
|
+
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA'],
|
6430
|
+
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'],
|
6626
6431
|
]
|
6627
6432
|
|
6628
6433
|
window('Contacts', 600, 600) { |w|
|
@@ -8234,7 +8039,7 @@ Mac | Windows | Linux
|
|
8234
8039
|
----|---------|------
|
8235
8040
|
![glimmer-dsl-libui-mac-snake.png](images/glimmer-dsl-libui-mac-snake.png) ![glimmer-dsl-libui-mac-snake-game-over.png](images/glimmer-dsl-libui-mac-snake-game-over.png) | ![glimmer-dsl-libui-windows-snake.png](images/glimmer-dsl-libui-windows-snake.png) ![glimmer-dsl-libui-windows-snake-game-over.png](images/glimmer-dsl-libui-windows-snake-game-over.png) | ![glimmer-dsl-libui-linux-snake.png](images/glimmer-dsl-libui-linux-snake.png) ![glimmer-dsl-libui-linux-snake-game-over.png](images/glimmer-dsl-libui-linux-snake-game-over.png)
|
8236
8041
|
|
8237
|
-
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
8042
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
8238
8043
|
|
8239
8044
|
```ruby
|
8240
8045
|
require 'glimmer-dsl-libui'
|
@@ -8326,6 +8131,108 @@ end
|
|
8326
8131
|
Snake.new.launch
|
8327
8132
|
```
|
8328
8133
|
|
8134
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (without [data-binding](#data-binding)):
|
8135
|
+
|
8136
|
+
```ruby
|
8137
|
+
require 'glimmer-dsl-libui'
|
8138
|
+
|
8139
|
+
require_relative 'snake/presenter/grid'
|
8140
|
+
|
8141
|
+
class Snake
|
8142
|
+
include Glimmer
|
8143
|
+
|
8144
|
+
CELL_SIZE = 15
|
8145
|
+
SNAKE_MOVE_DELAY = 0.1
|
8146
|
+
|
8147
|
+
def initialize
|
8148
|
+
@game = Model::Game.new
|
8149
|
+
@grid = Presenter::Grid.new(@game)
|
8150
|
+
@game.start
|
8151
|
+
@keypress_queue = []
|
8152
|
+
create_gui
|
8153
|
+
register_observers
|
8154
|
+
end
|
8155
|
+
|
8156
|
+
def launch
|
8157
|
+
@main_window.show
|
8158
|
+
end
|
8159
|
+
|
8160
|
+
def register_observers
|
8161
|
+
@game.height.times do |row|
|
8162
|
+
@game.width.times do |column|
|
8163
|
+
observe(@grid.cells[row][column], :color) do |new_color|
|
8164
|
+
@cell_grid[row][column].fill = new_color
|
8165
|
+
end
|
8166
|
+
end
|
8167
|
+
end
|
8168
|
+
|
8169
|
+
observe(@game, :over) do |game_over|
|
8170
|
+
Glimmer::LibUI.queue_main do
|
8171
|
+
if game_over
|
8172
|
+
msg_box('Game Over!', "Score: #{@game.score} | High Score: #{@game.high_score}")
|
8173
|
+
@game.start
|
8174
|
+
end
|
8175
|
+
end
|
8176
|
+
end
|
8177
|
+
|
8178
|
+
Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
|
8179
|
+
unless @game.over?
|
8180
|
+
process_queued_keypress
|
8181
|
+
@game.snake.move
|
8182
|
+
end
|
8183
|
+
end
|
8184
|
+
end
|
8185
|
+
|
8186
|
+
def process_queued_keypress
|
8187
|
+
# key press queue ensures one turn per snake move to avoid a double-turn resulting in instant death (due to snake illogically going back against itself)
|
8188
|
+
key = @keypress_queue.shift
|
8189
|
+
case [@game.snake.head.orientation, key]
|
8190
|
+
in [:north, :right] | [:east, :down] | [:south, :left] | [:west, :up]
|
8191
|
+
@game.snake.turn_right
|
8192
|
+
in [:north, :left] | [:west, :down] | [:south, :right] | [:east, :up]
|
8193
|
+
@game.snake.turn_left
|
8194
|
+
else
|
8195
|
+
# No Op
|
8196
|
+
end
|
8197
|
+
end
|
8198
|
+
|
8199
|
+
def create_gui
|
8200
|
+
@cell_grid = []
|
8201
|
+
@main_window = window {
|
8202
|
+
# data-bind window title to game score, converting it to a title string on read from the model
|
8203
|
+
title <= [@game, :score, on_read: -> (score) {"Snake (Score: #{@game.score})"}]
|
8204
|
+
content_size @game.width * CELL_SIZE, @game.height * CELL_SIZE
|
8205
|
+
resizable false
|
8206
|
+
|
8207
|
+
vertical_box {
|
8208
|
+
padded false
|
8209
|
+
|
8210
|
+
@game.height.times do |row|
|
8211
|
+
@cell_grid << []
|
8212
|
+
horizontal_box {
|
8213
|
+
padded false
|
8214
|
+
|
8215
|
+
@game.width.times do |column|
|
8216
|
+
area {
|
8217
|
+
@cell_grid.last << square(0, 0, CELL_SIZE) {
|
8218
|
+
fill Presenter::Cell::COLOR_CLEAR
|
8219
|
+
}
|
8220
|
+
|
8221
|
+
on_key_up do |area_key_event|
|
8222
|
+
@keypress_queue << area_key_event[:ext_key]
|
8223
|
+
end
|
8224
|
+
}
|
8225
|
+
end
|
8226
|
+
}
|
8227
|
+
end
|
8228
|
+
}
|
8229
|
+
}
|
8230
|
+
end
|
8231
|
+
end
|
8232
|
+
|
8233
|
+
Snake.new.launch
|
8234
|
+
```
|
8235
|
+
|
8329
8236
|
#### Tetris
|
8330
8237
|
|
8331
8238
|
Glimmer Tetris utilizes many small areas to represent Tetromino blocks because this ensures smaller redraws per tetromino block color change, thus achieving higher performance than redrawing one large area on every little change.
|
@@ -8741,7 +8648,7 @@ Mac | Windows | Linux
|
|
8741
8648
|
----|---------|------
|
8742
8649
|
![glimmer-dsl-libui-mac-tic-tac-toe.png](images/glimmer-dsl-libui-mac-tic-tac-toe.png) ![glimmer-dsl-libui-mac-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-mac-tic-tac-toe-player-o-wins.png) ![glimmer-dsl-libui-mac-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-mac-tic-tac-toe-player-x-wins.png) ![glimmer-dsl-libui-mac-tic-tac-toe-draw.png](images/glimmer-dsl-libui-mac-tic-tac-toe-draw.png) | ![glimmer-dsl-libui-windows-tic-tac-toe.png](images/glimmer-dsl-libui-windows-tic-tac-toe.png) ![glimmer-dsl-libui-windows-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-windows-tic-tac-toe-player-o-wins.png) ![glimmer-dsl-libui-windows-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-windows-tic-tac-toe-player-x-wins.png) ![glimmer-dsl-libui-windows-tic-tac-toe-draw.png](images/glimmer-dsl-libui-windows-tic-tac-toe-draw.png) | ![glimmer-dsl-libui-linux-tic-tac-toe.png](images/glimmer-dsl-libui-linux-tic-tac-toe.png) ![glimmer-dsl-libui-linux-tic-tac-toe-player-o-wins.png](images/glimmer-dsl-libui-linux-tic-tac-toe-player-o-wins.png) ![glimmer-dsl-libui-linux-tic-tac-toe-player-x-wins.png](images/glimmer-dsl-libui-linux-tic-tac-toe-player-x-wins.png) ![glimmer-dsl-libui-linux-tic-tac-toe-draw.png](images/glimmer-dsl-libui-linux-tic-tac-toe-draw.png)
|
8743
8650
|
|
8744
|
-
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
8651
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
8745
8652
|
|
8746
8653
|
```ruby
|
8747
8654
|
require 'glimmer-dsl-libui'
|
@@ -8787,6 +8694,7 @@ class TicTacToe
|
|
8787
8694
|
text(23, 19) {
|
8788
8695
|
string {
|
8789
8696
|
font family: 'Arial', size: OS.mac? ? 20 : 16
|
8697
|
+
# data-bind string property of area text attributed string to tic tac toe board cell sign
|
8790
8698
|
string <= [@tic_tac_toe_board[row + 1, column + 1], :sign] # board model is 1-based
|
8791
8699
|
}
|
8792
8700
|
}
|
@@ -8820,6 +8728,95 @@ end
|
|
8820
8728
|
TicTacToe.new.launch
|
8821
8729
|
```
|
8822
8730
|
|
8731
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (without [data-binding](#data-binding)):
|
8732
|
+
|
8733
|
+
```ruby
|
8734
|
+
|
8735
|
+
require 'glimmer-dsl-libui'
|
8736
|
+
|
8737
|
+
require_relative "tic_tac_toe/board"
|
8738
|
+
|
8739
|
+
class TicTacToe
|
8740
|
+
include Glimmer
|
8741
|
+
|
8742
|
+
def initialize
|
8743
|
+
@tic_tac_toe_board = Board.new
|
8744
|
+
end
|
8745
|
+
|
8746
|
+
def launch
|
8747
|
+
create_gui
|
8748
|
+
register_observers
|
8749
|
+
@main_window.show
|
8750
|
+
end
|
8751
|
+
|
8752
|
+
def register_observers
|
8753
|
+
observe(@tic_tac_toe_board, :game_status) do |game_status|
|
8754
|
+
display_win_message if game_status == Board::WIN
|
8755
|
+
display_draw_message if game_status == Board::DRAW
|
8756
|
+
end
|
8757
|
+
|
8758
|
+
3.times.map do |row|
|
8759
|
+
3.times.map do |column|
|
8760
|
+
observe(@tic_tac_toe_board[row + 1, column + 1], :sign) do |sign| # board model is 1-based
|
8761
|
+
@cells[row][column].string = sign
|
8762
|
+
end
|
8763
|
+
end
|
8764
|
+
end
|
8765
|
+
end
|
8766
|
+
|
8767
|
+
def create_gui
|
8768
|
+
@main_window = window('Tic-Tac-Toe', 180, 180) {
|
8769
|
+
resizable false
|
8770
|
+
|
8771
|
+
@cells = []
|
8772
|
+
vertical_box {
|
8773
|
+
padded false
|
8774
|
+
|
8775
|
+
3.times.map do |row|
|
8776
|
+
@cells << []
|
8777
|
+
horizontal_box {
|
8778
|
+
padded false
|
8779
|
+
|
8780
|
+
3.times.map do |column|
|
8781
|
+
area {
|
8782
|
+
square(0, 0, 60) {
|
8783
|
+
stroke :black, thickness: 2
|
8784
|
+
}
|
8785
|
+
text(23, 19) {
|
8786
|
+
@cells[row] << string('') {
|
8787
|
+
font family: 'Arial', size: OS.mac? ? 20 : 16
|
8788
|
+
}
|
8789
|
+
}
|
8790
|
+
on_mouse_up do
|
8791
|
+
@tic_tac_toe_board.mark(row + 1, column + 1) # board model is 1-based
|
8792
|
+
end
|
8793
|
+
}
|
8794
|
+
end
|
8795
|
+
}
|
8796
|
+
end
|
8797
|
+
}
|
8798
|
+
}
|
8799
|
+
end
|
8800
|
+
|
8801
|
+
def display_win_message
|
8802
|
+
display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
|
8803
|
+
end
|
8804
|
+
|
8805
|
+
def display_draw_message
|
8806
|
+
display_game_over_message("Draw!")
|
8807
|
+
end
|
8808
|
+
|
8809
|
+
def display_game_over_message(message_text)
|
8810
|
+
Glimmer::LibUI.queue_main do
|
8811
|
+
msg_box('Game Over', message_text)
|
8812
|
+
@tic_tac_toe_board.reset!
|
8813
|
+
end
|
8814
|
+
end
|
8815
|
+
end
|
8816
|
+
|
8817
|
+
TicTacToe.new.launch
|
8818
|
+
```
|
8819
|
+
|
8823
8820
|
#### Timer
|
8824
8821
|
|
8825
8822
|
To run this example, install [TiMidity](http://timidity.sourceforge.net) and ensure `timidity` command is in `PATH` (can be installed via [Homebrew](https://brew.sh) on Mac or [apt-get](https://help.ubuntu.com/community/AptGet/Howto) on Linux).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.10
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
data = [
|
7
|
+
['CPU', '0%', 0],
|
8
|
+
]
|
9
|
+
|
10
|
+
Glimmer::LibUI.timer(1) do
|
11
|
+
cpu_percentage_value = nil
|
12
|
+
if OS.windows?
|
13
|
+
cpu_percentage_raw_value = `wmic cpu get loadpercentage`
|
14
|
+
cpu_percentage_value = cpu_percentage_raw_value.split("\n")[2].to_i
|
15
|
+
elsif OS.mac?
|
16
|
+
cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
|
17
|
+
elsif OS.linux?
|
18
|
+
stats = `top -n 1`
|
19
|
+
idle_percentage = stats.split("\n")[2].match(/ni,.* (.*) .*id/)[1]
|
20
|
+
cpu_percentage_value = (BigDecimal(100) - BigDecimal(idle_percentage)).to_i
|
21
|
+
end
|
22
|
+
data[0][1] = "#{cpu_percentage_value}%"
|
23
|
+
data[0][2] = cpu_percentage_value
|
24
|
+
end
|
25
|
+
|
26
|
+
window('CPU Percentage', 400, 200) {
|
27
|
+
vertical_box {
|
28
|
+
table {
|
29
|
+
text_column('Name')
|
30
|
+
text_column('Value')
|
31
|
+
progress_bar_column('Percentage')
|
32
|
+
|
33
|
+
cell_rows data # implicit data-binding
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}.show
|
data/examples/snake2.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
require_relative 'snake/presenter/grid'
|
4
|
+
|
5
|
+
class Snake
|
6
|
+
include Glimmer
|
7
|
+
|
8
|
+
CELL_SIZE = 15
|
9
|
+
SNAKE_MOVE_DELAY = 0.1
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@game = Model::Game.new
|
13
|
+
@grid = Presenter::Grid.new(@game)
|
14
|
+
@game.start
|
15
|
+
@keypress_queue = []
|
16
|
+
create_gui
|
17
|
+
register_observers
|
18
|
+
end
|
19
|
+
|
20
|
+
def launch
|
21
|
+
@main_window.show
|
22
|
+
end
|
23
|
+
|
24
|
+
def register_observers
|
25
|
+
@game.height.times do |row|
|
26
|
+
@game.width.times do |column|
|
27
|
+
observe(@grid.cells[row][column], :color) do |new_color|
|
28
|
+
@cell_grid[row][column].fill = new_color
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
observe(@game, :over) do |game_over|
|
34
|
+
Glimmer::LibUI.queue_main do
|
35
|
+
if game_over
|
36
|
+
msg_box('Game Over!', "Score: #{@game.score} | High Score: #{@game.high_score}")
|
37
|
+
@game.start
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
|
43
|
+
unless @game.over?
|
44
|
+
process_queued_keypress
|
45
|
+
@game.snake.move
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_queued_keypress
|
51
|
+
# key press queue ensures one turn per snake move to avoid a double-turn resulting in instant death (due to snake illogically going back against itself)
|
52
|
+
key = @keypress_queue.shift
|
53
|
+
case [@game.snake.head.orientation, key]
|
54
|
+
in [:north, :right] | [:east, :down] | [:south, :left] | [:west, :up]
|
55
|
+
@game.snake.turn_right
|
56
|
+
in [:north, :left] | [:west, :down] | [:south, :right] | [:east, :up]
|
57
|
+
@game.snake.turn_left
|
58
|
+
else
|
59
|
+
# No Op
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_gui
|
64
|
+
@cell_grid = []
|
65
|
+
@main_window = window {
|
66
|
+
# data-bind window title to game score, converting it to a title string on read from the model
|
67
|
+
title <= [@game, :score, on_read: -> (score) {"Snake (Score: #{@game.score})"}]
|
68
|
+
content_size @game.width * CELL_SIZE, @game.height * CELL_SIZE
|
69
|
+
resizable false
|
70
|
+
|
71
|
+
vertical_box {
|
72
|
+
padded false
|
73
|
+
|
74
|
+
@game.height.times do |row|
|
75
|
+
@cell_grid << []
|
76
|
+
horizontal_box {
|
77
|
+
padded false
|
78
|
+
|
79
|
+
@game.width.times do |column|
|
80
|
+
area {
|
81
|
+
@cell_grid.last << square(0, 0, CELL_SIZE) {
|
82
|
+
fill Presenter::Cell::COLOR_CLEAR
|
83
|
+
}
|
84
|
+
|
85
|
+
on_key_up do |area_key_event|
|
86
|
+
@keypress_queue << area_key_event[:ext_key]
|
87
|
+
end
|
88
|
+
}
|
89
|
+
end
|
90
|
+
}
|
91
|
+
end
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
Snake.new.launch
|
data/examples/tic_tac_toe.rb
CHANGED
@@ -41,6 +41,7 @@ class TicTacToe
|
|
41
41
|
text(23, 19) {
|
42
42
|
string {
|
43
43
|
font family: 'Arial', size: OS.mac? ? 20 : 16
|
44
|
+
# data-bind string property of area text attributed string to tic tac toe board cell sign
|
44
45
|
string <= [@tic_tac_toe_board[row + 1, column + 1], :sign] # board model is 1-based
|
45
46
|
}
|
46
47
|
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
require 'glimmer-dsl-libui'
|
3
|
+
|
4
|
+
require_relative "tic_tac_toe/board"
|
5
|
+
|
6
|
+
class TicTacToe
|
7
|
+
include Glimmer
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@tic_tac_toe_board = Board.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def launch
|
14
|
+
create_gui
|
15
|
+
register_observers
|
16
|
+
@main_window.show
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_observers
|
20
|
+
observe(@tic_tac_toe_board, :game_status) do |game_status|
|
21
|
+
display_win_message if game_status == Board::WIN
|
22
|
+
display_draw_message if game_status == Board::DRAW
|
23
|
+
end
|
24
|
+
|
25
|
+
3.times.map do |row|
|
26
|
+
3.times.map do |column|
|
27
|
+
observe(@tic_tac_toe_board[row + 1, column + 1], :sign) do |sign| # board model is 1-based
|
28
|
+
@cells[row][column].string = sign
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_gui
|
35
|
+
@main_window = window('Tic-Tac-Toe', 180, 180) {
|
36
|
+
resizable false
|
37
|
+
|
38
|
+
@cells = []
|
39
|
+
vertical_box {
|
40
|
+
padded false
|
41
|
+
|
42
|
+
3.times.map do |row|
|
43
|
+
@cells << []
|
44
|
+
horizontal_box {
|
45
|
+
padded false
|
46
|
+
|
47
|
+
3.times.map do |column|
|
48
|
+
area {
|
49
|
+
square(0, 0, 60) {
|
50
|
+
stroke :black, thickness: 2
|
51
|
+
}
|
52
|
+
text(23, 19) {
|
53
|
+
@cells[row] << string('') {
|
54
|
+
font family: 'Arial', size: OS.mac? ? 20 : 16
|
55
|
+
}
|
56
|
+
}
|
57
|
+
on_mouse_up do
|
58
|
+
@tic_tac_toe_board.mark(row + 1, column + 1) # board model is 1-based
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def display_win_message
|
69
|
+
display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
|
70
|
+
end
|
71
|
+
|
72
|
+
def display_draw_message
|
73
|
+
display_game_over_message("Draw!")
|
74
|
+
end
|
75
|
+
|
76
|
+
def display_game_over_message(message_text)
|
77
|
+
Glimmer::LibUI.queue_main do
|
78
|
+
msg_box('Game Over', message_text)
|
79
|
+
@tic_tac_toe_board.reset!
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
TicTacToe.new.launch
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- examples/color_button2.rb
|
251
251
|
- examples/color_the_circles.rb
|
252
252
|
- examples/control_gallery.rb
|
253
|
+
- examples/cpu_percentage.rb
|
253
254
|
- examples/custom_draw_text.rb
|
254
255
|
- examples/custom_draw_text2.rb
|
255
256
|
- examples/date_time_picker.rb
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- examples/snake/model/vertebra.rb
|
289
290
|
- examples/snake/presenter/cell.rb
|
290
291
|
- examples/snake/presenter/grid.rb
|
292
|
+
- examples/snake2.rb
|
291
293
|
- examples/tetris.rb
|
292
294
|
- examples/tetris/model/block.rb
|
293
295
|
- examples/tetris/model/game.rb
|
@@ -296,6 +298,7 @@ files:
|
|
296
298
|
- examples/tic_tac_toe.rb
|
297
299
|
- examples/tic_tac_toe/board.rb
|
298
300
|
- examples/tic_tac_toe/cell.rb
|
301
|
+
- examples/tic_tac_toe2.rb
|
299
302
|
- examples/timer.rb
|
300
303
|
- examples/timer2.rb
|
301
304
|
- glimmer-dsl-libui.gemspec
|