glimmer-dsl-libui 0.3.3 → 0.4.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.4.1
@@ -7,9 +7,7 @@ window('Basic Area', 400, 400) {
7
7
 
8
8
  vertical_box {
9
9
  area {
10
- path { # a stable path is added declaratively
11
- rectangle(0, 0, 400, 400)
12
-
10
+ rectangle(0, 0, 400, 400) { # stable implicit path shape, added declaratively
13
11
  fill r: 102, g: 102, b: 204, a: 1.0
14
12
  }
15
13
  }
@@ -8,9 +8,7 @@ window('Basic Area', 400, 400) {
8
8
  vertical_box {
9
9
  area {
10
10
  on_draw do |area_draw_params|
11
- path { # a dynamic path is added semi-declaratively inside on_draw block
12
- rectangle(0, 0, 400, 400)
13
-
11
+ rectangle(0, 0, 400, 400) { # dynamic implicit path shape, added semi-declaratively inside on_draw block
14
12
  fill r: 102, g: 102, b: 204, a: 1.0
15
13
  }
16
14
  end
@@ -0,0 +1,17 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ path { # stable path, added declaratively
11
+ rectangle(0, 0, 400, 400)
12
+
13
+ fill r: 102, g: 102, b: 204, a: 1.0
14
+ }
15
+ }
16
+ }
17
+ }.show
@@ -0,0 +1,19 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ on_draw do |area_draw_params|
11
+ path { # dynamic path, added semi-declaratively inside on_draw block
12
+ rectangle(0, 0, 400, 400)
13
+
14
+ fill r: 102, g: 102, b: 204, a: 1.0
15
+ }
16
+ end
17
+ }
18
+ }
19
+ }.show
@@ -0,0 +1,79 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ class BasicScrollingArea
4
+ include Glimmer
5
+
6
+ SCROLLING_AREA_WIDTH = 800
7
+ SCROLLING_AREA_HEIGHT = 400
8
+ SCROLLING_AREA_PADDING_X = 20
9
+ SCROLLING_AREA_PADDING_Y = 20
10
+
11
+ def initialize
12
+ @x = SCROLLING_AREA_PADDING_X
13
+ @y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
14
+ create_gui
15
+ Glimmer::LibUI.timer(0.01) do
16
+ @x += SCROLLING_AREA_PADDING_X
17
+ @y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min
18
+ @graph.content { # re-open @graph's content and add a line
19
+ line(@x, @y)
20
+ }
21
+ # if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)`
22
+ # Note that `#scroll_to` does not seem to work on Linux, but normal scrolling does.
23
+ @scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied
24
+ # return false to stop timer once @x exceeds scrolling area width - padding
25
+ false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2)
26
+ end
27
+ end
28
+
29
+ def launch
30
+ @main_window.show
31
+ end
32
+
33
+ def x_axis
34
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
35
+ stroke :black, thickness: 3
36
+ }
37
+
38
+ ((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier|
39
+ x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2
40
+ y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
41
+
42
+ polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) {
43
+ stroke :black, thickness: 2
44
+ }
45
+ end
46
+ end
47
+
48
+ def y_axis
49
+ polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
50
+ stroke :black, thickness: 3
51
+ }
52
+
53
+ ((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier|
54
+ x = SCROLLING_AREA_PADDING_X
55
+ y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2
56
+
57
+ polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) {
58
+ stroke :black, thickness: 2
59
+ }
60
+ end
61
+ end
62
+
63
+ def create_gui
64
+ @main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) {
65
+ resizable false
66
+
67
+ @scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) { # double width of window enables horizontal scrolling
68
+ x_axis
69
+ y_axis
70
+
71
+ @graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
72
+ stroke :blue, thickness: 2
73
+ }
74
+ }
75
+ }
76
+ end
77
+ end
78
+
79
+ BasicScrollingArea.new.launch
@@ -26,7 +26,8 @@ class ColorTheCircles
26
26
  end
27
27
 
28
28
  def register_observers
29
- observer = Glimmer::DataBinding::Observer.proc do |new_score|
29
+ # observe automatically enhances self to become Glimmer::DataBinding::ObservableModel and notify observer block of score attribute changes
30
+ observe(self, :score) do |new_score|
30
31
  Glimmer::LibUI.queue_main do
31
32
  @score_label.text = new_score.to_s
32
33
  if new_score == -20
@@ -40,7 +41,6 @@ class ColorTheCircles
40
41
  end
41
42
  end
42
43
  end
43
- observer.observe(self, :score) # automatically enhances self to become Glimmer::DataBinding::ObservableModel and notify observer on score attribute changes
44
44
  end
45
45
 
46
46
  def setup_circle_factory
@@ -34,9 +34,9 @@ def label_pair(model, attribute, value)
34
34
  name_label = label(attribute.to_s.underscore.split('_').map(&:capitalize).join(' '))
35
35
  value_label = label(value.to_s)
36
36
  }
37
- Glimmer::DataBinding::Observer.proc do
37
+ observe(model, attribute) do
38
38
  value_label.text = model.send(attribute)
39
- end.observe(model, attribute)
39
+ end
40
40
  end
41
41
 
42
42
  def address(address)
@@ -18,12 +18,8 @@ class TinyMidiPlayer
18
18
 
19
19
  def stop_midi
20
20
  if @pid
21
- if @th.alive?
22
- Process.kill(:SIGKILL, @pid)
23
- @pid = nil
24
- else
25
- @pid = nil
26
- end
21
+ Process.kill(:SIGKILL, @pid) if @th.alive?
22
+ @pid = nil
27
23
  end
28
24
  end
29
25
 
@@ -6,8 +6,8 @@ require_relative 'apple'
6
6
  class Snake
7
7
  module Model
8
8
  class Game
9
- WIDTH_DEFAULT = 40
10
- HEIGHT_DEFAULT = 40
9
+ WIDTH_DEFAULT = 20
10
+ HEIGHT_DEFAULT = 20
11
11
  FILE_HIGH_SCORE = File.expand_path(File.join(Dir.home, '.glimmer-snake'))
12
12
 
13
13
  attr_reader :width, :height
@@ -1,10 +1,12 @@
1
- require 'glimmer/data_binding/observer'
1
+ require 'glimmer'
2
2
  require_relative '../model/game'
3
3
  require_relative 'cell'
4
4
 
5
5
  class Snake
6
6
  module Presenter
7
7
  class Grid
8
+ include Glimmer
9
+
8
10
  attr_reader :game, :cells
9
11
 
10
12
  def initialize(game = Model::Game.new)
@@ -14,7 +16,7 @@ class Snake
14
16
  Cell.new(grid: self, row: row, column: column)
15
17
  end
16
18
  end
17
- Glimmer::DataBinding::Observer.proc do |new_vertebrae|
19
+ observe(@game.snake, :vertebrae) do |new_vertebrae|
18
20
  occupied_snake_positions = @game.snake.vertebrae.map {|v| [v.row, v.column]}
19
21
  @cells.each_with_index do |row_cells, row|
20
22
  row_cells.each_with_index do |cell, column|
@@ -27,7 +29,7 @@ class Snake
27
29
  end
28
30
  end
29
31
  end
30
- end.observe(@game.snake, :vertebrae)
32
+ end
31
33
  end
32
34
 
33
35
  def clear
data/examples/snake.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'glimmer-dsl-libui'
2
- require 'glimmer/data_binding/observer'
3
2
 
4
3
  require_relative 'snake/presenter/grid'
5
4
 
6
5
  class Snake
6
+ include Glimmer
7
+
7
8
  CELL_SIZE = 15
8
9
  SNAKE_MOVE_DELAY = 0.1
9
- include Glimmer
10
10
 
11
11
  def initialize
12
12
  @game = Model::Game.new
@@ -21,48 +21,38 @@ class Snake
21
21
  end
22
22
 
23
23
  def register_observers
24
- @game.height.times do |row|
25
- @game.width.times do |column|
26
- Glimmer::DataBinding::Observer.proc do |new_color|
27
- @cell_grid[row][column].fill = new_color
28
- end.observe(@grid.cells[row][column], :color)
29
- end
30
- end
31
-
32
- Glimmer::DataBinding::Observer.proc do |game_over|
24
+ observe(@game, :over) do |game_over|
33
25
  Glimmer::LibUI.queue_main do
34
26
  if game_over
35
27
  msg_box('Game Over!', "Score: #{@game.score} | High Score: #{@game.high_score}")
36
28
  @game.start
37
29
  end
38
30
  end
39
- end.observe(@game, :over)
31
+ end
40
32
 
41
33
  Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
42
- unless @game.over?
43
- @game.snake.move
44
- @main_window.title = "Glimmer Snake (Score: #{@game.score} | High Score: #{@game.high_score})"
45
- end
34
+ @game.snake.move unless @game.over?
46
35
  end
47
36
  end
48
37
 
49
38
  def create_gui
50
- @cell_grid = []
51
- @main_window = window('Glimmer Snake', @game.width * CELL_SIZE, @game.height * CELL_SIZE) {
39
+ @main_window = window {
40
+ # data-bind window title to game score, converting it to a title string on read from the model
41
+ title <= [@game, :score, on_read: -> (score) {"Glimmer Snake (Score: #{@game.score})"}]
42
+ content_size @game.width * CELL_SIZE, @game.height * CELL_SIZE
52
43
  resizable false
53
44
 
54
45
  vertical_box {
55
46
  padded false
56
47
 
57
48
  @game.height.times do |row|
58
- @cell_grid << []
59
49
  horizontal_box {
60
50
  padded false
61
51
 
62
52
  @game.width.times do |column|
63
53
  area {
64
- @cell_grid.last << square(0, 0, CELL_SIZE) {
65
- fill Presenter::Cell::COLOR_CLEAR
54
+ square(0, 0, CELL_SIZE) {
55
+ fill <= [@grid.cells[row][column], :color] # data-bind square fill to grid cell color
66
56
  }
67
57
 
68
58
  on_key_up do |area_key_event|
data/examples/tetris.rb CHANGED
@@ -42,7 +42,7 @@ class Tetris
42
42
  end
43
43
 
44
44
  def register_observers
45
- Glimmer::DataBinding::Observer.proc do |game_over|
45
+ observe(@game, :game_over) do |game_over|
46
46
  if game_over
47
47
  @pause_menu_item.enabled = false
48
48
  show_game_over_dialog
@@ -50,11 +50,11 @@ class Tetris
50
50
  @pause_menu_item.enabled = true
51
51
  start_moving_tetrominos_down
52
52
  end
53
- end.observe(@game, :game_over)
53
+ end
54
54
 
55
55
  Model::Game::PLAYFIELD_HEIGHT.times do |row|
56
56
  Model::Game::PLAYFIELD_WIDTH.times do |column|
57
- Glimmer::DataBinding::Observer.proc do |new_color|
57
+ observe(@game.playfield[row][column], :color) do |new_color|
58
58
  Glimmer::LibUI.queue_main do
59
59
  color = Glimmer::LibUI.interpret_color(new_color)
60
60
  block = @playfield_blocks[row][column]
@@ -65,13 +65,13 @@ class Tetris
65
65
  block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
66
66
  block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
67
67
  end
68
- end.observe(@game.playfield[row][column], :color)
68
+ end
69
69
  end
70
70
  end
71
71
 
72
72
  Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
73
73
  Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
74
- Glimmer::DataBinding::Observer.proc do |new_color|
74
+ observe(@game.preview_playfield[row][column], :color) do |new_color|
75
75
  Glimmer::LibUI.queue_main do
76
76
  color = Glimmer::LibUI.interpret_color(new_color)
77
77
  block = @preview_playfield_blocks[row][column]
@@ -82,27 +82,27 @@ class Tetris
82
82
  block[:left_bevel_edge].fill = {r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT}
83
83
  block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
84
84
  end
85
- end.observe(@game.preview_playfield[row][column], :color)
85
+ end
86
86
  end
87
87
  end
88
88
 
89
- Glimmer::DataBinding::Observer.proc do |new_score|
89
+ observe(@game, :score) do |new_score|
90
90
  Glimmer::LibUI.queue_main do
91
91
  @score_label.text = new_score.to_s
92
92
  end
93
- end.observe(@game, :score)
93
+ end
94
94
 
95
- Glimmer::DataBinding::Observer.proc do |new_lines|
95
+ observe(@game, :lines) do |new_lines|
96
96
  Glimmer::LibUI.queue_main do
97
97
  @lines_label.text = new_lines.to_s
98
98
  end
99
- end.observe(@game, :lines)
99
+ end
100
100
 
101
- Glimmer::DataBinding::Observer.proc do |new_level|
101
+ observe(@game, :level) do |new_level|
102
102
  Glimmer::LibUI.queue_main do
103
103
  @level_label.text = new_level.to_s
104
104
  end
105
- end.observe(@game, :level)
105
+ end
106
106
  end
107
107
 
108
108
  def menu_bar
@@ -16,17 +16,9 @@ class TicTacToe
16
16
  end
17
17
 
18
18
  def register_observers
19
- Glimmer::DataBinding::Observer.proc do |game_status|
19
+ observe(@tic_tac_toe_board, :game_status) do |game_status|
20
20
  display_win_message if game_status == Board::WIN
21
21
  display_draw_message if game_status == Board::DRAW
22
- end.observe(@tic_tac_toe_board, :game_status)
23
-
24
- 3.times.map do |row|
25
- 3.times.map do |column|
26
- Glimmer::DataBinding::Observer.proc do |sign|
27
- @cells[row][column].string = sign
28
- end.observe(@tic_tac_toe_board[row + 1, column + 1], :sign) # board model is 1-based
29
- end
30
22
  end
31
23
  end
32
24
 
@@ -34,12 +26,10 @@ class TicTacToe
34
26
  @main_window = window('Tic-Tac-Toe', 180, 180) {
35
27
  resizable false
36
28
 
37
- @cells = []
38
29
  vertical_box {
39
30
  padded false
40
31
 
41
32
  3.times.map do |row|
42
- @cells << []
43
33
  horizontal_box {
44
34
  padded false
45
35
 
@@ -49,8 +39,9 @@ class TicTacToe
49
39
  stroke :black, thickness: 2
50
40
  }
51
41
  text(23, 19) {
52
- @cells[row] << string('') {
42
+ string {
53
43
  font family: 'Arial', size: OS.mac? ? 20 : 16
44
+ string <= [@tic_tac_toe_board[row + 1, column + 1], :sign] # board model is 1-based
54
45
  }
55
46
  }
56
47
  on_mouse_up do
data/examples/timer.rb CHANGED
@@ -19,12 +19,8 @@ class Timer
19
19
 
20
20
  def stop_alarm
21
21
  if @pid
22
- if @th.alive?
23
- Process.kill(:SIGKILL, @pid)
24
- @pid = nil
25
- else
26
- @pid = nil
27
- end
22
+ Process.kill(:SIGKILL, @pid) if @th.alive?
23
+ @pid = nil
28
24
  end
29
25
  end
30
26
 
Binary file
@@ -0,0 +1,36 @@
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/dsl/static_expression'
23
+ require 'glimmer/dsl/bind_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ # Responsible for setting up the return value of the bind keyword (command symbol)
29
+ # as a ModelBinding. It is then used by another command handler like
30
+ # DataBindingExpression
31
+ class BindExpression < StaticExpression
32
+ include Glimmer::DSL::BindExpression
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,47 @@
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/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ # Responsible for wiring data-binding
29
+ # Depends on BindExpression
30
+ class DataBindingExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ args.size == 1 and
33
+ args[0].is_a?(DataBinding::ModelBinding)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ model_binding = args[0]
38
+ model_attribute_observer = Glimmer::DataBinding::Observer.proc do
39
+ parent.send("#{keyword}=", model_binding.evaluate_property)
40
+ end
41
+ model_attribute_observer.observe(model_binding)
42
+ model_attribute_observer.call # initial update
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -37,7 +37,10 @@ module Glimmer
37
37
  Libui,
38
38
  %w[
39
39
  listener
40
+ data_binding
41
+ shine_data_binding
40
42
  property
43
+ string
41
44
  control
42
45
  shape
43
46
  ]
@@ -0,0 +1,35 @@
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/dsl/static_expression'
23
+ require 'glimmer/dsl/top_level_expression'
24
+ require 'glimmer/dsl/observe_expression'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module SWT
29
+ class ObserveExpression < StaticExpression
30
+ include TopLevelExpression
31
+ include Glimmer::DSL::ObserveExpression
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,42 @@
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/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/shine'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Libui
29
+ class ShineDataBindingExpression < Expression
30
+ def can_interpret?(parent, keyword, *args, &block)
31
+ args.size == 0 and
32
+ block.nil? and
33
+ parent.respond_to?(keyword, *args, &block)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ Glimmer::DataBinding::Shine.new(parent, keyword)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -19,7 +19,6 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/dsl/static_expression'
23
22
  require 'glimmer/dsl/parent_expression'
24
23
  require 'glimmer/libui/control_proxy/text_proxy'
25
24
  require 'glimmer/libui/attributed_string'
@@ -27,14 +26,14 @@ require 'glimmer/libui/attributed_string'
27
26
  module Glimmer
28
27
  module DSL
29
28
  module Libui
30
- class StringExpression < StaticExpression
29
+ class StringExpression < Expression
31
30
  include ParentExpression
32
31
 
33
32
  def can_interpret?(parent, keyword, *args, &block)
34
- super and
33
+ keyword == 'string' and
35
34
  (
36
35
  parent.is_a?(Glimmer::LibUI::ControlProxy::TextProxy) or
37
- parent.is_a?(Glimmer::LibUI::AttributedString)
36
+ (parent.is_a?(Glimmer::LibUI::AttributedString) and !args.empty?)
38
37
  )
39
38
  end
40
39
 
@@ -47,7 +46,7 @@ module Glimmer
47
46
  end
48
47
 
49
48
  def add_content(parent, keyword, *args, &block)
50
- parent.post_add_content
49
+ parent.post_add_content(block)
51
50
  end
52
51
  end
53
52
  end