class Umbra::Box

A box is a container around one, or more, widgets. Properties include `visible,` `justify` and `title.` It is not focusable, so no keys can be mapped to it.

FIXME box needs to resize components if it's dimensions are changed.
Or should components have a link to parent, so they can resize themselves ?

Attributes

widget[R]

@return [Widget] return widget added to this box

widgets[R]

@return [Array<Widget>] return widgets added to this box

Public Class Methods

new(config={}) click to toggle source
Calls superclass method
# File lib/umbra/box.rb, line 31
def initialize config={}, &block
  @focusable  = false
  @visible    = true
  super

  @int_height = self.height - 2
   
  @int_width  = self.width  - 2
  @hlines = []
  #@vlines = []   # UNUSED. TODO ???
end

Public Instance Methods

add(*w) click to toggle source

Add a variable list of components to a box, which are stacked horizontally by the box. @param w [Array<Widget>] comma separated list of widgets

# File lib/umbra/box.rb, line 57
def add *w
  @widgets = w
  num = w.size
  wid = @int_width 
  ht  = (@int_height / num)
  srow = @row + 1
  scol = @col + 1
  w.each_with_index do |e, ix|
    e.width = wid
    e.height = ht 
    e.row    = srow
    e.col    = scol
    srow += ht + 1
    @hlines << [ srow-1, scol ]
  end
  # FIXME there will be one additional hline in the end.
  w[-1].height -= (num-1)
end
Also aliased as: stack
fill(w) click to toggle source
Fill out a single widget into the entire box leaving an inset of 1.
@param [Widget]

NOTE: use if only one widget will expand into this box

# File lib/umbra/box.rb, line 111
def fill w
  # should have been nice if I could add widget to form, but then order might get wrong
  w.row = self.row + 1
  w.col = self.col + 1
  if w.respond_to? :width
    if @width < 0
      w.width = @width - 1   ## relative to bottom
    else
      w.width = @width - 2   ## absolute
    end
  end
  if w.respond_to? :height
    if @height < 0
      w.height = @height - 1   ## relative to bottom
    else
      w.height = @height - 2   ## absolute
    end
  end
  @widget = w
end
flow(*w) click to toggle source
 Horizontally place an array of widgets 
@param w [Array<Widget>] comma separated list of widgets
@note  this is best used for widgets that can be resized.

Prefer not to use for buttons since the looks gets messed (inconsistency between button and highlight). Therefore now, button calculates its own width which means that this program cannot determine what the width is and thus cannot center it.

# File lib/umbra/box.rb, line 85
def flow *w
  @widgets = w
  num = w.size
  wid = (@int_width / num).floor    ## FIXME how to recalc this if RESIZE
  ht  = @int_height 
  srow = self.row + 1
  scol = self.col + 1
  w.each_with_index do |e, ix|
    # unfortunately this is messing with button width calculation
    # maybe field and button should have resizable or expandable ?
    e.width = wid unless e.width
    e.height = ht 
    e.row    = srow
    e.col    = scol
    scol += wid + 1
    #@hlines << [ srow-1, scol ]
  end
  # FIXME there will be one additional hline in the end.
  # we added 1 to the scol each time, so decrement
  w[-1].width -= (num-1)
end
hline(row, col) click to toggle source

Paint a horizontal line, as a separator between widgets Called by `repaint`. @param row [Integer] row @param col [Integer] column

# File lib/umbra/box.rb, line 136
def hline row, col
  return if row >= self.row + self.height
  $log.debug "  hline: #{row} ... #{@row}   #{@height}  "
  FFI::NCurses.mvwhline( @graphic.pointer, row, col, FFI::NCurses::ACS_HLINE, self.width()-2)
end
stack(*w)
Alias for: add

Private Instance Methods

print_border(row, col, height, width, color, att=FFI::NCurses::A_NORMAL) click to toggle source
print_title(stitle) click to toggle source

print a title over the box on zeroth row