Class: Hokusai::Blocks::Panel

Inherits:
Hokusai::Block show all
Defined in:
ui/src/hokusai/blocks/panel.rb

Instance Attribute Summary collapse

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

Methods inherited from Hokusai::Block

#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

#initialize(**args) ⇒ Panel

Returns a new instance of Panel.



45
46
47
48
49
50
51
52
53
54
55
# File 'ui/src/hokusai/blocks/panel.rb', line 45

def initialize(**args)
  @top = nil
  @panel_height = 0.0
  @scroll_y = 0.0
  @scroll_percent = 0.0
  @scroll_goto_y = nil
  @clipped_offset = 0.0
  @clipped_content_height = 0.0

  super(**args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Attribute Details

#clipped_content_heightObject

Returns the value of attribute clipped_content_height.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def clipped_content_height
  @clipped_content_height
end

#clipped_offsetObject

Returns the value of attribute clipped_offset.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def clipped_offset
  @clipped_offset
end

#panel_heightObject

Returns the value of attribute panel_height.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def panel_height
  @panel_height
end

#scroll_goto_yObject

Returns the value of attribute scroll_goto_y.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def scroll_goto_y
  @scroll_goto_y
end

#scroll_percentObject

Returns the value of attribute scroll_percent.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def scroll_percent
  @scroll_percent
end

#scroll_yObject

Returns the value of attribute scroll_y.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def scroll_y
  @scroll_y
end

#topObject

Returns the value of attribute top.



42
43
44
# File 'ui/src/hokusai/blocks/panel.rb', line 42

def top
  @top
end

Instance Method Details

#content_heightObject



88
89
90
# File 'ui/src/hokusai/blocks/panel.rb', line 88

def content_height
  clipped_content_height
end

#offsetObject



84
85
86
# File 'ui/src/hokusai/blocks/panel.rb', line 84

def offset
  ((panel_content_height * scroll_percent) - (panel_height * scroll_percent))
end

#panel_content_heightObject



92
93
94
# File 'ui/src/hokusai/blocks/panel.rb', line 92

def panel_content_height
  clipped_content_height < panel_height ? panel_height : clipped_content_height
end

#panel_topObject



73
74
75
# File 'ui/src/hokusai/blocks/panel.rb', line 73

def panel_top
  top || 0.0
end

#render(canvas) {|canvas| ... } ⇒ Object

Yields:

  • (canvas)


120
121
122
123
124
125
# File 'ui/src/hokusai/blocks/panel.rb', line 120

def render(canvas)
  self.top = canvas.y
  self.panel_height = canvas.height

  yield canvas
end

#scroll_activeObject



96
97
98
# File 'ui/src/hokusai/blocks/panel.rb', line 96

def scroll_active
  clipped_content_height > panel_height
end

#scroll_complete(y, percent:) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'ui/src/hokusai/blocks/panel.rb', line 100

def scroll_complete(y, percent:)
  self.scroll_y = y
  self.scroll_percent = percent
  self.scroll_goto_y = nil

  # todo handle selection

  emit("scroll", y, percent: percent)
end

#scroll_control_heightObject



114
115
116
117
118
# File 'ui/src/hokusai/blocks/panel.rb', line 114

def scroll_control_height
  return 20.0 if panel_height <= 0.0

  (panel_height / panel_content_height) * panel_height
end

#scrollbar_gotoObject



110
111
112
# File 'ui/src/hokusai/blocks/panel.rb', line 110

def scrollbar_goto
  scroll_goto_y || scroll_goto
end

#set_size(_, height) ⇒ Object



77
78
79
80
81
82
# File 'ui/src/hokusai/blocks/panel.rb', line 77

def set_size(_, height)
  if panel_height != clipped_content_height || clipped_content_height.zero?
    self.clipped_content_height = height
    # self.scroll_goto_y = self.scroll_y unless scroll_y == top
  end
end

#wheel_handle(event) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'ui/src/hokusai/blocks/panel.rb', line 57

def wheel_handle(event)
  return if clipped_content_height <= panel_height

  new_scroll_y = scroll_y + event.scroll * 20

  if y = top
    if new_scroll_y < y
      self.scroll_goto_y = y
    elsif new_scroll_y > panel_height
      self.scroll_goto_y = panel_height
    else
      self.scroll_goto_y = new_scroll_y
    end
  end
end