Class: TuiTui::FocusRing
- Inherits:
-
Object
- Object
- TuiTui::FocusRing
- Defined in:
- lib/tui_tui/focus_ring.rb
Overview
Immutable focus state for a fixed set of targets.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #focus(target) ⇒ Object
- #focused?(target) ⇒ Boolean
-
#initialize(*targets, current: nil) ⇒ FocusRing
constructor
A new instance of FocusRing.
- #next ⇒ Object
Constructor Details
#initialize(*targets, current: nil) ⇒ FocusRing
Returns a new instance of FocusRing.
8 9 10 11 12 13 |
# File 'lib/tui_tui/focus_ring.rb', line 8 def initialize(*targets, current: nil) @targets = targets.flatten.freeze raise ArgumentError, "FocusRing needs at least one target" if @targets.empty? @current = current || @targets.first end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
6 7 8 |
# File 'lib/tui_tui/focus_ring.rb', line 6 def current @current end |
Instance Method Details
#focus(target) ⇒ Object
21 22 23 |
# File 'lib/tui_tui/focus_ring.rb', line 21 def focus(target) @targets.include?(target) ? self.class.new(@targets, current: target) : self end |
#focused?(target) ⇒ Boolean
15 |
# File 'lib/tui_tui/focus_ring.rb', line 15 def focused?(target) = @current == target |
#next ⇒ Object
17 18 19 |
# File 'lib/tui_tui/focus_ring.rb', line 17 def next focus(@targets[(@targets.index(@current) + 1) % @targets.size]) end |