Module: Glimmer::LibUI

Extended by:
FiddleConsumer
Defined in:
lib/glimmer/libui.rb,
lib/glimmer/libui/shape.rb,
lib/glimmer/libui/parent.rb,
lib/glimmer/libui/shape/arc.rb,
lib/glimmer/libui/shape/line.rb,
lib/glimmer/libui/custom_shape.rb,
lib/glimmer/libui/shape/bezier.rb,
lib/glimmer/libui/shape/circle.rb,
lib/glimmer/libui/shape/figure.rb,
lib/glimmer/libui/shape/square.rb,
lib/glimmer/libui/control_proxy.rb,
lib/glimmer/libui/custom_window.rb,
lib/glimmer/libui/data_bindable.rb,
lib/glimmer/libui/shape/polygon.rb,
lib/glimmer/libui/custom_control.rb,
lib/glimmer/libui/perfect_shaped.rb,
lib/glimmer/libui/shape/polyline.rb,
lib/glimmer/libui/shape/rectangle.rb,
lib/glimmer/libui/shape/polybezier.rb,
lib/glimmer/libui/attributed_string.rb,
lib/glimmer/libui/control_proxy/box.rb,
lib/glimmer/libui/image_path_renderer.rb,
lib/glimmer/libui/control_proxy/column.rb,
lib/glimmer/libui/shape/composite_shape.rb,
lib/glimmer/libui/control_proxy/area_proxy.rb,
lib/glimmer/libui/control_proxy/form_proxy.rb,
lib/glimmer/libui/control_proxy/grid_proxy.rb,
lib/glimmer/libui/control_proxy/menu_proxy.rb,
lib/glimmer/libui/control_proxy/path_proxy.rb,
lib/glimmer/libui/control_proxy/text_proxy.rb,
lib/glimmer/libui/custom_control/code_area.rb,
lib/glimmer/libui/control_proxy/dual_column.rb,
lib/glimmer/libui/control_proxy/entry_proxy.rb,
lib/glimmer/libui/control_proxy/group_proxy.rb,
lib/glimmer/libui/control_proxy/image_proxy.rb,
lib/glimmer/libui/control_proxy/label_proxy.rb,
lib/glimmer/libui/control_proxy/message_box.rb,
lib/glimmer/libui/control_proxy/table_proxy.rb,
lib/glimmer/libui/custom_control/code_entry.rb,
lib/glimmer/libui/control_proxy/button_proxy.rb,
lib/glimmer/libui/control_proxy/matrix_proxy.rb,
lib/glimmer/libui/control_proxy/slider_proxy.rb,
lib/glimmer/libui/control_proxy/window_proxy.rb,
lib/glimmer/libui/control_proxy/spinbox_proxy.rb,
lib/glimmer/libui/control_proxy/transformable.rb,
lib/glimmer/libui/control_proxy/triple_column.rb,
lib/glimmer/libui/control_proxy/checkbox_proxy.rb,
lib/glimmer/libui/control_proxy/combobox_proxy.rb,
lib/glimmer/libui/control_proxy/tab_item_proxy.rb,
lib/glimmer/libui/custom_control/refined_table.rb,
lib/glimmer/libui/control_proxy/editable_column.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/image_part_proxy.rb,
lib/glimmer/libui/control_proxy/enableable_column.rb,
lib/glimmer/libui/control_proxy/font_button_proxy.rb,
lib/glimmer/libui/control_proxy/color_button_proxy.rb,
lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb,
lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb,
lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb,
lib/glimmer/libui/control_proxy/box/vertical_box_proxy.rb,
lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb,
lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb,
lib/glimmer/libui/control_proxy/box/horizontal_box_proxy.rb,
lib/glimmer/libui/control_proxy/column/text_column_proxy.rb,
lib/glimmer/libui/control_proxy/open_type_features_proxy.rb,
lib/glimmer/libui/control_proxy/column/image_column_proxy.rb,
lib/glimmer/libui/control_proxy/message_box/msg_box_proxy.rb,
lib/glimmer/libui/control_proxy/column/button_column_proxy.rb,
lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb,
lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb,
lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb,
lib/glimmer/libui/control_proxy/entry_proxy/search_entry_proxy.rb,
lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb,
lib/glimmer/libui/control_proxy/message_box/msg_box_error_proxy.rb,
lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb,
lib/glimmer/libui/control_proxy/entry_proxy/password_entry_proxy.rb,
lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb,
lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb,
lib/glimmer/libui/control_proxy/column/image_text_color_column_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/about_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/column/checkbox_text_color_column_proxy.rb,
lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb,
lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb,
lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb

Defined Under Namespace

Modules: CustomControl, CustomShape, CustomWindow, DataBindable, Parent, PerfectShaped, Transformable Classes: AttributedString, ControlProxy, ImagePathRenderer, Shape

Constant Summary collapse

ICON =
File.expand_path('../../icons/blank.png', __dir__)
Application =
CustomWindow

Class Method Summary collapse

Methods included from FiddleConsumer

fiddle_closure_block_caller

Class Method Details

.blank_colorObject

returns a representation of a blank color when a path is first built, it has a blank color



120
121
122
# File 'lib/glimmer/libui.rb', line 120

def blank_color
  [{}]
end

.blank_color?(value) ⇒ Boolean

returns whether the value represents no color (blank) or a present color when a path is first built, it has a blank color

Returns:

  • (Boolean)


111
112
113
114
115
116
# File 'lib/glimmer/libui.rb', line 111

def blank_color?(value)
  value.nil? ||
    (value.respond_to?(:empty?) && value.empty?) ||
    (value.is_a?(Array) && value.compact.empty?) ||
    (value.is_a?(Hash) && value.values.compact.empty?)
end

.boolean_to_integer(bool, allow_nil: true, allow_integer: true) ⇒ Object



34
35
36
# File 'lib/glimmer/libui.rb', line 34

def boolean_to_integer(bool, allow_nil: true, allow_integer: true)
  bool.nil? ? (allow_nil ? nil : 0) : (allow_integer && bool.is_a?(Integer) ? bool : (bool.is_a?(TrueClass) || bool.is_a?(FalseClass) ? (bool == true ? 1 : 0) : (allow_nil ? nil : 0)))
end

.column_sort_indicator_to_integer(value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/glimmer/libui.rb', line 38

def column_sort_indicator_to_integer(value)
  return value if value.is_a?(Integer)
  
  if value.nil?
    0
  elsif 'ascending'.start_with?(value.to_s)
    1
  elsif 'descending'.start_with?(value.to_s)
    2
  else
    0
  end
end

.degrees_to_radians(degrees) ⇒ Object



65
66
67
# File 'lib/glimmer/libui.rb', line 65

def degrees_to_radians(degrees)
  ((Math::PI * 2.0) / 360.00) * degrees.to_f
end

.enum_namesObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/glimmer/libui.rb', line 146

def enum_names
 [
   :align,
   :at,
   :attribute_type,
   :draw_brush_type,
   :draw_fill_mode,
   :draw_line_cap,
   :draw_line_join,
   :draw_text_align,
   :ext_key,
   :modifier,
   :table_model_column,
   :table_value_type,
   :text_italic,
   :text_stretch,
   :text_weight,
   :underline,
   :underline_color
 ]
end

.enum_symbol_to_value(enum_name, enum_symbol, default_symbol: nil, default_index: 0) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
# File 'lib/glimmer/libui.rb', line 185

def enum_symbol_to_value(enum_name, enum_symbol, default_symbol: nil, default_index: 0)
  if enum_symbol.is_a?(Integer)
    enum_symbol
  elsif enum_symbols(enum_name).include?(enum_symbol.to_s.to_sym)
    enum_symbol_values(enum_name)[enum_symbol.to_s.to_sym]
  elsif default_symbol
    enum_symbol_to_value(enum_name, default_symbol)
  else
    enum_symbol_to_value(enum_name, enum_symbols(enum_name)[default_index])
  end
end

.enum_symbol_values(enum_name) ⇒ Object

Returns ruby underscored symbols for enum values starting with enum name (camelcase, e.g. ‘ext_key’)



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/glimmer/libui.rb', line 169

def enum_symbol_values(enum_name)
  enum_name = enum_name.to_s.underscore.to_sym
  @enum_symbols ||= {}
  @enum_symbols[enum_name] ||= ::LibUI.constants.select do |c|
    c.to_s.match(/#{enum_name.to_s.camelcase(:upper)}[A-Z]/)
  end.map do |c|
    [c.to_s.underscore.sub("#{enum_name}_", '').to_sym, ::LibUI.const_get(c)]
  end.reject do |key, value|
    enum_name == :underline && key.to_s.start_with?('color')
  end.to_h
end

.enum_symbols(enum_name) ⇒ Object



142
143
144
# File 'lib/glimmer/libui.rb', line 142

def enum_symbols(enum_name)
  enum_symbol_values(enum_name).keys
end

.enum_value_to_symbol(enum_name, enum_value) ⇒ Object



181
182
183
# File 'lib/glimmer/libui.rb', line 181

def enum_value_to_symbol(enum_name, enum_value)
  enum_symbol_values(enum_name).invert[enum_value]
end

.hex_to_rgb(value) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/glimmer/libui.rb', line 124

def hex_to_rgb(value)
  if value.is_a?(String)
    value = value[2..-1] if value.start_with?('0x')
    value = value[1..-1] if value.start_with?('#')
    value = value.chars.map {|char| [char, char]}.flatten.join if value.length == 3
    value = value.to_i(16)
  end
  if value.is_a?(Integer)
    hex_value = value
    value = {
      r: ((hex_value >> 16) & 0xFF),
      g: ((hex_value >> 8) & 0xFF),
      b: (hex_value & 0xFF),
    }
  end
  value
end

.integer_to_boolean(int, allow_nil: true, allow_boolean: true) ⇒ Object



30
31
32
# File 'lib/glimmer/libui.rb', line 30

def integer_to_boolean(int, allow_nil: true, allow_boolean: true)
  int.nil? ? (allow_nil ? nil : false) : (allow_boolean && (int.is_a?(TrueClass) || int.is_a?(FalseClass)) ? int : (int.is_a?(Integer) ? int == 1 : (allow_nil ? nil : false)))
end

.integer_to_column_sort_indicator(value) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/glimmer/libui.rb', line 52

def integer_to_column_sort_indicator(value)
  return value if value.is_a?(String) || value.is_a?(Symbol)
  
  case value
  when 1
    :ascending
  when 2
    :descending
  else
    nil
  end
end

.interpret_color(value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/glimmer/libui.rb', line 69

def interpret_color(value)
  if value.is_a?(Array) && value.last.is_a?(Hash)
    options = value.last
    value = value[0...-1]
  end
  value = value.first if value.is_a?(Array) && value.size == 1
  value = value[:color] if value.is_a?(Hash) && value[:color]
  value = value.to_s if value.is_a?(Symbol)
  result = if value.is_a?(Array)
    old_value = value
    value = {
      r: old_value[0],
      g: old_value[1],
      b: old_value[2],
    }
    value[:a] = old_value[3] unless old_value[3].nil?
    value
  elsif value.is_a?(Hash)
    old_value = value
    value = old_value.dup
    value[:r] = value.delete(:red) if value[:red]
    value[:g] = value.delete(:green) if value[:green]
    value[:b] = value.delete(:blue) if value[:blue]
    value[:a] = value.delete(:alpha) if value[:alpha]
    value
  elsif value.is_a?(String) && !value.start_with?('0x') && !value.start_with?('#') && !value.downcase.match(/^((([1-9a-f]){6})|(([1-9a-f]){3}))$/)
    require 'color'
    color = Color::RGB.extract_colors(value).first
    color.nil? ? {} : {
      r: color.red,
      g: color.green,
      b: color.blue,
    }
  else
    hex_to_rgb(value)
  end
  result.merge!(options) if options
  result
end

.method_missing(method_name, *args, &block) ⇒ Object



246
247
248
249
250
251
252
# File 'lib/glimmer/libui.rb', line 246

def method_missing(method_name, *args, &block)
  if ::LibUI.respond_to?(method_name, true)
    ::LibUI.send(method_name, *args, &block)
  else
    super
  end
end

.os_shortcut_keyObject

Returns OS shortcut key, meaning the key used with most shorcuts, like :command on the Mac (used in CMD+S for save) or :control on Windows and Linux (used in CONTROL+S for save)



205
206
207
# File 'lib/glimmer/libui.rb', line 205

def os_shortcut_key
  @os_shortcut_key ||= OS.mac? ? :command : :ctrl
end

.queue_main(&block) ⇒ Object

Queues block to execute at the nearest opportunity possible on the main GUI event loop



210
211
212
213
214
215
216
217
218
# File 'lib/glimmer/libui.rb', line 210

def queue_main(&block)
  closure = fiddle_closure_block_caller(4, [0]) do
    result = boolean_to_integer(block.call)
    result = 1 if result.nil?
    result
  end
  ::LibUI.queue_main(closure)
  closure
end

.respond_to?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/glimmer/libui.rb', line 242

def respond_to?(method_name, *args)
  super || ::LibUI.respond_to?(method_name, *args)
end

.timer(time_in_seconds = 0.1, repeat: true, &block) ⇒ Object

Calls block on the main GUI event loop after time_in_seconds delay, repeating indefinitely by default If ‘repeat:` keyword arg is passed with an Integer value, it repeats for that number of times If `repeat:` keyword arg is passed with false or 0, then the block is only called once If block returns false at any point, the timer is stopped from further repetitions regardless of `repeat:` keyword arg value If block returns true at any point, the timer continues for another repetition regardless of `repeat:` keyword arg value



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/glimmer/libui.rb', line 225

def timer(time_in_seconds = 0.1, repeat: true, &block)
  closure = fiddle_closure_block_caller(4, [0]) do
    result = boolean_to_integer(block.call, allow_integer: false)
    repeat -= 1 if repeat.is_a?(Integer)
    if result.nil?
      if (repeat == true || (repeat.is_a?(Integer) && repeat > 0))
        result = 1
      else
        result = 0
      end
    end
    result
  end
  ::LibUI.timer(time_in_seconds * 1000.0, closure)
  closure
end

.x11_colorsObject



197
198
199
200
# File 'lib/glimmer/libui.rb', line 197

def x11_colors
  require 'color'
  Color::RGB.constants.reject {|c| c.to_s.upcase == c.to_s}.map(&:to_s).map(&:underscore).map(&:to_sym)
end