Class: CyberarmEngine::Element
- Inherits:
-
Object
- Object
- CyberarmEngine::Element
show all
- Includes:
- Common, Event, Theme
- Defined in:
- lib/cyberarm_engine/ui/element.rb,
lib/cyberarm_engine/ui/elements/flow.rb,
lib/cyberarm_engine/ui/elements/menu.rb,
lib/cyberarm_engine/ui/elements/image.rb,
lib/cyberarm_engine/ui/elements/radio.rb,
lib/cyberarm_engine/ui/elements/stack.rb,
lib/cyberarm_engine/ui/elements/button.rb,
lib/cyberarm_engine/ui/elements/slider.rb,
lib/cyberarm_engine/ui/elements/edit_box.rb,
lib/cyberarm_engine/ui/elements/list_box.rb,
lib/cyberarm_engine/ui/elements/progress.rb,
lib/cyberarm_engine/ui/elements/check_box.rb,
lib/cyberarm_engine/ui/elements/container.rb,
lib/cyberarm_engine/ui/elements/edit_line.rb,
lib/cyberarm_engine/ui/elements/menu_item.rb,
lib/cyberarm_engine/ui/elements/text_block.rb,
lib/cyberarm_engine/ui/elements/toggle_button.rb
Defined Under Namespace
Classes: Banner, Button, Caption, CheckBox, Container, EditBox, EditLine, Flow, Image, Inscription, Link, ListBox, Menu, MenuItem, Para, Progress, Radio, Slider, Stack, Subtitle, Tagline, TextBlock, Title, ToggleButton, ToolTip
Constant Summary
Constants included
from Theme
Theme::THEME
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#background=(_background) ⇒ Object
-
#background_image=(image_path) ⇒ Object
-
#background_nine_slice=(_image_path) ⇒ Object
-
#blur(_sender) ⇒ Object
-
#button_down(id) ⇒ Object
-
#button_up(id) ⇒ Object
-
#child_of?(element) ⇒ Boolean
-
#clicked_left_mouse_button(_sender, _x, _y) ⇒ Object
-
#content_height ⇒ Object
-
#content_width ⇒ Object
-
#debug_draw ⇒ Object
-
#default_events ⇒ Object
-
#dimensional_size(size, dimension) ⇒ Object
-
#draggable?(_button) ⇒ Boolean
-
#draw ⇒ Object
-
#element_visible? ⇒ Boolean
-
#enabled=(boolean) ⇒ Object
-
#enabled? ⇒ Boolean
-
#enter(_sender) ⇒ Object
-
#focus(_) ⇒ Object
-
#focused? ⇒ Boolean
-
#height ⇒ Object
-
#hide ⇒ Object
-
#hit?(x, y) ⇒ Boolean
-
#initialize(options = {}, block = nil) ⇒ Element
constructor
A new instance of Element.
-
#inner_height ⇒ Object
-
#inner_width ⇒ Object
-
#inspect ⇒ Object
-
#is_root? ⇒ Boolean
-
#layout ⇒ Object
-
#leave(_sender) ⇒ Object
-
#left_mouse_button(_sender, _x, _y) ⇒ Object
-
#max_scroll_height ⇒ Object
-
#max_scroll_width ⇒ Object
-
#noncontent_height ⇒ Object
-
#noncontent_width ⇒ Object
-
#outer_height ⇒ Object
-
#outer_width ⇒ Object
-
#parent_of?(element) ⇒ Boolean
-
#recalculate ⇒ Object
-
#recalculate_if_size_changed ⇒ Object
-
#released_left_mouse_button(sender, _x, _y) ⇒ Object
-
#render ⇒ Object
-
#reposition ⇒ Object
-
#root ⇒ Object
-
#safe_style_fetch(key, fallback_key = nil) ⇒ Object
-
#scroll_height ⇒ Object
-
#scroll_width ⇒ Object
-
#set_background ⇒ Object
-
#set_background_image ⇒ Object
-
#set_background_nine_slice ⇒ Object
-
#set_border_color ⇒ Object
-
#set_border_thickness ⇒ Object
-
#set_color ⇒ Object
-
#set_font ⇒ Object
-
#set_margin ⇒ Object
-
#set_padding ⇒ Object
-
#set_static_position ⇒ Object
-
#show ⇒ Object
-
#space_available_height ⇒ Object
-
#space_available_width ⇒ Object
-
#stylize ⇒ Object
-
#to_s ⇒ Object
-
#toggle ⇒ Object
-
#update ⇒ Object
-
#update_background ⇒ Object
-
#update_background_image ⇒ Object
-
#update_background_nine_slice ⇒ Object
-
#update_styles(event = :default) ⇒ Object
-
#value ⇒ Object
-
#value=(_value) ⇒ Object
-
#visible? ⇒ Boolean
-
#width ⇒ Object
Methods included from Common
#alt_down?, #control_down?, #current_state, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_down?, #shift_state, #show_cursor, #show_cursor=, #window
Methods included from Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(options = {}, block = nil) ⇒ Element
Returns a new instance of Element.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/cyberarm_engine/ui/element.rb', line 10
def initialize(options = {}, block = nil)
@parent = options.delete(:parent) options = theme_defaults(options)
@options = options
@block = block
@focus = !@options.key?(:focus) ? false : @options[:focus]
@enabled = !@options.key?(:enabled) ? true : @options[:enabled]
@visible = !@options.key?(:visible) ? true : @options[:visible]
@tip = @options[:tip] || ""
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
@style = Style.new(options)
@root ||= nil
@gui_state ||= nil
@element_visible = true
@x = @style.x
@y = @style.y
@z = @style.z
@old_width = 0
@old_height = 0
@width = 0
@height = 0
@style.width = default(:width) || nil
@style.height = default(:height) || nil
@style.background_canvas = Background.new
@style.background_nine_slice_canvas = BackgroundNineSlice.new
@style.background_image_canvas = BackgroundImage.new
@style.border_canvas = BorderCanvas.new(element: self)
@style_event = :default
stylize
default_events
root.gui_state.request_focus(self) if @options[:autofocus]
end
|
Instance Attribute Details
#background_canvas ⇒ Object
Returns the value of attribute background_canvas.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def background_canvas
@background_canvas
end
|
#border_canvas ⇒ Object
Returns the value of attribute border_canvas.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def border_canvas
@border_canvas
end
|
#element_visible ⇒ Object
Returns the value of attribute element_visible.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def element_visible
@element_visible
end
|
#event_handler ⇒ Object
Returns the value of attribute event_handler.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def event_handler
@event_handler
end
|
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def options
@options
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def parent
@parent
end
|
#style ⇒ Object
Returns the value of attribute style.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def style
@style
end
|
#tip ⇒ Object
Returns the value of attribute tip.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def tip
@tip
end
|
#x ⇒ Object
Returns the value of attribute x.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def y
@y
end
|
#z ⇒ Object
Returns the value of attribute z.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def z
@z
end
|
Instance Method Details
#background=(_background) ⇒ Object
510
511
512
513
514
515
|
# File 'lib/cyberarm_engine/ui/element.rb', line 510
def background=(_background)
root.gui_state.request_repaint
@style.background_canvas.background = _background
update_background
end
|
#background_image=(image_path) ⇒ Object
556
557
558
559
560
561
|
# File 'lib/cyberarm_engine/ui/element.rb', line 556
def background_image=(image_path)
root.gui_state.request_repaint
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
update_background_image
end
|
#background_nine_slice=(_image_path) ⇒ Object
530
531
532
533
534
535
|
# File 'lib/cyberarm_engine/ui/element.rb', line 530
def background_nine_slice=(_image_path)
root.gui_state.request_repaint
@style.background_nine_slice_canvas.image = _image_path
update_background_nine_slice
end
|
#blur(_sender) ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/cyberarm_engine/ui/element.rb', line 263
def blur(_sender)
@focus = false
if @enabled
update_styles
else
update_styles(:disabled)
end
:handled
end
|
362
363
|
# File 'lib/cyberarm_engine/ui/element.rb', line 362
def button_down(id)
end
|
365
366
|
# File 'lib/cyberarm_engine/ui/element.rb', line 365
def button_up(id)
end
|
#child_of?(element) ⇒ Boolean
605
606
607
608
609
610
611
|
# File 'lib/cyberarm_engine/ui/element.rb', line 605
def child_of?(element)
return element == self if is_root?
return false unless element.is_a?(Container)
return true if element.children.find { |child| child == self }
element.children.find { |child| child.child_of?(element) if child.is_a?(Container) }
end
|
247
248
249
250
251
|
# File 'lib/cyberarm_engine/ui/element.rb', line 247
def clicked_left_mouse_button(_sender, _x, _y)
@block&.call(self) if @enabled && !self.is_a?(Container)
:handled
end
|
#content_height ⇒ Object
412
413
414
|
# File 'lib/cyberarm_engine/ui/element.rb', line 412
def content_height
@height
end
|
#content_width ⇒ Object
388
389
390
|
# File 'lib/cyberarm_engine/ui/element.rb', line 388
def content_width
@width
end
|
#debug_draw ⇒ Object
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
# File 'lib/cyberarm_engine/ui/element.rb', line 333
def debug_draw
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
Gosu.draw_line(
x, y, @debug_color,
x + outer_width, y, @debug_color,
Float::INFINITY
)
Gosu.draw_line(
x + outer_width, y, @debug_color,
x + outer_width, y + outer_height, @debug_color,
Float::INFINITY
)
Gosu.draw_line(
x + outer_width, y + outer_height, @debug_color,
x, y + outer_height, @debug_color,
Float::INFINITY
)
Gosu.draw_line(
x, y + outer_height, @debug_color,
x, y, @debug_color,
Float::INFINITY
)
end
|
#default_events ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/cyberarm_engine/ui/element.rb', line 188
def default_events
%i[left middle right].each do |button|
event(:"#{button}_mouse_button")
event(:"released_#{button}_mouse_button")
event(:"clicked_#{button}_mouse_button")
event(:"holding_#{button}_mouse_button")
end
event(:mouse_wheel_up)
event(:mouse_wheel_down)
event(:scroll_jump_to_top)
event(:scroll_jump_to_end)
event(:scroll_page_up)
event(:scroll_page_down)
event(:enter)
event(:hover)
event(:leave)
event(:focus)
event(:blur)
event(:changed)
end
|
#dimensional_size(size, dimension) ⇒ Object
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
# File 'lib/cyberarm_engine/ui/element.rb', line 471
def dimensional_size(size, dimension)
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
else
size
end
if @parent && @style.fill &&
(dimension == :width && @parent.is_a?(Flow) ||
dimension == :height && @parent.is_a?(Stack))
new_size = space_available_width - noncontent_width if dimension == :width && @parent.is_a?(Flow)
new_size = space_available_height - noncontent_height if dimension == :height && @parent.is_a?(Stack)
end
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
new_size
end
|
#draggable?(_button) ⇒ Boolean
368
369
370
|
# File 'lib/cyberarm_engine/ui/element.rb', line 368
def draggable?(_button)
false
end
|
#draw ⇒ Object
321
322
323
324
325
326
327
328
329
330
331
|
# File 'lib/cyberarm_engine/ui/element.rb', line 321
def draw
return unless visible?
return unless element_visible?
@style.background_canvas.draw
@style.background_nine_slice_canvas.draw
@style.background_image_canvas.draw
@style.border_canvas.draw
render
end
|
#element_visible? ⇒ Boolean
297
298
299
|
# File 'lib/cyberarm_engine/ui/element.rb', line 297
def element_visible?
@element_visible
end
|
#enabled=(boolean) ⇒ Object
275
276
277
278
279
280
281
282
283
|
# File 'lib/cyberarm_engine/ui/element.rb', line 275
def enabled=(boolean)
root.gui_state.request_repaint if @enabled != boolean
@enabled = boolean
recalculate
@enabled
end
|
#enabled? ⇒ Boolean
285
286
287
|
# File 'lib/cyberarm_engine/ui/element.rb', line 285
def enabled?
@enabled
end
|
#enter(_sender) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/cyberarm_engine/ui/element.rb', line 213
def enter(_sender)
@focus = false unless Gosu.button_down?(Gosu::MS_LEFT)
if !@enabled
update_styles(:disabled)
elsif @focus
update_styles(:active)
else
update_styles(:hover)
end
:handled
end
|
#focus(_) ⇒ Object
621
622
623
624
625
|
# File 'lib/cyberarm_engine/ui/element.rb', line 621
def focus(_)
warn "#{self.class}#focus was not overridden!"
:handled
end
|
#focused? ⇒ Boolean
289
290
291
|
# File 'lib/cyberarm_engine/ui/element.rb', line 289
def focused?
@focus
end
|
#height ⇒ Object
404
405
406
407
408
409
410
|
# File 'lib/cyberarm_engine/ui/element.rb', line 404
def height
if visible?
inner_height + @height
else
0
end
end
|
#hide ⇒ Object
314
315
316
317
318
319
|
# File 'lib/cyberarm_engine/ui/element.rb', line 314
def hide
bool = visible?
@visible = false
root.gui_state.request_recalculate if bool
root.gui_state.request_repaint if bool
end
|
#hit?(x, y) ⇒ Boolean
375
376
377
378
|
# File 'lib/cyberarm_engine/ui/element.rb', line 375
def hit?(x, y)
x.between?(@x, @x + width) &&
y.between?(@y, @y + height)
end
|
#inner_height ⇒ Object
424
425
426
|
# File 'lib/cyberarm_engine/ui/element.rb', line 424
def inner_height
(@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
end
|
#inner_width ⇒ Object
400
401
402
|
# File 'lib/cyberarm_engine/ui/element.rb', line 400
def inner_width
(@style.border_thickness_left + @style.padding_left) + (@style.padding_right + @style.border_thickness_right)
end
|
#inspect ⇒ Object
658
659
660
|
# File 'lib/cyberarm_engine/ui/element.rb', line 658
def inspect
to_s
end
|
#is_root? ⇒ Boolean
601
602
603
|
# File 'lib/cyberarm_engine/ui/element.rb', line 601
def is_root?
@gui_state != nil
end
|
#layout ⇒ Object
640
641
|
# File 'lib/cyberarm_engine/ui/element.rb', line 640
def layout
end
|
#leave(_sender) ⇒ Object
253
254
255
256
257
258
259
260
261
|
# File 'lib/cyberarm_engine/ui/element.rb', line 253
def leave(_sender)
if @enabled
update_styles
else
update_styles(:disabled)
end
:handled
end
|
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/cyberarm_engine/ui/element.rb', line 227
def left_mouse_button(_sender, _x, _y)
@focus = true
unless @enabled
update_styles(:disabled)
else
update_styles(:active)
end
window.current_state.focus = self
:handled
end
|
467
468
469
|
# File 'lib/cyberarm_engine/ui/element.rb', line 467
def max_scroll_height
(scroll_height - outer_height).positive? ? scroll_height - outer_height : scroll_height
end
|
463
464
465
|
# File 'lib/cyberarm_engine/ui/element.rb', line 463
def max_scroll_width
(scroll_width - outer_width).positive? ? scroll_width - outer_width : scroll_width
end
|
#noncontent_height ⇒ Object
416
417
418
|
# File 'lib/cyberarm_engine/ui/element.rb', line 416
def noncontent_height
(inner_height + outer_height) - height
end
|
#noncontent_width ⇒ Object
392
393
394
|
# File 'lib/cyberarm_engine/ui/element.rb', line 392
def noncontent_width
(inner_width + outer_width) - width
end
|
#outer_height ⇒ Object
420
421
422
|
# File 'lib/cyberarm_engine/ui/element.rb', line 420
def outer_height
@style.margin_top + height + @style.margin_bottom
end
|
#outer_width ⇒ Object
396
397
398
|
# File 'lib/cyberarm_engine/ui/element.rb', line 396
def outer_width
@style.margin_left + width + @style.margin_right
end
|
#parent_of?(element) ⇒ Boolean
613
614
615
616
617
618
619
|
# File 'lib/cyberarm_engine/ui/element.rb', line 613
def parent_of?(element)
return false if element == self
return false unless is_a?(Container)
return true if @children.find { |child| child == element }
@children.find { |child| child.parent_of?(element) if child.is_a?(Container) }
end
|
#recalculate ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/cyberarm_engine/ui/element.rb', line 627
def recalculate
old_width = width
old_height = height
stylize
layout
root.gui_state.request_recalculate if @parent && !is_a?(ToolTip) && (width != old_width || height != old_height)
root.gui_state.request_repaint if width != old_width || height != old_height
root.gui_state..recalculate if root.gui_state. && root.gui_state..parent == self
end
|
#recalculate_if_size_changed ⇒ Object
576
577
578
579
580
581
582
583
|
# File 'lib/cyberarm_engine/ui/element.rb', line 576
def recalculate_if_size_changed
if @parent && !is_a?(ToolTip) && (@old_width != width || @old_height != height)
root.gui_state.request_recalculate
@old_width = width
@old_height = height
end
end
|
241
242
243
244
245
|
# File 'lib/cyberarm_engine/ui/element.rb', line 241
def released_left_mouse_button(sender, _x, _y)
enter(sender)
:handled
end
|
#render ⇒ Object
372
373
|
# File 'lib/cyberarm_engine/ui/element.rb', line 372
def render
end
|
#reposition ⇒ Object
643
644
|
# File 'lib/cyberarm_engine/ui/element.rb', line 643
def reposition
end
|
#root ⇒ Object
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
|
# File 'lib/cyberarm_engine/ui/element.rb', line 585
def root
return self if is_root?
unless @root && @root.parent.nil?
@root = parent
loop do
break unless @root&.parent
@root = @root.parent
end
end
@root
end
|
#safe_style_fetch(key, fallback_key = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/cyberarm_engine/ui/element.rb', line 74
def safe_style_fetch(key, fallback_key = nil)
v = @style.hash.dig(@style_event, key)
return v if v
if fallback_key
v = @style.hash.dig(@style_event, fallback_key)
return v if v
end
@style.hash.dig(:default, key) || default(key)
end
|
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
# File 'lib/cyberarm_engine/ui/element.rb', line 434
def scroll_height
return @cached_scroll_height if @cached_scroll_height && is_a?(Container)
if is_a?(CyberarmEngine::Element::Flow)
return 0 if @children.size.zero?
pairs_ = []
sorted_children_ = @children.sort_by(&:y)
a_ = []
y_position_ = sorted_children_.first.y
sorted_children_.each do |child|
unless child.y == y_position_
y_position_ = child.y
pairs_ << a_
a_ = []
end
a_ << child
end
pairs_ << a_ unless pairs_.last == a_
@cached_scroll_height = pairs_.sum { |pair| + @style.padding_top + @style.border_thickness_top + pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
else
@cached_scroll_height = @style.padding_top + @style.border_thickness_top + @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
end
end
|
428
429
430
431
432
|
# File 'lib/cyberarm_engine/ui/element.rb', line 428
def scroll_width
return @cached_scroll_width if @cached_scroll_width && is_a?(Container)
@cached_scroll_width = @children.sum(&:outer_width)
end
|
#set_background ⇒ Object
103
104
105
106
107
|
# File 'lib/cyberarm_engine/ui/element.rb', line 103
def set_background
@style.background = safe_style_fetch(:background)
@style.background_canvas.background = @style.background
end
|
#set_background_image ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/cyberarm_engine/ui/element.rb', line 124
def set_background_image
@style.background_image = safe_style_fetch(:background_image)
@style.background_image_mode = safe_style_fetch(:background_image_mode) || :stretch
@style.background_image_color = safe_style_fetch(:background_image_color) || Gosu::Color::WHITE
@style.background_image_canvas.mode = @style.background_image_mode
@style.background_image_canvas.color = @style.background_image_color
end
|
#set_background_nine_slice ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/cyberarm_engine/ui/element.rb', line 109
def set_background_nine_slice
@style.background_nine_slice = safe_style_fetch(:background_nine_slice)
@style.background_nine_slice_mode = safe_style_fetch(:background_nine_slice_mode) || :stretch
@style.background_nine_slice_color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
@style.background_nine_slice_canvas.color = @style.background_nine_slice_color
@style.background_nine_slice_from_edge = safe_style_fetch(:background_nine_slice_from_edge)
@style.background_nine_slice_left = safe_style_fetch(:background_nine_slice_left, :background_nine_slice_from_edge)
@style.background_nine_slice_top = safe_style_fetch(:background_nine_slice_top, :background_nine_slice_from_edge)
@style.background_nine_slice_right = safe_style_fetch(:background_nine_slice_right, :background_nine_slice_from_edge)
@style.background_nine_slice_bottom = safe_style_fetch(:background_nine_slice_bottom, :background_nine_slice_from_edge)
end
|
#set_border_color ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/cyberarm_engine/ui/element.rb', line 141
def set_border_color
@style.border_color = safe_style_fetch(:border_color)
@style.border_color_left = safe_style_fetch(:border_color_left, :border_color)
@style.border_color_right = safe_style_fetch(:border_color_right, :border_color)
@style.border_color_top = safe_style_fetch(:border_color_top, :border_color)
@style.border_color_bottom = safe_style_fetch(:border_color_bottom, :border_color)
@style.border_canvas.color = [
@style.border_color_top,
@style.border_color_right,
@style.border_color_bottom,
@style.border_color_left
]
end
|
#set_border_thickness ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/cyberarm_engine/ui/element.rb', line 132
def set_border_thickness
@style.border_thickness = safe_style_fetch(:border_thickness)
@style.border_thickness_left = safe_style_fetch(:border_thickness_left, :border_thickness)
@style.border_thickness_right = safe_style_fetch(:border_thickness_right, :border_thickness)
@style.border_thickness_top = safe_style_fetch(:border_thickness_top, :border_thickness)
@style.border_thickness_bottom = safe_style_fetch(:border_thickness_bottom, :border_thickness)
end
|
#set_color ⇒ Object
94
95
96
97
|
# File 'lib/cyberarm_engine/ui/element.rb', line 94
def set_color
@style.color = safe_style_fetch(:color)
@text&.color = @style.color
end
|
#set_font ⇒ Object
99
100
101
|
# File 'lib/cyberarm_engine/ui/element.rb', line 99
def set_font
@text&.swap_font(safe_style_fetch(:text_size), safe_style_fetch(:font))
end
|
#set_margin ⇒ Object
166
167
168
169
170
171
172
173
|
# File 'lib/cyberarm_engine/ui/element.rb', line 166
def set_margin
@style.margin = safe_style_fetch(:margin)
@style.margin_left = safe_style_fetch(:margin_left, :margin)
@style.margin_right = safe_style_fetch(:margin_right, :margin)
@style.margin_top = safe_style_fetch(:margin_top, :margin)
@style.margin_bottom = safe_style_fetch(:margin_bottom, :margin)
end
|
#set_padding ⇒ Object
157
158
159
160
161
162
163
164
|
# File 'lib/cyberarm_engine/ui/element.rb', line 157
def set_padding
@style.padding = safe_style_fetch(:padding)
@style.padding_left = safe_style_fetch(:padding_left, :padding)
@style.padding_right = safe_style_fetch(:padding_right, :padding)
@style.padding_top = safe_style_fetch(:padding_top, :padding)
@style.padding_bottom = safe_style_fetch(:padding_bottom, :padding)
end
|
#set_static_position ⇒ Object
89
90
91
92
|
# File 'lib/cyberarm_engine/ui/element.rb', line 89
def set_static_position
@x = @style.x if @style.x != 0
@y = @style.y if @style.y != 0
end
|
#show ⇒ Object
307
308
309
310
311
312
|
# File 'lib/cyberarm_engine/ui/element.rb', line 307
def show
bool = visible?
@visible = true
root.gui_state.request_recalculate unless bool
root.gui_state.request_repaint unless bool
end
|
#space_available_height ⇒ Object
502
503
504
505
506
507
508
|
# File 'lib/cyberarm_engine/ui/element.rb', line 502
def space_available_height
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor end
|
#space_available_width ⇒ Object
494
495
496
497
498
499
500
|
# File 'lib/cyberarm_engine/ui/element.rb', line 494
def space_available_width
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f
available_space = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor end
|
#stylize ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/cyberarm_engine/ui/element.rb', line 55
def stylize
set_static_position
set_color
set_font
set_padding
set_margin
set_background
set_background_nine_slice
set_background_image
set_border_thickness
set_border_color
root.gui_state.request_repaint
end
|
#to_s ⇒ Object
654
655
656
|
# File 'lib/cyberarm_engine/ui/element.rb', line 654
def to_s
"#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{value.is_a?(String) ? "\"#{value}\"" : value}"
end
|
#toggle ⇒ Object
301
302
303
304
305
|
# File 'lib/cyberarm_engine/ui/element.rb', line 301
def toggle
@visible = !@visible
root.gui_state.request_recalculate
root.gui_state.request_repaint
end
|
#update ⇒ Object
358
359
360
|
# File 'lib/cyberarm_engine/ui/element.rb', line 358
def update
recalculate_if_size_changed
end
|
#update_background ⇒ Object
517
518
519
520
521
522
523
524
525
526
527
528
|
# File 'lib/cyberarm_engine/ui/element.rb', line 517
def update_background
@style.background_canvas.x = @x
@style.background_canvas.y = @y
@style.background_canvas.z = @z
@style.background_canvas.width = width
@style.background_canvas.height = height
@style.background_canvas.update
update_background_nine_slice
update_background_image
@style.border_canvas.update
end
|
#update_background_image ⇒ Object
563
564
565
566
567
568
569
570
571
572
573
574
|
# File 'lib/cyberarm_engine/ui/element.rb', line 563
def update_background_image
@style.background_image_canvas.x = @x
@style.background_image_canvas.y = @y
@style.background_image_canvas.z = @z
@style.background_image_canvas.width = width
@style.background_image_canvas.height = height
@style.background_image_canvas.mode = @style.background_image_mode
@style.background_image_canvas.color = @style.background_image_color
@style.background_image_canvas.image = @style.background_image
end
|
#update_background_nine_slice ⇒ Object
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
# File 'lib/cyberarm_engine/ui/element.rb', line 537
def update_background_nine_slice
@style.background_nine_slice_canvas.x = @x
@style.background_nine_slice_canvas.y = @y
@style.background_nine_slice_canvas.z = @z
@style.background_nine_slice_canvas.width = width
@style.background_nine_slice_canvas.height = height
@style.background_nine_slice_canvas.mode = @style.background_nine_slice_mode
@style.background_nine_slice_canvas.color = @style.background_nine_slice_color
@style.background_nine_slice_canvas.left = @style.background_nine_slice_left
@style.background_nine_slice_canvas.top = @style.background_nine_slice_top
@style.background_nine_slice_canvas.right = @style.background_nine_slice_right
@style.background_nine_slice_canvas.bottom = @style.background_nine_slice_bottom
@style.background_nine_slice_canvas.image = @style.background_nine_slice
end
|
#update_styles(event = :default) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/cyberarm_engine/ui/element.rb', line 175
def update_styles(event = :default)
old_width = width
old_height = height
@style_event = event
return if self.is_a?(ToolTip)
root.gui_state.request_recalculate if old_width != width || old_height != height
stylize
end
|
#value ⇒ Object
646
647
648
|
# File 'lib/cyberarm_engine/ui/element.rb', line 646
def value
raise "#{self.class}#value was not overridden!"
end
|
#value=(_value) ⇒ Object
650
651
652
|
# File 'lib/cyberarm_engine/ui/element.rb', line 650
def value=(_value)
raise "#{self.class}#value= was not overridden!"
end
|
#visible? ⇒ Boolean
293
294
295
|
# File 'lib/cyberarm_engine/ui/element.rb', line 293
def visible?
@visible
end
|
#width ⇒ Object
380
381
382
383
384
385
386
|
# File 'lib/cyberarm_engine/ui/element.rb', line 380
def width
if visible?
inner_width + @width
else
0
end
end
|