glimmer-dsl-libui 0.4.4 → 0.4.5
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 +8 -1
- data/README.md +625 -119
- data/VERSION +1 -1
- data/examples/dynamic_area.rb +77 -90
- data/examples/dynamic_area2.rb +14 -12
- data/examples/dynamic_area3.rb +90 -0
- data/examples/dynamic_area4.rb +95 -0
- data/examples/form_table.rb +0 -2
- data/examples/form_table2.rb +0 -2
- data/examples/histogram.rb +98 -91
- data/examples/histogram2.rb +109 -0
- data/examples/timer.rb +28 -31
- data/examples/timer2.rb +129 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/spinbox_proxy.rb +38 -0
- metadata +7 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# https://github.com/jamescook/libui-ruby/blob/master/example/histogram.rb
|
|
2
|
+
|
|
3
|
+
require 'glimmer-dsl-libui'
|
|
4
|
+
|
|
5
|
+
include Glimmer
|
|
6
|
+
|
|
7
|
+
X_OFF_LEFT = 20
|
|
8
|
+
Y_OFF_TOP = 20
|
|
9
|
+
X_OFF_RIGHT = 20
|
|
10
|
+
Y_OFF_BOTTOM = 20
|
|
11
|
+
POINT_RADIUS = 5
|
|
12
|
+
COLOR_BLUE = Glimmer::LibUI.interpret_color(0x1E90FF)
|
|
13
|
+
|
|
14
|
+
@datapoints = 10.times.map {Random.new.rand(90)}
|
|
15
|
+
@color = COLOR_BLUE
|
|
16
|
+
|
|
17
|
+
def graph_size(area_width, area_height)
|
|
18
|
+
graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT
|
|
19
|
+
graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM
|
|
20
|
+
[graph_width, graph_height]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def point_locations(width, height)
|
|
24
|
+
xincr = width / 9.0 # 10 - 1 to make the last point be at the end
|
|
25
|
+
yincr = height / 100.0
|
|
26
|
+
|
|
27
|
+
@datapoints.each_with_index.map do |value, i|
|
|
28
|
+
val = 100 - value
|
|
29
|
+
[xincr * i, yincr * val]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# method-based custom control representing a graph path
|
|
34
|
+
def graph_path(width, height, should_extend, &block)
|
|
35
|
+
locations = point_locations(width, height).flatten
|
|
36
|
+
path {
|
|
37
|
+
if should_extend
|
|
38
|
+
polygon(locations + [width, height, 0, height])
|
|
39
|
+
else
|
|
40
|
+
polyline(locations)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
|
|
44
|
+
transform {
|
|
45
|
+
translate X_OFF_LEFT, Y_OFF_TOP
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
block.call
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
window('histogram example', 640, 480) {
|
|
53
|
+
margined true
|
|
54
|
+
|
|
55
|
+
horizontal_box {
|
|
56
|
+
vertical_box {
|
|
57
|
+
stretchy false
|
|
58
|
+
|
|
59
|
+
10.times do |i|
|
|
60
|
+
spinbox(0, 100) { |sb|
|
|
61
|
+
stretchy false
|
|
62
|
+
value @datapoints[i]
|
|
63
|
+
|
|
64
|
+
on_changed do
|
|
65
|
+
@datapoints[i] = sb.value
|
|
66
|
+
@area.queue_redraw_all
|
|
67
|
+
end
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
color_button { |cb|
|
|
72
|
+
stretchy false
|
|
73
|
+
color COLOR_BLUE
|
|
74
|
+
|
|
75
|
+
on_changed do
|
|
76
|
+
@color = cb.color
|
|
77
|
+
@area.queue_redraw_all
|
|
78
|
+
end
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@area = area {
|
|
83
|
+
on_draw do |area_draw_params|
|
|
84
|
+
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height]) {
|
|
85
|
+
fill 0xFFFFFF
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
|
89
|
+
|
|
90
|
+
figure(X_OFF_LEFT, Y_OFF_TOP) {
|
|
91
|
+
line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
|
|
92
|
+
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
|
93
|
+
|
|
94
|
+
stroke 0x000000, thickness: 2, miter_limit: 10
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# now create the fill for the graph below the graph line
|
|
98
|
+
graph_path(graph_width, graph_height, true) {
|
|
99
|
+
fill @color.merge(a: 0.5)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# now draw the histogram line
|
|
103
|
+
graph_path(graph_width, graph_height, false) {
|
|
104
|
+
stroke @color.merge(thickness: 2, miter_limit: 10)
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}.show
|
data/examples/timer.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
1
|
require 'glimmer-dsl-libui'
|
|
4
2
|
|
|
5
3
|
class Timer
|
|
@@ -9,9 +7,12 @@ class Timer
|
|
|
9
7
|
MINUTE_MAX = 59
|
|
10
8
|
HOUR_MAX = 23
|
|
11
9
|
|
|
10
|
+
attr_accessor :hour, :min, :sec, :started, :played
|
|
11
|
+
|
|
12
12
|
def initialize
|
|
13
13
|
@pid = nil
|
|
14
14
|
@alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
|
|
15
|
+
@hour = @min = @sec = 0
|
|
15
16
|
at_exit { stop_alarm }
|
|
16
17
|
setup_timer
|
|
17
18
|
create_gui
|
|
@@ -41,31 +42,29 @@ class Timer
|
|
|
41
42
|
unless @setup_timer
|
|
42
43
|
Glimmer::LibUI.timer(1) do
|
|
43
44
|
if @started
|
|
44
|
-
seconds = @
|
|
45
|
-
minutes = @
|
|
46
|
-
hours = @
|
|
45
|
+
seconds = @sec
|
|
46
|
+
minutes = @min
|
|
47
|
+
hours = @hour
|
|
47
48
|
if seconds > 0
|
|
48
|
-
|
|
49
|
+
self.sec = seconds -= 1
|
|
49
50
|
end
|
|
50
51
|
if seconds == 0
|
|
51
52
|
if minutes > 0
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
self.min = minutes -= 1
|
|
54
|
+
self.sec = seconds = SECOND_MAX
|
|
54
55
|
end
|
|
55
56
|
if minutes == 0
|
|
56
57
|
if hours > 0
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
self.hour = hours -= 1
|
|
59
|
+
self.min = minutes = MINUTE_MAX
|
|
60
|
+
self.sec = seconds = SECOND_MAX
|
|
60
61
|
end
|
|
61
62
|
if hours == 0 && minutes == 0 && seconds == 0
|
|
62
|
-
|
|
63
|
-
@stop_button.enabled = false
|
|
64
|
-
@started = false
|
|
63
|
+
self.started = false
|
|
65
64
|
unless @played
|
|
66
65
|
play_alarm
|
|
67
66
|
msg_box('Alarm', 'Countdown Is Finished!')
|
|
68
|
-
|
|
67
|
+
self.played = true
|
|
69
68
|
end
|
|
70
69
|
end
|
|
71
70
|
end
|
|
@@ -83,42 +82,40 @@ class Timer
|
|
|
83
82
|
group('Countdown') {
|
|
84
83
|
vertical_box {
|
|
85
84
|
horizontal_box {
|
|
86
|
-
|
|
85
|
+
spinbox(0, HOUR_MAX) {
|
|
87
86
|
stretchy false
|
|
88
|
-
value
|
|
87
|
+
value <=> [self, :hour]
|
|
89
88
|
}
|
|
90
89
|
label(':') {
|
|
91
90
|
stretchy false
|
|
92
91
|
}
|
|
93
|
-
|
|
92
|
+
spinbox(0, MINUTE_MAX) {
|
|
94
93
|
stretchy false
|
|
95
|
-
value
|
|
94
|
+
value <=> [self, :min]
|
|
96
95
|
}
|
|
97
96
|
label(':') {
|
|
98
97
|
stretchy false
|
|
99
98
|
}
|
|
100
|
-
|
|
99
|
+
spinbox(0, SECOND_MAX) {
|
|
101
100
|
stretchy false
|
|
102
|
-
value
|
|
101
|
+
value <=> [self, :sec]
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
horizontal_box {
|
|
106
|
-
|
|
105
|
+
button('Start') {
|
|
106
|
+
enabled <= [self, :started, on_read: :!]
|
|
107
|
+
|
|
107
108
|
on_clicked do
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
@started = true
|
|
111
|
-
@played = false
|
|
109
|
+
self.started = true
|
|
110
|
+
self.played = false
|
|
112
111
|
end
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
enabled
|
|
114
|
+
button('Stop') {
|
|
115
|
+
enabled <= [self, :started]
|
|
117
116
|
|
|
118
117
|
on_clicked do
|
|
119
|
-
|
|
120
|
-
@stop_button.enabled = false
|
|
121
|
-
@started = false
|
|
118
|
+
self.started = false
|
|
122
119
|
end
|
|
123
120
|
}
|
|
124
121
|
}
|
data/examples/timer2.rb
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
require 'glimmer-dsl-libui'
|
|
2
|
+
|
|
3
|
+
class Timer
|
|
4
|
+
include Glimmer
|
|
5
|
+
|
|
6
|
+
SECOND_MAX = 59
|
|
7
|
+
MINUTE_MAX = 59
|
|
8
|
+
HOUR_MAX = 23
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@pid = nil
|
|
12
|
+
@alarm_file = File.expand_path('../sounds/AlanWalker-Faded.mid', __dir__)
|
|
13
|
+
at_exit { stop_alarm }
|
|
14
|
+
setup_timer
|
|
15
|
+
create_gui
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def stop_alarm
|
|
19
|
+
if @pid
|
|
20
|
+
Process.kill(:SIGKILL, @pid) if @th.alive?
|
|
21
|
+
@pid = nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def play_alarm
|
|
26
|
+
stop_alarm
|
|
27
|
+
if @pid.nil?
|
|
28
|
+
begin
|
|
29
|
+
@pid = spawn "timidity -G 0.0-10.0 #{@alarm_file}"
|
|
30
|
+
@th = Process.detach @pid
|
|
31
|
+
rescue Errno::ENOENT
|
|
32
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
|
33
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def setup_timer
|
|
39
|
+
unless @setup_timer
|
|
40
|
+
Glimmer::LibUI.timer(1) do
|
|
41
|
+
if @started
|
|
42
|
+
seconds = @sec_spinbox.value
|
|
43
|
+
minutes = @min_spinbox.value
|
|
44
|
+
hours = @hour_spinbox.value
|
|
45
|
+
if seconds > 0
|
|
46
|
+
@sec_spinbox.value = seconds -= 1
|
|
47
|
+
end
|
|
48
|
+
if seconds == 0
|
|
49
|
+
if minutes > 0
|
|
50
|
+
@min_spinbox.value = minutes -= 1
|
|
51
|
+
@sec_spinbox.value = seconds = SECOND_MAX
|
|
52
|
+
end
|
|
53
|
+
if minutes == 0
|
|
54
|
+
if hours > 0
|
|
55
|
+
@hour_spinbox.value = hours -= 1
|
|
56
|
+
@min_spinbox.value = minutes = MINUTE_MAX
|
|
57
|
+
@sec_spinbox.value = seconds = SECOND_MAX
|
|
58
|
+
end
|
|
59
|
+
if hours == 0 && minutes == 0 && seconds == 0
|
|
60
|
+
@start_button.enabled = true
|
|
61
|
+
@stop_button.enabled = false
|
|
62
|
+
@started = false
|
|
63
|
+
unless @played
|
|
64
|
+
play_alarm
|
|
65
|
+
msg_box('Alarm', 'Countdown Is Finished!')
|
|
66
|
+
@played = true
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
@setup_timer = true
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def create_gui
|
|
78
|
+
window('Timer') {
|
|
79
|
+
margined true
|
|
80
|
+
|
|
81
|
+
group('Countdown') {
|
|
82
|
+
vertical_box {
|
|
83
|
+
horizontal_box {
|
|
84
|
+
@hour_spinbox = spinbox(0, HOUR_MAX) {
|
|
85
|
+
stretchy false
|
|
86
|
+
value 0
|
|
87
|
+
}
|
|
88
|
+
label(':') {
|
|
89
|
+
stretchy false
|
|
90
|
+
}
|
|
91
|
+
@min_spinbox = spinbox(0, MINUTE_MAX) {
|
|
92
|
+
stretchy false
|
|
93
|
+
value 0
|
|
94
|
+
}
|
|
95
|
+
label(':') {
|
|
96
|
+
stretchy false
|
|
97
|
+
}
|
|
98
|
+
@sec_spinbox = spinbox(0, SECOND_MAX) {
|
|
99
|
+
stretchy false
|
|
100
|
+
value 0
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
horizontal_box {
|
|
104
|
+
@start_button = button('Start') {
|
|
105
|
+
on_clicked do
|
|
106
|
+
@start_button.enabled = false
|
|
107
|
+
@stop_button.enabled = true
|
|
108
|
+
@started = true
|
|
109
|
+
@played = false
|
|
110
|
+
end
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@stop_button = button('Stop') {
|
|
114
|
+
enabled false
|
|
115
|
+
|
|
116
|
+
on_clicked do
|
|
117
|
+
@start_button.enabled = true
|
|
118
|
+
@stop_button.enabled = false
|
|
119
|
+
@started = false
|
|
120
|
+
end
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}.show
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
Timer.new
|
data/glimmer-dsl-libui.gemspec
CHANGED
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
# a copy of this software and associated documentation files (the
|
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
# the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be
|
|
12
|
+
# included in all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
require 'glimmer/libui/control_proxy'
|
|
23
|
+
|
|
24
|
+
module Glimmer
|
|
25
|
+
module LibUI
|
|
26
|
+
class ControlProxy
|
|
27
|
+
# Proxy for LibUI spinbox objects
|
|
28
|
+
#
|
|
29
|
+
# Follows the Proxy Design Pattern
|
|
30
|
+
class SpinboxProxy < ControlProxy
|
|
31
|
+
def data_bind(property, model_binding)
|
|
32
|
+
super
|
|
33
|
+
handle_listener('on_changed') { model_binding.call(value) } if property == 'value'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glimmer-dsl-libui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Maleh
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-11-
|
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: glimmer
|
|
@@ -254,6 +254,8 @@ files:
|
|
|
254
254
|
- examples/date_time_picker.rb
|
|
255
255
|
- examples/dynamic_area.rb
|
|
256
256
|
- examples/dynamic_area2.rb
|
|
257
|
+
- examples/dynamic_area3.rb
|
|
258
|
+
- examples/dynamic_area4.rb
|
|
257
259
|
- examples/editable_column_table.rb
|
|
258
260
|
- examples/editable_table.rb
|
|
259
261
|
- examples/font_button.rb
|
|
@@ -263,6 +265,7 @@ files:
|
|
|
263
265
|
- examples/form_table2.rb
|
|
264
266
|
- examples/grid.rb
|
|
265
267
|
- examples/histogram.rb
|
|
268
|
+
- examples/histogram2.rb
|
|
266
269
|
- examples/login.rb
|
|
267
270
|
- examples/login2.rb
|
|
268
271
|
- examples/login3.rb
|
|
@@ -289,6 +292,7 @@ files:
|
|
|
289
292
|
- examples/tic_tac_toe/board.rb
|
|
290
293
|
- examples/tic_tac_toe/cell.rb
|
|
291
294
|
- examples/timer.rb
|
|
295
|
+
- examples/timer2.rb
|
|
292
296
|
- glimmer-dsl-libui.gemspec
|
|
293
297
|
- icons/glimmer.png
|
|
294
298
|
- lib/glimmer-dsl-libui.rb
|
|
@@ -366,6 +370,7 @@ files:
|
|
|
366
370
|
- lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb
|
|
367
371
|
- lib/glimmer/libui/control_proxy/path_proxy.rb
|
|
368
372
|
- lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb
|
|
373
|
+
- lib/glimmer/libui/control_proxy/spinbox_proxy.rb
|
|
369
374
|
- lib/glimmer/libui/control_proxy/tab_item_proxy.rb
|
|
370
375
|
- lib/glimmer/libui/control_proxy/table_proxy.rb
|
|
371
376
|
- lib/glimmer/libui/control_proxy/text_proxy.rb
|