Class: Fidgit::ScrollArea

Inherits:
Container show all
Defined in:
lib/fidgit/elements/scroll_area.rb

Overview

A basic scrolling area. It is not managed in any way (use ScrollWindow for that).

Constant Summary

Constants inherited from Element

Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V

Instance Attribute Summary collapse

Attributes inherited from Element

#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z

Instance Method Summary collapse

Methods inherited from Container

#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree, #x=, #y=

Methods inherited from Element

#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=

Methods included from Event

#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe

Constructor Details

#initialize(options = {}) ⇒ ScrollArea

Returns a new instance of ScrollArea.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :offset (Number) — default: 0
  • :offset_x (Number) — default: value of :offset option
  • :offset_y (Number) — default: value of :offset option
  • :owner (Element)

    The owner of the content, such as the scroll-window containing the content.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fidgit/elements/scroll_area.rb', line 24

def initialize(options = {})
  options = {
    offset: 0,
    owner: nil,
  }.merge! options

  @owner = options[:owner]

  super(options)

  @content = Vertical.new(parent: self, padding: 0)

  self.offset_x = options[:offset_x] || options[:offset]
  self.offset_y = options[:offset_y] || options[:offset]
end

Instance Attribute Details

#contentVertical (readonly)

Returns The content shown within this ScrollArea.

Returns:

  • (Vertical)

    The content shown within this ScrollArea



7
8
9
# File 'lib/fidgit/elements/scroll_area.rb', line 7

def content
  @content
end

Instance Method Details

#hit_element(x, y) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/fidgit/elements/scroll_area.rb', line 40

def hit_element(x, y)
  # Only pass on mouse events if they are inside the window.
  if hit?(x, y)
    @content.hit_element(x, y) || self
  else
    nil
  end
end

#offset_xObject



9
# File 'lib/fidgit/elements/scroll_area.rb', line 9

def offset_x; x - @content.x; end

#offset_x=(value) ⇒ Object



12
13
14
# File 'lib/fidgit/elements/scroll_area.rb', line 12

def offset_x=(value)
  @content.x = x - [[@content.width - width, value].min, 0].max
end

#offset_yObject



10
# File 'lib/fidgit/elements/scroll_area.rb', line 10

def offset_y; y - @content.y; end

#offset_y=(value) ⇒ Object



16
17
18
# File 'lib/fidgit/elements/scroll_area.rb', line 16

def offset_y=(value)
  @content.y = y - [[@content.height - height, value].min, 0].max
end

#recalcObject



49
50
51
52
53
54
# File 'lib/fidgit/elements/scroll_area.rb', line 49

def recalc
  super
  # Always recalc our owner if our content resizes, even though our size can't change even if the content changes
  # (may encourage ScrollWindow to show/hide scroll-bars, for example)
  @owner.recalc if @owner
end