Class: Nuklear::UI::Window

Inherits:
Base
  • Object
show all
Includes:
Container
Defined in:
lib/nuklear/ui/window.rb

Direct Known Subclasses

Popup

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Container

#<<, #commands, #find, #layout_row_dynamic, #method_missing, #run_command, #run_commands, #traverse, #ui_checkbox, #ui_color_picker, #ui_combo, #ui_edit_focus, #ui_edit_string, #ui_layout_row_begin, #ui_layout_row_dynamic, #ui_layout_row_push, #ui_layout_row_static, #ui_layout_row_template_begin, #ui_layout_row_template_dynamic, #ui_layout_row_template_end, #ui_layout_row_template_static, #ui_layout_row_template_variable, #ui_layout_space_begin, #ui_layout_space_end, #ui_layout_space_push, #ui_layout_widget_bounds, #ui_menu_item, #ui_option, #ui_selectable, #ui_window_close

Methods inherited from Base

descendants, #dsl, inherited

Methods included from Enableable

#disable, #disabled=, #disabled?, #enable, #enabled?

Methods included from Events

#event_listeners_for, #on, #trigger

Constructor Details

#initialize(title, id: object_id.to_s, left:, top:, width:, height:, flags: 0, border: nil, movable: nil, scalable: nil, closable: nil, minimizable: nil, no_scrollbar: nil, titlebar: nil, scroll_auto_hide: nil, background: nil, scale_left: nil, no_input: nil, enabled: true) ⇒ Window

Returns a new instance of Window.



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
# File 'lib/nuklear/ui/window.rb', line 10

def initialize(title, id: object_id.to_s, left:, top:, width:, height:, flags: 0,
               border: nil, movable: nil, scalable: nil, closable: nil,
               minimizable: nil, no_scrollbar: nil, titlebar: nil,
               scroll_auto_hide: nil, background: nil, scale_left: nil,
               no_input: nil, enabled: true)
  super enabled: enabled

  @title = title
  @id = id
  @left = left
  @top = top
  @width = width
  @height = height
  @flags = Nuklear.parse_flags :window, flags
  @hiding = false
  @last_state = nil
  @content_area = Struct.new(:left, :top, :width, :height).new(left, top, width, height)

  self.border           = border           unless border.nil?
  self.movable          = movable          unless movable.nil?
  self.scalable         = scalable         unless scalable.nil?
  self.closable         = closable         unless closable.nil?
  self.minimizable      = minimizable      unless minimizable.nil?
  self.no_scrollbar     = no_scrollbar     unless no_scrollbar.nil?
  self.titlebar         = titlebar         unless titlebar.nil?
  self.scroll_auto_hide = scroll_auto_hide unless scroll_auto_hide.nil?
  self.background       = background       unless background.nil?
  self.scale_left       = scale_left       unless scale_left.nil?
  self.no_input         = no_input         unless no_input.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Nuklear::UI::Container

Instance Attribute Details

#content_areaObject (readonly)

Returns the value of attribute content_area.



8
9
10
# File 'lib/nuklear/ui/window.rb', line 8

def content_area
  @content_area
end

#flagsObject

Returns the value of attribute flags.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def flags
  @flags
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def height
  @height
end

#idObject



137
138
139
# File 'lib/nuklear/ui/window.rb', line 137

def id
  @id || title
end

#leftObject

Returns the value of attribute left.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def left
  @left
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def title
  @title
end

#topObject

Returns the value of attribute top.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def top
  @top
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/nuklear/ui/window.rb', line 6

def width
  @width
end

Instance Method Details

#background=(a) ⇒ Object



117
118
119
# File 'lib/nuklear/ui/window.rb', line 117

def background=(a)
  set_flag Nuklear::NK_WINDOW_BACKGROUND, a
end

#background?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/nuklear/ui/window.rb', line 73

def background?
  check_flag Nuklear::NK_WINDOW_BACKGROUND
end

#border=(a) ⇒ Object



85
86
87
# File 'lib/nuklear/ui/window.rb', line 85

def border=(a)
  set_flag Nuklear::NK_WINDOW_BORDER, a
end

#border?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/nuklear/ui/window.rb', line 41

def border?
  check_flag Nuklear::NK_WINDOW_BORDER
end

#check_flag(flag) ⇒ Object



133
134
135
# File 'lib/nuklear/ui/window.rb', line 133

def check_flag(flag)
  @flags & flag > 0
end

#closable=(a) ⇒ Object



97
98
99
# File 'lib/nuklear/ui/window.rb', line 97

def closable=(a)
  set_flag Nuklear::NK_WINDOW_CLOSABLE, a
end

#closable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/nuklear/ui/window.rb', line 53

def closable?
  check_flag Nuklear::NK_WINDOW_CLOSABLE
end

#closeObject



149
150
151
# File 'lib/nuklear/ui/window.rb', line 149

def close
  self.enabled = false
end

#enabled=(b) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/nuklear/ui/window.rb', line 141

def enabled=(b)
  if @enabled && !b
    @hiding = true
  else
    super b
  end
end

#minimizable=(a) ⇒ Object



101
102
103
# File 'lib/nuklear/ui/window.rb', line 101

def minimizable=(a)
  set_flag Nuklear::NK_WINDOW_MINIMIZABLE, a
end

#minimizable?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/nuklear/ui/window.rb', line 57

def minimizable?
  check_flag Nuklear::NK_WINDOW_MINIMIZABLE
end

#movable=(a) ⇒ Object



89
90
91
# File 'lib/nuklear/ui/window.rb', line 89

def movable=(a)
  set_flag Nuklear::NK_WINDOW_MOVABLE, a
end

#movable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/nuklear/ui/window.rb', line 45

def movable?
  check_flag Nuklear::NK_WINDOW_MOVABLE
end

#no_input=(a) ⇒ Object



125
126
127
# File 'lib/nuklear/ui/window.rb', line 125

def no_input=(a)
  set_flag Nuklear::NK_WINDOW_NO_INPUT, a
end

#no_input?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/nuklear/ui/window.rb', line 81

def no_input?
  check_flag Nuklear::NK_WINDOW_NO_INPUT
end

#no_scrollbar=(a) ⇒ Object



105
106
107
# File 'lib/nuklear/ui/window.rb', line 105

def no_scrollbar=(a)
  set_flag Nuklear::NK_WINDOW_NO_SCROLLBAR, a
end

#no_scrollbar?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/nuklear/ui/window.rb', line 61

def no_scrollbar?
  check_flag Nuklear::NK_WINDOW_NO_SCROLLBAR
end

#result(new_state, context) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/nuklear/ui/window.rb', line 153

def result(new_state, context)
  if new_state != @last_state
    @left, @top, @width, @height = *new_state[0...4]
    @content_area.left, @content_area.top, @content_area.width, @content_area.height = *new_state[4..-1]
    trigger(:resized)
    @last_event = nil
    @last_state = new_state
  end
  run_commands(context)
end

#scalable=(a) ⇒ Object



93
94
95
# File 'lib/nuklear/ui/window.rb', line 93

def scalable=(a)
  set_flag Nuklear::NK_WINDOW_SCALABLE, a
end

#scalable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/nuklear/ui/window.rb', line 49

def scalable?
  check_flag Nuklear::NK_WINDOW_SCALABLE
end

#scale_left=(a) ⇒ Object



121
122
123
# File 'lib/nuklear/ui/window.rb', line 121

def scale_left=(a)
  set_flag Nuklear::NK_WINDOW_SCALE_LEFT, a
end

#scale_left?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/nuklear/ui/window.rb', line 77

def scale_left?
  check_flag Nuklear::NK_WINDOW_SCALE_LEFT
end

#scroll_auto_hide=(a) ⇒ Object



113
114
115
# File 'lib/nuklear/ui/window.rb', line 113

def scroll_auto_hide=(a)
  set_flag Nuklear::NK_WINDOW_SCROLL_AUTO_HIDE, a
end

#scroll_auto_hide?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/nuklear/ui/window.rb', line 69

def scroll_auto_hide?
  check_flag Nuklear::NK_WINDOW_SCROLL_AUTO_HIDE
end

#set_flag(flag, enabled) ⇒ Object



129
130
131
# File 'lib/nuklear/ui/window.rb', line 129

def set_flag(flag, enabled)
  @flags = enabled ? @flags | flag : @flags & ~flag
end

#titlebar=(a) ⇒ Object



109
110
111
# File 'lib/nuklear/ui/window.rb', line 109

def titlebar=(a)
  set_flag Nuklear::NK_WINDOW_TITLE, a
end

#titlebar?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/nuklear/ui/window.rb', line 65

def titlebar?
  check_flag Nuklear::NK_WINDOW_TITLE
end

#to_commandObject



164
165
166
167
168
169
170
171
172
# File 'lib/nuklear/ui/window.rb', line 164

def to_command
  if @hiding
    @hiding = false
    @enabled = false
    [ :ui_window_close, id ]
  else
    [ :ui_window, id, title, flags, left, top, width, height ]
  end
end