Class: TT::GUI::Control Abstract

Inherits:
Object
  • Object
show all
Includes:
ControlEvents
Defined in:
TT_Lib2/gui.rb

Overview

This class is abstract.

All GUI elements inherit this class.

Since:

  • 2.4.0

Direct Known Subclasses

Button, Checkbox, Container, Label, Listbox, Textbox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ControlEvents

included

Constructor Details

#initialize(*args) ⇒ Control

Returns a new instance of Control

Since:

  • 2.4.0



74
75
76
77
78
79
80
81
82
# File 'TT_Lib2/gui.rb', line 74

def initialize( *args )
  # Unique identifier used in the WebDialog's HTML.
  @ui_id = 'UI_' + self.object_id.to_s
  # Hash with Symbols for keys idenitfying the event.
  # Each event is an array of Proc's.
  @events = {}
  
  @disabled = false
end

Instance Attribute Details

#bottomObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def bottom
  @bottom
end

#font_boldObject

Since:

  • 2.7.0



62
63
64
# File 'TT_Lib2/gui.rb', line 62

def font_bold
  @font_bold
end

#font_italicObject

Since:

  • 2.7.0



62
63
64
# File 'TT_Lib2/gui.rb', line 62

def font_italic
  @font_italic
end

#font_nameObject

Since:

  • 2.7.0



62
63
64
# File 'TT_Lib2/gui.rb', line 62

def font_name
  @font_name
end

#font_sizeObject

Since:

  • 2.7.0



62
63
64
# File 'TT_Lib2/gui.rb', line 62

def font_size
  @font_size
end

#heightObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def height
  @height
end

#leftObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def left
  @left
end

#nameObject

Since:

  • 2.7.0



58
59
60
# File 'TT_Lib2/gui.rb', line 58

def name
  @name
end

#parentObject

Since:

  • 2.4.0



60
61
62
# File 'TT_Lib2/gui.rb', line 60

def parent
  @parent
end

#rightObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def right
  @right
end

#tooltipObject

Since:

  • 2.5.0



61
62
63
# File 'TT_Lib2/gui.rb', line 61

def tooltip
  @tooltip
end

#topObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def top
  @top
end

#ui_idObject

Since:

  • 2.4.0



57
58
59
# File 'TT_Lib2/gui.rb', line 57

def ui_id
  @ui_id
end

#widthObject

Since:

  • 2.4.0



59
60
61
# File 'TT_Lib2/gui.rb', line 59

def width
  @width
end

#windowObject

Since:

  • 2.4.0



60
61
62
# File 'TT_Lib2/gui.rb', line 60

def window
  @window
end

Class Method Details

.eventsArray<Symbol>

Returns:

  • (Array<Symbol>)

Since:

  • 2.6.0



87
88
89
# File 'TT_Lib2/gui.rb', line 87

def self.events
  @control_events.keys
end

.has_event?(event) ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)

Since:

  • 2.6.0



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.

Parameters:

  • event (Symbol)
  • block (Proc)

Returns:

  • (nil)

Since:

  • 2.5.0



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.

Parameters:

  • event (Symbol)
  • args (Array) (defaults to: nil)

    Set of arguments to be passed to the called procs.

Returns:

  • (Boolean)

Since:

  • 2.5.0



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? # In case Button control where made without a block.
      # Add self to argument list so the called event can get the handle for
      # the control triggering it.
      if args.nil?
        proc.call( self )
      else
        args.unshift( self )
        proc.call( *args )
      end
    }
    true
  else
    # (?) Raise error?
    false
  end
end

#disabled=(value) ⇒ Boolean

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)

Since:

  • 2.7.0



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

Returns:

  • (Boolean)

Since:

  • 2.7.0



145
146
147
# File 'TT_Lib2/gui.rb', line 145

def disabled?
  @disabled == true
end

#enabled=(value) ⇒ Boolean

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)

Since:

  • 2.7.0



163
164
165
# File 'TT_Lib2/gui.rb', line 163

def enabled=( value )
  self.disabled = !value
end

#enabled?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



169
170
171
# File 'TT_Lib2/gui.rb', line 169

def enabled?
  !@disabled
end

#inspectString

Returns:

  • (String)

Since:

  • 2.6.0



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>

Parameters:

  • left (Numeric)
  • top (Numeric)

Returns:

  • (Array<Numeric,Numeric>)

Since:

  • 2.4.0



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>

Parameters:

  • top (Numeric)
  • right (Numeric)
  • bottom (Numeric)
  • left (Numeric)

Returns:

  • (Array<Numeric,Numeric,Numeric,Numeric>)

Since:

  • 2.4.0



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.

Returns:

  • (Boolean)

Since:

  • 2.5.0



282
283
284
# File 'TT_Lib2/gui.rb', line 282

def positioned?
  ( @left || @right || @top || @bottom ) ? true : false
end

#propertiesTT::JSON

Returns:

Since:

  • 2.5.0



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.

Returns:

  • (Nil)

Since:

  • 2.6.0



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>

Parameters:

  • width (Numeric)
  • height (Numeric)

Returns:

  • (Array<Numeric,Numeric>)

Since:

  • 2.4.0



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