glimmer-dsl-libui 0.2.3 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
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.7
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.7](#-glimmer-dsl-for-libui-027)
201
201
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
202
202
  - [Usage](#usage)
203
203
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
@@ -235,6 +235,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
235
235
  - [Basic Table Checkbox](#basic-table-checkbox)
236
236
  - [Basic Table Checkbox Text](#basic-table-checkbox-text)
237
237
  - [Basic Table Progress Bar](#basic-table-progress-bar)
238
+ - [Basic Table Color](#basic-table-color)
238
239
  - [Form Table](#form-table)
239
240
  - [Basic Area](#basic-area)
240
241
  - [Dynamic Area](#dynamic-area)
@@ -245,6 +246,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
245
246
  - [Timer](#timer)
246
247
  - [Color The Circles](#color-the-circles)
247
248
  - [Basic Draw Text](#basic-draw-text)
249
+ - [Custom Draw Text](#custom-draw-text)
248
250
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
249
251
  - [Help](#help)
250
252
  - [Issues](#issues)
@@ -332,7 +334,7 @@ gem install glimmer-dsl-libui
332
334
  Or install via Bundler `Gemfile`:
333
335
 
334
336
  ```ruby
335
- gem 'glimmer-dsl-libui', '~> 0.2.3'
337
+ gem 'glimmer-dsl-libui', '~> 0.2.7'
336
338
  ```
337
339
 
338
340
  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.
@@ -408,12 +410,14 @@ Control(Args) | Properties | Listeners
408
410
  `about_menu_item` | None | `on_clicked`
409
411
  `area` | None | `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)`
410
412
  `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)` | `x_center` (`Numeric`), `y_center` (`Numeric`), `radius` (`Numeric`), `start_angle` (`Numeric`), `sweep` (`Numeric`), `is_negative` (Boolean) | None
413
+ `background_color_column(name as String)` | None | None
411
414
  `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)` | `c1_x` (`Numeric`), `c1_y` (`Numeric`), `c2_x` (`Numeric`), `c2_y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
412
415
  `button(text as String)` | `text` (`String`) | `on_clicked`
413
416
  `button_column(name as String)` | `enabled` (Boolean) | None
414
417
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
415
418
  `checkbox_column(name as String)` | `editable` (Boolean) | None
416
419
  `checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
420
+ `checkbox_text_color_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
417
421
  `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
418
422
  `color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
419
423
  `date_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
@@ -431,6 +435,7 @@ Control(Args) | Properties | Listeners
431
435
  `image_part(pixels as String [encoded image rgba byte array], width as Numeric, height as Numeric, byte_stride as Numeric [usually width*4])` | None | None
432
436
  `image_column(name as String)` | None | None
433
437
  `image_text_column(name as String)` | None | None
438
+ `image_text_color_column(name as String)` | None | None
434
439
  `label(text as String)` | `text` (`String`) | None
435
440
  `line(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`) | None
436
441
  `matrix(m11 = nil as Numeric, m12 = nil as Numeric, m21 = nil as Numeric, m22 = nil as Numeric, m31 = nil as Numeric, m32 = nil as Numeric)` | `m11` (`Numeric`), `m12` (`Numeric`), `m21` (`Numeric`), `m22` (`Numeric`), `m31` (`Numeric`), `m32` (`Numeric`) | None
@@ -452,10 +457,13 @@ Control(Args) | Properties | Listeners
452
457
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
453
458
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
454
459
  `square(x as Numeric, y as Numeric, length as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `length` (`Numeric`) | None
460
+ `string` | `font`, `color`, `background`, `underline`, `underline_color`, `open_type_features` | None
455
461
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
456
462
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
457
463
  `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values for `text_column` cells or `Array` of `image`/`String` for `image_text_column`)), `editable` as Boolean | None
464
+ `text(x = 0 as Numeric, y = 0 as Numeric, width = area_width as Numeric)` | `align`, `default_font` | None
458
465
  `text_column(name as String)` | `editable` (Boolean) | None
466
+ `text_color_column(name as String)` | `editable` (Boolean) | None
459
467
  `time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`) | `on_changed`
460
468
  `vertical_box` | `padded` (Boolean) | None
461
469
  `vertical_separator` | None | None
@@ -509,12 +517,16 @@ All operations that could normally be called on `LibUI` can also be called on `G
509
517
  ### Table API
510
518
 
511
519
  The `table` control must first declare its columns via one of these column keywords (mentioned in [Supported Controls](#supported-controls)):
520
+ - `background_color_column`: expects color cell values
512
521
  - `button_column`: expects `String` cell values
513
522
  - `checkbox_column`: expects Boolean cell values
514
523
  - `checkbox_text_column`: expects dual-element `Array` of Boolean and `String` cell values
524
+ - `checkbox_text_color_column`: expects triple-element `Array` of Boolean, `String`, and color cell values
515
525
  - `image_column`: expects `image` cell values (produced by `image` and `image_part` keywords as per [Supported Controls](#supported-controls))
516
526
  - `image_text_column`: expects dual-element `Array` of `image` and `String` cell values
527
+ - `image_text_color_column`: expects triple-element `Array` of `image`, `String`, and color cell values
517
528
  - `text_column`: expects `String` cell values
529
+ - `text_color_column`: expects dual-element `Array` of `String` and color cell values
518
530
  - `progress_bar_column`: expects `Integer` cell values
519
531
 
520
532
  Afterwards, it must declare its `cell_rows` array (`Array` of `Array`s of column cell values) and whether it is `editable` (Boolean) for all its columns.
@@ -789,6 +801,50 @@ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wi
789
801
 
790
802
  Check [Histogram](#histogram) example for use of hex colors.
791
803
 
804
+ To draw `text` in an `area`, you simply nest a `text(x, y, width)` control directly under `area` or inside a `on_draw` listener, and then nest attributed `string {string_value}` controls underneath it returning an actual `String` (think of them as the `<span>` element in html, which contains a string of text).
805
+
806
+ `text` control can have the following properties:
807
+ - `default_font`:
808
+ - `align`: `:left` (default), `:center`, or `:right` (`align` currently seems not to work on the Mac)
809
+
810
+ `string` can have the following properties:
811
+ - `font`: font descriptor hash consisting of `:family`, `:size`, `:weight` (`[:minimum, :thin, :ultra_light, :light, :book, :normal, :medium, :semi_bold, :bold, :ultra_bold, :heavy, :ultra_heavy, :maximum]`), `:italic` (`[:normal, :oblique, :italic]`), and `:stretch` (`[:ultra_condensed, :extra_condensed, :condensed, :semi_condensed, :normal, :semi_expanded, :expanded, :extra_expanded, :ultra_expanded]`) key values
812
+ - `color`: rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
813
+ - `background`: rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
814
+ - `underline`: one of `:none`, `:single`, `:double`, `:suggestion`, `:color_custom`, `:color_spelling`, `:color_grammar`, `:color_auxiliary`
815
+ - `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
816
+ - `open_type_features`: it must have a block containing `open_type_tag` occurrances, which take the a, b, c, d arguments plus a number at the end.
817
+
818
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
819
+
820
+ ```ruby
821
+ window('area text drawing') {
822
+ area {
823
+ text {
824
+ default_font family: 'Helvetica', size: 12, weight: :normal, italic: :normal, stretch: :normal
825
+
826
+ string {
827
+ font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
828
+ color r: 230, g: 100, b: 50, a: 0.5
829
+ background r: 230, g: 200, b: 250, a: 0.8
830
+ underline :single
831
+ underline_color :spelling
832
+ open_type_features {
833
+ open_type_tag 'l', 'i', 'g', 'a', 0
834
+ open_type_tag 'l', 'i', 'g', 'a', 1
835
+ }
836
+
837
+ "This is a test\n\n"
838
+ }
839
+
840
+ string {
841
+ 'This is another test'
842
+ }
843
+ }
844
+ }
845
+ }.show
846
+ ```
847
+
792
848
  ### Smart Defaults and Conventions
793
849
 
794
850
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
@@ -830,7 +886,7 @@ Check [Histogram](#histogram) example for use of hex colors.
830
886
 
831
887
  - There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`).
832
888
  - `table` `checkbox_column` and `checkbox_text_column` checkbox editing only works on Windows and Linux (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
833
- - It seems that `arc` `start_angle` and `sweep` properties are ignored by [libui](https://github.com/andlabs/libui) and always set to `0` and `360` respectively, producing a full circle.
889
+ - `text` `align` property seems not to work on the Mac ([libui](https://github.com/andlabs/libui) has an [issue](https://github.com/andlabs/libui/pull/407) about it)
834
890
 
835
891
  ### Original API
836
892
 
@@ -2539,7 +2595,7 @@ window('Editable column animal sounds', 400, 200) {
2539
2595
 
2540
2596
  ### Basic Table Image
2541
2597
 
2542
- This example has a prerequisite of installing `chunky_png` Ruby gem:
2598
+ This example requires pre-installing `chunky_png` Ruby gem:
2543
2599
 
2544
2600
  ```
2545
2601
  gem install chunky_png -v1.4.0
@@ -2996,6 +3052,78 @@ window('Task Progress', 300, 200) {
2996
3052
  }.show
2997
3053
  ```
2998
3054
 
3055
+ ### Basic Table Color
3056
+
3057
+ This example requires pre-installing `chunky_png` Ruby gem:
3058
+
3059
+ ```
3060
+ gem install chunky_png -v1.4.0
3061
+ ```
3062
+
3063
+ [examples/basic_table_color.rb](examples/basic_table_color.rb)
3064
+
3065
+ Run with this command from the root of the project if you cloned the project:
3066
+
3067
+ ```
3068
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_color.rb
3069
+ ```
3070
+
3071
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
3072
+
3073
+ ```
3074
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_color'"
3075
+ ```
3076
+
3077
+ Mac
3078
+
3079
+ ![glimmer-dsl-libui-mac-basic-table-color.png](images/glimmer-dsl-libui-mac-basic-table-color.png)
3080
+
3081
+ Linux
3082
+
3083
+ ![glimmer-dsl-libui-linux-basic-table-color.png](images/glimmer-dsl-libui-linux-basic-table-color.png)
3084
+
3085
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3086
+
3087
+ ```ruby
3088
+ require 'glimmer-dsl-libui'
3089
+ require 'chunky_png'
3090
+
3091
+ include Glimmer
3092
+
3093
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
3094
+ canvas = ChunkyPNG::Canvas.from_io(f)
3095
+ f.close
3096
+ canvas.resample_nearest_neighbor!(24, 24)
3097
+ data = canvas.to_rgba_stream
3098
+ width = canvas.width
3099
+ height = canvas.height
3100
+ img = image {
3101
+ image_part(data, width, height, width * 4)
3102
+ }
3103
+
3104
+ data = [
3105
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
3106
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
3107
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
3108
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
3109
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
3110
+ ]
3111
+
3112
+ window('Animals', 500, 200) {
3113
+ horizontal_box {
3114
+ table {
3115
+ text_color_column('Animal')
3116
+ text_color_column('Sound')
3117
+ checkbox_text_color_column('Description')
3118
+ image_text_color_column('GUI')
3119
+ background_color_column('Mammal')
3120
+
3121
+ cell_rows data
3122
+ }
3123
+ }
3124
+ }.show
3125
+ ```
3126
+
2999
3127
  ### Form Table
3000
3128
 
3001
3129
  [examples/form_table.rb](examples/form_table.rb)
@@ -4566,8 +4694,6 @@ Linux
4566
4694
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4567
4695
 
4568
4696
  ```ruby
4569
- # frozen_string_literal: true
4570
-
4571
4697
  require 'glimmer-dsl-libui'
4572
4698
 
4573
4699
  class Timer
@@ -4579,13 +4705,13 @@ class Timer
4579
4705
 
4580
4706
  def initialize
4581
4707
  @pid = nil
4582
- @midi_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
4583
- at_exit { stop_midi }
4708
+ @alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
4709
+ at_exit { stop_alarm }
4584
4710
  setup_timer
4585
4711
  create_gui
4586
4712
  end
4587
4713
 
4588
- def stop_midi
4714
+ def stop_alarm
4589
4715
  if @pid
4590
4716
  if @th.alive?
4591
4717
  Process.kill(:SIGKILL, @pid)
@@ -4596,11 +4722,11 @@ class Timer
4596
4722
  end
4597
4723
  end
4598
4724
 
4599
- def play_midi
4600
- stop_midi
4725
+ def play_alarm
4726
+ stop_alarm
4601
4727
  if @pid.nil?
4602
4728
  begin
4603
- @pid = spawn "timidity -G 0.0-10.0 #{@midi_file}"
4729
+ @pid = spawn "timidity -G 0.0-10.0 #{@alarm_file}"
4604
4730
  @th = Process.detach @pid
4605
4731
  rescue Errno::ENOENT
4606
4732
  warn 'Timidty++ not found. Please install Timidity++.'
@@ -4635,7 +4761,8 @@ class Timer
4635
4761
  @stop_button.enabled = false
4636
4762
  @started = false
4637
4763
  unless @played
4638
- play_midi
4764
+ play_alarm
4765
+ msg_box('Alarm', 'Countdown Is Finished!')
4639
4766
  @played = true
4640
4767
  end
4641
4768
  end
@@ -4964,7 +5091,123 @@ Linux
4964
5091
 
4965
5092
  ![glimmer-dsl-libui-linux-basic-draw-text.png](images/glimmer-dsl-libui-linux-basic-draw-text.png)
4966
5093
 
4967
- New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
5094
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
5095
+
5096
+ ```ruby
5097
+ require 'libui'
5098
+
5099
+ UI = LibUI
5100
+
5101
+ UI.init
5102
+
5103
+ handler = UI::FFI::AreaHandler.malloc
5104
+ area = UI.new_area(handler)
5105
+
5106
+ # Michael Ende (1929-1995)
5107
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5108
+ # The English version, translated by Ralph Manheim, was published in 1983.
5109
+
5110
+ TITLE = 'Michael Ende (1929-1995) The Neverending Story'
5111
+
5112
+ str1 = \
5113
+ ' At last Ygramul sensed that something was coming toward ' \
5114
+ 'her. With the speed of lightning, she turned about, confronting ' \
5115
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5116
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
5117
+
5118
+ str2 = \
5119
+ ' A cry of fear escaped Bastian. '
5120
+
5121
+ str3 = \
5122
+ ' A cry of terror passed through the ravine and echoed from ' \
5123
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5124
+ 'someone else had arrived, for that sound could not have been ' \
5125
+ 'made by the boy who stood there as though paralyzed with ' \
5126
+ 'horror. '
5127
+
5128
+ str4 = \
5129
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5130
+ "But that's not possible. "
5131
+
5132
+ str5 = \
5133
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5134
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5135
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5136
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5137
+ 'words. '
5138
+
5139
+ str = ''
5140
+ attr_str = UI.new_attributed_string(str)
5141
+
5142
+ def attr_str.append(what, color)
5143
+ case color
5144
+ when :red
5145
+ color_attribute = UI.new_color_attribute(0.0, 0.5, 0.0, 0.7)
5146
+ when :green
5147
+ color_attribute = UI.new_color_attribute(0.5, 0.0, 0.25, 0.7)
5148
+ end
5149
+ start = UI.attributed_string_len(self)
5150
+ UI.attributed_string_append_unattributed(self, what)
5151
+ UI.attributed_string_set_attribute(self, color_attribute, start, start + what.size)
5152
+ UI.attributed_string_append_unattributed(self, "\n\n")
5153
+ end
5154
+
5155
+ attr_str.append(str1, :green)
5156
+ attr_str.append(str2, :red)
5157
+ attr_str.append(str3, :green)
5158
+ attr_str.append(str4, :red)
5159
+ attr_str.append(str5, :green)
5160
+
5161
+ Georgia = 'Georgia'
5162
+
5163
+ handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, adp|
5164
+ area_draw_params = UI::FFI::AreaDrawParams.new(adp)
5165
+ default_font = UI::FFI::FontDescriptor.malloc
5166
+ default_font.Family = Georgia
5167
+ default_font.Size = 13
5168
+ default_font.Weight = 500
5169
+ default_font.Italic = 0
5170
+ default_font.Stretch = 4
5171
+ params = UI::FFI::DrawTextLayoutParams.malloc
5172
+
5173
+ # UI.font_button_font(font_button, default_font)
5174
+ params.String = attr_str
5175
+ params.DefaultFont = default_font
5176
+ params.Width = area_draw_params.AreaWidth
5177
+ params.Align = 0
5178
+ text_layout = UI.draw_new_text_layout(params)
5179
+ UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
5180
+ UI.draw_free_text_layout(text_layout)
5181
+ end
5182
+
5183
+ handler.Draw = handler_draw_event
5184
+ # Assigning to local variables
5185
+ # This is intended to protect Fiddle::Closure from garbage collection.
5186
+ handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5187
+ handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5188
+ handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5189
+ handler.KeyEvent = (c4 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
5190
+
5191
+ box = UI.new_vertical_box
5192
+ UI.box_set_padded(box, 1)
5193
+ UI.box_append(box, area, 1)
5194
+
5195
+ main_window = UI.new_window(TITLE, 600, 400, 1)
5196
+ UI.window_set_margined(main_window, 1)
5197
+ UI.window_set_child(main_window, box)
5198
+
5199
+ UI.window_on_closing(main_window) do
5200
+ UI.control_destroy(main_window)
5201
+ UI.quit
5202
+ 0
5203
+ end
5204
+ UI.control_show(main_window)
5205
+
5206
+ UI.main
5207
+ UI.quit
5208
+ ```
5209
+
5210
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4968
5211
 
4969
5212
  ```ruby
4970
5213
  require 'glimmer-dsl-libui'
@@ -4975,8 +5218,78 @@ require 'glimmer-dsl-libui'
4975
5218
  class BasicDrawText
4976
5219
  include Glimmer
4977
5220
 
4978
- def alternating_color_string(&block)
4979
- @index ||= 0
5221
+ def alternating_color_string(initial: false, &block)
5222
+ @index = 0 if initial
5223
+ @index += 1
5224
+ string {
5225
+ if @index.odd?
5226
+ color r: 0.5, g: 0, b: 0.25, a: 0.7
5227
+ else
5228
+ color r: 0, g: 0.5, b: 0, a: 0.7
5229
+ end
5230
+
5231
+ block.call + "\n\n"
5232
+ }
5233
+ end
5234
+
5235
+ def launch
5236
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5237
+ margined true
5238
+
5239
+ area {
5240
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5241
+ # align :left # default alignment
5242
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
5243
+
5244
+ alternating_color_string(initial: true) {
5245
+ ' At last Ygramul sensed that something was coming toward ' \
5246
+ 'her. With the speed of lightning, she turned about, confronting ' \
5247
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5248
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
5249
+ }
5250
+ alternating_color_string {
5251
+ ' A cry of fear escaped Bastian. '
5252
+ }
5253
+ alternating_color_string {
5254
+ ' A cry of terror passed through the ravine and echoed from ' \
5255
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5256
+ 'someone else had arrived, for that sound could not have been ' \
5257
+ 'made by the boy who stood there as though paralyzed with ' \
5258
+ 'horror. '
5259
+ }
5260
+ alternating_color_string {
5261
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5262
+ "But that's not possible. "
5263
+ }
5264
+ alternating_color_string {
5265
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5266
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5267
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5268
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5269
+ 'words. '
5270
+ }
5271
+ }
5272
+ }
5273
+ }.show
5274
+ end
5275
+ end
5276
+
5277
+ BasicDrawText.new.launch
5278
+ ```
5279
+
5280
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
5281
+
5282
+ ```ruby
5283
+ require 'glimmer-dsl-libui'
5284
+
5285
+ # Michael Ende (1929-1995)
5286
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5287
+ # The English version, translated by Ralph Manheim, was published in 1983.
5288
+ class BasicDrawText
5289
+ include Glimmer
5290
+
5291
+ def alternating_color_string(initial: false, &block)
5292
+ @index = 0 if initial
4980
5293
  @index += 1
4981
5294
  string {
4982
5295
  if @index.odd?
@@ -4995,11 +5308,11 @@ class BasicDrawText
4995
5308
 
4996
5309
  area {
4997
5310
  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
5311
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5312
+ # align :left # default alignment
5313
+ default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
5001
5314
 
5002
- alternating_color_string {
5315
+ alternating_color_string(initial: true) {
5003
5316
  ' At last Ygramul sensed that something was coming toward ' \
5004
5317
  'her. With the speed of lightning, she turned about, confronting ' \
5005
5318
  'Atreyu with an enormous steel-blue face. Her single eye had a ' \
@@ -5036,6 +5349,222 @@ end
5036
5349
  BasicDrawText.new.launch
5037
5350
  ```
5038
5351
 
5352
+ ### Custom Draw Text
5353
+
5354
+ [examples/custom_draw_text.rb](examples/custom_draw_text.rb)
5355
+
5356
+ Run with this command from the root of the project if you cloned the project:
5357
+
5358
+ ```
5359
+ ruby -r './lib/glimmer-dsl-libui' examples/custom_draw_text.rb
5360
+ ```
5361
+
5362
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
5363
+
5364
+ ```
5365
+ ruby -r glimmer-dsl-libui -e "require 'examples/custom_draw_text'"
5366
+ ```
5367
+
5368
+ Mac
5369
+
5370
+ ![glimmer-dsl-libui-mac-custom-draw-text.png](images/glimmer-dsl-libui-mac-custom-draw-text.png)
5371
+ ![glimmer-dsl-libui-mac-custom-draw-text-changed.png](images/glimmer-dsl-libui-mac-custom-draw-text-changed.png)
5372
+
5373
+ Linux
5374
+
5375
+ ![glimmer-dsl-libui-linux-custom-draw-text.png](images/glimmer-dsl-libui-linux-custom-draw-text.png)
5376
+ ![glimmer-dsl-libui-linux-custom-draw-text-changed.png](images/glimmer-dsl-libui-linux-custom-draw-text-changed.png)
5377
+
5378
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
5379
+
5380
+ ```ruby
5381
+ require 'glimmer-dsl-libui'
5382
+
5383
+ # Michael Ende (1929-1995)
5384
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5385
+ # The English version, translated by Ralph Manheim, was published in 1983.
5386
+ class CustomDrawText
5387
+ include Glimmer
5388
+
5389
+ def launch
5390
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
5391
+ margined true
5392
+
5393
+ vertical_box {
5394
+ form {
5395
+ stretchy false
5396
+
5397
+ font_button { |fb|
5398
+ label 'Font'
5399
+
5400
+ on_changed do
5401
+ @string.font = fb.font
5402
+ end
5403
+ }
5404
+ color_button { |cb|
5405
+ label 'Color'
5406
+
5407
+ on_changed do
5408
+ @string.color = cb.color
5409
+ end
5410
+ }
5411
+ color_button { |cb|
5412
+ label 'Background'
5413
+
5414
+ on_changed do
5415
+ @string.background = cb.color
5416
+ end
5417
+ }
5418
+ combobox { |c|
5419
+ label 'Underline'
5420
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
5421
+ selected 'None'
5422
+
5423
+ on_selected do
5424
+ @string.underline = c.selected_item.underscore
5425
+ end
5426
+ }
5427
+ }
5428
+
5429
+ area {
5430
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5431
+ # align :left # default alignment
5432
+
5433
+ @string = string {
5434
+ ' At last Ygramul sensed that something was coming toward ' \
5435
+ 'her. With the speed of lightning, she turned about, confronting ' \
5436
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5437
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
5438
+ "\n\n" \
5439
+ ' A cry of fear escaped Bastian. ' \
5440
+ "\n\n" \
5441
+ ' A cry of terror passed through the ravine and echoed from ' \
5442
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5443
+ 'someone else had arrived, for that sound could not have been ' \
5444
+ 'made by the boy who stood there as though paralyzed with ' \
5445
+ 'horror. ' \
5446
+ "\n\n" \
5447
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5448
+ "But that's not possible. " \
5449
+ "\n\n" \
5450
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5451
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5452
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5453
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5454
+ 'words. ' \
5455
+ "\n\n"
5456
+ }
5457
+ }
5458
+ }
5459
+ }
5460
+ }.show
5461
+ end
5462
+ end
5463
+
5464
+ CustomDrawText.new.launch
5465
+ ```
5466
+
5467
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
5468
+
5469
+ ```ruby
5470
+ require 'glimmer-dsl-libui'
5471
+
5472
+ # Michael Ende (1929-1995)
5473
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
5474
+ # The English version, translated by Ralph Manheim, was published in 1983.
5475
+ class CustomDrawText
5476
+ include Glimmer
5477
+
5478
+ def launch
5479
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
5480
+ margined true
5481
+
5482
+ vertical_box {
5483
+ form {
5484
+ stretchy false
5485
+
5486
+ font_button { |fb|
5487
+ label 'Font'
5488
+
5489
+ on_changed do
5490
+ @font = fb.font
5491
+ @area.queue_redraw_all
5492
+ end
5493
+ }
5494
+ color_button { |cb|
5495
+ label 'Color'
5496
+
5497
+ on_changed do
5498
+ @color = cb.color
5499
+ @area.queue_redraw_all
5500
+ end
5501
+ }
5502
+ color_button { |cb|
5503
+ label 'Background'
5504
+
5505
+ on_changed do
5506
+ @background = cb.color
5507
+ @area.queue_redraw_all
5508
+ end
5509
+ }
5510
+ combobox { |c|
5511
+ label 'Underline'
5512
+ items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
5513
+ selected 'None'
5514
+
5515
+ on_selected do
5516
+ @underline = c.selected_item.underscore
5517
+ @area.queue_redraw_all
5518
+ end
5519
+ }
5520
+ }
5521
+
5522
+ @area = area {
5523
+ on_draw do |area_draw_params|
5524
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5525
+ # align :left # default alignment
5526
+
5527
+ string {
5528
+ font @font
5529
+ color @color
5530
+ background @background
5531
+ underline @underline
5532
+
5533
+ ' At last Ygramul sensed that something was coming toward ' \
5534
+ 'her. With the speed of lightning, she turned about, confronting ' \
5535
+ 'Atreyu with an enormous steel-blue face. Her single eye had a ' \
5536
+ 'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
5537
+ "\n\n" \
5538
+ ' A cry of fear escaped Bastian. ' \
5539
+ "\n\n" \
5540
+ ' A cry of terror passed through the ravine and echoed from ' \
5541
+ 'side to side. Ygramul turned her eye to left and right, to see if ' \
5542
+ 'someone else had arrived, for that sound could not have been ' \
5543
+ 'made by the boy who stood there as though paralyzed with ' \
5544
+ 'horror. ' \
5545
+ "\n\n" \
5546
+ ' Could she have heard my cry? Bastion wondered in alarm. ' \
5547
+ "But that's not possible. " \
5548
+ "\n\n" \
5549
+ ' And then Atreyu heard Ygramuls voice. It was very high ' \
5550
+ 'and slightly hoarse, not at all the right kind of voice for that ' \
5551
+ 'enormous face. Her lips did not move as she spoke. It was the ' \
5552
+ 'buzzing of a great swarm of hornets that shaped itself into ' \
5553
+ 'words. ' \
5554
+ "\n\n"
5555
+ }
5556
+ }
5557
+ end
5558
+ }
5559
+ }
5560
+ }.show
5561
+ end
5562
+ end
5563
+
5564
+ CustomDrawText.new.launch
5565
+
5566
+ ```
5567
+
5039
5568
  ## Contributing to glimmer-dsl-libui
5040
5569
 
5041
5570
  - Check out the latest master to make sure the feature hasn't been