glimmer-dsl-libui 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 979ea7d60d873acdbe09e6ae2ceb48318798fa41ed13bb3a6bc8dcb642933165
4
- data.tar.gz: 7cc05757477a0a42b85a20a6b298c147b5fba948f9e1eedd21701ab392a2d78a
3
+ metadata.gz: 9b5839a358a532ac1bef6daae1352c655beb83586ebaec5310f9ea585560bce2
4
+ data.tar.gz: c624d4787132b6d35e91432b551866515f1d99a29882c4395275752bed58bbf5
5
5
  SHA512:
6
- metadata.gz: 8feb498d6d9eae22df82c9c9e2b0bd12ef11eb1ec9e4f90ac94f7151be28225f7dce775b8352b25ef98e4bc36f2aedd56370a1265a313f0997161396034f16d0
7
- data.tar.gz: f76393bfebc577d9ce5e5add450ee70e337b67e7a63be24f5f91e4180d65c0d72c7236680f5843c446161710961ec51aa6520f037fcdcc0fc617d21ac182b850
6
+ metadata.gz: 5637badd742ecea707c0e0b976f616f99175ff16cd15302d5f9ab5ce8d5beab1684582d061299454599926c9028ec01ec3767e0313f3ed1cb24575c36eb4eee6
7
+ data.tar.gz: 63ffa8f18c75c6aea32e9a9302b3203bd03e011d342d5320d2023709e6dbd949dda89a9afdc282fb53580ddbcce7d2022a0bb484df55f854ab9e100920ed5384
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.4.2
4
+
5
+ - examples/button_counter.rb (takes advantage of unidirectional data-binding)
6
+ - Ensure that upon re-opening `#content {}` of `area`, `path`, shapes, `image`, `table`, `text`, and general controls, `post_add_content` initialization is prevented from running multiple times where inappropriate.
7
+ - Document `LibUI` API methods
8
+ - Fix issue with examples/meta_example.rb showing more versions in counts than available
9
+
3
10
  ## 0.4.1
4
11
 
5
12
  - Document `observe` keyword
@@ -14,7 +21,7 @@
14
21
  - Upgrade to LibUI 0.0.13
15
22
  - Support general control/shape/attributed_string property unidirectional data-binding (with `<=` sign or `<=>`)
16
23
  - Support `observe` DSL keyword for simple model observation outside of GUI (e.g. `observe(model, attribute) { do_something }` )
17
- - Simplify examples/snake.rb with data-binding
24
+ - Simplify examples/snake.rb with data-binding and make smaller (20x20) to be more challenging and fun
18
25
  - Simplify examples/tic_tac_toe.rb with data-binding
19
26
  - Fix issue with `Shape#redraw` method calling `AreaProxy#auto_redraw` instead of `AreaProxy#redraw`
20
27
 
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
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.2
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)
@@ -264,6 +264,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
264
264
  - [Basic Draw Text](#basic-draw-text)
265
265
  - [Advanced Examples](#advanced-examples)
266
266
  - [Area Gallery](#area-gallery)
267
+ - [Button Counter](#button-counter)
267
268
  - [Color The Circles](#color-the-circles)
268
269
  - [Control Gallery](#control-gallery)
269
270
  - [Custom Draw Text](#custom-draw-text)
@@ -372,7 +373,7 @@ gem install glimmer-dsl-libui
372
373
  Or install via Bundler `Gemfile`:
373
374
 
374
375
  ```ruby
375
- gem 'glimmer-dsl-libui', '~> 0.4.1'
376
+ gem 'glimmer-dsl-libui', '~> 0.4.2'
376
377
  ```
377
378
 
378
379
  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.
@@ -1398,6 +1399,270 @@ Learn more from data-binding usage in [Snake](#snake) and [Tic Tac Toe](#tic_tac
1398
1399
 
1399
1400
  ### Original API
1400
1401
 
1402
+ 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):
1403
+ - `alloc_control`
1404
+ - `area_begin_user_window_move`
1405
+ - `area_begin_user_window_resize`
1406
+ - `area_queue_redraw_all`
1407
+ - `area_scroll_to`
1408
+ - `area_set_size`
1409
+ - `attribute_color`
1410
+ - `attribute_family`
1411
+ - `attribute_features`
1412
+ - `attribute_get_type`
1413
+ - `attribute_italic`
1414
+ - `attribute_size`
1415
+ - `attribute_stretch`
1416
+ - `attribute_underline`
1417
+ - `attribute_underline_color`
1418
+ - `attribute_weight`
1419
+ - `attributed_string_append_unattributed`
1420
+ - `attributed_string_byte_index_to_grapheme`
1421
+ - `attributed_string_delete`
1422
+ - `attributed_string_for_each_attribute`
1423
+ - `attributed_string_grapheme_to_byte_index`
1424
+ - `attributed_string_insert_at_unattributed`
1425
+ - `attributed_string_len`
1426
+ - `attributed_string_num_graphemes`
1427
+ - `attributed_string_set_attribute`
1428
+ - `attributed_string_string`
1429
+ - `box_append`
1430
+ - `box_delete`
1431
+ - `box_padded`
1432
+ - `box_set_padded`
1433
+ - `button_on_clicked`
1434
+ - `button_set_text`
1435
+ - `button_text`
1436
+ - `checkbox_checked`
1437
+ - `checkbox_on_toggled`
1438
+ - `checkbox_set_checked`
1439
+ - `checkbox_set_text`
1440
+ - `checkbox_text`
1441
+ - `color_button_color`
1442
+ - `color_button_on_changed`
1443
+ - `color_button_set_color`
1444
+ - `combobox_append`
1445
+ - `combobox_on_selected`
1446
+ - `combobox_selected`
1447
+ - `combobox_set_selected`
1448
+ - `control_destroy`
1449
+ - `control_disable`
1450
+ - `control_enable`
1451
+ - `control_enabled`
1452
+ - `control_enabled_to_user`
1453
+ - `control_handle`
1454
+ - `control_hide`
1455
+ - `control_parent`
1456
+ - `control_set_parent`
1457
+ - `control_show`
1458
+ - `control_toplevel`
1459
+ - `control_verify_set_parent`
1460
+ - `control_visible`
1461
+ - `date_time_picker_on_changed`
1462
+ - `date_time_picker_set_time`
1463
+ - `date_time_picker_time`
1464
+ - `draw_clip`
1465
+ - `draw_fill`
1466
+ - `draw_free_path`
1467
+ - `draw_free_text_layout`
1468
+ - `draw_matrix_invert`
1469
+ - `draw_matrix_invertible`
1470
+ - `draw_matrix_multiply`
1471
+ - `draw_matrix_rotate`
1472
+ - `draw_matrix_scale`
1473
+ - `draw_matrix_set_identity`
1474
+ - `draw_matrix_skew`
1475
+ - `draw_matrix_transform_point`
1476
+ - `draw_matrix_transform_size`
1477
+ - `draw_matrix_translate`
1478
+ - `draw_new_path`
1479
+ - `draw_new_text_layout`
1480
+ - `draw_path_add_rectangle`
1481
+ - `draw_path_arc_to`
1482
+ - `draw_path_bezier_to`
1483
+ - `draw_path_close_figure`
1484
+ - `draw_path_end`
1485
+ - `draw_path_line_to`
1486
+ - `draw_path_new_figure`
1487
+ - `draw_path_new_figure_with_arc`
1488
+ - `draw_restore`
1489
+ - `draw_save`
1490
+ - `draw_stroke`
1491
+ - `draw_text`
1492
+ - `draw_text_layout_extents`
1493
+ - `draw_transform`
1494
+ - `editable_combobox_append`
1495
+ - `editable_combobox_on_changed`
1496
+ - `editable_combobox_set_text`
1497
+ - `editable_combobox_text`
1498
+ - `entry_on_changed`
1499
+ - `entry_read_only`
1500
+ - `entry_set_read_only`
1501
+ - `entry_set_text`
1502
+ - `entry_text`
1503
+ - `ffi_lib`
1504
+ - `ffi_lib=`
1505
+ - `font_button_font`
1506
+ - `font_button_on_changed`
1507
+ - `form_append`
1508
+ - `form_delete`
1509
+ - `form_padded`
1510
+ - `form_set_padded`
1511
+ - `free_attribute`
1512
+ - `free_attributed_string`
1513
+ - `free_control`
1514
+ - `free_font_button_font`
1515
+ - `free_image`
1516
+ - `free_init_error`
1517
+ - `free_open_type_features`
1518
+ - `free_table_model`
1519
+ - `free_table_value`
1520
+ - `free_text`
1521
+ - `grid_append`
1522
+ - `grid_insert_at`
1523
+ - `grid_padded`
1524
+ - `grid_set_padded`
1525
+ - `group_margined`
1526
+ - `group_set_child`
1527
+ - `group_set_margined`
1528
+ - `group_set_title`
1529
+ - `group_title`
1530
+ - `image_append`
1531
+ - `init`
1532
+ - `label_set_text`
1533
+ - `label_text`
1534
+ - `main`
1535
+ - `main_step`
1536
+ - `main_steps`
1537
+ - `menu_append_about_item`
1538
+ - `menu_append_check_item`
1539
+ - `menu_append_item`
1540
+ - `menu_append_preferences_item`
1541
+ - `menu_append_quit_item`
1542
+ - `menu_append_separator`
1543
+ - `menu_item_checked`
1544
+ - `menu_item_disable`
1545
+ - `menu_item_enable`
1546
+ - `menu_item_on_clicked`
1547
+ - `menu_item_set_checked`
1548
+ - `msg_box`
1549
+ - `msg_box_error`
1550
+ - `multiline_entry_append`
1551
+ - `multiline_entry_on_changed`
1552
+ - `multiline_entry_read_only`
1553
+ - `multiline_entry_set_read_only`
1554
+ - `multiline_entry_set_text`
1555
+ - `multiline_entry_text`
1556
+ - `new_area`
1557
+ - `new_attributed_string`
1558
+ - `new_background_attribute`
1559
+ - `new_button`
1560
+ - `new_checkbox`
1561
+ - `new_color_attribute`
1562
+ - `new_color_button`
1563
+ - `new_combobox`
1564
+ - `new_date_picker`
1565
+ - `new_date_time_picker`
1566
+ - `new_editable_combobox`
1567
+ - `new_entry`
1568
+ - `new_family_attribute`
1569
+ - `new_features_attribute`
1570
+ - `new_font_button`
1571
+ - `new_form`
1572
+ - `new_grid`
1573
+ - `new_group`
1574
+ - `new_horizontal_box`
1575
+ - `new_horizontal_separator`
1576
+ - `new_image`
1577
+ - `new_italic_attribute`
1578
+ - `new_label`
1579
+ - `new_menu`
1580
+ - `new_multiline_entry`
1581
+ - `new_non_wrapping_multiline_entry`
1582
+ - `new_open_type_features`
1583
+ - `new_password_entry`
1584
+ - `new_progress_bar`
1585
+ - `new_radio_buttons`
1586
+ - `new_scrolling_area`
1587
+ - `new_search_entry`
1588
+ - `new_size_attribute`
1589
+ - `new_slider`
1590
+ - `new_spinbox`
1591
+ - `new_stretch_attribute`
1592
+ - `new_tab`
1593
+ - `new_table`
1594
+ - `new_table_model`
1595
+ - `new_table_value_color`
1596
+ - `new_table_value_image`
1597
+ - `new_table_value_int`
1598
+ - `new_table_value_string`
1599
+ - `new_time_picker`
1600
+ - `new_underline_attribute`
1601
+ - `new_underline_color_attribute`
1602
+ - `new_vertical_box`
1603
+ - `new_vertical_separator`
1604
+ - `new_weight_attribute`
1605
+ - `new_window`
1606
+ - `on_should_quit`
1607
+ - `open_file`
1608
+ - `open_type_features_add`
1609
+ - `open_type_features_clone`
1610
+ - `open_type_features_for_each`
1611
+ - `open_type_features_get`
1612
+ - `open_type_features_remove`
1613
+ - `progress_bar_set_value`
1614
+ - `progress_bar_value`
1615
+ - `queue_main`
1616
+ - `quit`
1617
+ - `radio_buttons_append`
1618
+ - `radio_buttons_on_selected`
1619
+ - `radio_buttons_selected`
1620
+ - `radio_buttons_set_selected`
1621
+ - `save_file`
1622
+ - `slider_on_changed`
1623
+ - `slider_set_value`
1624
+ - `slider_value`
1625
+ - `spinbox_on_changed`
1626
+ - `spinbox_set_value`
1627
+ - `spinbox_value`
1628
+ - `tab_append`
1629
+ - `tab_delete`
1630
+ - `tab_insert_at`
1631
+ - `tab_margined`
1632
+ - `tab_num_pages`
1633
+ - `tab_set_margined`
1634
+ - `table_append_button_column`
1635
+ - `table_append_checkbox_column`
1636
+ - `table_append_checkbox_text_column`
1637
+ - `table_append_image_column`
1638
+ - `table_append_image_text_column`
1639
+ - `table_append_progress_bar_column`
1640
+ - `table_append_text_column`
1641
+ - `table_model_row_changed`
1642
+ - `table_model_row_deleted`
1643
+ - `table_model_row_inserted`
1644
+ - `table_value_color`
1645
+ - `table_value_get_type`
1646
+ - `table_value_image`
1647
+ - `table_value_int`
1648
+ - `table_value_string`
1649
+ - `timer`
1650
+ - `uninit`
1651
+ - `user_bug_cannot_set_parent_on_toplevel`
1652
+ - `window_borderless`
1653
+ - `window_content_size`
1654
+ - `window_fullscreen`
1655
+ - `window_margined`
1656
+ - `window_on_closing`
1657
+ - `window_on_content_size_changed`
1658
+ - `window_set_borderless`
1659
+ - `window_set_child`
1660
+ - `window_set_content_size`
1661
+ - `window_set_fullscreen`
1662
+ - `window_set_margined`
1663
+ - `window_set_title`
1664
+ - `window_title`
1665
+
1401
1666
  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):
1402
1667
  - Check out [LibUI ffi.rb](https://github.com/kojix2/LibUI/blob/main/lib/libui/ffi.rb)
1403
1668
  - Check out the [libui C Headers](https://github.com/andlabs/libui/blob/master/ui.h)
@@ -3110,9 +3375,9 @@ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/
3110
3375
  ruby -r glimmer-dsl-libui -e "require 'examples/basic_scrolling_area'"
3111
3376
  ```
3112
3377
 
3113
- Mac |
3114
- ----|
3115
- ![glimmer-dsl-libui-mac-dynamic-area.png](images/glimmer-dsl-libui-mac-basic-scrolling-area.png) ![glimmer-dsl-libui-mac-dynamic-area-updated.png](images/glimmer-dsl-libui-mac-basic-scrolling-area-scrolled.png)
3378
+ Mac | Linux
3379
+ ----|------
3380
+ ![glimmer-dsl-libui-mac-dynamic-area.png](images/glimmer-dsl-libui-mac-basic-scrolling-area.png) ![glimmer-dsl-libui-mac-dynamic-area-updated.png](images/glimmer-dsl-libui-mac-basic-scrolling-area-scrolled.png) | ![glimmer-dsl-libui-linux-dynamic-area.png](images/glimmer-dsl-libui-linux-basic-scrolling-area.png) ![glimmer-dsl-libui-linux-dynamic-area-updated.png](images/glimmer-dsl-libui-linux-basic-scrolling-area-scrolled.png)
3116
3381
 
3117
3382
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3118
3383
 
@@ -4433,6 +4698,56 @@ window('Area Gallery', 400, 400) {
4433
4698
  }.show
4434
4699
  ```
4435
4700
 
4701
+ #### Button Counter
4702
+
4703
+ [examples/button_counter.rb](examples/button_counter.rb)
4704
+
4705
+ Run with this command from the root of the project if you cloned the project:
4706
+
4707
+ ```
4708
+ ruby -r './lib/glimmer-dsl-libui' examples/button_counter.rb
4709
+ ```
4710
+
4711
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
4712
+
4713
+ ```
4714
+ ruby -r glimmer-dsl-libui -e "require 'examples/button_counter'"
4715
+ ```
4716
+
4717
+ Mac | Linux
4718
+ ----|------
4719
+ ![glimmer-dsl-libui-mac-button-counter.png](images/glimmer-dsl-libui-mac-button-counter.png) | ![glimmer-dsl-libui-linux-button-counter.png](images/glimmer-dsl-libui-linux-button-counter.png)
4720
+
4721
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4722
+
4723
+ ```ruby
4724
+ require 'glimmer-dsl-libui'
4725
+
4726
+ class ButtonCounter
4727
+ include Glimmer
4728
+
4729
+ attr_accessor :count
4730
+
4731
+ def initialize
4732
+ @count = 0
4733
+ end
4734
+
4735
+ def launch
4736
+ window('Hello, Button!') {
4737
+ button {
4738
+ text <= [self, :count, on_read: ->(count) {"Count: #{count}"}] # data-bind button text to self count, converting to string on read.
4739
+
4740
+ on_clicked do
4741
+ self.count += 1
4742
+ end
4743
+ }
4744
+ }.show
4745
+ end
4746
+ end
4747
+
4748
+ ButtonCounter.new.launch
4749
+ ```
4750
+
4436
4751
  #### Color The Circles
4437
4752
 
4438
4753
  [examples/color_the_circles.rb](examples/color_the_circles.rb)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -0,0 +1,27 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ class ButtonCounter
4
+ include Glimmer
5
+
6
+ attr_accessor :count
7
+
8
+ def initialize
9
+ @count = 0
10
+ end
11
+
12
+ def launch
13
+ window('Hello, Button!', 190, 20) {
14
+ vertical_box {
15
+ button {
16
+ text <= [self, :count, on_read: ->(count) {"Count: #{count}"}] # data-bind button text to self count, converting to string on read.
17
+
18
+ on_clicked do
19
+ self.count += 1
20
+ end
21
+ }
22
+ }
23
+ }.show
24
+ end
25
+ end
26
+
27
+ ButtonCounter.new.launch
@@ -40,7 +40,7 @@ class MetaExample
40
40
  end
41
41
 
42
42
  def version_count_for(example)
43
- Dir.glob(File.join(File.expand_path('.', __dir__), "#{example.underscore}*.rb")).select {|file| file.match(/\d\.rb$/)}.count + 1
43
+ Dir.glob(File.join(File.expand_path('.', __dir__), "#{example.underscore}*.rb")).select {|file| file.match(/#{example.underscore}\d\.rb$/)}.count + 1
44
44
  end
45
45
 
46
46
  def glimmer_dsl_libui_file
data/examples/snake.rb CHANGED
@@ -38,7 +38,7 @@ class Snake
38
38
  def create_gui
39
39
  @main_window = window {
40
40
  # data-bind window title to game score, converting it to a title string on read from the model
41
- title <= [@game, :score, on_read: -> (score) {"Glimmer Snake (Score: #{@game.score})"}]
41
+ title <= [@game, :score, on_read: -> (score) {"Snake (Score: #{@game.score})"}]
42
42
  content_size @game.width * CELL_SIZE, @game.height * CELL_SIZE
43
43
  resizable false
44
44
 
Binary file
@@ -86,14 +86,17 @@ module Glimmer
86
86
 
87
87
  def post_add_content
88
88
  unless parent_proxy.is_a?(Box)
89
- original_parent_proxy = @parent_proxy
90
- @vertical_box_parent_proxy = ControlProxy.create('vertical_box', parent_proxy, []) {} # block prevents calling post add content
91
- append_properties.each do |property|
92
- @vertical_box_parent_proxy.append_property(property, append_property(property))
89
+ unless @content_added
90
+ original_parent_proxy = @parent_proxy
91
+ @vertical_box_parent_proxy = ControlProxy.create('vertical_box', parent_proxy, []) {} # block prevents calling post add content
92
+ append_properties.each do |property|
93
+ @vertical_box_parent_proxy.append_property(property, append_property(property))
94
+ end
95
+ @vertical_box_parent_proxy.post_add_content
96
+ @parent_proxy = @vertical_box_parent_proxy
97
+ @vertical_box_parent_proxy.post_initialize_child(self)
98
+ @content_added = true
93
99
  end
94
- @vertical_box_parent_proxy.post_add_content
95
- @parent_proxy = @vertical_box_parent_proxy
96
- @vertical_box_parent_proxy.post_initialize_child(self)
97
100
  else
98
101
  super
99
102
  end
@@ -142,48 +145,51 @@ module Glimmer
142
145
  end
143
146
 
144
147
  def install_listeners
145
- @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
146
- area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
147
- area_draw_params = area_draw_params_hash(area_draw_params)
148
- AreaProxy.current_area_draw_params = area_draw_params
149
- draw(area_draw_params)
150
- AreaProxy.current_area_draw_params = nil
151
- end
152
- @area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
153
- area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
154
- area_mouse_event = area_mouse_event_hash(area_mouse_event)
155
- on_mouse_event.each { |listener| listener.call(area_mouse_event)}
156
- on_mouse_move.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height])
157
- unless @last_area_mouse_event.nil?
158
- on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
159
- on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
160
- on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
161
- on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
162
- on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
148
+ unless @listeners_installed
149
+ @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
150
+ area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
151
+ area_draw_params = area_draw_params_hash(area_draw_params)
152
+ AreaProxy.current_area_draw_params = area_draw_params
153
+ draw(area_draw_params)
154
+ AreaProxy.current_area_draw_params = nil
163
155
  end
164
- @last_area_mouse_event = area_mouse_event
165
- end
166
- @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left|
167
- left = Glimmer::LibUI.integer_to_boolean(left)
168
- on_mouse_crossed.each { |listener| listener.call(left) }
169
- if left
170
- on_mouse_exit.each { |listener| listener.call(left) }
171
- else
172
- on_mouse_enter.each { |listener| listener.call(left) }
156
+ @area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
157
+ area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
158
+ area_mouse_event = area_mouse_event_hash(area_mouse_event)
159
+ on_mouse_event.each { |listener| listener.call(area_mouse_event)}
160
+ on_mouse_move.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height])
161
+ unless @last_area_mouse_event.nil?
162
+ on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
163
+ on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
164
+ on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
165
+ on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
166
+ on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
167
+ end
168
+ @last_area_mouse_event = area_mouse_event
173
169
  end
174
- end
175
- @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
176
- on_drag_broken.each { |listener| listener.call }
177
- end
178
- @area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event|
179
- area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event)
180
- area_key_event = area_key_event_hash(area_key_event)
181
- on_key_event.each { |listener| listener.call(area_key_event) }
182
- if area_key_event[:up]
183
- on_key_up.each { |listener| listener.call(area_key_event) }
184
- else
185
- on_key_down.each { |listener| listener.call(area_key_event) }
170
+ @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left|
171
+ left = Glimmer::LibUI.integer_to_boolean(left)
172
+ on_mouse_crossed.each { |listener| listener.call(left) }
173
+ if left
174
+ on_mouse_exit.each { |listener| listener.call(left) }
175
+ else
176
+ on_mouse_enter.each { |listener| listener.call(left) }
177
+ end
178
+ end
179
+ @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
180
+ on_drag_broken.each { |listener| listener.call }
181
+ end
182
+ @area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event|
183
+ area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event)
184
+ area_key_event = area_key_event_hash(area_key_event)
185
+ on_key_event.each { |listener| listener.call(area_key_event) }
186
+ if area_key_event[:up]
187
+ on_key_up.each { |listener| listener.call(area_key_event) }
188
+ else
189
+ on_key_down.each { |listener| listener.call(area_key_event) }
190
+ end
186
191
  end
192
+ @listeners_installed = true
187
193
  end
188
194
  end
189
195
 
@@ -56,9 +56,8 @@ module Glimmer
56
56
  draw(AreaProxy.current_area_draw_params)
57
57
  destroy
58
58
  end
59
- @content_added = true
60
59
  else # image object not control
61
- build_control
60
+ build_control unless @content_added
62
61
  super
63
62
  end
64
63
  end
@@ -68,7 +67,7 @@ module Glimmer
68
67
  @args[0]
69
68
  else
70
69
  @args[0] = value
71
- if @content_added
70
+ if area_image? && @content_added
72
71
  post_add_content
73
72
  request_auto_redraw
74
73
  end
@@ -167,8 +166,8 @@ module Glimmer
167
166
  end
168
167
  canvas.resample_nearest_neighbor!(width, height) if width && height
169
168
  @data = canvas.to_rgba_stream
170
- self.width = canvas.width
171
- self.height = canvas.height
169
+ @args[1] = canvas.width
170
+ @args[2] = canvas.height
172
171
  [@data, width, height]
173
172
  end
174
173
 
@@ -55,7 +55,7 @@ module Glimmer
55
55
  end
56
56
 
57
57
  def post_add_content
58
- build_control
58
+ build_control unless @content_added
59
59
  super
60
60
  end
61
61
 
@@ -136,7 +136,10 @@ module Glimmer
136
136
 
137
137
  # Subclasses may override to perform post add_content work (normally must call super)
138
138
  def post_add_content
139
- @parent_proxy&.post_initialize_child(self)
139
+ unless @content_added
140
+ @parent_proxy&.post_initialize_child(self)
141
+ @content_added = true
142
+ end
140
143
  end
141
144
 
142
145
  # Subclasses may override to perform post initialization work on an added child
@@ -79,8 +79,11 @@ module Glimmer
79
79
 
80
80
  # Subclasses may override to perform post add_content work (normally must call super)
81
81
  def post_add_content
82
- @parent&.post_initialize_child(self)
83
- @parent.post_add_content if implicit_path? && dynamic?
82
+ unless @content_added
83
+ @parent&.post_initialize_child(self)
84
+ @parent.post_add_content if implicit_path? && dynamic?
85
+ @content_added = true
86
+ end
84
87
  end
85
88
 
86
89
  def post_initialize_child(child, add_child: true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -244,6 +244,7 @@ files:
244
244
  - examples/basic_transform2.rb
245
245
  - examples/basic_window.rb
246
246
  - examples/basic_window2.rb
247
+ - examples/button_counter.rb
247
248
  - examples/color_button.rb
248
249
  - examples/color_the_circles.rb
249
250
  - examples/control_gallery.rb