Class: Tuile::Component::Tabs::Tab
- Inherits:
-
Object
- Object
- Tuile::Component::Tabs::Tab
- Defined in:
- lib/tuile/component/tabs.rb,
sig/tuile.rbs
Overview
A single tab: a caption, plus its identity on the strip.
tab = tabs.add_tab("Payment")
tab.caption = "Payment ⚠" # repaints the strip
tab.remove # `tab` now raises on every mutator
Apps don't construct tabs; #add_tab mints them. A removed handle raises RuntimeError on every mutator and on every reader that consults the strip — answering confidently about a tab the strip no longer holds would hide the bug. #caption and #attached? stay readable (the caption lives here, so an error message can still name it), and #remove is a silent no-op so a cleanup path can call it blindly.
Instance Attribute Summary collapse
-
#caption ⇒ StyledString, ...
@return — the label painted on the strip.
Instance Method Summary collapse
-
#attached? ⇒ Boolean
@return —
truewhile the tab is owned by its Tuile::Component::Tabs;falsepermanently once removed. - #check_attached ⇒ void
- #detach ⇒ void
-
#initialize(strip, caption) ⇒ Tab
constructor
@param
strip— the owning strip. - #inspect ⇒ String
-
#remove ⇒ void
Removes this tab from its strip and detaches the handle permanently — #remove_tab has what that does to the selection.
-
#selected? ⇒ Boolean
@return — whether this is the strip's selected tab.
Constructor Details
#initialize(strip, caption) ⇒ Tab
@param strip — the owning strip.
@param caption — already coerced by the caller.
79 80 81 82 |
# File 'lib/tuile/component/tabs.rb', line 79 def initialize(strip, caption) @strip = strip @caption = caption end |
Instance Attribute Details
#caption ⇒ StyledString, ...
@return — the label painted on the strip. Safe to read on a removed tab.
88 89 90 |
# File 'lib/tuile/component/tabs.rb', line 88 def caption @caption end |
Instance Method Details
#attached? ⇒ Boolean
@return — true while the tab is owned by its Tuile::Component::Tabs; false
permanently once removed.
109 |
# File 'lib/tuile/component/tabs.rb', line 109 def attached? = !@strip.nil? |
#check_attached ⇒ void
This method returns an undefined value.
140 141 142 |
# File 'lib/tuile/component/tabs.rb', line 140 def check_attached raise "tab has been removed" unless attached? end |
#detach ⇒ void
This method returns an undefined value.
134 135 136 |
# File 'lib/tuile/component/tabs.rb', line 134 def detach @strip = nil end |
#inspect ⇒ String
129 |
# File 'lib/tuile/component/tabs.rb', line 129 def inspect = "#<#{self.class.name} #{caption.to_s.inspect}#{attached? ? "" : " (removed)"}>" |
#remove ⇒ void
This method returns an undefined value.
Removes this tab from its strip and detaches the handle permanently — Tuile::Component::Tabs#remove_tab has what that does to the selection. Idempotent on an already-removed tab, unlike the mutators.
122 123 124 125 126 |
# File 'lib/tuile/component/tabs.rb', line 122 def remove return unless attached? @strip.remove_tab(self) end |
#selected? ⇒ Boolean
@return — whether this is the strip's selected tab.
113 114 115 116 |
# File 'lib/tuile/component/tabs.rb', line 113 def selected? check_attached @strip.selected.equal?(self) end |