glimmer-dsl-libui 0.2.2 → 0.2.6
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 +4 -4
- data/CHANGELOG.md +34 -0
- data/README.md +559 -16
- data/VERSION +1 -1
- data/examples/basic_draw_text.rb +65 -0
- data/examples/basic_draw_text2.rb +68 -0
- data/examples/custom_draw_text.rb +106 -0
- data/examples/custom_draw_text2.rb +120 -0
- data/examples/midi_player.rb +1 -1
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +0 -1
- data/lib/glimmer/dsl/libui/property_expression.rb +3 -1
- data/lib/glimmer/dsl/libui/string_expression.rb +48 -0
- data/lib/glimmer/libui/attributed_string.rb +176 -0
- data/lib/glimmer/libui/control_proxy/area_proxy.rb +1 -1
- data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +2 -1
- data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +18 -0
- data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +3 -3
- data/lib/glimmer/libui/control_proxy/open_type_features_proxy.rb +53 -0
- data/lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb +59 -0
- data/lib/glimmer/libui/control_proxy/path_proxy.rb +0 -2
- data/lib/glimmer/libui/control_proxy/text_proxy.rb +173 -0
- data/lib/glimmer/libui.rb +15 -5
- metadata +11 -2
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.
|
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.6
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[](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.
|
200
|
+
- [Glimmer DSL for LibUI 0.2.6](#-glimmer-dsl-for-libui-026)
|
201
201
|
- [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
|
202
202
|
- [Usage](#usage)
|
203
203
|
- [Girb (Glimmer IRB)](#girb-glimmer-irb)
|
@@ -244,6 +244,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
244
244
|
- [Login](#login)
|
245
245
|
- [Timer](#timer)
|
246
246
|
- [Color The Circles](#color-the-circles)
|
247
|
+
- [Basic Draw Text](#basic-draw-text)
|
248
|
+
- [Custom Draw Text](#custom-draw-text)
|
247
249
|
- [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
|
248
250
|
- [Help](#help)
|
249
251
|
- [Issues](#issues)
|
@@ -331,7 +333,7 @@ gem install glimmer-dsl-libui
|
|
331
333
|
Or install via Bundler `Gemfile`:
|
332
334
|
|
333
335
|
```ruby
|
334
|
-
gem 'glimmer-dsl-libui', '~> 0.2.
|
336
|
+
gem 'glimmer-dsl-libui', '~> 0.2.6'
|
335
337
|
```
|
336
338
|
|
337
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.
|
@@ -788,6 +790,50 @@ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wi
|
|
788
790
|
|
789
791
|
Check [Histogram](#histogram) example for use of hex colors.
|
790
792
|
|
793
|
+
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).
|
794
|
+
|
795
|
+
`text` control can have the following properties:
|
796
|
+
- `default_font`:
|
797
|
+
- `align`: `:left` (default), `:center`, or `:right` (`align` currently seems not to work on the Mac)
|
798
|
+
|
799
|
+
`string` can have the following properties:
|
800
|
+
- `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
|
801
|
+
- `color`: rgba, hex, or x11 color
|
802
|
+
- `background`: rgba, hex, or x11 color
|
803
|
+
- `underline`: one of `:none`, `:single`, `:double`, `:suggestion`, `:color_custom`, `:color_spelling`, `:color_grammar`, `:color_auxiliary`
|
804
|
+
- `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or x11 color
|
805
|
+
- `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.
|
806
|
+
|
807
|
+
Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
|
808
|
+
|
809
|
+
```ruby
|
810
|
+
window('area text drawing') {
|
811
|
+
area {
|
812
|
+
text {
|
813
|
+
default_font family: 'Helvetica', size: 12, weight: :normal, italic: :normal, stretch: :normal
|
814
|
+
|
815
|
+
string {
|
816
|
+
font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
|
817
|
+
color r: 230, g: 100, b: 50, a: 0.5
|
818
|
+
background r: 230, g: 200, b: 250, a: 0.8
|
819
|
+
underline :single
|
820
|
+
underline_color :spelling
|
821
|
+
open_type_features {
|
822
|
+
open_type_tag 'l', 'i', 'g', 'a', 0
|
823
|
+
open_type_tag 'l', 'i', 'g', 'a', 1
|
824
|
+
}
|
825
|
+
|
826
|
+
"This is a test\n\n"
|
827
|
+
}
|
828
|
+
|
829
|
+
string {
|
830
|
+
'This is another test'
|
831
|
+
}
|
832
|
+
}
|
833
|
+
}
|
834
|
+
}.show
|
835
|
+
```
|
836
|
+
|
791
837
|
### Smart Defaults and Conventions
|
792
838
|
|
793
839
|
- `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
|
@@ -1276,9 +1322,7 @@ window('Notepad', 500, 300) {
|
|
1276
1322
|
|
1277
1323
|
### Midi Player
|
1278
1324
|
|
1279
|
-
|
1280
|
-
- Install [TiMidity](http://timidity.sourceforge.net) and ensure `timidity` command is in `PATH` (can be installed via [Homebrew](https://brew.sh) on Mac or [apt-get](https://help.ubuntu.com/community/AptGet/Howto) on Linux).
|
1281
|
-
- Add `*.mid` files to `~/Music` directory (you may copy the ones included in [sounds](sounds) directory)
|
1325
|
+
To run this example, install [TiMidity](http://timidity.sourceforge.net) and ensure `timidity` command is in `PATH` (can be installed via [Homebrew](https://brew.sh) on Mac or [apt-get](https://help.ubuntu.com/community/AptGet/Howto) on Linux).
|
1282
1326
|
|
1283
1327
|
[examples/midi_player.rb](examples/midi_player.rb)
|
1284
1328
|
|
@@ -1417,7 +1461,7 @@ class TinyMidiPlayer
|
|
1417
1461
|
|
1418
1462
|
def initialize
|
1419
1463
|
@pid = nil
|
1420
|
-
@music_directory = File.expand_path(
|
1464
|
+
@music_directory = File.expand_path('../sounds', __dir__)
|
1421
1465
|
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
1422
1466
|
.sort_by { |path| File.basename(path) }
|
1423
1467
|
at_exit { stop_midi }
|
@@ -4538,6 +4582,8 @@ window('Login') {
|
|
4538
4582
|
|
4539
4583
|
### Timer
|
4540
4584
|
|
4585
|
+
To run this example, install [TiMidity](http://timidity.sourceforge.net) and ensure `timidity` command is in `PATH` (can be installed via [Homebrew](https://brew.sh) on Mac or [apt-get](https://help.ubuntu.com/community/AptGet/Howto) on Linux).
|
4586
|
+
|
4541
4587
|
[examples/timer.rb](examples/timer.rb)
|
4542
4588
|
|
4543
4589
|
Run with this command from the root of the project if you cloned the project:
|
@@ -4565,8 +4611,6 @@ Linux
|
|
4565
4611
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
4566
4612
|
|
4567
4613
|
```ruby
|
4568
|
-
# frozen_string_literal: true
|
4569
|
-
|
4570
4614
|
require 'glimmer-dsl-libui'
|
4571
4615
|
|
4572
4616
|
class Timer
|
@@ -4578,13 +4622,13 @@ class Timer
|
|
4578
4622
|
|
4579
4623
|
def initialize
|
4580
4624
|
@pid = nil
|
4581
|
-
@
|
4582
|
-
at_exit {
|
4625
|
+
@alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
|
4626
|
+
at_exit { stop_alarm }
|
4583
4627
|
setup_timer
|
4584
4628
|
create_gui
|
4585
4629
|
end
|
4586
4630
|
|
4587
|
-
def
|
4631
|
+
def stop_alarm
|
4588
4632
|
if @pid
|
4589
4633
|
if @th.alive?
|
4590
4634
|
Process.kill(:SIGKILL, @pid)
|
@@ -4595,11 +4639,11 @@ class Timer
|
|
4595
4639
|
end
|
4596
4640
|
end
|
4597
4641
|
|
4598
|
-
def
|
4599
|
-
|
4642
|
+
def play_alarm
|
4643
|
+
stop_alarm
|
4600
4644
|
if @pid.nil?
|
4601
4645
|
begin
|
4602
|
-
@pid = spawn "timidity -G 0.0-10.0 #{@
|
4646
|
+
@pid = spawn "timidity -G 0.0-10.0 #{@alarm_file}"
|
4603
4647
|
@th = Process.detach @pid
|
4604
4648
|
rescue Errno::ENOENT
|
4605
4649
|
warn 'Timidty++ not found. Please install Timidity++.'
|
@@ -4634,7 +4678,8 @@ class Timer
|
|
4634
4678
|
@stop_button.enabled = false
|
4635
4679
|
@started = false
|
4636
4680
|
unless @played
|
4637
|
-
|
4681
|
+
play_alarm
|
4682
|
+
msg_box('Alarm', 'Countdown Is Finished!')
|
4638
4683
|
@played = true
|
4639
4684
|
end
|
4640
4685
|
end
|
@@ -4939,6 +4984,504 @@ end
|
|
4939
4984
|
ColorTheCircles.new.launch
|
4940
4985
|
```
|
4941
4986
|
|
4987
|
+
### Basic Draw Text
|
4988
|
+
|
4989
|
+
[examples/basic_draw_text.rb](examples/basic_draw_text.rb)
|
4990
|
+
|
4991
|
+
Run with this command from the root of the project if you cloned the project:
|
4992
|
+
|
4993
|
+
```
|
4994
|
+
ruby -r './lib/glimmer-dsl-libui' examples/basic_draw_text.rb
|
4995
|
+
```
|
4996
|
+
|
4997
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
4998
|
+
|
4999
|
+
```
|
5000
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/basic_draw_text'"
|
5001
|
+
```
|
5002
|
+
|
5003
|
+
Mac
|
5004
|
+
|
5005
|
+

|
5006
|
+
|
5007
|
+
Linux
|
5008
|
+
|
5009
|
+

|
5010
|
+
|
5011
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
5012
|
+
|
5013
|
+
```ruby
|
5014
|
+
require 'libui'
|
5015
|
+
|
5016
|
+
UI = LibUI
|
5017
|
+
|
5018
|
+
UI.init
|
5019
|
+
|
5020
|
+
handler = UI::FFI::AreaHandler.malloc
|
5021
|
+
area = UI.new_area(handler)
|
5022
|
+
|
5023
|
+
# Michael Ende (1929-1995)
|
5024
|
+
# The Neverending Story is a fantasy novel by German writer Michael Ende,
|
5025
|
+
# The English version, translated by Ralph Manheim, was published in 1983.
|
5026
|
+
|
5027
|
+
TITLE = 'Michael Ende (1929-1995) The Neverending Story'
|
5028
|
+
|
5029
|
+
str1 = \
|
5030
|
+
' At last Ygramul sensed that something was coming toward ' \
|
5031
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
5032
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
5033
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
|
5034
|
+
|
5035
|
+
str2 = \
|
5036
|
+
' A cry of fear escaped Bastian. '
|
5037
|
+
|
5038
|
+
str3 = \
|
5039
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
5040
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
5041
|
+
'someone else had arrived, for that sound could not have been ' \
|
5042
|
+
'made by the boy who stood there as though paralyzed with ' \
|
5043
|
+
'horror. '
|
5044
|
+
|
5045
|
+
str4 = \
|
5046
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
5047
|
+
"But that's not possible. "
|
5048
|
+
|
5049
|
+
str5 = \
|
5050
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
5051
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
5052
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
5053
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
5054
|
+
'words. '
|
5055
|
+
|
5056
|
+
str = ''
|
5057
|
+
attr_str = UI.new_attributed_string(str)
|
5058
|
+
|
5059
|
+
def attr_str.append(what, color)
|
5060
|
+
case color
|
5061
|
+
when :red
|
5062
|
+
color_attribute = UI.new_color_attribute(0.0, 0.5, 0.0, 0.7)
|
5063
|
+
when :green
|
5064
|
+
color_attribute = UI.new_color_attribute(0.5, 0.0, 0.25, 0.7)
|
5065
|
+
end
|
5066
|
+
start = UI.attributed_string_len(self)
|
5067
|
+
UI.attributed_string_append_unattributed(self, what)
|
5068
|
+
UI.attributed_string_set_attribute(self, color_attribute, start, start + what.size)
|
5069
|
+
UI.attributed_string_append_unattributed(self, "\n\n")
|
5070
|
+
end
|
5071
|
+
|
5072
|
+
attr_str.append(str1, :green)
|
5073
|
+
attr_str.append(str2, :red)
|
5074
|
+
attr_str.append(str3, :green)
|
5075
|
+
attr_str.append(str4, :red)
|
5076
|
+
attr_str.append(str5, :green)
|
5077
|
+
|
5078
|
+
Georgia = 'Georgia'
|
5079
|
+
|
5080
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, adp|
|
5081
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(adp)
|
5082
|
+
default_font = UI::FFI::FontDescriptor.malloc
|
5083
|
+
default_font.Family = Georgia
|
5084
|
+
default_font.Size = 13
|
5085
|
+
default_font.Weight = 500
|
5086
|
+
default_font.Italic = 0
|
5087
|
+
default_font.Stretch = 4
|
5088
|
+
params = UI::FFI::DrawTextLayoutParams.malloc
|
5089
|
+
|
5090
|
+
# UI.font_button_font(font_button, default_font)
|
5091
|
+
params.String = attr_str
|
5092
|
+
params.DefaultFont = default_font
|
5093
|
+
params.Width = area_draw_params.AreaWidth
|
5094
|
+
params.Align = 0
|
5095
|
+
text_layout = UI.draw_new_text_layout(params)
|
5096
|
+
UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
|
5097
|
+
UI.draw_free_text_layout(text_layout)
|
5098
|
+
end
|
5099
|
+
|
5100
|
+
handler.Draw = handler_draw_event
|
5101
|
+
# Assigning to local variables
|
5102
|
+
# This is intended to protect Fiddle::Closure from garbage collection.
|
5103
|
+
handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
5104
|
+
handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
5105
|
+
handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
5106
|
+
handler.KeyEvent = (c4 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
5107
|
+
|
5108
|
+
box = UI.new_vertical_box
|
5109
|
+
UI.box_set_padded(box, 1)
|
5110
|
+
UI.box_append(box, area, 1)
|
5111
|
+
|
5112
|
+
main_window = UI.new_window(TITLE, 600, 400, 1)
|
5113
|
+
UI.window_set_margined(main_window, 1)
|
5114
|
+
UI.window_set_child(main_window, box)
|
5115
|
+
|
5116
|
+
UI.window_on_closing(main_window) do
|
5117
|
+
UI.control_destroy(main_window)
|
5118
|
+
UI.quit
|
5119
|
+
0
|
5120
|
+
end
|
5121
|
+
UI.control_show(main_window)
|
5122
|
+
|
5123
|
+
UI.main
|
5124
|
+
UI.quit
|
5125
|
+
```
|
5126
|
+
|
5127
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
5128
|
+
|
5129
|
+
```ruby
|
5130
|
+
require 'glimmer-dsl-libui'
|
5131
|
+
|
5132
|
+
# Michael Ende (1929-1995)
|
5133
|
+
# The Neverending Story is a fantasy novel by German writer Michael Ende,
|
5134
|
+
# The English version, translated by Ralph Manheim, was published in 1983.
|
5135
|
+
class BasicDrawText
|
5136
|
+
include Glimmer
|
5137
|
+
|
5138
|
+
def alternating_color_string(initial: false, &block)
|
5139
|
+
@index = 0 if initial
|
5140
|
+
@index += 1
|
5141
|
+
string {
|
5142
|
+
if @index.odd?
|
5143
|
+
color r: 0.5, g: 0, b: 0.25, a: 0.7
|
5144
|
+
else
|
5145
|
+
color r: 0, g: 0.5, b: 0, a: 0.7
|
5146
|
+
end
|
5147
|
+
|
5148
|
+
block.call + "\n\n"
|
5149
|
+
}
|
5150
|
+
end
|
5151
|
+
|
5152
|
+
def launch
|
5153
|
+
window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
|
5154
|
+
margined true
|
5155
|
+
|
5156
|
+
area {
|
5157
|
+
text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
|
5158
|
+
# align :left # default alignment
|
5159
|
+
default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
|
5160
|
+
|
5161
|
+
alternating_color_string(initial: true) {
|
5162
|
+
' At last Ygramul sensed that something was coming toward ' \
|
5163
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
5164
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
5165
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
|
5166
|
+
}
|
5167
|
+
alternating_color_string {
|
5168
|
+
' A cry of fear escaped Bastian. '
|
5169
|
+
}
|
5170
|
+
alternating_color_string {
|
5171
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
5172
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
5173
|
+
'someone else had arrived, for that sound could not have been ' \
|
5174
|
+
'made by the boy who stood there as though paralyzed with ' \
|
5175
|
+
'horror. '
|
5176
|
+
}
|
5177
|
+
alternating_color_string {
|
5178
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
5179
|
+
"But that's not possible. "
|
5180
|
+
}
|
5181
|
+
alternating_color_string {
|
5182
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
5183
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
5184
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
5185
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
5186
|
+
'words. '
|
5187
|
+
}
|
5188
|
+
}
|
5189
|
+
}
|
5190
|
+
}.show
|
5191
|
+
end
|
5192
|
+
end
|
5193
|
+
|
5194
|
+
BasicDrawText.new.launch
|
5195
|
+
```
|
5196
|
+
|
5197
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
|
5198
|
+
|
5199
|
+
```ruby
|
5200
|
+
require 'glimmer-dsl-libui'
|
5201
|
+
|
5202
|
+
# Michael Ende (1929-1995)
|
5203
|
+
# The Neverending Story is a fantasy novel by German writer Michael Ende,
|
5204
|
+
# The English version, translated by Ralph Manheim, was published in 1983.
|
5205
|
+
class BasicDrawText
|
5206
|
+
include Glimmer
|
5207
|
+
|
5208
|
+
def alternating_color_string(initial: false, &block)
|
5209
|
+
@index = 0 if initial
|
5210
|
+
@index += 1
|
5211
|
+
string {
|
5212
|
+
if @index.odd?
|
5213
|
+
color r: 0.5, g: 0, b: 0.25, a: 0.7
|
5214
|
+
else
|
5215
|
+
color r: 0, g: 0.5, b: 0, a: 0.7
|
5216
|
+
end
|
5217
|
+
|
5218
|
+
block.call + "\n\n"
|
5219
|
+
}
|
5220
|
+
end
|
5221
|
+
|
5222
|
+
def launch
|
5223
|
+
window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
|
5224
|
+
margined true
|
5225
|
+
|
5226
|
+
area {
|
5227
|
+
on_draw do |area_draw_params|
|
5228
|
+
text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
|
5229
|
+
# align :left # default alignment
|
5230
|
+
default_font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
|
5231
|
+
|
5232
|
+
alternating_color_string(initial: true) {
|
5233
|
+
' At last Ygramul sensed that something was coming toward ' \
|
5234
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
5235
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
5236
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
|
5237
|
+
}
|
5238
|
+
alternating_color_string {
|
5239
|
+
' A cry of fear escaped Bastian. '
|
5240
|
+
}
|
5241
|
+
alternating_color_string {
|
5242
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
5243
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
5244
|
+
'someone else had arrived, for that sound could not have been ' \
|
5245
|
+
'made by the boy who stood there as though paralyzed with ' \
|
5246
|
+
'horror. '
|
5247
|
+
}
|
5248
|
+
alternating_color_string {
|
5249
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
5250
|
+
"But that's not possible. "
|
5251
|
+
}
|
5252
|
+
alternating_color_string {
|
5253
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
5254
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
5255
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
5256
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
5257
|
+
'words. '
|
5258
|
+
}
|
5259
|
+
}
|
5260
|
+
end
|
5261
|
+
}
|
5262
|
+
}.show
|
5263
|
+
end
|
5264
|
+
end
|
5265
|
+
|
5266
|
+
BasicDrawText.new.launch
|
5267
|
+
```
|
5268
|
+
|
5269
|
+
### Custom Draw Text
|
5270
|
+
|
5271
|
+
[examples/custom_draw_text.rb](examples/custom_draw_text.rb)
|
5272
|
+
|
5273
|
+
Run with this command from the root of the project if you cloned the project:
|
5274
|
+
|
5275
|
+
```
|
5276
|
+
ruby -r './lib/glimmer-dsl-libui' examples/custom_draw_text.rb
|
5277
|
+
```
|
5278
|
+
|
5279
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
5280
|
+
|
5281
|
+
```
|
5282
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/custom_draw_text'"
|
5283
|
+
```
|
5284
|
+
|
5285
|
+
Mac
|
5286
|
+
|
5287
|
+

|
5288
|
+

|
5289
|
+
|
5290
|
+
Linux
|
5291
|
+
|
5292
|
+

|
5293
|
+

|
5294
|
+
|
5295
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
5296
|
+
|
5297
|
+
```ruby
|
5298
|
+
require 'glimmer-dsl-libui'
|
5299
|
+
|
5300
|
+
# Michael Ende (1929-1995)
|
5301
|
+
# The Neverending Story is a fantasy novel by German writer Michael Ende,
|
5302
|
+
# The English version, translated by Ralph Manheim, was published in 1983.
|
5303
|
+
class CustomDrawText
|
5304
|
+
include Glimmer
|
5305
|
+
|
5306
|
+
def launch
|
5307
|
+
window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
|
5308
|
+
margined true
|
5309
|
+
|
5310
|
+
vertical_box {
|
5311
|
+
form {
|
5312
|
+
stretchy false
|
5313
|
+
|
5314
|
+
font_button { |fb|
|
5315
|
+
label 'Font'
|
5316
|
+
|
5317
|
+
on_changed do
|
5318
|
+
@string.font = fb.font
|
5319
|
+
end
|
5320
|
+
}
|
5321
|
+
color_button { |cb|
|
5322
|
+
label 'Color'
|
5323
|
+
|
5324
|
+
on_changed do
|
5325
|
+
@string.color = cb.color
|
5326
|
+
end
|
5327
|
+
}
|
5328
|
+
color_button { |cb|
|
5329
|
+
label 'Background'
|
5330
|
+
|
5331
|
+
on_changed do
|
5332
|
+
@string.background = cb.color
|
5333
|
+
end
|
5334
|
+
}
|
5335
|
+
combobox { |c|
|
5336
|
+
label 'Underline'
|
5337
|
+
items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
|
5338
|
+
selected 'None'
|
5339
|
+
|
5340
|
+
on_selected do
|
5341
|
+
@string.underline = c.selected_item.underscore
|
5342
|
+
end
|
5343
|
+
}
|
5344
|
+
}
|
5345
|
+
|
5346
|
+
area {
|
5347
|
+
text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
|
5348
|
+
# align :left # default alignment
|
5349
|
+
|
5350
|
+
@string = string {
|
5351
|
+
' At last Ygramul sensed that something was coming toward ' \
|
5352
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
5353
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
5354
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
|
5355
|
+
"\n\n" \
|
5356
|
+
' A cry of fear escaped Bastian. ' \
|
5357
|
+
"\n\n" \
|
5358
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
5359
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
5360
|
+
'someone else had arrived, for that sound could not have been ' \
|
5361
|
+
'made by the boy who stood there as though paralyzed with ' \
|
5362
|
+
'horror. ' \
|
5363
|
+
"\n\n" \
|
5364
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
5365
|
+
"But that's not possible. " \
|
5366
|
+
"\n\n" \
|
5367
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
5368
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
5369
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
5370
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
5371
|
+
'words. ' \
|
5372
|
+
"\n\n"
|
5373
|
+
}
|
5374
|
+
}
|
5375
|
+
}
|
5376
|
+
}
|
5377
|
+
}.show
|
5378
|
+
end
|
5379
|
+
end
|
5380
|
+
|
5381
|
+
CustomDrawText.new.launch
|
5382
|
+
```
|
5383
|
+
|
5384
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
|
5385
|
+
|
5386
|
+
```ruby
|
5387
|
+
require 'glimmer-dsl-libui'
|
5388
|
+
|
5389
|
+
# Michael Ende (1929-1995)
|
5390
|
+
# The Neverending Story is a fantasy novel by German writer Michael Ende,
|
5391
|
+
# The English version, translated by Ralph Manheim, was published in 1983.
|
5392
|
+
class CustomDrawText
|
5393
|
+
include Glimmer
|
5394
|
+
|
5395
|
+
def launch
|
5396
|
+
window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
|
5397
|
+
margined true
|
5398
|
+
|
5399
|
+
vertical_box {
|
5400
|
+
form {
|
5401
|
+
stretchy false
|
5402
|
+
|
5403
|
+
font_button { |fb|
|
5404
|
+
label 'Font'
|
5405
|
+
|
5406
|
+
on_changed do
|
5407
|
+
@font = fb.font
|
5408
|
+
@area.queue_redraw_all
|
5409
|
+
end
|
5410
|
+
}
|
5411
|
+
color_button { |cb|
|
5412
|
+
label 'Color'
|
5413
|
+
|
5414
|
+
on_changed do
|
5415
|
+
@color = cb.color
|
5416
|
+
@area.queue_redraw_all
|
5417
|
+
end
|
5418
|
+
}
|
5419
|
+
color_button { |cb|
|
5420
|
+
label 'Background'
|
5421
|
+
|
5422
|
+
on_changed do
|
5423
|
+
@background = cb.color
|
5424
|
+
@area.queue_redraw_all
|
5425
|
+
end
|
5426
|
+
}
|
5427
|
+
combobox { |c|
|
5428
|
+
label 'Underline'
|
5429
|
+
items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
|
5430
|
+
selected 'None'
|
5431
|
+
|
5432
|
+
on_selected do
|
5433
|
+
@underline = c.selected_item.underscore
|
5434
|
+
@area.queue_redraw_all
|
5435
|
+
end
|
5436
|
+
}
|
5437
|
+
}
|
5438
|
+
|
5439
|
+
@area = area {
|
5440
|
+
on_draw do |area_draw_params|
|
5441
|
+
text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
|
5442
|
+
# align :left # default alignment
|
5443
|
+
|
5444
|
+
@string = string {
|
5445
|
+
font @font unless @font.nil?
|
5446
|
+
color @color unless @color.nil?
|
5447
|
+
background @background unless @background.nil?
|
5448
|
+
underline @underline unless @underline.nil?
|
5449
|
+
|
5450
|
+
' At last Ygramul sensed that something was coming toward ' \
|
5451
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
5452
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
5453
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. ' \
|
5454
|
+
"\n\n" \
|
5455
|
+
' A cry of fear escaped Bastian. ' \
|
5456
|
+
"\n\n" \
|
5457
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
5458
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
5459
|
+
'someone else had arrived, for that sound could not have been ' \
|
5460
|
+
'made by the boy who stood there as though paralyzed with ' \
|
5461
|
+
'horror. ' \
|
5462
|
+
"\n\n" \
|
5463
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
5464
|
+
"But that's not possible. " \
|
5465
|
+
"\n\n" \
|
5466
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
5467
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
5468
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
5469
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
5470
|
+
'words. ' \
|
5471
|
+
"\n\n"
|
5472
|
+
}
|
5473
|
+
}
|
5474
|
+
end
|
5475
|
+
}
|
5476
|
+
}
|
5477
|
+
}.show
|
5478
|
+
end
|
5479
|
+
end
|
5480
|
+
|
5481
|
+
CustomDrawText.new.launch
|
5482
|
+
|
5483
|
+
```
|
5484
|
+
|
4942
5485
|
## Contributing to glimmer-dsl-libui
|
4943
5486
|
|
4944
5487
|
- Check out the latest master to make sure the feature hasn't been
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|