Class: TT::GUI::Control
Abstract
Overview
All GUI elements inherit this class.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_event_handler(event, &block) ⇒ nil
Adds an event to the stack.
-
#call_event(event, args = nil) ⇒ Boolean
Triggers the given event.
-
#disabled=(value) ⇒ Boolean
-
#disabled? ⇒ Boolean
-
#enabled=(value) ⇒ Boolean
-
#enabled? ⇒ Boolean
-
#initialize(*args) ⇒ Control
constructor
A new instance of Control.
-
#inspect ⇒ String
-
#move(left, top) ⇒ Array<Numeric,Numeric>
-
#position(top, right, bottom, left) ⇒ Array<Numeric,Numeric,Numeric,Numeric>
-
#positioned? ⇒ Boolean
(!) Need explicit :position property.
-
#properties ⇒ TT::JSON
-
#release! ⇒ Nil
Release all references to other objects.
-
#size(width, height) ⇒ Array<Numeric,Numeric>
included
Constructor Details
#initialize(*args) ⇒ Control
Returns a new instance of Control
74
75
76
77
78
79
80
81
82
|
# File 'TT_Lib2/gui.rb', line 74
def initialize( *args )
@ui_id = 'UI_' + self.object_id.to_s
@events = {}
@disabled = false
end
|
Instance Attribute Details
#bottom ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def bottom
@bottom
end
|
#font_bold ⇒ Object
62
63
64
|
# File 'TT_Lib2/gui.rb', line 62
def font_bold
@font_bold
end
|
#font_italic ⇒ Object
62
63
64
|
# File 'TT_Lib2/gui.rb', line 62
def font_italic
@font_italic
end
|
#font_name ⇒ Object
62
63
64
|
# File 'TT_Lib2/gui.rb', line 62
def font_name
@font_name
end
|
#font_size ⇒ Object
62
63
64
|
# File 'TT_Lib2/gui.rb', line 62
def font_size
@font_size
end
|
#height ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def height
@height
end
|
#left ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def left
@left
end
|
#name ⇒ Object
58
59
60
|
# File 'TT_Lib2/gui.rb', line 58
def name
@name
end
|
#parent ⇒ Object
60
61
62
|
# File 'TT_Lib2/gui.rb', line 60
def parent
@parent
end
|
#right ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def right
@right
end
|
61
62
63
|
# File 'TT_Lib2/gui.rb', line 61
def tooltip
@tooltip
end
|
#top ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def top
@top
end
|
#ui_id ⇒ Object
57
58
59
|
# File 'TT_Lib2/gui.rb', line 57
def ui_id
@ui_id
end
|
#width ⇒ Object
59
60
61
|
# File 'TT_Lib2/gui.rb', line 59
def width
@width
end
|
#window ⇒ Object
60
61
62
|
# File 'TT_Lib2/gui.rb', line 60
def window
@window
end
|
Class Method Details
.events ⇒ Array<Symbol>
87
88
89
|
# File 'TT_Lib2/gui.rb', line 87
def self.events
@control_events.keys
end
|
.has_event?(event) ⇒ Array<Symbol>
93
94
95
|
# File 'TT_Lib2/gui.rb', line 93
def self.has_event?( event )
@control_events.key?( event )
end
|
Instance Method Details
#add_event_handler(event, &block) ⇒ nil
Adds an event to the stack.
105
106
107
108
109
110
111
112
|
# File 'TT_Lib2/gui.rb', line 105
def add_event_handler( event, &block )
unless self.class.has_event?( event )
raise( ArgumentError, "Event #{event} not defined for #{self.class}" )
end
@events[event] ||= []
@events[event] << block
nil
end
|
#call_event(event, args = nil) ⇒ Boolean
Triggers the given event. All attached procs for that event will be called.
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'TT_Lib2/gui.rb', line 121
def call_event( event, args = nil )
TT::debug "call_event(#{event.to_s})"
TT::debug args.inspect
if @events.key?( event )
@events[event].each { |proc|
next if proc.nil? if args.nil?
proc.call( self )
else
args.unshift( self )
proc.call( *args )
end
}
true
else
false
end
end
|
#disabled=(value) ⇒ Boolean
153
154
155
156
157
|
# File 'TT_Lib2/gui.rb', line 153
def disabled=( value )
@disabled = value
update_html_element( { :disabled => value } )
value
end
|
#disabled? ⇒ Boolean
145
146
147
|
# File 'TT_Lib2/gui.rb', line 145
def disabled?
@disabled == true
end
|
#enabled=(value) ⇒ Boolean
163
164
165
|
# File 'TT_Lib2/gui.rb', line 163
def enabled=( value )
self.disabled = !value
end
|
#enabled? ⇒ Boolean
169
170
171
|
# File 'TT_Lib2/gui.rb', line 169
def enabled?
!@disabled
end
|
#inspect ⇒ String
332
333
334
|
# File 'TT_Lib2/gui.rb', line 332
def inspect
"<#{self.class}:#{TT.object_id_hex(self)}>"
end
|
#move(left, top) ⇒ Array<Numeric,Numeric>
238
239
240
241
242
243
|
# File 'TT_Lib2/gui.rb', line 238
def move( left, top )
@left = left
@top = top
update_html_element( { :left => left, :top => top } )
[ left, top ]
end
|
#position(top, right, bottom, left) ⇒ Array<Numeric,Numeric,Numeric,Numeric>
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'TT_Lib2/gui.rb', line 264
def position( top, right, bottom, left )
@top = top
@right = right
@bottom = bottom
@left = left
properties = {
:top => top,
:right => right,
:bottom => bottom,
:left => left
}
update_html_element( properties )
[ top, right, bottom, left ]
end
|
#positioned? ⇒ Boolean
(!) Need explicit :position property.
282
283
284
|
# File 'TT_Lib2/gui.rb', line 282
def positioned?
( @left || @right || @top || @bottom ) ? true : false
end
|
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'TT_Lib2/gui.rb', line 308
def properties
options = TT::JSON.new
options['id'] = @ui_id
options['parent'] = @parent.ui_id if @parent.is_a?( Control )
options['type'] = self.class.name
if positioned?
options['top'] = @top if @top
options['bottom'] = @bottom if @bottom
options['left'] = @left if @left
options['right'] = @right if @right
end
options['width'] = @width if @width
options['height'] = @height if @height
options['font_name'] = @font_name if @font_name
options['font_size'] = @font_size if @font_size
options['disabled'] = @disabled if @disabled
if self.respond_to?( :custom_properties )
options.merge!( custom_properties() )
end
options
end
|
#release! ⇒ Nil
Release all references to other objects. Setting them to nil. So that the
GC can collect them.
341
342
343
344
345
346
|
# File 'TT_Lib2/gui.rb', line 341
def release!
@parent = nil
@window = nil
@events.clear
nil
end
|
#size(width, height) ⇒ Array<Numeric,Numeric>
250
251
252
253
254
255
|
# File 'TT_Lib2/gui.rb', line 250
def size( width, height )
@width = width
@height = height
update_html_element( { :width => width, :height => height } )
[ width, height ]
end
|