white_gold 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/ext/dll/tgui.dll +0 -0
  3. data/ext/so/libtgui.so +0 -0
  4. data/lib/white_gold/abi/enum.rb +0 -8
  5. data/lib/white_gold/abi/extern_object.rb +6 -1
  6. data/lib/white_gold/abi/unpacker.rb +4 -2
  7. data/lib/white_gold/convention/bang_nest.rb +12 -2
  8. data/lib/white_gold/convention/bang_nested_caller.rb +34 -34
  9. data/lib/white_gold/convention/container_widgets.rb +53 -51
  10. data/lib/white_gold/convention/page.rb +22 -4
  11. data/lib/white_gold/{dsl → convention}/theme/color_attribute.rb +2 -0
  12. data/lib/white_gold/{dsl → convention}/theme/outline_attribute.rb +2 -0
  13. data/lib/white_gold/convention/theme/text_styles_attribute.rb +18 -0
  14. data/lib/white_gold/{dsl → convention}/theme/texture_attribute.rb +2 -0
  15. data/lib/white_gold/{dsl → convention}/theme/theme_attributed.rb +4 -18
  16. data/lib/white_gold/{dsl → convention}/theme/theme_component.rb +14 -3
  17. data/lib/white_gold/convention/theme_attributes.rb +49 -0
  18. data/lib/white_gold/convention/tree_node.rb +43 -0
  19. data/lib/white_gold/convention/widget_like.rb +0 -6
  20. data/lib/white_gold/dsl/backend_gui.rb +1 -0
  21. data/lib/white_gold/dsl/button_base.rb +17 -2
  22. data/lib/white_gold/dsl/canvas.rb +40 -0
  23. data/lib/white_gold/dsl/chat_box.rb +12 -1
  24. data/lib/white_gold/dsl/child_window.rb +22 -1
  25. data/lib/white_gold/dsl/color.rb +5 -2
  26. data/lib/white_gold/dsl/color_picker.rb +9 -0
  27. data/lib/white_gold/dsl/combo_box.rb +30 -2
  28. data/lib/white_gold/dsl/container.rb +17 -11
  29. data/lib/white_gold/dsl/edit_box.rb +29 -0
  30. data/lib/white_gold/dsl/file_dialog.rb +17 -0
  31. data/lib/white_gold/dsl/font.rb +5 -1
  32. data/lib/white_gold/dsl/grid.rb +3 -3
  33. data/lib/white_gold/dsl/group.rb +5 -0
  34. data/lib/white_gold/dsl/knob.rb +10 -0
  35. data/lib/white_gold/dsl/label.rb +14 -0
  36. data/lib/white_gold/dsl/list_box.rb +27 -11
  37. data/lib/white_gold/dsl/list_view.rb +29 -6
  38. data/lib/white_gold/dsl/menu_bar.rb +21 -48
  39. data/lib/white_gold/dsl/message_box.rb +8 -2
  40. data/lib/white_gold/dsl/panel_list_box.rb +3 -3
  41. data/lib/white_gold/dsl/progress_bar.rb +14 -0
  42. data/lib/white_gold/dsl/radio_button.rb +25 -0
  43. data/lib/white_gold/dsl/range_slider.rb +8 -0
  44. data/lib/white_gold/dsl/scrollbar.rb +19 -0
  45. data/lib/white_gold/dsl/separator_line.rb +5 -0
  46. data/lib/white_gold/dsl/sfml/circle_shape.rb +7 -0
  47. data/lib/white_gold/dsl/sfml/convex_shape.rb +15 -0
  48. data/lib/white_gold/dsl/sfml/rectangle_shape.rb +7 -0
  49. data/lib/white_gold/dsl/sfml/shape.rb +19 -0
  50. data/lib/white_gold/dsl/sfml/text.rb +22 -0
  51. data/lib/white_gold/dsl/signal/global_signal.rb +1 -1
  52. data/lib/white_gold/dsl/signal/signal.rb +1 -1
  53. data/lib/white_gold/dsl/signal/signal_animation_type.rb +1 -1
  54. data/lib/white_gold/dsl/signal/signal_bool.rb +1 -1
  55. data/lib/white_gold/dsl/signal/signal_color.rb +1 -1
  56. data/lib/white_gold/dsl/signal/signal_float.rb +1 -1
  57. data/lib/white_gold/dsl/signal/signal_int.rb +1 -1
  58. data/lib/white_gold/dsl/signal/signal_pointer.rb +1 -1
  59. data/lib/white_gold/dsl/signal/signal_range.rb +1 -1
  60. data/lib/white_gold/dsl/signal/signal_show_effect.rb +1 -1
  61. data/lib/white_gold/dsl/signal/signal_string.rb +1 -1
  62. data/lib/white_gold/dsl/signal/signal_u_int.rb +1 -1
  63. data/lib/white_gold/dsl/signal/signal_vector2f.rb +1 -1
  64. data/lib/white_gold/dsl/slider.rb +15 -0
  65. data/lib/white_gold/dsl/spin_button.rb +14 -0
  66. data/lib/white_gold/dsl/tab_container.rb +2 -2
  67. data/lib/white_gold/dsl/tabs.rb +26 -2
  68. data/lib/white_gold/dsl/text_area.rb +16 -0
  69. data/lib/white_gold/dsl/theme.rb +11 -51
  70. data/lib/white_gold/dsl/tree_view.rb +41 -33
  71. data/lib/white_gold/dsl/widget.rb +81 -39
  72. data/lib/white_gold/generated/tgui-abi-loader.gf.rb +197 -47
  73. data/lib/white_gold/library/theme/light.rb +15 -3
  74. data/lib/white_gold/master.rb +21 -40
  75. data/lib/white_gold/path/object.path.rb +0 -11
  76. data/lib/white_gold/tgui-abi.rb +17 -16
  77. data/lib/white_gold/version.rb +3 -0
  78. data/lib/white_gold.rb +29 -28
  79. metadata +26 -39
  80. data/lib/white_gold/dsl/theme/button_theme.rb +0 -19
  81. data/lib/white_gold/dsl/theme/chat_box_theme.rb +0 -16
  82. data/lib/white_gold/dsl/theme/child_window_theme.rb +0 -25
  83. data/lib/white_gold/dsl/theme/color_picker_theme.rb +0 -14
  84. data/lib/white_gold/dsl/theme/combo_box_theme.rb +0 -33
  85. data/lib/white_gold/dsl/theme/common_renderer.rb +0 -7
  86. data/lib/white_gold/dsl/theme/edit_box_theme.rb +0 -34
  87. data/lib/white_gold/dsl/theme/file_dialog_theme.rb +0 -22
  88. data/lib/white_gold/dsl/theme/group_theme.rb +0 -9
  89. data/lib/white_gold/dsl/theme/knob_theme.rb +0 -15
  90. data/lib/white_gold/dsl/theme/label_theme.rb +0 -20
  91. data/lib/white_gold/dsl/theme/list_box_theme.rb +0 -25
  92. data/lib/white_gold/dsl/theme/list_view_theme.rb +0 -27
  93. data/lib/white_gold/dsl/theme/menu_bar_theme.rb +0 -21
  94. data/lib/white_gold/dsl/theme/message_box_theme.rb +0 -11
  95. data/lib/white_gold/dsl/theme/progress_bar_theme.rb +0 -19
  96. data/lib/white_gold/dsl/theme/radio_button_theme.rb +0 -30
  97. data/lib/white_gold/dsl/theme/scrollbar_theme.rb +0 -24
  98. data/lib/white_gold/dsl/theme/separator_line_theme.rb +0 -9
  99. data/lib/white_gold/dsl/theme/slider_theme.rb +0 -20
  100. data/lib/white_gold/dsl/theme/spin_button_theme.rb +0 -19
  101. data/lib/white_gold/dsl/theme/tabs_theme.rb +0 -29
  102. data/lib/white_gold/dsl/theme/text_area_theme.rb +0 -22
  103. data/lib/white_gold/dsl/theme/text_styles_attribute.rb +0 -13
  104. data/lib/white_gold/dsl/theme/tree_view_theme.rb +0 -26
  105. data/lib/white_gold/dsl/theme/widget_theme.rb +0 -12
  106. /data/lib/white_gold/{dsl → convention}/theme/boolean_attribute.rb +0 -0
  107. /data/lib/white_gold/{dsl → convention}/theme/float_attribute.rb +0 -0
  108. /data/lib/white_gold/dsl/{checkbox.rb → check_box.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2602400f722a11d0ea3f31366f29c3b31471fa0b001061e3c614518c0ae4f52e
4
- data.tar.gz: d1c55ab3f33f03c59d389fe2739bd6ddcc10d13d9ecab594b826a365a9d41ec3
3
+ metadata.gz: 6727469d73967f049141a5c7b128bfb88b5c18cb128ce7b00417e7f889648138
4
+ data.tar.gz: f30fed9fdbfc915eb0fb70fded0aabe9593991037af91253427d59b22f053913
5
5
  SHA512:
6
- metadata.gz: fe6e0e9ce7881149ed8d5912fda0dc7dcbcb3e4ae4ca8dcc242765a35f8066499eb89fed57d05a47906ab66e910e92a48ff6e60522473cff7604974498b1bdb3
7
- data.tar.gz: 3ec8c60dcd97eacd677ddcd158c71db4e7947036f1f6313ec3805f9e7b18c4e1160fbfb996524143dc9bf3b4d30770e679f7666a4a5ddfeb234fe90a7ed2eb41
6
+ metadata.gz: c9373c37d6ccbbb45b973b55c92dd924ec9bc9511ee4a5b1e244859f956f9133d767b30874255535b3fd715d396fb5b96787076014fcfdd5354005973631ac7e
7
+ data.tar.gz: 240acb40c4ef8d00788e704c40eff66c93535b20d57c3973c9a04e50c18e7dae3c3fc808a1f63308700eb11efe4458dcc970033b385f922e38d72ea53e9c88f0
data/ext/dll/tgui.dll CHANGED
Binary file
data/ext/so/libtgui.so CHANGED
Binary file
@@ -32,12 +32,4 @@ class Enum
32
32
  def symbols
33
33
  @symbol_to_int
34
34
  end
35
-
36
- def to_abi o
37
- self[o]
38
- end
39
-
40
- def to_api o
41
- self[o]
42
- end
43
35
  end
@@ -17,6 +17,7 @@ class ExternObject
17
17
  end
18
18
  ObjectSpace.define_finalizer(self, cl.proc.finalizer(pointer))
19
19
  end
20
+ initialized
20
21
  end
21
22
 
22
23
  def initialized
@@ -102,7 +103,11 @@ class ExternObject
102
103
  getter = "#{original_name}#{name}".delete_suffix("?").to_sym
103
104
  setter = "set_#{name}".delete_suffix("?").to_sym
104
105
  else
105
- getter = "get_#{original_name}".to_sym
106
+ if name.end_with? "?"
107
+ getter = "is_#{original_name}".to_sym
108
+ else
109
+ getter = "get_#{original_name}".to_sym
110
+ end
106
111
  setter = "set_#{original_name}".to_sym
107
112
  end
108
113
  else
@@ -2,15 +2,17 @@ require_relative 'interface/interface'
2
2
 
3
3
  module Unpacker
4
4
  def abi_unpacker base, &body
5
+ method_name = abi_unpacker_method_name(base)
5
6
  if block_given?
6
- define_method abi_unpacker_method_name(base), &body
7
+ define_method method_name, &body
7
8
  elsif base.is_a? Module
8
- define_method abi_unpacker_method_name(base) do |o|
9
+ define_method method_name do |o|
9
10
  base.new pointer: o
10
11
  end
11
12
  else
12
13
  raise "..."
13
14
  end
15
+ method_name
14
16
  end
15
17
 
16
18
  def abi_unpacker_method_name base
@@ -4,13 +4,23 @@ module BangNest
4
4
  include BangNestedCaller
5
5
 
6
6
  def respond_to? name
7
- super || bang_respond_to?(name)
7
+ super || (name.end_with?("!") && bang_respond_to?(name[...-1]))
8
8
  end
9
9
 
10
10
  def method_missing name, *a, **na, &b
11
11
  if name.end_with? "!"
12
- bang_method_missing name, *a, **na, &b
12
+ bang_method_missing name[...-1], *a, **na, &b
13
13
  else super
14
14
  end
15
15
  end
16
+
17
+ def send! *a, **na, &b
18
+ a.each do |k|
19
+ send("#{k}=", true)
20
+ end
21
+ na.each do |k, v|
22
+ send("#{k}=", v)
23
+ end
24
+ super(&b)
25
+ end
16
26
  end
@@ -1,48 +1,48 @@
1
1
  module BangNestedCaller
2
- def bang_respond_to? name
3
- name.end_with?("!") && (respond_to?("#{name[...-1]}=") || respond_to?("api_bang_#{name[...-1]}") || (@bang_target && @bang_target.respond_to?(name)))
4
- end
5
-
6
- def bang_method_missing name, *a, **na, &b
7
- return @bang_target.send(name, *a, **na, &b) if @bang_target && @bang_target.respond_to?(name)
8
2
 
9
- api_name = "api_bang_#{name[...-1]}".to_sym
10
- return send(api_name, *a, **na, &b) if respond_to? api_name
11
-
12
- setter = "#{name[...-1]}=".to_sym
13
- if respond_to? setter
14
- return send(setter, a) if !a.empty?
15
- return send(setter, na) if !na.empty?
16
- return send(setter, b) if block_given?
17
- return send(setter)
18
- end
19
-
20
- no_method_error = NoMethodError.new("undefined bang nested method `#{name}` for #{bang_object_stack.map(&:class).join("/")}")
21
- raise no_method_error
22
- end
3
+ @@bang_stack = []
23
4
 
24
5
  def self!
25
- @bang_target&.respond_to?(:self!) ? @bang_target.self! : self
6
+ @@bang_stack.last
26
7
  end
27
8
 
28
- def bang_object_stack root = true
29
- stack = []
30
- stack << self if root
31
- stack << @bang_target if @bang_target
32
- stack += @bang_target.bang_object_stack(false) if @bang_target&.respond_to? :bang_object_stack
33
- return stack
9
+ def bang_respond_to? name
10
+ top = @@bang_stack.include?(self) ? @@bang_stack.last : self
11
+ top.respond_to?("#{name}=") || top.respond_to?("api_bang_#{name}")
34
12
  end
35
13
 
14
+ def bang_send name, *a, **na, &b
15
+ top = @@bang_stack.last
16
+ api_bang_name = "api_bang_#{name}".to_sym
17
+ return top.send(api_bang_name, *a, **na, &b) if top.respond_to? api_bang_name
18
+ setter = "#{name}=".to_sym
19
+ if top.respond_to? setter
20
+ return top.send(setter, a) if !a.empty?
21
+ return top.send(setter, na) if !na.empty?
22
+ return top.send(setter, b) if block_given?
23
+ return top.send(setter)
24
+ end
25
+ no_method_error = NoMethodError.new("bang method missing `#{name}!` for #{top.class}")
26
+ raise no_method_error
27
+ end
36
28
 
37
- def upon! item, **na, &b
38
- na.each do |k, v|
39
- item.send("#{k}=", v)
29
+ def bang_method_missing name, *a, **na, &b
30
+ if @@bang_stack.include?(self)
31
+ bang_send name, *a, **na, &b
32
+ else
33
+ @@bang_stack.push self
34
+ result = bang_send name, *a, **na, &b
35
+ @@bang_stack.pop
36
+ result
40
37
  end
38
+ end
39
+
40
+ def send! &b
41
41
  if b
42
- @bang_target, original_bang_target = item, @bang_target
43
- b.call item
44
- @bang_target = original_bang_target
42
+ @@bang_stack.push self
43
+ b.call self
44
+ @@bang_stack.pop
45
45
  end
46
- item
46
+ self
47
47
  end
48
48
  end
@@ -2,52 +2,59 @@ require_relative '../convention/api_child'
2
2
 
3
3
  module Tgui
4
4
 
5
- WIDGETS_COLLECTION = {
6
- label: Tgui::Label,
5
+ ORDINARY_WIDGETS = {
6
+ bitmap_button: Tgui::BitmapButton,
7
7
  button: Tgui::Button,
8
- radio: false,
9
- radio_button: Tgui::RadioButton,
8
+ canvas: Tgui::Canvas,
9
+ chatbox: Tgui::ChatBox,
10
10
  checkbox: Tgui::CheckBox,
11
11
  child_window: Tgui::ChildWindow,
12
- editbox: Tgui::EditBox,
13
- combobox: Tgui::ComboBox,
14
12
  color_picker: Tgui::ColorPicker,
13
+ combobox: Tgui::ComboBox,
14
+ editbox: Tgui::EditBox,
15
+ file_dialog: Tgui::FileDialog,
16
+ grid: Tgui::Grid,
17
+ group: Tgui::Group,
15
18
  hola: Tgui::HorizontalLayout,
16
- vela: Tgui::VerticalLayout,
17
19
  howr: Tgui::HorizontalWrap,
18
- group: Tgui::Group,
19
- radio_button_group: Tgui::RadioButtonGroup,
20
- grid: Tgui::Grid,
21
- list_view: Tgui::ListView,
22
- picture: false,
23
- bitmap_button: Tgui::BitmapButton,
24
20
  knob: Tgui::Knob,
25
- message_box: Tgui::MessageBox,
26
- file_dialog: Tgui::FileDialog,
21
+ label: Tgui::Label,
27
22
  listbox: Tgui::ListBox,
23
+ listview: Tgui::ListView,
28
24
  menu: Tgui::MenuBar,
29
- panel_list_box: Tgui::PanelListBox,
30
- progress_bar: Tgui::ProgressBar,
25
+ messagebox: Tgui::MessageBox,
26
+ panel: Tgui::Panel,
27
+ panel_listbox: Tgui::PanelListBox,
28
+ panel_tabs: Tgui::TabContainer,
29
+ progressbar: Tgui::ProgressBar,
30
+ radio_button: Tgui::RadioButton,
31
+ radio_button_group: Tgui::RadioButtonGroup,
31
32
  range_slider: Tgui::RangeSlider,
32
- rich_text_label: Tgui::RichTextLabel,
33
- separator_line: Tgui::SeparatorLine,
33
+ fancy_label: Tgui::RichTextLabel,
34
+ scrollbar: Tgui::Scrollbar,
35
+ separator: Tgui::SeparatorLine,
34
36
  slider: Tgui::Slider,
35
37
  spin_button: Tgui::SpinButton,
36
38
  spin_control: Tgui::SpinControl,
37
39
  tabs: Tgui::Tabs,
38
- tab_container: Tgui::TabContainer,
39
- text_area: Tgui::TextArea,
40
+ textarea: Tgui::TextArea,
40
41
  toggle_button: Tgui::ToggleButton,
41
- tree_view: Tgui::TreeView,
42
- scrollbar: Tgui::Scrollbar,
43
- panel: Tgui::Panel,
44
- chat_box: Tgui::ChatBox
42
+ treeview: Tgui::TreeView,
43
+ vela: Tgui::VerticalLayout,
45
44
  }.freeze
46
45
 
46
+ UNORDINARY_WIDGETS = {
47
+ picture: Tgui::Picture
48
+ }
49
+
50
+ def self.widget_set
51
+ {}.merge ORDINARY_WIDGETS, UNORDINARY_WIDGETS
52
+ end
53
+
47
54
  module WidgetOwner
48
55
  extend BangDef
49
56
 
50
- def common_widget_nest widget, *keys, id: nil, **na, &b
57
+ def self_common_widget_nest widget, *keys, id: nil, **na, &b
51
58
  club_params = {}
52
59
  Enumerator.new do |e|
53
60
  cl = widget.class
@@ -72,18 +79,18 @@ module Tgui
72
79
  club_params.merge! club.params
73
80
  end
74
81
 
75
- upon! widget, **club_params, **na, &b
82
+ widget.send! **club_params, **na, &b
76
83
  end
77
84
 
78
- def child_methods
85
+ def self_child_methods
79
86
  ## TO OPTIMIZE
80
87
  methods.filter{ _1.start_with? ApiChild::API_CHILD_PREFIX }
81
88
  end
82
89
 
83
- def equip_child_widget widget
90
+ def self_equip_child_widget widget
84
91
  widget.page = page
85
92
  parent = self
86
- child_methods.each do |method|
93
+ self_child_methods.each do |method|
87
94
  widget.define_singleton_method method[ApiChild::API_CHILD_PREFIX.length..] do |*a|
88
95
  parent.send(method, self, *a)
89
96
  end
@@ -91,10 +98,10 @@ module Tgui
91
98
  widget
92
99
  end
93
100
 
94
- WIDGETS_COLLECTION.each do |m, c|
101
+ ORDINARY_WIDGETS.each do |m, c|
95
102
  if c
96
103
  def! m do |*a, **na, &b|
97
- common_widget_post_initialize equip_child_widget(c.new), *a, **na, &b
104
+ self_common_widget_equip self_equip_child_widget(c.new), *a, **na, &b
98
105
  end
99
106
  end
100
107
  end
@@ -110,16 +117,16 @@ module Tgui
110
117
  )
111
118
  transparent = na[:transparent] || false
112
119
  pic = Tgui::Picture.new texture, transparent
113
- equip_child_widget pic
114
- common_widget_post_initialize pic, *a, **na.except(:url, :part_rect, :smooth, :transparent), &b
120
+ self_equip_child_widget pic
121
+ self_common_widget_equip pic, *a, **na.except(:url, :part_rect, :smooth, :transparent), &b
115
122
  end
116
123
 
117
124
  def! :radio do |object, *a, **na, &b|
118
125
  radio = RadioButton.new
119
- equip_child_widget radio
126
+ self_equip_child_widget radio
120
127
  radio.object = object
121
128
  na[:text] ||= object.to_s
122
- common_widget_post_initialize radio, *a, **na, &b
129
+ self_common_widget_equip radio, *a, **na, &b
123
130
  end
124
131
 
125
132
  def! :msg do |text, **buttons|
@@ -133,13 +140,10 @@ module Tgui
133
140
  end)
134
141
  end
135
142
 
136
- @@auto_button_name = "Button1"
143
+ @@auto_button_name = "Button0"
137
144
 
138
145
  def! :btn do |text = nil, **na, &on_press|
139
- if !text
140
- text = @@auto_button_name
141
- @@auto_button_name = @@auto_button_name.next
142
- end
146
+ text = @@auto_button_name = @@auto_button_name.next if !text
143
147
  api_bang_button text:, on_press:, **na
144
148
  end
145
149
  end
@@ -149,22 +153,20 @@ module Tgui
149
153
 
150
154
  @@auto_widget_id = "@/"
151
155
 
152
- def common_widget_post_initialize widget, *keys, **na, &b
156
+ def self_common_widget_equip widget, *keys, **na, &b
153
157
  @@auto_widget_id = id = @@auto_widget_id.next
154
158
  add widget, id
155
- common_widget_nest widget, *keys, id:, **na, &b
159
+ self_common_widget_nest widget, *keys, id:, **na, &b
156
160
  end
157
161
 
158
162
  end
159
163
 
160
164
  class TabContainer
161
- WIDGETS_COLLECTION.each do |m, c|
162
- if !method_defined? m
163
- def! m do |name = nil, **na, &b|
164
- raise NoMethodError.new("Method `#{m}` should be called on Panel from TabContainer, not TabContainer itself")
165
- end
166
- end
165
+
166
+ def add widget, name
167
+ raise NoMethodError.new("Widget can't be added to TabContainer directly. Add it to TabContainer panel instead.")
167
168
  end
169
+
168
170
  end
169
171
 
170
172
  class ToolTip
@@ -172,9 +174,9 @@ module Tgui
172
174
 
173
175
  attr :widget
174
176
 
175
- def common_widget_post_initialize widget, *keys, **na, &b
177
+ def self_common_widget_equip widget, *keys, **na, &b
176
178
  @widget = widget
177
- common_widget_nest widget, *keys, **na, &b
179
+ self_common_widget_nest widget, *keys, **na, &b
178
180
  end
179
181
  end
180
182
 
@@ -22,6 +22,24 @@ class Page < Tgui::Group
22
22
  def build
23
23
  end
24
24
 
25
+ def respond_to? name
26
+ super ||
27
+ (name.end_with?("!") && bang_respond_to?(name[...-1])) ||
28
+ @tgui.gui.respond_to?(name) ||
29
+ @tgui.window.respond_to?(name)
30
+ end
31
+
32
+ def method_missing name, *a, **na, &b
33
+ if name.end_with? "!"
34
+ bang_method_missing name[...-1], *a, **na, &b
35
+ elsif @tgui.gui.respond_to? name
36
+ @tgui.gui.send name, *a, **na, &b
37
+ elsif @tgui.window.respond_to? name
38
+ @tgui.window.send name, *a, **na, &b
39
+ else super
40
+ end
41
+ end
42
+
25
43
  def disconnect
26
44
  @global_callbacks.each do |id, signal|
27
45
  signal.disconnect id
@@ -72,18 +90,18 @@ class Page < Tgui::Group
72
90
  end
73
91
 
74
92
  def theme
75
- Theme.default
93
+ Tgui::Theme.default
76
94
  end
77
95
 
78
96
  def! :theme do |seed = nil, **na, &b|
79
97
  theme = self.theme
80
98
  if seed
81
99
  theme.reset_attributes
82
- upon! theme do
83
- load Theme.loadpath(seed)
100
+ theme.send! do
101
+ load Tgui::Theme.loadpath(seed)
84
102
  end
85
103
  end
86
- upon! theme, **na, &b
104
+ theme.send! **na, &b
87
105
  theme.self_commit @custom_renderers
88
106
  end
89
107
 
@@ -1,3 +1,5 @@
1
+ require_relative '../../dsl/color'
2
+
1
3
  class ColorAttribute
2
4
  def initialize name, value
3
5
  @name = name
@@ -1,3 +1,5 @@
1
+ require_relative '../../dsl/outline'
2
+
1
3
  class OutlineAttribute
2
4
  def initialize name, value
3
5
  @name = name
@@ -0,0 +1,18 @@
1
+ require_relative '../../abi/extern_object'
2
+
3
+ class TextStylesAttribute
4
+ def initialize name, value
5
+ @name = name
6
+ @value = Array(value).map do |style|
7
+ raise "Invalid style #{style}" if !ExternObject::TextStyles[style]
8
+ style.to_s.upcase
9
+ end.join("|")
10
+ end
11
+
12
+ attr :name
13
+ attr :value
14
+
15
+ def to_theme
16
+ "#{name} = #{value};"
17
+ end
18
+ end
@@ -1,3 +1,5 @@
1
+ require_relative '../../dsl/texture'
2
+
1
3
  class TextureAttribute
2
4
  def initialize name, value
3
5
  @name = name
@@ -1,6 +1,3 @@
1
- require_relative '../color'
2
- require_relative '../outline'
3
- require_relative '../texture'
4
1
  require_relative 'boolean_attribute'
5
2
  require_relative 'color_attribute'
6
3
  require_relative 'float_attribute'
@@ -29,22 +26,11 @@ module Tgui
29
26
  end
30
27
  end
31
28
 
32
- def theme_comp name, type, tgui_attr_name = nil
33
- attr_name = tgui_attr_name || name.to_s.pascalcase
29
+ def theme_comp name, type
34
30
  def! name do |custom_name = nil, base_name = nil, **na, &b|
35
- if base_name
36
- attribute = attributes[custom_name]
37
- if !attribute || attribute.name != base_name
38
- attribute = attributes[custom_name] = type.new base_name, custom_name
39
- end
40
- else
41
- a_name = custom_name || attr_name
42
- attribute = attributes[a_name]
43
- if !attribute || attribute.name != attr_name
44
- attribute = attributes[a_name] = type.new attr_name, custom_name
45
- end
46
- end
47
- upon! attribute, **na, &b
31
+ attribute = type.new(base_name, custom_name)
32
+ attribute = attributes[attribute.name] ||= attribute
33
+ attribute.send! **na, &b
48
34
  end
49
35
  end
50
36
  end
@@ -1,5 +1,4 @@
1
1
  require_relative 'theme_attributed'
2
- require_relative 'common_renderer'
3
2
 
4
3
  module Tgui
5
4
  class ThemeComponent
@@ -14,9 +13,21 @@ module Tgui
14
13
 
15
14
  attr :name, :attributes
16
15
 
16
+ def default_name
17
+ self.class.name.split("::")[-2]
18
+ end
19
+
20
+ def base_name
21
+ @name || default_name
22
+ end
23
+
24
+ def name
25
+ @custom_name || base_name
26
+ end
27
+
17
28
  def to_theme
18
- return "" if @attributes.empty?
19
- header = @custom_name ? "#{@custom_name} : #{@name}" : @name
29
+ return "" if @attributes.empty? && !@custom_name
30
+ header = @custom_name ? "#{@custom_name} : #{base_name}" : name
20
31
  "#{header} {\n#{@attributes.values.map(&:to_theme).join("\n")}\n}"
21
32
  end
22
33
  end
@@ -0,0 +1,49 @@
1
+ module Tgui
2
+ class Theme
3
+ theme_attr :text_color, :color
4
+ theme_attr :text_color_hover, :color
5
+ theme_attr :text_color_disabled, :color
6
+ theme_attr :background_color, :color
7
+ theme_attr :background_color_hover, :color
8
+ theme_attr :background_color_disabled, :color
9
+ theme_attr :selected_text_color, :color
10
+ theme_attr :selected_text_color_hover, :color
11
+ theme_attr :selected_background_color, :color
12
+ theme_attr :selected_background_color_hover, :color
13
+ theme_attr :border_color, :color
14
+ theme_attr :borders, :outline
15
+ theme_attr :scrollbar_width, :float
16
+ theme_attr :arrow_background_color, :color
17
+ theme_attr :arrow_background_color_hover, :color
18
+ theme_attr :arrow_background_color_disabled, :color
19
+ theme_attr :arrow_color, :color
20
+ theme_attr :arrow_color_hover, :color
21
+ theme_attr :arrow_color_disabled, :color
22
+
23
+ theme_comp :button, ButtonBase::Theme
24
+ theme_comp :chatbox, ChatBox::Theme
25
+ theme_comp :child_window, ChildWindow::Theme
26
+ theme_comp :color_picker, ColorPicker::Theme
27
+ theme_comp :combobox, ComboBox::Theme
28
+ theme_comp :editbox, EditBox::Theme
29
+ theme_comp :file_dialog, FileDialog::Theme
30
+ theme_comp :group, Group::Theme
31
+ theme_comp :knob, Knob::Theme
32
+ theme_comp :label, Label::Theme
33
+ theme_comp :listbox, ListBox::Theme
34
+ theme_comp :listview, ListView::Theme
35
+ theme_comp :menu, MenuBar::Theme
36
+ theme_comp :messagebox, MessageBox::Theme
37
+ theme_comp :progressbar, ProgressBar::Theme
38
+ theme_comp :radio_button, RadioButton::Theme
39
+ theme_comp :range_slider, RangeSlider::Theme
40
+ theme_comp :scrollbar, Scrollbar::Theme
41
+ theme_comp :separator, SeparatorLine::Theme
42
+ theme_comp :slider, Slider::Theme
43
+ theme_comp :spin_button, SpinButton::Theme
44
+ theme_comp :tabs, Tabs::Theme
45
+ theme_comp :text_area, TextArea::Theme
46
+ theme_comp :tree_view, TreeView::Theme
47
+ theme_comp :widget, Widget::Theme
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ class TreeNode
2
+ def initialize text
3
+ @text = text
4
+ @nodes = {}
5
+ end
6
+
7
+ attr_accessor :text
8
+ attr :nodes
9
+
10
+ def [](*path, grow: false)
11
+ if grow
12
+ path.reduce(self){|node, o| node.nodes[o] ||= TreeNode.new(nil) }
13
+ else
14
+ path.reduce(self){|node, o| node&.nodes[o] }
15
+ end
16
+ end
17
+
18
+ def cut *path, last
19
+ self[*path].nodes.delete last
20
+ end
21
+
22
+ def cut_branches *path
23
+ self[*path].nodes = {}
24
+ end
25
+
26
+ def path_str_to_object *path
27
+ object_path = []
28
+ path.reduce self do |node, str|
29
+ o, node = *node.nodes.find{|k, v| v.text == str }
30
+ object_path << o
31
+ node
32
+ end
33
+ object_path
34
+ end
35
+
36
+ def path_object_to_str *path
37
+ str_path = []
38
+ path.reduce self do |node, o|
39
+ node[o].tap{ str_path << _1.text }
40
+ end
41
+ str_path
42
+ end
43
+ end
@@ -137,10 +137,4 @@ class WidgetLike
137
137
 
138
138
  attr :host
139
139
  attr :id
140
-
141
- def flags=(flags)
142
- flags.each do |f|
143
- send("#{f}=", true)
144
- end
145
- end
146
140
  end
@@ -31,6 +31,7 @@ module Tgui
31
31
  abi_def :pop_mouse_cursor, :restore_override_mouse_cursor
32
32
  abi_def :px_to_crd, :map_pixel_to_coords, [Integer, Integer] => [Float, Float]
33
33
  abi_def :crd_to_px, :map_coords_to_pixel, [Float, Float] => [Float, Float]
34
+ abi_attr :keyboard_navigation?, Boolean, :keyboard_navigation_enabled
34
35
  abi_signal :on_view_change, ViewSignal
35
36
 
36
37
  end
@@ -3,8 +3,23 @@ require_relative 'clickable_widget'
3
3
  module Tgui
4
4
  class ButtonBase < ClickableWidget
5
5
 
6
- def theme_comp
7
- :button
6
+ class Theme < Widget::Theme
7
+
8
+ def default_name
9
+ "Button"
10
+ end
11
+
12
+ theme_attr :borders, :outline
13
+ [ '', :_down, :_hover, :_down_hover, :_disabled, :_down_disabled, :_focused, :_down_focused ].each do |v|
14
+ theme_attr "text_color#{v}".to_sym, :color
15
+ theme_attr "background_color#{v}".to_sym, :color
16
+ theme_attr "border_color#{v}".to_sym, :color
17
+ theme_attr "texture#{v}".to_sym, :texture
18
+ theme_attr "text_style#{v}".to_sym, :text_styles
19
+ end
20
+ theme_attr :text_outline_color, :color
21
+ theme_attr :text_outline_thickness, :float
22
+ theme_attr :rounded_border_radius, :float
8
23
  end
9
24
 
10
25
  def abi_pack_text_position_vector o