Class: Bureau::Bureau

Inherits:
UIViewController
  • Object
show all
Defined in:
lib/bureau/bureau.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bureau_sections, options = {}) ⇒ Bureau

Returns a new instance of Bureau.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bureau/bureau.rb', line 7

def initialize(bureau_sections, options = {})
  setup_bureau_table
  @state = options[:state] || :closed
  @drawer_width = options[:drawer_width] || 250
  @drawer_height = options[:drawer_height] || 44
  @slide_duration = options[:slide_duration] || 0.3
  @bureau_sections = bureau_sections
  initialize_controllers
  update_active_controller
  init
end

Instance Attribute Details

#active_controllerObject

Returns the value of attribute active_controller.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def active_controller
  @active_controller
end

#active_view_originObject

Returns the value of attribute active_view_origin.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def active_view_origin
  @active_view_origin
end

#bureau_sectionsObject

Returns the value of attribute bureau_sections.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def bureau_sections
  @bureau_sections
end

#bureau_tableObject

Returns the value of attribute bureau_table.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def bureau_table
  @bureau_table
end

#drawer_heightObject

Returns the value of attribute drawer_height.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def drawer_height
  @drawer_height
end

#drawer_widthObject

Returns the value of attribute drawer_width.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def drawer_width
  @drawer_width
end

#reuse_idObject

Returns the value of attribute reuse_id.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def reuse_id
  @reuse_id
end

#slide_durationObject

Returns the value of attribute slide_duration.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def slide_duration
  @slide_duration
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/bureau/bureau.rb', line 3

def state
  @state
end

Instance Method Details

#closeObject



33
34
35
36
37
38
# File 'lib/bureau/bureau.rb', line 33

def close
  UIView.animateWithDuration(@slide_duration, delay:0, options:0, animations: lambda do
    @active_controller.view.frame = @active_controller.view.frame.left(@drawer_width)
  end, completion: nil)
  @state = :closed
end

#numberOfSectionsInTableView(table_view) ⇒ Object



109
110
111
# File 'lib/bureau/bureau.rb', line 109

def numberOfSectionsInTableView(table_view)
  @bureau_sections.count
end

#openObject



40
41
42
43
44
45
# File 'lib/bureau/bureau.rb', line 40

def open
  UIView.animateWithDuration(@slide_duration, delay:0, options:0, animations: lambda do
    @active_controller.view.frame = @active_controller.view.frame.right(@drawer_width)
  end, completion: nil)
  @state = :open
end

#section(section, header: header) ⇒ Object

stubbed for menu customization in a subclass:



163
164
165
# File 'lib/bureau/bureau.rb', line 163

def section(section, row:row, cell:cell)
  cell
end

#tableView(table_view, heightForRowAtIndexPath: index_path) ⇒ Object

def tableView(table_view, viewForHeaderInSection: section)

puts "getting header for section #{section}"
header = UIView.alloc.init.tap do |view|
  view.backgroundColor = :blue.uicolor
  view.frame = [[0,0], [320,60]]
  view << UILabel.alloc.init.tap do |label|
    label.text = @bureau_sections[section][:title]
    label.frame = [[15,4], [74,17]]
  end
end
section(section, header:header)

end



134
135
136
# File 'lib/bureau/bureau.rb', line 134

def tableView(table_view, numberOfRowsInSection:section)
  @bureau_sections[section].count
end

#toggleObject



25
26
27
28
29
30
31
# File 'lib/bureau/bureau.rb', line 25

def toggle
  if @state == :open
    close
  else
    open
  end
end

#viewDidLoadObject



19
20
21
22
23
# File 'lib/bureau/bureau.rb', line 19

def viewDidLoad
  super
  view.backgroundColor = UIColor.whiteColor
  view.addSubview(@bureau_sections_table.tableView)
end