glimmer-dsl-libui 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7033d9033941a3dac53c927ae7ddfdd27127eb4286a936d36e86acb226e57f99
4
- data.tar.gz: e88c6c0fd4dd246e4f4f7d9f38cc3c8d10f31e0c3cbbd329de4bdd70b4618cf0
3
+ metadata.gz: 65d8bf2e6e00eeece96482279bc7dedb367ee21f4a88dd8b96869ff78e051e2f
4
+ data.tar.gz: 3b3ca0d276675e9787a22f8318089bf4d88f3fea1df0d225d024a1037f63d5fc
5
5
  SHA512:
6
- metadata.gz: 97140fa3ac706b51f054a047d310172c7469eadca3b90307ff8174443c7f9655a6369e59e6f0ce68c52e7dc1189e5c53abd6654b89e0d5b52f2eed638f347d32
7
- data.tar.gz: 24687499c2bd93b4514d6e7d472e57a788d50315b944bc7289a871b7286b91e46e43fd7651b28b0f1ac4a074f80efdae385a1f3b6d3cdbeaab2cbf46cc0f4c30
6
+ metadata.gz: 00a8a549d4aa8c13fe2824f2fda437d6de675b02108ac3e6196c149db02ee0fd48a6ff11e509155eecf512a9ae66e89c60b850cd99cae44ad1302c1533405330
7
+ data.tar.gz: 9432f12897bad09cbaf9b72077d15968bc87852a35055e083923779ad311ef5b1221e1a9e1382f7623c0a1524540d98e2e20e91583530facaac5d505cece357c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.4
4
+
5
+ - Support examples/custom_draw_text.rb
6
+ - Support stable `text` control nestable under `area`
7
+ - Support `string` control property `background`
8
+ - Support `string` control property `font`
9
+ - Support `string` control property `underline`
10
+ - Enhance `combobox` to accept `String` value for `selected` item instead of just `Integer` index
11
+ - Add `selected_item` read-only property to `combobox` to return selected item `String` value
12
+ - Fix `color` property support for `string` to accept 255-based rgb values
13
+ - Fix issue with alternating string colors in examples/basic_draw_text.rb
14
+
3
15
  ## 0.2.3
4
16
 
5
17
  - Update examples/midi_player.rb to read sounds locally from gem
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.2.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.2.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
  [![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
@@ -197,7 +197,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
197
197
 
198
198
  ## Table of Contents
199
199
 
200
- - [Glimmer DSL for LibUI 0.2.3](#-glimmer-dsl-for-libui-023)
200
+ - [Glimmer DSL for LibUI 0.2.4](#-glimmer-dsl-for-libui-024)
201
201
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
202
202
  - [Usage](#usage)
203
203
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
@@ -245,6 +245,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
245
245
  - [Timer](#timer)
246
246
  - [Color The Circles](#color-the-circles)
247
247
  - [Basic Draw Text](#basic-draw-text)
248
+ - [Custom Draw Text](#custom-draw-text)
248
249
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
249
250
  - [Help](#help)
250
251
  - [Issues](#issues)
@@ -332,7 +333,7 @@ gem install glimmer-dsl-libui
332
333
  Or install via Bundler `Gemfile`:
333
334
 
334
335
  ```ruby
335
- gem 'glimmer-dsl-libui', '~> 0.2.3'
336
+ gem 'glimmer-dsl-libui', '~> 0.2.4'
336
337
  ```
337
338
 
338
339
  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.
@@ -4566,8 +4567,6 @@ Linux
4566
4567
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4567
4568
 
4568
4569
  ```ruby
4569
- # frozen_string_literal: true
4570
-
4571
4570
  require 'glimmer-dsl-libui'
4572
4571
 
4573
4572
  class Timer
@@ -4579,13 +4578,13 @@ class Timer
4579
4578
 
4580
4579
  def initialize
4581
4580
  @pid = nil
4582
- @midi_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
4583
- at_exit { stop_midi }
4581
+ @alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
4582
+ at_exit { stop_alarm }
4584
4583
  setup_timer
4585
4584
  create_gui
4586
4585
  end
4587
4586
 
4588
- def stop_midi
4587
+ def stop_alarm
4589
4588
  if @pid
4590
4589
  if @th.alive?
4591
4590
  Process.kill(:SIGKILL, @pid)
@@ -4596,11 +4595,11 @@ class Timer
4596
4595
  end
4597
4596
  end
4598
4597
 
4599
- def play_midi
4600
- stop_midi
4598
+ def play_alarm
4599
+ stop_alarm
4601
4600
  if @pid.nil?
4602
4601
  begin
4603
- @pid = spawn "timidity -G 0.0-10.0 #{@midi_file}"
4602
+ @pid = spawn "timidity -G 0.0-10.0 #{@alarm_file}"
4604
4603
  @th = Process.detach @pid
4605
4604
  rescue Errno::ENOENT
4606
4605
  warn 'Timidty++ not found. Please install Timidity++.'
@@ -4635,7 +4634,8 @@ class Timer
4635
4634
  @stop_button.enabled = false
4636
4635
  @started = false
4637
4636
  unless @played
4638
- play_midi
4637
+ play_alarm
4638
+ msg_box('Alarm', 'Countdown Is Finished!')
4639
4639
  @played = true
4640
4640
  end
4641
4641
  end
@@ -4964,7 +4964,123 @@ Linux
4964
4964
 
4965
4965
  ![glimmer-dsl-libui-linux-basic-draw-text.png](images/glimmer-dsl-libui-linux-basic-draw-text.png)
4966
4966
 
4967
- New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4967
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
4968
+
4969
+ ```ruby
4970
+ require 'libui'
4971
+
4972
+ UI = LibUI
4973
+
4974
+ UI.init
4975
+
4976
+ handler = UI::FFI::AreaHandler.malloc
4977
+ area = UI.new_area(handler)
4978
+
4979
+ # Michael Ende (1929-1995)
4980
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
4981
+ # The English version, translated by Ralph Manheim, was published in 1983.
4982
+
4983
+ TITLE = 'Michael Ende (1929-1995) The Neverending Story'
4984
+
4985
+ str1 = \
4986
+ ' At last Ygramul sensed that something was coming toward ' \
4987
+ 'her. With the speed of lightning, she turned about, confronting ' \
4988
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
4989
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
4990
+
4991
+ str2 = \
4992
+ ' A cry of fear escaped Bastian. '
4993
+
4994
+ str3 = \
4995
+ ' A cry of terror passed through the ravine and echoed from ' \
4996
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
4997
+ 'someone else had arrived, for that sound could not have been ' \
4998
+ 'made by the boy who stood there as though paralyzed with ' \
4999
+ 'horror. '
5000
+
5001
+ str4 = \
5002
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5003
+ "But that's not possible. "
5004
+
5005
+ str5 = \
5006
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5007
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5008
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5009
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5010
+ 'words. '
5011
+
5012
+ str = ''
5013
+ attr_str = UI.new_attributed_string(str)
5014
+
5015
+ def attr_str.append(what, color)
5016
+ case color
5017
+ when :red
5018
+ color_attribute = UI.new_color_attribute(0.0, 0.5, 0.0, 0.7)
5019
+ when :green
5020
+ color_attribute = UI.new_color_attribute(0.5, 0.0, 0.25, 0.7)
5021
+ end
5022
+ start = UI.attributed_string_len(self)
5023
+ UI.attributed_string_append_unattributed(self, what)
5024
+ UI.attributed_string_set_attribute(self, color_attribute, start, start + what.size)
5025
+ UI.attributed_string_append_unattributed(self, "\n\n")
5026
+ end
5027
+
5028
+ attr_str.append(str1, :green)
5029
+ attr_str.append(str2, :red)
5030
+ attr_str.append(str3, :green)
5031
+ attr_str.append(str4, :red)
5032
+ attr_str.append(str5, :green)
5033
+
5034
+ Georgia = 'Georgia'
5035
+
5036
+ handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, adp|
5037
+ area_draw_params = UI::FFI::AreaDrawParams.new(adp)
5038
+ default_font = UI::FFI::FontDescriptor.malloc
5039
+ default_font.Family = Georgia
5040
+ default_font.Size = 13
5041
+ default_font.Weight = 500
5042
+ default_font.Italic = 0
5043
+ default_font.Stretch = 4
5044
+ params = UI::FFI::DrawTextLayoutParams.malloc
5045
+
5046
+ # UI.font_button_font(font_button, default_font)
5047
+ params.String = attr_str
5048
+ params.DefaultFont = default_font
5049
+ params.Width = area_draw_params.AreaWidth
5050
+ params.Align = 0
5051
+ text_layout = UI.draw_new_text_layout(params)
5052
+ UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
5053
+ UI.draw_free_text_layout(text_layout)
5054
+ end
5055
+
5056
+ handler.Draw = handler_draw_event
5057
+ # Assigning to local variables
5058
+ # This is intended to protect Fiddle::Closure from garbage collection.
5059
+ handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5060
+ handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5061
+ handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5062
+ handler.KeyEvent = (c4 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5063
+
5064
+ box = UI.new_vertical_box
5065
+ UI.box_set_padded(box, 1)
5066
+ UI.box_append(box, area, 1)
5067
+
5068
+ main_window = UI.new_window(TITLE, 600, 400, 1)
5069
+ UI.window_set_margined(main_window, 1)
5070
+ UI.window_set_child(main_window, box)
5071
+
5072
+ UI.window_on_closing(main_window) do
5073
+ UI.control_destroy(main_window)
5074
+ UI.quit
5075
+ 0
5076
+ end
5077
+ UI.control_show(main_window)
5078
+
5079
+ UI.main
5080
+ UI.quit
5081
+ ```
5082
+
5083
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4968
5084
 
4969
5085
  ```ruby
4970
5086
  require 'glimmer-dsl-libui'
@@ -4975,8 +5091,78 @@ require 'glimmer-dsl-libui'
4975
5091
  class BasicDrawText
4976
5092
  include Glimmer
4977
5093
 
4978
- def alternating_color_string(&block)
4979
- @index ||= 0
5094
+ def alternating_color_string(initial: false, &block)
5095
+ @index = 0 if initial
5096
+ @index += 1
5097
+ string {
5098
+ if @index.odd?
5099
+ color r: 0.5, g: 0, b: 0.25, a: 0.7
5100
+ else
5101
+ color r: 0, g: 0.5, b: 0, a: 0.7
5102
+ end
5103
+
5104
+ block.call + "\n\n"
5105
+ }
5106
+ end
5107
+
5108
+ def launch
5109
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5110
+ margined true
5111
+
5112
+ area {
5113
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5114
+ # align :left # default alignment
5115
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
5116
+
5117
+ alternating_color_string(initial: true) {
5118
+ ' At last Ygramul sensed that something was coming toward ' \
5119
+ 'her. With the speed of lightning, she turned about, confronting ' \
5120
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5121
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
5122
+ }
5123
+ alternating_color_string {
5124
+ ' A cry of fear escaped Bastian. '
5125
+ }
5126
+ alternating_color_string {
5127
+ ' A cry of terror passed through the ravine and echoed from ' \
5128
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5129
+ 'someone else had arrived, for that sound could not have been ' \
5130
+ 'made by the boy who stood there as though paralyzed with ' \
5131
+ 'horror. '
5132
+ }
5133
+ alternating_color_string {
5134
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5135
+ "But that's not possible. "
5136
+ }
5137
+ alternating_color_string {
5138
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5139
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5140
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5141
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5142
+ 'words. '
5143
+ }
5144
+ }
5145
+ }
5146
+ }.show
5147
+ end
5148
+ end
5149
+
5150
+ BasicDrawText.new.launch
5151
+ ```
5152
+
5153
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
5154
+
5155
+ ```ruby
5156
+ require 'glimmer-dsl-libui'
5157
+
5158
+ # Michael Ende (1929-1995)
5159
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5160
+ # The English version, translated by Ralph Manheim, was published in 1983.
5161
+ class BasicDrawText
5162
+ include Glimmer
5163
+
5164
+ def alternating_color_string(initial: false, &block)
5165
+ @index = 0 if initial
4980
5166
  @index += 1
4981
5167
  string {
4982
5168
  if @index.odd?
@@ -4995,11 +5181,11 @@ class BasicDrawText
4995
5181
 
4996
5182
  area {
4997
5183
  on_draw do |area_draw_params|
4998
- text(0, 0, area_draw_params[:area_width]) {
4999
- align 0
5000
- default_font family: 'Georgia', size: 13, weight: 500, italic: 0, stretch: 4
5184
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5185
+ # align :left # default alignment
5186
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
5001
5187
 
5002
- alternating_color_string {
5188
+ alternating_color_string(initial: true) {
5003
5189
  ' At last Ygramul sensed that something was coming toward ' \
5004
5190
  'her. With the speed of lightning, she turned about, confronting ' \
5005
5191
  'Atreyu with an enormous steel-blue face. Her single eye had a ' \
@@ -5036,6 +5222,222 @@ end
5036
5222
  BasicDrawText.new.launch
5037
5223
  ```
5038
5224
 
5225
+ ### Custom Draw Text
5226
+
5227
+ [examples/custom_draw_text.rb](examples/custom_draw_text.rb)
5228
+
5229
+ Run with this command from the root of the project if you cloned the project:
5230
+
5231
+ ```
5232
+ ruby -r './lib/glimmer-dsl-libui' examples/custom_draw_text.rb
5233
+ ```
5234
+
5235
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
5236
+
5237
+ ```
5238
+ ruby -r glimmer-dsl-libui -e "require 'examples/custom_draw_text'"
5239
+ ```
5240
+
5241
+ Mac
5242
+
5243
+ ![glimmer-dsl-libui-mac-custom-draw-text.png](images/glimmer-dsl-libui-mac-custom-draw-text.png)
5244
+ ![glimmer-dsl-libui-mac-custom-draw-text-changed.png](images/glimmer-dsl-libui-mac-custom-draw-text-changed.png)
5245
+
5246
+ Linux
5247
+
5248
+ ![glimmer-dsl-libui-linux-custom-draw-text.png](images/glimmer-dsl-libui-linux-custom-draw-text.png)
5249
+ ![glimmer-dsl-libui-linux-custom-draw-text-changed.png](images/glimmer-dsl-libui-linux-custom-draw-text-changed.png)
5250
+
5251
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
5252
+
5253
+ ```ruby
5254
+ require 'glimmer-dsl-libui'
5255
+
5256
+ # Michael Ende (1929-1995)
5257
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5258
+ # The English version, translated by Ralph Manheim, was published in 1983.
5259
+ class CustomDrawText
5260
+ include Glimmer
5261
+
5262
+ def launch
5263
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5264
+ margined true
5265
+
5266
+ vertical_box {
5267
+ form {
5268
+ stretchy false
5269
+
5270
+ font_button { |fb|
5271
+ label 'Font'
5272
+
5273
+ on_changed do
5274
+ @string.font = fb.font
5275
+ end
5276
+ }
5277
+ color_button { |cb|
5278
+ label 'Color'
5279
+
5280
+ on_changed do
5281
+ @string.color = cb.color
5282
+ end
5283
+ }
5284
+ color_button { |cb|
5285
+ label 'Background'
5286
+
5287
+ on_changed do
5288
+ @string.background = cb.color
5289
+ end
5290
+ }
5291
+ combobox { |c|
5292
+ label 'Underline'
5293
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
5294
+ selected 'None'
5295
+
5296
+ on_selected do
5297
+ @string.underline = c.selected_item.underscore
5298
+ end
5299
+ }
5300
+ }
5301
+
5302
+ area {
5303
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5304
+ # align :left # default alignment
5305
+
5306
+ @string = string {
5307
+ ' At last Ygramul sensed that something was coming toward ' \
5308
+ 'her. With the speed of lightning, she turned about, confronting ' \
5309
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5310
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
5311
+ "\n\n" \
5312
+ ' A cry of fear escaped Bastian. ' \
5313
+ "\n\n" \
5314
+ ' A cry of terror passed through the ravine and echoed from ' \
5315
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5316
+ 'someone else had arrived, for that sound could not have been ' \
5317
+ 'made by the boy who stood there as though paralyzed with ' \
5318
+ 'horror. ' \
5319
+ "\n\n" \
5320
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5321
+ "But that's not possible. " \
5322
+ "\n\n" \
5323
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5324
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5325
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5326
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5327
+ 'words. ' \
5328
+ "\n\n"
5329
+ }
5330
+ }
5331
+ }
5332
+ }
5333
+ }.show
5334
+ end
5335
+ end
5336
+
5337
+ CustomDrawText.new.launch
5338
+ ```
5339
+
5340
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
5341
+
5342
+ ```ruby
5343
+ require 'glimmer-dsl-libui'
5344
+
5345
+ # Michael Ende (1929-1995)
5346
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5347
+ # The English version, translated by Ralph Manheim, was published in 1983.
5348
+ class CustomDrawText
5349
+ include Glimmer
5350
+
5351
+ def launch
5352
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5353
+ margined true
5354
+
5355
+ vertical_box {
5356
+ form {
5357
+ stretchy false
5358
+
5359
+ font_button { |fb|
5360
+ label 'Font'
5361
+
5362
+ on_changed do
5363
+ @font = fb.font
5364
+ @area.queue_redraw_all
5365
+ end
5366
+ }
5367
+ color_button { |cb|
5368
+ label 'Color'
5369
+
5370
+ on_changed do
5371
+ @color = cb.color
5372
+ @area.queue_redraw_all
5373
+ end
5374
+ }
5375
+ color_button { |cb|
5376
+ label 'Background'
5377
+
5378
+ on_changed do
5379
+ @background = cb.color
5380
+ @area.queue_redraw_all
5381
+ end
5382
+ }
5383
+ combobox { |c|
5384
+ label 'Underline'
5385
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
5386
+ selected 'None'
5387
+
5388
+ on_selected do
5389
+ @underline = c.selected_item.underscore
5390
+ @area.queue_redraw_all
5391
+ end
5392
+ }
5393
+ }
5394
+
5395
+ @area = area {
5396
+ on_draw do |area_draw_params|
5397
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5398
+ # align :left # default alignment
5399
+
5400
+ @string = string {
5401
+ font @font unless @font.nil?
5402
+ color @color unless @color.nil?
5403
+ background @background unless @background.nil?
5404
+ underline @underline unless @underline.nil?
5405
+
5406
+ ' At last Ygramul sensed that something was coming toward ' \
5407
+ 'her. With the speed of lightning, she turned about, confronting ' \
5408
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5409
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
5410
+ "\n\n" \
5411
+ ' A cry of fear escaped Bastian. ' \
5412
+ "\n\n" \
5413
+ ' A cry of terror passed through the ravine and echoed from ' \
5414
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5415
+ 'someone else had arrived, for that sound could not have been ' \
5416
+ 'made by the boy who stood there as though paralyzed with ' \
5417
+ 'horror. ' \
5418
+ "\n\n" \
5419
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5420
+ "But that's not possible. " \
5421
+ "\n\n" \
5422
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5423
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5424
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5425
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5426
+ 'words. ' \
5427
+ "\n\n"
5428
+ }
5429
+ }
5430
+ end
5431
+ }
5432
+ }
5433
+ }.show
5434
+ end
5435
+ end
5436
+
5437
+ CustomDrawText.new.launch
5438
+
5439
+ ```
5440
+
5039
5441
  ## Contributing to glimmer-dsl-libui
5040
5442
 
5041
5443
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -6,14 +6,14 @@ require 'glimmer-dsl-libui'
6
6
  class BasicDrawText
7
7
  include Glimmer
8
8
 
9
- def alternating_color_string(&block)
10
- @index ||= 0
9
+ def alternating_color_string(initial: false, &block)
10
+ @index = 0 if initial
11
11
  @index += 1
12
12
  string {
13
13
  if @index.odd?
14
- color r: 0.5, g: 0, b: 0.25, a: 0.7
14
+ color r: 128, g: 0, b: 64, a: 0.7
15
15
  else
16
- color r: 0, g: 0.5, b: 0, a: 0.7
16
+ color r: 0, g: 128, b: 0, a: 0.7
17
17
  end
18
18
 
19
19
  block.call + "\n\n"
@@ -25,40 +25,38 @@ class BasicDrawText
25
25
  margined true
26
26
 
27
27
  area {
28
- on_draw do |area_draw_params|
29
- text(0, 0, area_draw_params[:area_width]) {
30
- align 0
31
- default_font family: 'Georgia', size: 13, weight: 500, italic: 0, stretch: 4
32
-
33
- alternating_color_string {
34
- ' At last Ygramul sensed that something was coming toward ' \
35
- 'her. With the speed of lightning, she turned about, confronting ' \
36
- 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
37
- 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
38
- }
39
- alternating_color_string {
40
- ' A cry of fear escaped Bastian. '
41
- }
42
- alternating_color_string {
43
- ' A cry of terror passed through the ravine and echoed from ' \
44
- 'side to side. Ygramul turned her eye to left and right, to see if ' \
45
- 'someone else had arrived, for that sound could not have been ' \
46
- 'made by the boy who stood there as though paralyzed with ' \
47
- 'horror. '
48
- }
49
- alternating_color_string {
50
- ' Could she have heard my cry? Bastion wondered in alarm. ' \
51
- "But that's not possible. "
52
- }
53
- alternating_color_string {
54
- ' And then Atreyu heard Ygramuls voice. It was very high ' \
55
- 'and slightly hoarse, not at all the right kind of voice for that ' \
56
- 'enormous face. Her lips did not move as she spoke. It was the ' \
57
- 'buzzing of a great swarm of hornets that shaped itself into ' \
58
- 'words. '
59
- }
28
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
29
+ # align :left # default alignment
30
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
31
+
32
+ alternating_color_string(initial: true) {
33
+ ' At last Ygramul sensed that something was coming toward ' \
34
+ 'her. With the speed of lightning, she turned about, confronting ' \
35
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
36
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
60
37
  }
61
- end
38
+ alternating_color_string {
39
+ ' A cry of fear escaped Bastian. '
40
+ }
41
+ alternating_color_string {
42
+ ' A cry of terror passed through the ravine and echoed from ' \
43
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
44
+ 'someone else had arrived, for that sound could not have been ' \
45
+ 'made by the boy who stood there as though paralyzed with ' \
46
+ 'horror. '
47
+ }
48
+ alternating_color_string {
49
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
50
+ "But that's not possible. "
51
+ }
52
+ alternating_color_string {
53
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
54
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
55
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
56
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
57
+ 'words. '
58
+ }
59
+ }
62
60
  }
63
61
  }.show
64
62
  end
@@ -0,0 +1,68 @@
1
+
2
+ require 'glimmer-dsl-libui'
3
+
4
+ # Michael Ende (1929-1995)
5
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
6
+ # The English version, translated by Ralph Manheim, was published in 1983.
7
+ class BasicDrawText
8
+ include Glimmer
9
+
10
+ def alternating_color_string(initial: false, &block)
11
+ @index = 0 if initial
12
+ @index += 1
13
+ string {
14
+ if @index.odd?
15
+ color r: 128, g: 0, b: 64, a: 0.7
16
+ else
17
+ color r: 0, g: 128, b: 0, a: 0.7
18
+ end
19
+
20
+ block.call + "\n\n"
21
+ }
22
+ end
23
+
24
+ def launch
25
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
26
+ margined true
27
+
28
+ area {
29
+ on_draw do |area_draw_params|
30
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
31
+ # align :left # default alignment
32
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
33
+
34
+ alternating_color_string(initial: true) {
35
+ ' At last Ygramul sensed that something was coming toward ' \
36
+ 'her. With the speed of lightning, she turned about, confronting ' \
37
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
38
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
39
+ }
40
+ alternating_color_string {
41
+ ' A cry of fear escaped Bastian. '
42
+ }
43
+ alternating_color_string {
44
+ ' A cry of terror passed through the ravine and echoed from ' \
45
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
46
+ 'someone else had arrived, for that sound could not have been ' \
47
+ 'made by the boy who stood there as though paralyzed with ' \
48
+ 'horror. '
49
+ }
50
+ alternating_color_string {
51
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
52
+ "But that's not possible. "
53
+ }
54
+ alternating_color_string {
55
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
56
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
57
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
58
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
59
+ 'words. '
60
+ }
61
+ }
62
+ end
63
+ }
64
+ }.show
65
+ end
66
+ end
67
+
68
+ BasicDrawText.new.launch
@@ -0,0 +1,84 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ # Michael Ende (1929-1995)
4
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5
+ # The English version, translated by Ralph Manheim, was published in 1983.
6
+ class CustomDrawText
7
+ include Glimmer
8
+
9
+ def launch
10
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
11
+ margined true
12
+
13
+ vertical_box {
14
+ form {
15
+ stretchy false
16
+
17
+ font_button { |fb|
18
+ label 'Font'
19
+
20
+ on_changed do
21
+ @string.font = fb.font
22
+ end
23
+ }
24
+ color_button { |cb|
25
+ label 'Color'
26
+
27
+ on_changed do
28
+ @string.color = cb.color
29
+ end
30
+ }
31
+ color_button { |cb|
32
+ label 'Background'
33
+
34
+ on_changed do
35
+ @string.background = cb.color
36
+ end
37
+ }
38
+ combobox { |c|
39
+ label 'Underline'
40
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
41
+ selected 'None'
42
+
43
+ on_selected do
44
+ @string.underline = c.selected_item.underscore
45
+ end
46
+ }
47
+ }
48
+
49
+ area {
50
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
51
+ # align :left # default alignment
52
+
53
+ @string = string {
54
+ ' At last Ygramul sensed that something was coming toward ' \
55
+ 'her. With the speed of lightning, she turned about, confronting ' \
56
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
57
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
58
+ "\n\n" \
59
+ ' A cry of fear escaped Bastian. ' \
60
+ "\n\n" \
61
+ ' A cry of terror passed through the ravine and echoed from ' \
62
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
63
+ 'someone else had arrived, for that sound could not have been ' \
64
+ 'made by the boy who stood there as though paralyzed with ' \
65
+ 'horror. ' \
66
+ "\n\n" \
67
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
68
+ "But that's not possible. " \
69
+ "\n\n" \
70
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
71
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
72
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
73
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
74
+ 'words. ' \
75
+ "\n\n"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }.show
81
+ end
82
+ end
83
+
84
+ CustomDrawText.new.launch
@@ -0,0 +1,95 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ # Michael Ende (1929-1995)
4
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5
+ # The English version, translated by Ralph Manheim, was published in 1983.
6
+ class CustomDrawText
7
+ include Glimmer
8
+
9
+ def launch
10
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
11
+ margined true
12
+
13
+ vertical_box {
14
+ form {
15
+ stretchy false
16
+
17
+ font_button { |fb|
18
+ label 'Font'
19
+
20
+ on_changed do
21
+ @font = fb.font
22
+ @area.queue_redraw_all
23
+ end
24
+ }
25
+ color_button { |cb|
26
+ label 'Color'
27
+
28
+ on_changed do
29
+ @color = cb.color
30
+ @area.queue_redraw_all
31
+ end
32
+ }
33
+ color_button { |cb|
34
+ label 'Background'
35
+
36
+ on_changed do
37
+ @background = cb.color
38
+ @area.queue_redraw_all
39
+ end
40
+ }
41
+ combobox { |c|
42
+ label 'Underline'
43
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
44
+ selected 'None'
45
+
46
+ on_selected do
47
+ @underline = c.selected_item.underscore
48
+ @area.queue_redraw_all
49
+ end
50
+ }
51
+ }
52
+
53
+ @area = area {
54
+ on_draw do |area_draw_params|
55
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
56
+ # align :left # default alignment
57
+
58
+ @string = string {
59
+ font @font
60
+ color @color
61
+ background @background
62
+ underline @underline
63
+
64
+ ' At last Ygramul sensed that something was coming toward ' \
65
+ 'her. With the speed of lightning, she turned about, confronting ' \
66
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
67
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
68
+ "\n\n" \
69
+ ' A cry of fear escaped Bastian. ' \
70
+ "\n\n" \
71
+ ' A cry of terror passed through the ravine and echoed from ' \
72
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
73
+ 'someone else had arrived, for that sound could not have been ' \
74
+ 'made by the boy who stood there as though paralyzed with ' \
75
+ 'horror. ' \
76
+ "\n\n" \
77
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
78
+ "But that's not possible. " \
79
+ "\n\n" \
80
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
81
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
82
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
83
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
84
+ 'words. ' \
85
+ "\n\n"
86
+ }
87
+ }
88
+ end
89
+ }
90
+ }
91
+ }.show
92
+ end
93
+ end
94
+
95
+ CustomDrawText.new.launch
Binary file
@@ -40,24 +40,48 @@ module Glimmer
40
40
  end
41
41
 
42
42
  def font(value = nil)
43
- # UI.attributed_string_set_attribute(@parent_proxy.attributed_string, color_attribute, start, start + @string.size)
43
+ if value.nil?
44
+ @font
45
+ else
46
+ @font = value
47
+ redraw
48
+ end
44
49
  end
50
+ alias font= font
51
+ alias set_font font
45
52
 
46
53
  def color(value = nil)
47
54
  if value.nil?
48
55
  @color
49
56
  else
50
57
  @color = Glimmer::LibUI.interpret_color(value)
58
+ redraw
51
59
  end
52
60
  end
61
+ alias color= color
62
+ alias set_color color
53
63
 
54
64
  def background(value = nil)
55
- # UI.attributed_string_set_attribute(@parent_proxy.attributed_string, color_attribute, start, start + @string.size)
65
+ if value.nil?
66
+ @background
67
+ else
68
+ @background = Glimmer::LibUI.interpret_color(value)
69
+ redraw
70
+ end
56
71
  end
72
+ alias background= background
73
+ alias background background
57
74
 
58
75
  def underline(value = nil)
59
- # UI.attributed_string_set_attribute(@parent_proxy.attributed_string, color_attribute, start, start + @string.size)
76
+ if value.nil?
77
+ @underline
78
+ else
79
+ @underline = value
80
+ redraw
81
+ end
60
82
  end
83
+ alias underline= underline
84
+ alias underline underline
61
85
 
62
86
  def post_add_content
63
87
  block_result = block&.call
@@ -69,9 +93,30 @@ module Glimmer
69
93
  @start = ::LibUI.attributed_string_len(@parent_proxy.attributed_string)
70
94
  ::LibUI.attributed_string_append_unattributed(@parent_proxy.attributed_string, @string)
71
95
  unless color.nil?
72
- color_attribute = ::LibUI.new_color_attribute(@color[:r], @color[:g], @color[:b], @color[:a] || 1.0)
96
+ color_attribute = ::LibUI.new_color_attribute(@color[:r].to_f / 255.0, @color[:g].to_f / 255.0, @color[:b].to_f / 255.0, @color[:a] || 1.0)
73
97
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, color_attribute, @start, @start + @string.size)
74
98
  end
99
+ unless background.nil?
100
+ background_attribute = ::LibUI.new_background_attribute(@background[:r].to_f / 255.0, @background[:g].to_f / 255.0, @background[:b].to_f / 255.0, @background[:a] || 1.0)
101
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, background_attribute, @start, @start + @string.size)
102
+ end
103
+ unless underline.nil?
104
+ underline_attribute = ::LibUI.new_underline_attribute(Glimmer::LibUI.enum_symbol_to_value(:underline, @underline))
105
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_attribute, @start, @start + @string.size)
106
+ end
107
+ unless font.nil?
108
+ family_attribute = ::LibUI.new_family_attribute(font[:family])
109
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
110
+ size_attribute = ::LibUI.new_size_attribute(font[:size])
111
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, size_attribute, @start, @start + @string.size)
112
+ weight_attribute = ::LibUI.new_weight_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_weight, font[:weight]))
113
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, weight_attribute, @start, @start + @string.size)
114
+ italic_attribute = ::LibUI.new_italic_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_italic, font[:italic]))
115
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, italic_attribute, @start, @start + @string.size)
116
+ stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
117
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
118
+ end
119
+ destroy if area_proxy.nil?
75
120
  end
76
121
 
77
122
  def destroy
@@ -29,7 +29,6 @@ module Glimmer
29
29
  # Follows the Proxy Design Pattern
30
30
  class ColorButtonProxy < ControlProxy
31
31
  def color(value = nil)
32
- # TODO support hex color value
33
32
  if value.nil?
34
33
  @red ||= Fiddle::Pointer.malloc(8) # double
35
34
  @green ||= Fiddle::Pointer.malloc(8) # double
@@ -28,6 +28,20 @@ module Glimmer
28
28
  #
29
29
  # Follows the Proxy Design Pattern
30
30
  class ComboboxProxy < ControlProxy
31
+ def selected(value = nil)
32
+ if value.nil?
33
+ super()
34
+ else
35
+ if value.is_a?(String)
36
+ super(items.index(value).to_i)
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+ alias selected= selected
43
+ alias set_selected selected
44
+
31
45
  def items(*values)
32
46
  values = values.first if values.first.is_a?(Array)
33
47
  if values.empty?
@@ -39,6 +53,10 @@ module Glimmer
39
53
  end
40
54
  alias set_items items
41
55
  alias items= items
56
+
57
+ def selected_item
58
+ items[selected]
59
+ end
42
60
  end
43
61
  end
44
62
  end
@@ -51,6 +51,7 @@ module Glimmer
51
51
  end
52
52
 
53
53
  def draw(area_draw_params)
54
+ reset_attributed_string
54
55
  children.dup.each {|child| child.draw(area_draw_params)}
55
56
  build_control
56
57
  ::LibUI.draw_text(area_draw_params[:context], @libui, x, y)
@@ -88,23 +89,35 @@ module Glimmer
88
89
 
89
90
  def width(value = nil)
90
91
  if value.nil?
91
- @width ||= args[2] || (AreaProxy.current_area_draw_params && AreaProxy.current_area_draw_params[:width])
92
+ @width ||= args[2] || (AreaProxy.current_area_draw_params && AreaProxy.current_area_draw_params[:area_width])
92
93
  else
93
94
  @width = value
95
+ redraw
94
96
  end
95
97
  end
96
98
  alias width= width
97
99
  alias set_width width
98
100
 
99
101
  def attributed_string
100
- @attributed_string ||= ::LibUI.new_attributed_string('')
102
+ @attributed_string ||= reset_attributed_string
103
+ end
104
+
105
+ def reset_attributed_string
106
+ @attributed_string = ::LibUI.new_attributed_string('')
101
107
  end
102
108
 
103
109
  def default_font(value = nil)
104
110
  if value.nil?
105
- @default_font ||= {}
111
+ @default_font ||= {
112
+ family: 'Helvetica',
113
+ size: 12.0,
114
+ weight: :normal,
115
+ italic: :normal,
116
+ stretch: :normal,
117
+ }
106
118
  else
107
119
  @default_font = value
120
+ redraw
108
121
  end
109
122
  end
110
123
  alias default_font= default_font
@@ -122,9 +135,10 @@ module Glimmer
122
135
 
123
136
  def align(value = nil)
124
137
  if value.nil?
125
- @align ||= {}
138
+ @align
126
139
  else
127
140
  @align = value
141
+ redraw
128
142
  end
129
143
  end
130
144
  alias align= align
@@ -135,7 +149,7 @@ module Glimmer
135
149
  @draw_text_layout_params.String = attributed_string
136
150
  @draw_text_layout_params.DefaultFont = default_font_descriptor
137
151
  @draw_text_layout_params.Width = width
138
- @draw_text_layout_params.Align = Glimmer::LibUI.enum_symbol_to_value(:draw_text_align, align, default_symbol: :center)
152
+ @draw_text_layout_params.Align = Glimmer::LibUI.enum_symbol_to_value(:draw_text_align, align, default_symbol: :left)
139
153
  @draw_text_layout_params
140
154
  end
141
155
 
data/lib/glimmer/libui.rb CHANGED
@@ -115,7 +115,7 @@ module Glimmer
115
115
  if enum_symbol.is_a?(Integer)
116
116
  enum_symbol
117
117
  elsif enum_symbols(enum_name).include?(enum_symbol.to_s.to_sym)
118
- enum_symbol_values(enum_name)[enum_symbol]
118
+ enum_symbol_values(enum_name)[enum_symbol.to_s.to_sym]
119
119
  elsif default_symbol
120
120
  enum_symbol_to_value(enum_name, default_symbol)
121
121
  else
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -216,6 +216,7 @@ files:
216
216
  - examples/basic_area2.rb
217
217
  - examples/basic_button.rb
218
218
  - examples/basic_draw_text.rb
219
+ - examples/basic_draw_text2.rb
219
220
  - examples/basic_entry.rb
220
221
  - examples/basic_table.rb
221
222
  - examples/basic_table_button.rb
@@ -230,6 +231,8 @@ files:
230
231
  - examples/color_button.rb
231
232
  - examples/color_the_circles.rb
232
233
  - examples/control_gallery.rb
234
+ - examples/custom_draw_text.rb
235
+ - examples/custom_draw_text2.rb
233
236
  - examples/date_time_picker.rb
234
237
  - examples/dynamic_area.rb
235
238
  - examples/dynamic_area2.rb