glimmer-dsl-libui 0.4.16 → 0.4.20
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 +26 -0
- data/README.md +451 -68
- data/VERSION +1 -1
- data/examples/area_based_custom_controls.rb +278 -0
- data/examples/basic_table.rb +1 -1
- data/examples/cpu_percentage.rb +1 -1
- data/examples/custom_draw_text.rb +14 -7
- data/examples/custom_draw_text2.rb +15 -8
- data/examples/method_based_custom_keyword.rb +9 -9
- data/examples/method_based_custom_keyword2.rb +9 -9
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/dsl.rb +1 -0
- data/lib/glimmer/dsl/libui/observe_expression.rb +1 -1
- data/lib/glimmer/dsl/libui/operation_expression.rb +47 -0
- data/lib/glimmer/dsl/libui/property_expression.rb +2 -2
- data/lib/glimmer/libui/control_proxy/box.rb +1 -0
- data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/checkbox_text_color_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/image_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/image_text_color_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column/text_column_proxy.rb +6 -0
- data/lib/glimmer/libui/control_proxy/column.rb +7 -0
- data/lib/glimmer/libui/control_proxy/form_proxy.rb +1 -0
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +1 -0
- data/lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb +0 -1
- data/lib/glimmer/libui/control_proxy/path_proxy.rb +6 -4
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +51 -28
- data/lib/glimmer/libui/control_proxy.rb +1 -0
- data/lib/glimmer/libui/data_bindable.rb +1 -1
- data/lib/glimmer/libui/shape/bezier.rb +20 -3
- data/lib/glimmer/libui/shape/line.rb +23 -3
- data/lib/glimmer-dsl-libui.rb +6 -0
- metadata +23 -6
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.4. | 
| 1 | 
            +
            0.4.20
         | 
| @@ -0,0 +1,278 @@ | |
| 1 | 
            +
            require 'glimmer-dsl-libui'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class AreaBasedCustomControls
         | 
| 4 | 
            +
              include Glimmer
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
              attr_accessor :label_width, :label_height, :label_font_descriptor,
         | 
| 7 | 
            +
                            :label_text_color, :label_background_fill, :label_border_stroke,
         | 
| 8 | 
            +
                            :label_text_x, :label_text_y,
         | 
| 9 | 
            +
                            :button_width, :button_height, :button_font_descriptor,
         | 
| 10 | 
            +
                            :button_text_color, :button_background_fill, :button_border_stroke,
         | 
| 11 | 
            +
                            :button_text_x, :button_text_y
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              def initialize
         | 
| 14 | 
            +
                self.label_width = 335
         | 
| 15 | 
            +
                self.label_height = 50
         | 
| 16 | 
            +
                self.label_font_descriptor = {family: OS.linux? ? 'Monospace Bold Italic' : 'Courier New', size: 16, weight: :bold, italic: :italic}
         | 
| 17 | 
            +
                self.label_text_color = :red
         | 
| 18 | 
            +
                self.label_background_fill = :yellow
         | 
| 19 | 
            +
                self.label_border_stroke = :limegreen
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
                self.button_width = 150
         | 
| 22 | 
            +
                self.button_height = 50
         | 
| 23 | 
            +
                self.button_font_descriptor = {family: OS.linux? ? 'Monospace Bold Italic' : 'Courier New', size: 36, weight: OS.linux? ? :normal : :bold, italic: :italic}
         | 
| 24 | 
            +
                self.button_text_color = :green
         | 
| 25 | 
            +
                self.button_background_fill = :yellow
         | 
| 26 | 
            +
                self.button_border_stroke = :limegreen
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              def rebuild_text_label
         | 
| 30 | 
            +
                @text_label.destroy
         | 
| 31 | 
            +
                @text_label_vertical_box.content { # re-open vertical box content and shove in a new button
         | 
| 32 | 
            +
                  @text_label = text_label('This is a text label.',
         | 
| 33 | 
            +
                                           width: label_width, height: label_height, font_descriptor: label_font_descriptor,
         | 
| 34 | 
            +
                                           background_fill: label_background_fill, text_color: label_text_color, border_stroke: label_border_stroke,
         | 
| 35 | 
            +
                                           text_x: label_text_x, text_y: label_text_y)
         | 
| 36 | 
            +
                }
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
              
         | 
| 39 | 
            +
              def rebuild_push_button
         | 
| 40 | 
            +
                @push_button.destroy
         | 
| 41 | 
            +
                @push_button_vertical_box.content { # re-open vertical box content and shove in a new button
         | 
| 42 | 
            +
                  @push_button = push_button('Push',
         | 
| 43 | 
            +
                                             width: button_width, height: button_height, font_descriptor: button_font_descriptor,
         | 
| 44 | 
            +
                                             background_fill: button_background_fill, text_color: button_text_color, border_stroke: button_border_stroke,
         | 
| 45 | 
            +
                                             text_x: button_text_x, text_y: button_text_y) {
         | 
| 46 | 
            +
                    on_mouse_up do
         | 
| 47 | 
            +
                      message_box('Button Pushed', 'Thank you for pushing the button!')
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
                  }
         | 
| 50 | 
            +
                }
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
              
         | 
| 53 | 
            +
              def launch
         | 
| 54 | 
            +
                window('Area-Based Custom Controls', 385, 385) { |w|
         | 
| 55 | 
            +
                  margined true
         | 
| 56 | 
            +
                  
         | 
| 57 | 
            +
                  tab {
         | 
| 58 | 
            +
                    tab_item('Text Label') {
         | 
| 59 | 
            +
                      @text_label_vertical_box = vertical_box {
         | 
| 60 | 
            +
                        vertical_box {
         | 
| 61 | 
            +
                          text_label('Text Label Form:', width: 385, height: 30, background_fill: OS.windows? ? :white : {a: 0}, border_stroke: OS.windows? ? :white : {a: 0}, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: OS.windows? ? 0 : 5)
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                          horizontal_box {
         | 
| 64 | 
            +
                            label('Width')
         | 
| 65 | 
            +
                            spinbox(1, 1000) {
         | 
| 66 | 
            +
                              value <=> [self, :label_width, after_write: method(:rebuild_text_label)]
         | 
| 67 | 
            +
                            }
         | 
| 68 | 
            +
                          }
         | 
| 69 | 
            +
                          
         | 
| 70 | 
            +
                          horizontal_box {
         | 
| 71 | 
            +
                            label('Height')
         | 
| 72 | 
            +
                            spinbox(1, 1000) {
         | 
| 73 | 
            +
                              value <=> [self, :label_height, after_write: method(:rebuild_text_label)]
         | 
| 74 | 
            +
                            }
         | 
| 75 | 
            +
                          }
         | 
| 76 | 
            +
                          
         | 
| 77 | 
            +
                          horizontal_box {
         | 
| 78 | 
            +
                            label('Font')
         | 
| 79 | 
            +
                            font_button {
         | 
| 80 | 
            +
                              font <=> [self, :label_font_descriptor, after_write: method(:rebuild_text_label)]
         | 
| 81 | 
            +
                            }
         | 
| 82 | 
            +
                          }
         | 
| 83 | 
            +
                          
         | 
| 84 | 
            +
                          horizontal_box {
         | 
| 85 | 
            +
                            label('Text Color')
         | 
| 86 | 
            +
                            color_button {
         | 
| 87 | 
            +
                              color <=> [self, :label_text_color, after_write: method(:rebuild_text_label)]
         | 
| 88 | 
            +
                            }
         | 
| 89 | 
            +
                          }
         | 
| 90 | 
            +
                          
         | 
| 91 | 
            +
                          horizontal_box {
         | 
| 92 | 
            +
                            label('Background Color')
         | 
| 93 | 
            +
                            color_button {
         | 
| 94 | 
            +
                              color <=> [self, :label_background_fill, after_write: method(:rebuild_text_label)]
         | 
| 95 | 
            +
                            }
         | 
| 96 | 
            +
                          }
         | 
| 97 | 
            +
                          
         | 
| 98 | 
            +
                          horizontal_box {
         | 
| 99 | 
            +
                            label('Border Color')
         | 
| 100 | 
            +
                            color_button {
         | 
| 101 | 
            +
                              color <=> [self, :label_border_stroke, after_write: method(:rebuild_text_label)]
         | 
| 102 | 
            +
                            }
         | 
| 103 | 
            +
                          }
         | 
| 104 | 
            +
                          
         | 
| 105 | 
            +
                          horizontal_box {
         | 
| 106 | 
            +
                            label('Text X (0=centered)')
         | 
| 107 | 
            +
                            spinbox(0, 1000) {
         | 
| 108 | 
            +
                              value <=> [self, :label_text_x, on_read: ->(x) {x.nil? ? 0 : x}, on_write: ->(x) {x == 0 ? nil : x}, after_write: method(:rebuild_text_label)]
         | 
| 109 | 
            +
                            }
         | 
| 110 | 
            +
                          }
         | 
| 111 | 
            +
                          
         | 
| 112 | 
            +
                          horizontal_box {
         | 
| 113 | 
            +
                            label('Text Y (0=centered)')
         | 
| 114 | 
            +
                            spinbox(0, 1000) {
         | 
| 115 | 
            +
                              value <=> [self, :label_text_y, on_read: ->(y) {y.nil? ? 0 : y}, on_write: ->(y) {y == 0 ? nil : y}, after_write: method(:rebuild_text_label)]
         | 
| 116 | 
            +
                            }
         | 
| 117 | 
            +
                          }
         | 
| 118 | 
            +
                        }
         | 
| 119 | 
            +
                        
         | 
| 120 | 
            +
                        @text_label = text_label('This is a text label.',
         | 
| 121 | 
            +
                                                 width: label_width, height: label_height, font_descriptor: label_font_descriptor,
         | 
| 122 | 
            +
                                                 background_fill: label_background_fill, text_color: label_text_color, border_stroke: label_border_stroke,
         | 
| 123 | 
            +
                                                 text_x: label_text_x, text_y: label_text_y)
         | 
| 124 | 
            +
                      }
         | 
| 125 | 
            +
                    }
         | 
| 126 | 
            +
                    
         | 
| 127 | 
            +
                    tab_item('Push Button') {
         | 
| 128 | 
            +
                      @push_button_vertical_box = vertical_box {
         | 
| 129 | 
            +
                        vertical_box {
         | 
| 130 | 
            +
                          text_label('Push Button Form:', width: 385, height: 30, background_fill: OS.windows? ? :white : {a: 0}, border_stroke: OS.windows? ? :white : {a: 0}, font_descriptor: {size: 16, weight: :bold}, text_x: 0, text_y: OS.windows? ? 0 : 5)
         | 
| 131 | 
            +
                          
         | 
| 132 | 
            +
                          horizontal_box {
         | 
| 133 | 
            +
                            label('Width')
         | 
| 134 | 
            +
                            spinbox(1, 1000) {
         | 
| 135 | 
            +
                              value <=> [self, :button_width, after_write: method(:rebuild_push_button)]
         | 
| 136 | 
            +
                            }
         | 
| 137 | 
            +
                          }
         | 
| 138 | 
            +
                          
         | 
| 139 | 
            +
                          horizontal_box {
         | 
| 140 | 
            +
                            label('Height')
         | 
| 141 | 
            +
                            spinbox(1, 1000) {
         | 
| 142 | 
            +
                              value <=> [self, :button_height, after_write: method(:rebuild_push_button)]
         | 
| 143 | 
            +
                            }
         | 
| 144 | 
            +
                          }
         | 
| 145 | 
            +
                          
         | 
| 146 | 
            +
                          horizontal_box {
         | 
| 147 | 
            +
                            label('Font')
         | 
| 148 | 
            +
                            font_button {
         | 
| 149 | 
            +
                              font <=> [self, :button_font_descriptor, after_write: method(:rebuild_push_button)]
         | 
| 150 | 
            +
                            }
         | 
| 151 | 
            +
                          }
         | 
| 152 | 
            +
                          
         | 
| 153 | 
            +
                          horizontal_box {
         | 
| 154 | 
            +
                            label('Text Color')
         | 
| 155 | 
            +
                            color_button {
         | 
| 156 | 
            +
                              color <=> [self, :button_text_color, after_write: method(:rebuild_push_button)]
         | 
| 157 | 
            +
                            }
         | 
| 158 | 
            +
                          }
         | 
| 159 | 
            +
                          
         | 
| 160 | 
            +
                          horizontal_box {
         | 
| 161 | 
            +
                            label('Background Color')
         | 
| 162 | 
            +
                            color_button {
         | 
| 163 | 
            +
                              color <=> [self, :button_background_fill, after_write: method(:rebuild_push_button)]
         | 
| 164 | 
            +
                            }
         | 
| 165 | 
            +
                          }
         | 
| 166 | 
            +
                          
         | 
| 167 | 
            +
                          horizontal_box {
         | 
| 168 | 
            +
                            label('Border Color')
         | 
| 169 | 
            +
                            color_button {
         | 
| 170 | 
            +
                              color <=> [self, :button_border_stroke, after_write: method(:rebuild_push_button)]
         | 
| 171 | 
            +
                            }
         | 
| 172 | 
            +
                          }
         | 
| 173 | 
            +
                          
         | 
| 174 | 
            +
                          horizontal_box {
         | 
| 175 | 
            +
                            label('Text X (0=centered)')
         | 
| 176 | 
            +
                            spinbox(0, 1000) {
         | 
| 177 | 
            +
                              value <=> [self, :button_text_x, on_read: ->(x) {x.nil? ? 0 : x}, on_write: ->(x) {x == 0 ? nil : x}, after_write: method(:rebuild_push_button)]
         | 
| 178 | 
            +
                            }
         | 
| 179 | 
            +
                          }
         | 
| 180 | 
            +
                          
         | 
| 181 | 
            +
                          horizontal_box {
         | 
| 182 | 
            +
                            label('Text Y (0=centered)')
         | 
| 183 | 
            +
                            spinbox(0, 1000) {
         | 
| 184 | 
            +
                              value <=> [self, :button_text_y, on_read: ->(y) {y.nil? ? 0 : y}, on_write: ->(y) {y == 0 ? nil : y}, after_write: method(:rebuild_push_button)]
         | 
| 185 | 
            +
                            }
         | 
| 186 | 
            +
                          }
         | 
| 187 | 
            +
                        }
         | 
| 188 | 
            +
                        
         | 
| 189 | 
            +
                        @push_button = push_button('Push',
         | 
| 190 | 
            +
                                                   width: button_width, height: button_height, font_descriptor: button_font_descriptor,
         | 
| 191 | 
            +
                                                   background_fill: button_background_fill, text_color: button_text_color, border_stroke: button_border_stroke,
         | 
| 192 | 
            +
                                                   text_x: button_text_x, text_y: button_text_y) {
         | 
| 193 | 
            +
                          on_mouse_up do
         | 
| 194 | 
            +
                            message_box('Button Pushed', 'Thank you for pushing the button!')
         | 
| 195 | 
            +
                          end
         | 
| 196 | 
            +
                        }
         | 
| 197 | 
            +
                      }
         | 
| 198 | 
            +
                    }
         | 
| 199 | 
            +
                  }
         | 
| 200 | 
            +
                }.show
         | 
| 201 | 
            +
              end
         | 
| 202 | 
            +
                
         | 
| 203 | 
            +
              # text label (area-based custom control) built with vector graphics on top of area.
         | 
| 204 | 
            +
              #
         | 
| 205 | 
            +
              # background_fill is transparent by default.
         | 
| 206 | 
            +
              # background_fill can accept a single color or gradient stops just as per `fill` property in README.
         | 
| 207 | 
            +
              # border_stroke is transparent by default.
         | 
| 208 | 
            +
              # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
         | 
| 209 | 
            +
              def text_label(label_text,
         | 
| 210 | 
            +
                              width: 80, height: 30, font_descriptor: {},
         | 
| 211 | 
            +
                              background_fill: {a: 0}, text_color: :black, border_stroke: {a: 0},
         | 
| 212 | 
            +
                              text_x: nil, text_y: nil,
         | 
| 213 | 
            +
                              &content)
         | 
| 214 | 
            +
                area { |the_area|
         | 
| 215 | 
            +
                  rectangle(1, 1, width, height) {
         | 
| 216 | 
            +
                    fill background_fill
         | 
| 217 | 
            +
                  }
         | 
| 218 | 
            +
                  rectangle(1, 1, width, height) {
         | 
| 219 | 
            +
                    stroke border_stroke
         | 
| 220 | 
            +
                  }
         | 
| 221 | 
            +
                  
         | 
| 222 | 
            +
                  text_height = (font_descriptor[:size] || 12) * (OS.mac? ? 0.75 : 1.35)
         | 
| 223 | 
            +
                  text_width = (text_height * label_text.size) * (OS.mac? ? 0.75 : 0.60)
         | 
| 224 | 
            +
                  text_x ||= (width - text_width) / 2.0
         | 
| 225 | 
            +
                  text_y ||= (height - 4 - text_height) / 2.0
         | 
| 226 | 
            +
                  text(text_x, text_y, width) {
         | 
| 227 | 
            +
                    string(label_text) {
         | 
| 228 | 
            +
                      color text_color
         | 
| 229 | 
            +
                      font font_descriptor
         | 
| 230 | 
            +
                    }
         | 
| 231 | 
            +
                  }
         | 
| 232 | 
            +
                  
         | 
| 233 | 
            +
                  content&.call(the_area)
         | 
| 234 | 
            +
                }
         | 
| 235 | 
            +
              end
         | 
| 236 | 
            +
              
         | 
| 237 | 
            +
              # push button (area-based custom control) built with vector graphics on top of area.
         | 
| 238 | 
            +
              #
         | 
| 239 | 
            +
              # background_fill is white by default.
         | 
| 240 | 
            +
              # background_fill can accept a single color or gradient stops just as per `fill` property in README.
         | 
| 241 | 
            +
              # border_stroke is black by default.
         | 
| 242 | 
            +
              # border_stroke can accept thickness and dashes in addition to color just as per `stroke` property in README.
         | 
| 243 | 
            +
              # text_x and text_y are the offset of the button text in releation to its top-left corner
         | 
| 244 | 
            +
              # When text_x, text_y are left nil, the text is automatically centered in the button area.
         | 
| 245 | 
            +
              # Sometimes, the centering calculation is not perfect due to using a custom font, so
         | 
| 246 | 
            +
              # in that case, pass in text_x, and text_y manually
         | 
| 247 | 
            +
              #
         | 
| 248 | 
            +
              # reuses the text_label custom control
         | 
| 249 | 
            +
              def push_button(button_text,
         | 
| 250 | 
            +
                              width: 80, height: 30, font_descriptor: {},
         | 
| 251 | 
            +
                              background_fill: :white, text_color: :black, border_stroke: {r: 201, g: 201, b: 201},
         | 
| 252 | 
            +
                              text_x: nil, text_y: nil,
         | 
| 253 | 
            +
                              &content)
         | 
| 254 | 
            +
                text_label(button_text,
         | 
| 255 | 
            +
                              width: width, height: height, font_descriptor: font_descriptor,
         | 
| 256 | 
            +
                              background_fill: background_fill, text_color: text_color, border_stroke: border_stroke,
         | 
| 257 | 
            +
                              text_x: text_x, text_y: text_y) { |the_area|
         | 
| 258 | 
            +
                  
         | 
| 259 | 
            +
                  # dig into the_area content and grab elements to modify in mouse listeners below
         | 
| 260 | 
            +
                  background_rectangle = the_area.children[0]
         | 
| 261 | 
            +
                  button_string = the_area.children[2].children[0]
         | 
| 262 | 
            +
                  
         | 
| 263 | 
            +
                  on_mouse_down do
         | 
| 264 | 
            +
                    background_rectangle.fill = {x0: 0, y0: 0, x1: 0, y1: height, stops: [{pos: 0, r: 72, g: 146, b: 247}, {pos: 1, r: 12, g: 85, b: 214}]}
         | 
| 265 | 
            +
                    button_string.color = :white
         | 
| 266 | 
            +
                  end
         | 
| 267 | 
            +
                  
         | 
| 268 | 
            +
                  on_mouse_up do
         | 
| 269 | 
            +
                    background_rectangle.fill = background_fill
         | 
| 270 | 
            +
                    button_string.color = text_color
         | 
| 271 | 
            +
                  end
         | 
| 272 | 
            +
                  
         | 
| 273 | 
            +
                  content&.call(the_area)
         | 
| 274 | 
            +
                }
         | 
| 275 | 
            +
              end
         | 
| 276 | 
            +
            end
         | 
| 277 | 
            +
             | 
| 278 | 
            +
            AreaBasedCustomControls.new.launch
         | 
    
        data/examples/basic_table.rb
    CHANGED
    
    
    
        data/examples/cpu_percentage.rb
    CHANGED
    
    | @@ -11,7 +11,7 @@ Glimmer::LibUI.timer(1) do | |
| 11 11 | 
             
              cpu_percentage_value = nil
         | 
| 12 12 | 
             
              if OS.windows?
         | 
| 13 13 | 
             
                cpu_percentage_raw_value = `wmic cpu get loadpercentage`
         | 
| 14 | 
            -
                cpu_percentage_value = cpu_percentage_raw_value.split("\n") | 
| 14 | 
            +
                cpu_percentage_value = cpu_percentage_raw_value.split("\n").map(&:strip).find {|l| l.match(/^\d+$/)}.to_i
         | 
| 15 15 | 
             
              elsif OS.mac?
         | 
| 16 16 | 
             
                cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
         | 
| 17 17 | 
             
              elsif OS.linux?
         | 
| @@ -21,6 +21,7 @@ class CustomDrawText | |
| 21 21 | 
             
                          @string.font = fb.font
         | 
| 22 22 | 
             
                        end
         | 
| 23 23 | 
             
                      }
         | 
| 24 | 
            +
             | 
| 24 25 | 
             
                      color_button { |cb|
         | 
| 25 26 | 
             
                        label 'Color'
         | 
| 26 27 |  | 
| @@ -28,13 +29,17 @@ class CustomDrawText | |
| 28 29 | 
             
                          @string.color = cb.color
         | 
| 29 30 | 
             
                        end
         | 
| 30 31 | 
             
                      }
         | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
                        
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                           | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 32 | 
            +
             | 
| 33 | 
            +
                      unless OS.windows?
         | 
| 34 | 
            +
                        color_button { |cb|
         | 
| 35 | 
            +
                          label 'Background'
         | 
| 36 | 
            +
                          
         | 
| 37 | 
            +
                          on_changed do
         | 
| 38 | 
            +
                            @string.background = cb.color
         | 
| 39 | 
            +
                          end
         | 
| 40 | 
            +
                        }
         | 
| 41 | 
            +
                      end
         | 
| 42 | 
            +
             | 
| 38 43 | 
             
                      combobox { |c|
         | 
| 39 44 | 
             
                        label 'Underline'
         | 
| 40 45 | 
             
                        items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
         | 
| @@ -44,6 +49,7 @@ class CustomDrawText | |
| 44 49 | 
             
                          @string.underline = c.selected_item.underscore
         | 
| 45 50 | 
             
                        end
         | 
| 46 51 | 
             
                      }
         | 
| 52 | 
            +
             | 
| 47 53 | 
             
                      combobox { |c|
         | 
| 48 54 | 
             
                        label 'Underline Built-In Color'
         | 
| 49 55 | 
             
                        items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
         | 
| @@ -59,6 +65,7 @@ class CustomDrawText | |
| 59 65 | 
             
                          end
         | 
| 60 66 | 
             
                        end
         | 
| 61 67 | 
             
                      }
         | 
| 68 | 
            +
             | 
| 62 69 | 
             
                      @underline_custom_color_button = color_button {
         | 
| 63 70 | 
             
                        label 'Underline Custom Color'
         | 
| 64 71 |  | 
| @@ -22,6 +22,7 @@ class CustomDrawText | |
| 22 22 | 
             
                          @area.queue_redraw_all
         | 
| 23 23 | 
             
                        end
         | 
| 24 24 | 
             
                      }
         | 
| 25 | 
            +
             | 
| 25 26 | 
             
                      color_button { |cb|
         | 
| 26 27 | 
             
                        label 'Color'
         | 
| 27 28 |  | 
| @@ -30,14 +31,18 @@ class CustomDrawText | |
| 30 31 | 
             
                          @area.queue_redraw_all
         | 
| 31 32 | 
             
                        end
         | 
| 32 33 | 
             
                      }
         | 
| 33 | 
            -
                       | 
| 34 | 
            -
             | 
| 35 | 
            -
                        
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                           | 
| 38 | 
            -
                           | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 34 | 
            +
                      
         | 
| 35 | 
            +
                      unless OS.windows?
         | 
| 36 | 
            +
                        color_button { |cb|
         | 
| 37 | 
            +
                          label 'Background'
         | 
| 38 | 
            +
                          
         | 
| 39 | 
            +
                          on_changed do
         | 
| 40 | 
            +
                            @background = cb.color
         | 
| 41 | 
            +
                            @area.queue_redraw_all
         | 
| 42 | 
            +
                          end
         | 
| 43 | 
            +
                        }
         | 
| 44 | 
            +
                      end
         | 
| 45 | 
            +
             | 
| 41 46 | 
             
                      combobox { |c|
         | 
| 42 47 | 
             
                        label 'Underline'
         | 
| 43 48 | 
             
                        items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
         | 
| @@ -48,6 +53,7 @@ class CustomDrawText | |
| 48 53 | 
             
                          @area.queue_redraw_all
         | 
| 49 54 | 
             
                        end
         | 
| 50 55 | 
             
                      }
         | 
| 56 | 
            +
             | 
| 51 57 | 
             
                      combobox { |c|
         | 
| 52 58 | 
             
                        label 'Underline Built-In Color'
         | 
| 53 59 | 
             
                        items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
         | 
| @@ -64,6 +70,7 @@ class CustomDrawText | |
| 64 70 | 
             
                          @area.queue_redraw_all
         | 
| 65 71 | 
             
                        end
         | 
| 66 72 | 
             
                      }
         | 
| 73 | 
            +
             | 
| 67 74 | 
             
                      @underline_custom_color_button = color_button {
         | 
| 68 75 | 
             
                        label 'Underline Custom Color'
         | 
| 69 76 |  | 
| @@ -13,13 +13,13 @@ def form_field(model, attribute) | |
| 13 13 | 
             
              }
         | 
| 14 14 | 
             
            end
         | 
| 15 15 |  | 
| 16 | 
            -
            def address_form( | 
| 16 | 
            +
            def address_form(address_model)
         | 
| 17 17 | 
             
              form {
         | 
| 18 | 
            -
                form_field( | 
| 19 | 
            -
                form_field( | 
| 20 | 
            -
                form_field( | 
| 21 | 
            -
                form_field( | 
| 22 | 
            -
                form_field( | 
| 18 | 
            +
                form_field(address_model, :street)
         | 
| 19 | 
            +
                form_field(address_model, :p_o_box)
         | 
| 20 | 
            +
                form_field(address_model, :city)
         | 
| 21 | 
            +
                form_field(address_model, :state)
         | 
| 22 | 
            +
                form_field(address_model, :zip_code)
         | 
| 23 23 | 
             
              }
         | 
| 24 24 | 
             
            end
         | 
| 25 25 |  | 
| @@ -32,10 +32,10 @@ def label_pair(model, attribute, value) | |
| 32 32 | 
             
              }
         | 
| 33 33 | 
             
            end
         | 
| 34 34 |  | 
| 35 | 
            -
            def address( | 
| 35 | 
            +
            def address(address_model)
         | 
| 36 36 | 
             
              vertical_box {
         | 
| 37 | 
            -
                 | 
| 38 | 
            -
                  label_pair( | 
| 37 | 
            +
                address_model.each_pair do |attribute, value|
         | 
| 38 | 
            +
                  label_pair(address_model, attribute, value)
         | 
| 39 39 | 
             
                end
         | 
| 40 40 | 
             
              }
         | 
| 41 41 | 
             
            end
         | 
| @@ -17,13 +17,13 @@ def form_field(model, property) | |
| 17 17 | 
             
              }
         | 
| 18 18 | 
             
            end
         | 
| 19 19 |  | 
| 20 | 
            -
            def address_form( | 
| 20 | 
            +
            def address_form(address_model)
         | 
| 21 21 | 
             
              form {
         | 
| 22 | 
            -
                form_field( | 
| 23 | 
            -
                form_field( | 
| 24 | 
            -
                form_field( | 
| 25 | 
            -
                form_field( | 
| 26 | 
            -
                form_field( | 
| 22 | 
            +
                form_field(address_model, :street)
         | 
| 23 | 
            +
                form_field(address_model, :p_o_box)
         | 
| 24 | 
            +
                form_field(address_model, :city)
         | 
| 25 | 
            +
                form_field(address_model, :state)
         | 
| 26 | 
            +
                form_field(address_model, :zip_code)
         | 
| 27 27 | 
             
              }
         | 
| 28 28 | 
             
            end
         | 
| 29 29 |  | 
| @@ -39,10 +39,10 @@ def label_pair(model, attribute, value) | |
| 39 39 | 
             
              end
         | 
| 40 40 | 
             
            end
         | 
| 41 41 |  | 
| 42 | 
            -
            def address( | 
| 42 | 
            +
            def address(address_model)
         | 
| 43 43 | 
             
              vertical_box {
         | 
| 44 | 
            -
                 | 
| 45 | 
            -
                  label_pair( | 
| 44 | 
            +
                address_model.each_pair do |attribute, value|
         | 
| 45 | 
            +
                  label_pair(address_model, attribute, value)
         | 
| 46 46 | 
             
                end
         | 
| 47 47 | 
             
              }
         | 
| 48 48 | 
             
            end
         | 
    
        data/glimmer-dsl-libui.gemspec
    CHANGED
    
    | Binary file | 
| @@ -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/libui/control_proxy'
         | 
| 24 | 
            +
            require 'glimmer/libui/shape'
         | 
| 25 | 
            +
            require 'glimmer/libui/attributed_string'
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            module Glimmer
         | 
| 28 | 
            +
              module DSL
         | 
| 29 | 
            +
                module Libui
         | 
| 30 | 
            +
                  class OperationExpression < Expression
         | 
| 31 | 
            +
                    def can_interpret?(parent, keyword, *args, &block)
         | 
| 32 | 
            +
                      (
         | 
| 33 | 
            +
                        parent.is_a?(Glimmer::LibUI::ControlProxy) or
         | 
| 34 | 
            +
                          parent.is_a?(Glimmer::LibUI::Shape) or
         | 
| 35 | 
            +
                          parent.is_a?(Glimmer::LibUI::AttributedString)
         | 
| 36 | 
            +
                      ) and
         | 
| 37 | 
            +
                        block.nil? and
         | 
| 38 | 
            +
                        parent.respond_to?(keyword, *args)
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
              
         | 
| 41 | 
            +
                    def interpret(parent, keyword, *args, &block)
         | 
| 42 | 
            +
                      parent.send(keyword, *args)
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| @@ -35,11 +35,11 @@ module Glimmer | |
| 35 35 | 
             
                          parent.is_a?(Glimmer::LibUI::AttributedString)
         | 
| 36 36 | 
             
                      ) and
         | 
| 37 37 | 
             
                        block.nil? and
         | 
| 38 | 
            -
                        parent.respond_to?(keyword, *args)
         | 
| 38 | 
            +
                        parent.respond_to?("#{keyword}=", *args)
         | 
| 39 39 | 
             
                    end
         | 
| 40 40 |  | 
| 41 41 | 
             
                    def interpret(parent, keyword, *args, &block)
         | 
| 42 | 
            -
                      parent.send(keyword, *args)
         | 
| 42 | 
            +
                      parent.send("#{keyword}=", *args)
         | 
| 43 43 | 
             
                    end
         | 
| 44 44 | 
             
                  end
         | 
| 45 45 | 
             
                end
         | 
| @@ -32,6 +32,12 @@ module Glimmer | |
| 32 32 | 
             
                    #
         | 
| 33 33 | 
             
                    # Follows the Proxy Design Pattern
         | 
| 34 34 | 
             
                    class CheckboxTextColorColumnProxy < ControlProxy
         | 
| 35 | 
            +
                      class << self
         | 
| 36 | 
            +
                        def default_value
         | 
| 37 | 
            +
                          [false, '', :black]
         | 
| 38 | 
            +
                        end
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                      
         | 
| 35 41 | 
             
                      include Column
         | 
| 36 42 | 
             
                      include TripleColumn
         | 
| 37 43 | 
             
                      include EditableColumn
         | 
| @@ -32,6 +32,12 @@ module Glimmer | |
| 32 32 | 
             
                    #
         | 
| 33 33 | 
             
                    # Follows the Proxy Design Pattern
         | 
| 34 34 | 
             
                    class ImageTextColorColumnProxy < ControlProxy
         | 
| 35 | 
            +
                      class << self
         | 
| 36 | 
            +
                        def default_value
         | 
| 37 | 
            +
                          [Glimmer::LibUI::ICON, '', :black]
         | 
| 38 | 
            +
                        end
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                      
         | 
| 35 41 | 
             
                      include Column
         | 
| 36 42 | 
             
                      include TripleColumn
         | 
| 37 43 | 
             
                      include EditableColumn
         | 
| @@ -32,6 +32,12 @@ module Glimmer | |
| 32 32 | 
             
                    #
         | 
| 33 33 | 
             
                    # Follows the Proxy Design Pattern
         | 
| 34 34 | 
             
                    class ImageTextColumnProxy < ControlProxy
         | 
| 35 | 
            +
                      class << self
         | 
| 36 | 
            +
                        def default_value
         | 
| 37 | 
            +
                          [Glimmer::LibUI::ICON, '']
         | 
| 38 | 
            +
                        end
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                      
         | 
| 35 41 | 
             
                      include Column
         | 
| 36 42 | 
             
                      include DualColumn
         | 
| 37 43 | 
             
                      include EditableColumn
         |