Class: Tuile::Component::Tabs::Tab

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(strip, caption) ⇒ Tab

@param strip — the owning strip.

@param caption — already coerced by the caller.

Parameters:



79
80
81
82
# File 'lib/tuile/component/tabs.rb', line 79

def initialize(strip, caption)
  @strip = strip
  @caption = caption
end

Instance Attribute Details

#captionStyledString, ...

@return — the label painted on the strip. Safe to read on a removed tab.

Returns:



88
89
90
# File 'lib/tuile/component/tabs.rb', line 88

def caption
  @caption
end

Instance Method Details

#attached?Boolean

@returntrue while the tab is owned by its Tuile::Component::Tabs; false permanently once removed.

Returns:

  • (Boolean)


109
# File 'lib/tuile/component/tabs.rb', line 109

def attached? = !@strip.nil?

#check_attachedvoid

This method returns an undefined value.

Raises:

  • (RuntimeError)

    when the tab has been removed.



140
141
142
# File 'lib/tuile/component/tabs.rb', line 140

def check_attached
  raise "tab has been removed" unless attached?
end

#detachvoid

This method returns an undefined value.



134
135
136
# File 'lib/tuile/component/tabs.rb', line 134

def detach
  @strip = nil
end

#inspectString

Returns:

  • (String)


129
# File 'lib/tuile/component/tabs.rb', line 129

def inspect = "#<#{self.class.name} #{caption.to_s.inspect}#{attached? ? "" : " (removed)"}>"

#removevoid

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.

Returns:

  • (Boolean)


113
114
115
116
# File 'lib/tuile/component/tabs.rb', line 113

def selected?
  check_attached
  @strip.selected.equal?(self)
end