glimmer-dsl-libui 0.3.3 → 0.3.4

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: 2210fdb10cbd7cc9cf2c32801f90497e4b2017a0bc2e1b7e07e101b858475cb6
4
- data.tar.gz: 32455357fd8a67d860149daab6434b7a33e955eeb5f7551dd23071a4f8ce139d
3
+ metadata.gz: ca4d302e851d275aad52599a64d0fc9ee6d6414efa753b023d38aaa1bfca283d
4
+ data.tar.gz: 3185bb17a987adadc03dfaac631c89850b726e36775bacd4885a40d2bfaa3e7c
5
5
  SHA512:
6
- metadata.gz: 43d0fb73ca06474723dfe371c8da6c22016f2db46a111467e27bca21494bd1af55ecb9160a2fc2414324517f83b4bb78c00bbdd3a4e13e836707e67be7c81002
7
- data.tar.gz: 959439c28a1bbaccdeb5d5489ad8259bb6efc4f374b4b05f4148f611fb2fdde115e5fc4a2ad1e08294a7db21d99d470a9fdd2701ae48e94bbe4a29e1b51f4158
6
+ metadata.gz: 157a6fa09dded3a1b52689dcc06effaf094f29b2d8975051b1838565720b15987e4faebdfcea9a90d67b841468f93ca8f2c9c8089b7d5d8cf81a851f408ff68f
7
+ data.tar.gz: c9b606a58e391302e760d54a227b0e6d8e9e972ce9fce8ac742fcc0b82c377a4a13d4b78f3cc19f432dff01a3cda1432954aeba4065a65ef18098e3bdff5e134
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.3.4
4
+
5
+ - New examples/basic_scrolling_area.rb
6
+ - Smart defaults for `scrolling_area` control + convenience `width` and `height` attributes
7
+ - Simplify examples/basic_area.rb (all versions) by nesting shapes directly under `area`
8
+ - Support `#content {}` method in `figure` to be able to reopen a `figure`'s content to add more shapes in.
9
+
3
10
  ## 0.3.3
4
11
 
5
12
  - Support nesting shapes directly under `area` to represent paths having one shape, and nesting `fill`/`stroke` within the shapes (not `path`)
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.3.3
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.3.4
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)
@@ -86,21 +86,6 @@ include Glimmer
86
86
 
87
87
  window('Area Gallery', 400, 400) {
88
88
  area {
89
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
90
- square(0, 0, 100)
91
- square(100, 100, 400)
92
-
93
- fill r: 102, g: 102, b: 204
94
- }
95
-
96
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
97
- rectangle(0, 100, 100, 400)
98
- rectangle(100, 0, 400, 100)
99
-
100
- # linear gradient (has x0, y0, x1, y1, and stops)
101
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
102
- }
103
-
104
89
  polygon(100, 100, 100, 400, 400, 100, 400, 400) { # declarative stable path (implicit path syntax for a single shape nested directly under area)
105
90
  fill r: 202, g: 102, b: 104, a: 0.5
106
91
  stroke r: 0, g: 0, b: 0
@@ -129,6 +114,21 @@ window('Area Gallery', 400, 400) {
129
114
  stroke r: 0, g: 0, b: 0, thickness: 2
130
115
  }
131
116
 
117
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
118
+ square(0, 0, 100)
119
+ square(100, 100, 400)
120
+
121
+ fill r: 102, g: 102, b: 204
122
+ }
123
+
124
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
125
+ rectangle(0, 100, 100, 400)
126
+ rectangle(100, 0, 400, 100)
127
+
128
+ # linear gradient (has x0, y0, x1, y1, and stops)
129
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
130
+ }
131
+
132
132
  text(161, 40, 100) { # declarative stable text
133
133
  string('Area Gallery') {
134
134
  font family: 'Arial', size: (OS.mac? ? 14 : 11)
@@ -222,6 +222,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
222
222
  - [Extra Operations](#extra-operations)
223
223
  - [Table API](#table-api)
224
224
  - [Area API](#area-api)
225
+ - [Scrolling Area](#scrolling_area)
225
226
  - [Area Path Shapes](#area-path-shapes)
226
227
  - [Area Text](#area-text)
227
228
  - [Area Image](#area-image)
@@ -261,6 +262,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
261
262
  - [Form Table](#form-table)
262
263
  - [Basic Area](#basic-area)
263
264
  - [Dynamic Area](#dynamic-area)
265
+ - [Basic Scrolling Area](#basic-scrolling-area)
264
266
  - [Area Gallery](#area-gallery)
265
267
  - [Basic Image](#basic-image)
266
268
  - [Histogram](#histogram)
@@ -366,7 +368,7 @@ gem install glimmer-dsl-libui
366
368
  Or install via Bundler `Gemfile`:
367
369
 
368
370
  ```ruby
369
- gem 'glimmer-dsl-libui', '~> 0.3.3'
371
+ gem 'glimmer-dsl-libui', '~> 0.3.4'
370
372
  ```
371
373
 
372
374
  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.
@@ -493,6 +495,7 @@ Keyword(Args) | Properties | Listeners
493
495
  `quit_menu_item` | None | `on_clicked`
494
496
  `radio_buttons` | `selected` (`Integer`) | `on_selected`
495
497
  `rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `width` (`Numeric`), `height` (`Numeric`) | None
498
+ `scrolling_area(width = main_window.width, height = main_window.height)` | `auto_draw_enabled` (Boolean), `size` (`Array` of `width` (`Numeric`) and `height` (`Numeric`)), `width` (`Numeric`), `height` (`Numeric`) | `on_draw(area_draw_params)`, `on_mouse_event(area_mouse_event)`, `on_mouse_down(area_mouse_event)`, `on_mouse_up(area_mouse_event)`, `on_mouse_drag_started(area_mouse_event)`, `on_mouse_dragged(area_mouse_event)`, `on_mouse_dropped(area_mouse_event)`, `on_mouse_entered`, `on_mouse_exited`, `on_key_event(area_key_event)`, `on_key_down(area_key_event)`, `on_key_up(area_key_event)`
496
499
  `search_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
497
500
  `separator_menu_item` | None | None
498
501
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
@@ -508,7 +511,7 @@ Keyword(Args) | Properties | Listeners
508
511
  `time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`) | `on_changed`
509
512
  `vertical_box` | `padded` (Boolean) | None
510
513
  `vertical_separator` | None | None
511
- `window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`), `resizable` (Boolean) | `on_closing`, `on_content_size_changed`, `on_destroy`
514
+ `window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `width` (`Numeric`), `height` (`Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`), `resizable` (Boolean) | `on_closing`, `on_content_size_changed`, `on_destroy`
512
515
 
513
516
  ### Common Control Properties
514
517
  - `enabled` (Boolean)
@@ -764,6 +767,18 @@ window('Basic Area', 400, 400) {
764
767
 
765
768
  Check [examples/dynamic_area.rb](#dynamic-area) for a more detailed semi-declarative example.
766
769
 
770
+ #### Scrolling Area
771
+
772
+ `scrolling_area(width as Numeric = main_window.width, height as Numeric = main_window.height)` is similar to `area`, but has the following additional methods:
773
+ - `scroll_to(x as Numeric, y as Numeric, width as Numeric = main_window.width, height as Numeric = main_window.height)`: scrolls to `x`/`y` location with `width` and `height` viewport size.
774
+ - `set_size(width as Numeric, height as Numeric)`: set size of scrolling area, which must must exceed that of visible viewport in order for scrolling to be enabled.
775
+
776
+ Mac |
777
+ ----|
778
+ ![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)
779
+
780
+ Check [examples/basic_scrolling_area.rb](#basic-scrolling-area) for a more detailed example.
781
+
767
782
  #### Area Path Shapes
768
783
 
769
784
  `path` can receive a `draw_fill_mode` argument that can accept values `:winding` or `:alternate` and defaults to `:winding`.
@@ -1026,7 +1041,7 @@ Check [Histogram](#histogram) example for use of hex colors.
1026
1041
 
1027
1042
  #### Area Draw Params
1028
1043
 
1029
- The `area_draw_params` argument for `on_draw` block is a hash consisting of the following keys:
1044
+ The `area_draw_params` `Hash` argument for `on_draw` block is a hash consisting of the following keys:
1030
1045
  - `:context`: the drawing context object
1031
1046
  - `:area_width`: area width
1032
1047
  - `:area_height`: area height
@@ -1182,6 +1197,8 @@ Note that `area`, `path`, and nested shapes are all truly declarative, meaning t
1182
1197
  - `image` instances are automatically freed from memory after `window` is destroyed.
1183
1198
  - `image` `width` and `height` can be left off if it has one `image_part` only as they default to the same `width` and `height` of the `image_part`
1184
1199
  - Automatically provide shifted `:key` characters in `area_key_event` provided in `area` key listeners `on_key_event`, `on_key_down`, and `on_key_up`
1200
+ - `scrolling_area` `width` and `height` default to main window width and height if not specified.
1201
+ - `scrolling_area` `#scroll_to` 3rd and 4th arguments (`width` and `height`) default to main window width and height if not specified.
1185
1202
  - `area` paths are specified declaratively with figures underneath (e.g. `rectangle`) and `area` draw listener is automatically generated
1186
1203
  - Observe figure properties (e.g. `rectangle` `width`) for changes and automatically redraw containing area accordingly
1187
1204
  - Observe `path` `fill` and `stroke` hashes for changes and automatically redraw containing area accordingly
@@ -1352,15 +1369,13 @@ Example:
1352
1369
  }
1353
1370
  ```
1354
1371
 
1355
- **3 - Control property declarations always have arguments that are never wrapped inside parentheses and never take a block.**
1372
+ **3 - Control property declarations always have arguments that are not wrapped inside parentheses and typically do not take a block.**
1356
1373
 
1357
1374
  Example:
1358
1375
 
1359
1376
  ```ruby
1360
- spinbox(0, 100) {
1361
- stretchy false
1362
- value 42
1363
- }
1377
+ stretchy false
1378
+ value 42
1364
1379
  ```
1365
1380
 
1366
1381
  **4 - Control listeners are always declared starting with on_ prefix and affixing listener event method name afterwards in underscored lowercase form. Their multi-line blocks have a `do; end` style.**
@@ -1964,12 +1979,8 @@ class TinyMidiPlayer
1964
1979
 
1965
1980
  def stop_midi
1966
1981
  if @pid
1967
- if @th.alive?
1968
- Process.kill(:SIGKILL, @pid)
1969
- @pid = nil
1970
- else
1971
- @pid = nil
1972
- end
1982
+ Process.kill(:SIGKILL, @pid) if @th.alive?
1983
+ @pid = nil
1973
1984
  end
1974
1985
  end
1975
1986
 
@@ -1995,6 +2006,20 @@ class TinyMidiPlayer
1995
2006
  end
1996
2007
 
1997
2008
  def create_gui
2009
+ # loop_menu = UI.new_menu('Repeat')
2010
+ # items = %w[Off One].map do |item_name|
2011
+ # item = UI.menu_append_check_item(loop_menu, item_name)
2012
+ # end
2013
+ # items.each_with_index do |item, idx|
2014
+ # UI.menu_item_on_clicked(item) do
2015
+ # @repeat = idx
2016
+ # (items - [item]).each do |i|
2017
+ # UI.menu_item_set_checked(i, 0)
2018
+ # end
2019
+ # 0
2020
+ # end
2021
+ # end
2022
+
1998
2023
  help_menu = UI.new_menu('Help')
1999
2024
  version_item = UI.menu_append_item(help_menu, 'Version')
2000
2025
 
@@ -2009,11 +2034,11 @@ class TinyMidiPlayer
2009
2034
 
2010
2035
  UI.new_horizontal_box.tap do |hbox|
2011
2036
  UI.new_vertical_box.tap do |vbox|
2012
- UI.new_button('â–¶').tap do |button1|
2037
+ UI.new_button('').tap do |button1|
2013
2038
  UI.button_on_clicked(button1) { play_midi }
2014
2039
  UI.box_append(vbox, button1, 1)
2015
2040
  end
2016
- UI.new_button('â– ').tap do |button2|
2041
+ UI.new_button('').tap do |button2|
2017
2042
  UI.button_on_clicked(button2) { stop_midi }
2018
2043
  UI.box_append(vbox, button2, 1)
2019
2044
  end
@@ -2107,12 +2132,12 @@ class TinyMidiPlayer
2107
2132
  vertical_box {
2108
2133
  stretchy false
2109
2134
 
2110
- button('â–¶') {
2135
+ button('') {
2111
2136
  on_clicked do
2112
2137
  play_midi
2113
2138
  end
2114
2139
  }
2115
- button('â– ') {
2140
+ button('') {
2116
2141
  on_clicked do
2117
2142
  stop_midi
2118
2143
  end
@@ -4195,6 +4220,109 @@ window('Dynamic Area', 240, 600) {
4195
4220
  }.show
4196
4221
  ```
4197
4222
 
4223
+ ### Basic Scrolling Area
4224
+
4225
+ [examples/basic_scrolling_area.rb](examples/basic_scrolling_area.rb)
4226
+
4227
+ Run with this command from the root of the project if you cloned the project:
4228
+
4229
+ ```
4230
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_scrolling_area.rb
4231
+ ```
4232
+
4233
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
4234
+
4235
+ ```
4236
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_scrolling_area'"
4237
+ ```
4238
+
4239
+ Mac |
4240
+ ----|
4241
+ ![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)
4242
+
4243
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4244
+
4245
+ ```ruby
4246
+ require 'glimmer-dsl-libui'
4247
+
4248
+ class BasicScrollingArea
4249
+ include Glimmer
4250
+
4251
+ SCROLLING_AREA_WIDTH = 800
4252
+ SCROLLING_AREA_HEIGHT = 400
4253
+ SCROLLING_AREA_PADDING_X = 20
4254
+ SCROLLING_AREA_PADDING_Y = 20
4255
+
4256
+ def initialize
4257
+ @x = SCROLLING_AREA_PADDING_X
4258
+ @y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
4259
+ create_gui
4260
+ Glimmer::LibUI.timer(0.01) do
4261
+ @x += SCROLLING_AREA_PADDING_X
4262
+ @y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min
4263
+ @graph.content { # re-open @graph's content and add a line
4264
+ line(@x, @y)
4265
+ }
4266
+ # if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)`
4267
+ @scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied
4268
+ # return false to stop timer once @x exceeds scrolling area width - padding
4269
+ false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2)
4270
+ end
4271
+ end
4272
+
4273
+ def launch
4274
+ @main_window.show
4275
+ end
4276
+
4277
+ def x_axis
4278
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
4279
+ stroke :black, thickness: 3
4280
+ }
4281
+
4282
+ ((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier|
4283
+ x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2
4284
+ y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
4285
+
4286
+ polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) {
4287
+ stroke :black, thickness: 2
4288
+ }
4289
+ end
4290
+ end
4291
+
4292
+ def y_axis
4293
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
4294
+ stroke :black, thickness: 3
4295
+ }
4296
+
4297
+ ((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier|
4298
+ x = SCROLLING_AREA_PADDING_X
4299
+ y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2
4300
+
4301
+ polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) {
4302
+ stroke :black, thickness: 2
4303
+ }
4304
+ end
4305
+ end
4306
+
4307
+ def create_gui
4308
+ @main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) {
4309
+ resizable false
4310
+
4311
+ @scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) {
4312
+ x_axis
4313
+ y_axis
4314
+
4315
+ @graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
4316
+ stroke :blue, thickness: 2
4317
+ }
4318
+ }
4319
+ }
4320
+ end
4321
+ end
4322
+
4323
+ BasicScrollingArea.new.launch
4324
+ ```
4325
+
4198
4326
  ### Area Gallery
4199
4327
 
4200
4328
  [examples/area_gallery.rb](examples/area_gallery.rb)
@@ -4224,21 +4352,6 @@ include Glimmer
4224
4352
 
4225
4353
  window('Area Gallery', 400, 400) {
4226
4354
  area {
4227
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
4228
- square(0, 0, 100)
4229
- square(100, 100, 400)
4230
-
4231
- fill r: 102, g: 102, b: 204
4232
- }
4233
-
4234
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
4235
- rectangle(0, 100, 100, 400)
4236
- rectangle(100, 0, 400, 100)
4237
-
4238
- # linear gradient (has x0, y0, x1, y1, and stops)
4239
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4240
- }
4241
-
4242
4355
  polygon(100, 100, 100, 400, 400, 100, 400, 400) { # declarative stable path (implicit path syntax for a single shape nested directly under area)
4243
4356
  fill r: 202, g: 102, b: 104, a: 0.5
4244
4357
  stroke r: 0, g: 0, b: 0
@@ -4267,6 +4380,21 @@ window('Area Gallery', 400, 400) {
4267
4380
  stroke r: 0, g: 0, b: 0, thickness: 2
4268
4381
  }
4269
4382
 
4383
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
4384
+ square(0, 0, 100)
4385
+ square(100, 100, 400)
4386
+
4387
+ fill r: 102, g: 102, b: 204
4388
+ }
4389
+
4390
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
4391
+ rectangle(0, 100, 100, 400)
4392
+ rectangle(100, 0, 400, 100)
4393
+
4394
+ # linear gradient (has x0, y0, x1, y1, and stops)
4395
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4396
+ }
4397
+
4270
4398
  text(161, 40, 100) { # declarative stable text
4271
4399
  string('Area Gallery') {
4272
4400
  font family: 'Arial', size: (OS.mac? ? 14 : 11)
@@ -4334,41 +4462,7 @@ include Glimmer
4334
4462
 
4335
4463
  window('Area Gallery', 400, 400) {
4336
4464
  area {
4337
- path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
4338
- square {
4339
- x 0
4340
- y 0
4341
- length 100
4342
- }
4343
-
4344
- square {
4345
- x 100
4346
- y 100
4347
- length 400
4348
- }
4349
-
4350
- fill r: 102, g: 102, b: 204
4351
- }
4352
-
4353
- path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
4354
- rectangle {
4355
- x 0
4356
- y 100
4357
- width 100
4358
- height 400
4359
- }
4360
-
4361
- rectangle {
4362
- x 100
4363
- y 0
4364
- width 400
4365
- height 100
4366
- }
4367
-
4368
- # linear gradient (has x0, y0, x1, y1, and stops)
4369
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4370
- }
4371
-
4465
+
4372
4466
  figure { # declarative stable path with explicit attributes (implicit path syntax for a single shape nested directly under area)
4373
4467
  x 100
4374
4468
  y 100
@@ -4475,6 +4569,41 @@ window('Area Gallery', 400, 400) {
4475
4569
  stroke r: 0, g: 0, b: 0, thickness: 2
4476
4570
  }
4477
4571
 
4572
+ path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
4573
+ square {
4574
+ x 0
4575
+ y 0
4576
+ length 100
4577
+ }
4578
+
4579
+ square {
4580
+ x 100
4581
+ y 100
4582
+ length 400
4583
+ }
4584
+
4585
+ fill r: 102, g: 102, b: 204
4586
+ }
4587
+
4588
+ path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
4589
+ rectangle {
4590
+ x 0
4591
+ y 100
4592
+ width 100
4593
+ height 400
4594
+ }
4595
+
4596
+ rectangle {
4597
+ x 100
4598
+ y 0
4599
+ width 400
4600
+ height 100
4601
+ }
4602
+
4603
+ # linear gradient (has x0, y0, x1, y1, and stops)
4604
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4605
+ }
4606
+
4478
4607
  text { # declarative stable text with explicit attributes
4479
4608
  x 161
4480
4609
  y 40
@@ -4549,21 +4678,6 @@ include Glimmer
4549
4678
  window('Area Gallery', 400, 400) {
4550
4679
  area {
4551
4680
  on_draw do |area_draw_params|
4552
- path { # dynamic path, added semi-declaratively inside on_draw block
4553
- square(0, 0, 100)
4554
- square(100, 100, 400)
4555
-
4556
- fill r: 102, g: 102, b: 204
4557
- }
4558
-
4559
- path { # dynamic path, added semi-declaratively inside on_draw block
4560
- rectangle(0, 100, 100, 400)
4561
- rectangle(100, 0, 400, 100)
4562
-
4563
- # linear gradient (has x0, y0, x1, y1, and stops)
4564
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4565
- }
4566
-
4567
4681
  polygon(100, 100, 100, 400, 400, 100, 400, 400) { # dynamic path, added semi-declaratively inside on_draw block
4568
4682
  fill r: 202, g: 102, b: 104, a: 0.5
4569
4683
  stroke r: 0, g: 0, b: 0
@@ -4592,6 +4706,21 @@ window('Area Gallery', 400, 400) {
4592
4706
  stroke r: 0, g: 0, b: 0, thickness: 2
4593
4707
  }
4594
4708
 
4709
+ path { # dynamic path, added semi-declaratively inside on_draw block
4710
+ square(0, 0, 100)
4711
+ square(100, 100, 400)
4712
+
4713
+ fill r: 102, g: 102, b: 204
4714
+ }
4715
+
4716
+ path { # dynamic path, added semi-declaratively inside on_draw block
4717
+ rectangle(0, 100, 100, 400)
4718
+ rectangle(100, 0, 400, 100)
4719
+
4720
+ # linear gradient (has x0, y0, x1, y1, and stops)
4721
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4722
+ }
4723
+
4595
4724
  text(161, 40, 100) { # dynamic text added semi-declaratively inside on_draw block
4596
4725
  string('Area Gallery') {
4597
4726
  font family: 'Arial', size: (OS.mac? ? 14 : 11)
@@ -4661,41 +4790,6 @@ include Glimmer
4661
4790
  window('Area Gallery', 400, 400) {
4662
4791
  area {
4663
4792
  on_draw do |area_draw_params|
4664
- path { # dynamic path, added semi-declaratively inside on_draw block
4665
- square {
4666
- x 0
4667
- y 0
4668
- length 100
4669
- }
4670
-
4671
- square {
4672
- x 100
4673
- y 100
4674
- length 400
4675
- }
4676
-
4677
- fill r: 102, g: 102, b: 204
4678
- }
4679
-
4680
- path { # dynamic path, added semi-declaratively inside on_draw block
4681
- rectangle {
4682
- x 0
4683
- y 100
4684
- width 100
4685
- height 400
4686
- }
4687
-
4688
- rectangle {
4689
- x 100
4690
- y 0
4691
- width 400
4692
- height 100
4693
- }
4694
-
4695
- # linear gradient (has x0, y0, x1, y1, and stops)
4696
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4697
- }
4698
-
4699
4793
  figure { # dynamic path, added semi-declaratively inside on_draw block
4700
4794
  x 100
4701
4795
  y 100
@@ -4802,6 +4896,41 @@ window('Area Gallery', 400, 400) {
4802
4896
  stroke r: 0, g: 0, b: 0, thickness: 2
4803
4897
  }
4804
4898
 
4899
+ path { # dynamic path, added semi-declaratively inside on_draw block
4900
+ square {
4901
+ x 0
4902
+ y 0
4903
+ length 100
4904
+ }
4905
+
4906
+ square {
4907
+ x 100
4908
+ y 100
4909
+ length 400
4910
+ }
4911
+
4912
+ fill r: 102, g: 102, b: 204
4913
+ }
4914
+
4915
+ path { # dynamic path, added semi-declaratively inside on_draw block
4916
+ rectangle {
4917
+ x 0
4918
+ y 100
4919
+ width 100
4920
+ height 400
4921
+ }
4922
+
4923
+ rectangle {
4924
+ x 100
4925
+ y 0
4926
+ width 400
4927
+ height 100
4928
+ }
4929
+
4930
+ # linear gradient (has x0, y0, x1, y1, and stops)
4931
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
4932
+ }
4933
+
4805
4934
  text { # dynamic path, added semi-declaratively inside on_draw block
4806
4935
  x 161
4807
4936
  y 40
@@ -7128,7 +7257,7 @@ class Snake
7128
7257
  Glimmer::DataBinding::Observer.proc do |game_over|
7129
7258
  Glimmer::LibUI.queue_main do
7130
7259
  if game_over
7131
- msg_box('Game Over!', "Score: #{@game.score}")
7260
+ msg_box('Game Over!', "Score: #{@game.score} | High Score: #{@game.high_score}")
7132
7261
  @game.start
7133
7262
  end
7134
7263
  end
@@ -7137,7 +7266,7 @@ class Snake
7137
7266
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
7138
7267
  unless @game.over?
7139
7268
  @game.snake.move
7140
- @main_window.title = "Glimmer Snake (Score: #{@game.score})"
7269
+ @main_window.title = "Glimmer Snake (Score: #{@game.score} | High Score: #{@game.high_score})"
7141
7270
  end
7142
7271
  end
7143
7272
  end
@@ -7157,9 +7286,7 @@ class Snake
7157
7286
 
7158
7287
  @game.width.times do |column|
7159
7288
  area {
7160
- @cell_grid.last << path {
7161
- square(0, 0, CELL_SIZE)
7162
-
7289
+ @cell_grid.last << square(0, 0, CELL_SIZE) {
7163
7290
  fill Presenter::Cell::COLOR_CLEAR
7164
7291
  }
7165
7292
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -4,21 +4,6 @@ include Glimmer
4
4
 
5
5
  window('Area Gallery', 400, 400) {
6
6
  area {
7
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
8
- square(0, 0, 100)
9
- square(100, 100, 400)
10
-
11
- fill r: 102, g: 102, b: 204
12
- }
13
-
14
- path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
15
- rectangle(0, 100, 100, 400)
16
- rectangle(100, 0, 400, 100)
17
-
18
- # linear gradient (has x0, y0, x1, y1, and stops)
19
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
20
- }
21
-
22
7
  polygon(100, 100, 100, 400, 400, 100, 400, 400) { # declarative stable path (implicit path syntax for a single shape nested directly under area)
23
8
  fill r: 202, g: 102, b: 104, a: 0.5
24
9
  stroke r: 0, g: 0, b: 0
@@ -47,6 +32,21 @@ window('Area Gallery', 400, 400) {
47
32
  stroke r: 0, g: 0, b: 0, thickness: 2
48
33
  }
49
34
 
35
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
36
+ square(0, 0, 100)
37
+ square(100, 100, 400)
38
+
39
+ fill r: 102, g: 102, b: 204
40
+ }
41
+
42
+ path { # declarative stable path (explicit path syntax for multiple shapes sharing attributes)
43
+ rectangle(0, 100, 100, 400)
44
+ rectangle(100, 0, 400, 100)
45
+
46
+ # linear gradient (has x0, y0, x1, y1, and stops)
47
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
48
+ }
49
+
50
50
  text(161, 40, 100) { # declarative stable text
51
51
  string('Area Gallery') {
52
52
  font family: 'Arial', size: (OS.mac? ? 14 : 11)
@@ -4,41 +4,7 @@ include Glimmer
4
4
 
5
5
  window('Area Gallery', 400, 400) {
6
6
  area {
7
- path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
8
- square {
9
- x 0
10
- y 0
11
- length 100
12
- }
13
-
14
- square {
15
- x 100
16
- y 100
17
- length 400
18
- }
19
-
20
- fill r: 102, g: 102, b: 204
21
- }
22
-
23
- path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
24
- rectangle {
25
- x 0
26
- y 100
27
- width 100
28
- height 400
29
- }
30
-
31
- rectangle {
32
- x 100
33
- y 0
34
- width 400
35
- height 100
36
- }
37
-
38
- # linear gradient (has x0, y0, x1, y1, and stops)
39
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
40
- }
41
-
7
+
42
8
  figure { # declarative stable path with explicit attributes (implicit path syntax for a single shape nested directly under area)
43
9
  x 100
44
10
  y 100
@@ -145,6 +111,41 @@ window('Area Gallery', 400, 400) {
145
111
  stroke r: 0, g: 0, b: 0, thickness: 2
146
112
  }
147
113
 
114
+ path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
115
+ square {
116
+ x 0
117
+ y 0
118
+ length 100
119
+ }
120
+
121
+ square {
122
+ x 100
123
+ y 100
124
+ length 400
125
+ }
126
+
127
+ fill r: 102, g: 102, b: 204
128
+ }
129
+
130
+ path { # declarative stable path with explicit attributes (explicit path syntax for multiple shapes sharing attributes)
131
+ rectangle {
132
+ x 0
133
+ y 100
134
+ width 100
135
+ height 400
136
+ }
137
+
138
+ rectangle {
139
+ x 100
140
+ y 0
141
+ width 400
142
+ height 100
143
+ }
144
+
145
+ # linear gradient (has x0, y0, x1, y1, and stops)
146
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
147
+ }
148
+
148
149
  text { # declarative stable text with explicit attributes
149
150
  x 161
150
151
  y 40
@@ -5,21 +5,6 @@ include Glimmer
5
5
  window('Area Gallery', 400, 400) {
6
6
  area {
7
7
  on_draw do |area_draw_params|
8
- path { # dynamic path, added semi-declaratively inside on_draw block
9
- square(0, 0, 100)
10
- square(100, 100, 400)
11
-
12
- fill r: 102, g: 102, b: 204
13
- }
14
-
15
- path { # dynamic path, added semi-declaratively inside on_draw block
16
- rectangle(0, 100, 100, 400)
17
- rectangle(100, 0, 400, 100)
18
-
19
- # linear gradient (has x0, y0, x1, y1, and stops)
20
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
21
- }
22
-
23
8
  polygon(100, 100, 100, 400, 400, 100, 400, 400) { # dynamic path, added semi-declaratively inside on_draw block
24
9
  fill r: 202, g: 102, b: 104, a: 0.5
25
10
  stroke r: 0, g: 0, b: 0
@@ -48,6 +33,21 @@ window('Area Gallery', 400, 400) {
48
33
  stroke r: 0, g: 0, b: 0, thickness: 2
49
34
  }
50
35
 
36
+ path { # dynamic path, added semi-declaratively inside on_draw block
37
+ square(0, 0, 100)
38
+ square(100, 100, 400)
39
+
40
+ fill r: 102, g: 102, b: 204
41
+ }
42
+
43
+ path { # dynamic path, added semi-declaratively inside on_draw block
44
+ rectangle(0, 100, 100, 400)
45
+ rectangle(100, 0, 400, 100)
46
+
47
+ # linear gradient (has x0, y0, x1, y1, and stops)
48
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
49
+ }
50
+
51
51
  text(161, 40, 100) { # dynamic text added semi-declaratively inside on_draw block
52
52
  string('Area Gallery') {
53
53
  font family: 'Arial', size: (OS.mac? ? 14 : 11)
@@ -5,41 +5,6 @@ include Glimmer
5
5
  window('Area Gallery', 400, 400) {
6
6
  area {
7
7
  on_draw do |area_draw_params|
8
- path { # dynamic path, added semi-declaratively inside on_draw block
9
- square {
10
- x 0
11
- y 0
12
- length 100
13
- }
14
-
15
- square {
16
- x 100
17
- y 100
18
- length 400
19
- }
20
-
21
- fill r: 102, g: 102, b: 204
22
- }
23
-
24
- path { # dynamic path, added semi-declaratively inside on_draw block
25
- rectangle {
26
- x 0
27
- y 100
28
- width 100
29
- height 400
30
- }
31
-
32
- rectangle {
33
- x 100
34
- y 0
35
- width 400
36
- height 100
37
- }
38
-
39
- # linear gradient (has x0, y0, x1, y1, and stops)
40
- fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
41
- }
42
-
43
8
  figure { # dynamic path, added semi-declaratively inside on_draw block
44
9
  x 100
45
10
  y 100
@@ -146,6 +111,41 @@ window('Area Gallery', 400, 400) {
146
111
  stroke r: 0, g: 0, b: 0, thickness: 2
147
112
  }
148
113
 
114
+ path { # dynamic path, added semi-declaratively inside on_draw block
115
+ square {
116
+ x 0
117
+ y 0
118
+ length 100
119
+ }
120
+
121
+ square {
122
+ x 100
123
+ y 100
124
+ length 400
125
+ }
126
+
127
+ fill r: 102, g: 102, b: 204
128
+ }
129
+
130
+ path { # dynamic path, added semi-declaratively inside on_draw block
131
+ rectangle {
132
+ x 0
133
+ y 100
134
+ width 100
135
+ height 400
136
+ }
137
+
138
+ rectangle {
139
+ x 100
140
+ y 0
141
+ width 400
142
+ height 100
143
+ }
144
+
145
+ # linear gradient (has x0, y0, x1, y1, and stops)
146
+ fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
147
+ }
148
+
149
149
  text { # dynamic path, added semi-declaratively inside on_draw block
150
150
  x 161
151
151
  y 40
@@ -7,9 +7,7 @@ window('Basic Area', 400, 400) {
7
7
 
8
8
  vertical_box {
9
9
  area {
10
- path { # a stable path is added declaratively
11
- rectangle(0, 0, 400, 400)
12
-
10
+ rectangle(0, 0, 400, 400) { # stable implicit path shape, added declaratively
13
11
  fill r: 102, g: 102, b: 204, a: 1.0
14
12
  }
15
13
  }
@@ -8,9 +8,7 @@ window('Basic Area', 400, 400) {
8
8
  vertical_box {
9
9
  area {
10
10
  on_draw do |area_draw_params|
11
- path { # a dynamic path is added semi-declaratively inside on_draw block
12
- rectangle(0, 0, 400, 400)
13
-
11
+ rectangle(0, 0, 400, 400) { # dynamic implicit path shape, added semi-declaratively inside on_draw block
14
12
  fill r: 102, g: 102, b: 204, a: 1.0
15
13
  }
16
14
  end
@@ -0,0 +1,17 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ path { # stable path, added declaratively
11
+ rectangle(0, 0, 400, 400)
12
+
13
+ fill r: 102, g: 102, b: 204, a: 1.0
14
+ }
15
+ }
16
+ }
17
+ }.show
@@ -0,0 +1,19 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ on_draw do |area_draw_params|
11
+ path { # dynamic path, added semi-declaratively inside on_draw block
12
+ rectangle(0, 0, 400, 400)
13
+
14
+ fill r: 102, g: 102, b: 204, a: 1.0
15
+ }
16
+ end
17
+ }
18
+ }
19
+ }.show
@@ -0,0 +1,79 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ class BasicScrollingArea
4
+ include Glimmer
5
+
6
+ SCROLLING_AREA_WIDTH = 800
7
+ SCROLLING_AREA_HEIGHT = 400
8
+ SCROLLING_AREA_PADDING_X = 20
9
+ SCROLLING_AREA_PADDING_Y = 20
10
+
11
+ def initialize
12
+ @x = SCROLLING_AREA_PADDING_X
13
+ @y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
14
+ create_gui
15
+ Glimmer::LibUI.timer(0.01) do
16
+ @x += SCROLLING_AREA_PADDING_X
17
+ @y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min
18
+ @graph.content { # re-open @graph's content and add a line
19
+ line(@x, @y)
20
+ }
21
+ # if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)`
22
+ # Note that `#scroll_to` does not seem to work on Linux, but normal scrolling does.
23
+ @scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied
24
+ # return false to stop timer once @x exceeds scrolling area width - padding
25
+ false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2)
26
+ end
27
+ end
28
+
29
+ def launch
30
+ @main_window.show
31
+ end
32
+
33
+ def x_axis
34
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
35
+ stroke :black, thickness: 3
36
+ }
37
+
38
+ ((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier|
39
+ x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2
40
+ y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
41
+
42
+ polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) {
43
+ stroke :black, thickness: 2
44
+ }
45
+ end
46
+ end
47
+
48
+ def y_axis
49
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
50
+ stroke :black, thickness: 3
51
+ }
52
+
53
+ ((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier|
54
+ x = SCROLLING_AREA_PADDING_X
55
+ y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2
56
+
57
+ polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) {
58
+ stroke :black, thickness: 2
59
+ }
60
+ end
61
+ end
62
+
63
+ def create_gui
64
+ @main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) {
65
+ resizable false
66
+
67
+ @scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) { # double width of window enables horizontal scrolling
68
+ x_axis
69
+ y_axis
70
+
71
+ @graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
72
+ stroke :blue, thickness: 2
73
+ }
74
+ }
75
+ }
76
+ end
77
+ end
78
+
79
+ BasicScrollingArea.new.launch
Binary file
@@ -31,8 +31,43 @@ module Glimmer
31
31
  class ScrollingAreaProxy < AreaProxy
32
32
  def build_control
33
33
  @area_handler = ::LibUI::FFI::AreaHandler.malloc
34
+ @args[0] ||= Glimmer::LibUI::ControlProxy.main_window_proxy.width
35
+ @args[1] ||= Glimmer::LibUI::ControlProxy.main_window_proxy.height
34
36
  @libui = ::LibUI.new_scrolling_area(@area_handler, *@args)
35
37
  end
38
+
39
+ def width(value = nil)
40
+ if value.nil?
41
+ @args[0]
42
+ else
43
+ @args[0] = value
44
+ set_size(width, height)
45
+ end
46
+ end
47
+ alias width= width
48
+ alias set_width width
49
+
50
+ def height(value = nil)
51
+ if value.nil?
52
+ @args[1]
53
+ else
54
+ @args[1] = value
55
+ set_size(width, height)
56
+ end
57
+ end
58
+ alias height= height
59
+ alias set_height height
60
+
61
+ def set_size(width, height)
62
+ @args[0] = width
63
+ @args[1] = height
64
+ super(width, height)
65
+ end
66
+
67
+ def scroll_to(scroll_x, scroll_y, scroll_width = nil, scroll_height = nil)
68
+ scroll_width, scroll_height = Glimmer::LibUI::ControlProxy.main_window_proxy.content_size
69
+ super(scroll_x, scroll_y, scroll_width, scroll_height)
70
+ end
36
71
  end
37
72
  end
38
73
  end
@@ -113,6 +113,26 @@ module Glimmer
113
113
  alias content_size= content_size
114
114
  alias set_content_size content_size
115
115
 
116
+ def width(value = nil)
117
+ if value.nil?
118
+ content_size.first
119
+ else
120
+ set_content_size(value, height)
121
+ end
122
+ end
123
+ alias width= width
124
+ alias set_width width
125
+
126
+ def height(value = nil)
127
+ if value.nil?
128
+ content_size.last
129
+ else
130
+ set_content_size(width, value)
131
+ end
132
+ end
133
+ alias height= height
134
+ alias set_height height
135
+
116
136
  def resizable(value = nil)
117
137
  if value.nil?
118
138
  @resizable = true if @resizable.nil?
@@ -91,6 +91,11 @@ module Glimmer
91
91
  end
92
92
  end
93
93
 
94
+ def content(&block)
95
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ShapeExpression.new, @keyword, &block)
96
+ request_auto_redraw
97
+ end
98
+
94
99
  # Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
95
100
  def draw(area_draw_params)
96
101
  destroy if area_proxy.nil?
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.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -217,6 +217,8 @@ files:
217
217
  - examples/area_gallery4.rb
218
218
  - examples/basic_area.rb
219
219
  - examples/basic_area2.rb
220
+ - examples/basic_area3.rb
221
+ - examples/basic_area4.rb
220
222
  - examples/basic_button.rb
221
223
  - examples/basic_draw_text.rb
222
224
  - examples/basic_draw_text2.rb
@@ -226,6 +228,7 @@ files:
226
228
  - examples/basic_image3.rb
227
229
  - examples/basic_image4.rb
228
230
  - examples/basic_image5.rb
231
+ - examples/basic_scrolling_area.rb
229
232
  - examples/basic_table.rb
230
233
  - examples/basic_table_button.rb
231
234
  - examples/basic_table_checkbox.rb