Class: Potty::Widgets::StatusBar
- Defined in:
- lib/potty/widgets/status_bar.rb
Overview
Status bar at bottom of screen
Instance Attribute Summary collapse
-
#center_text ⇒ Object
Returns the value of attribute center_text.
-
#left_text ⇒ Object
Returns the value of attribute left_text.
-
#right_text ⇒ Object
Returns the value of attribute right_text.
Attributes inherited from Base
#app, #focused, #parent, #rect
Instance Method Summary collapse
-
#initialize(app) ⇒ StatusBar
constructor
A new instance of StatusBar.
- #preferred_height(width) ⇒ Object
- #render(window) ⇒ Object
Methods inherited from Base
#activate, #blur, #can_focus?, #deactivate, #focus, #handle_escape, #handle_key, #hide, #layout, #on_blur, #on_focus, #on_layout, #show, #theme, #tick, #visible=, #visible?
Methods included from Events
#emit, #listeners?, #off, #on
Constructor Details
#initialize(app) ⇒ StatusBar
Returns a new instance of StatusBar.
11 12 13 14 15 16 |
# File 'lib/potty/widgets/status_bar.rb', line 11 def initialize(app) super @left_text = "" @center_text = "" @right_text = "" end |
Instance Attribute Details
#center_text ⇒ Object
Returns the value of attribute center_text.
9 10 11 |
# File 'lib/potty/widgets/status_bar.rb', line 9 def center_text @center_text end |
#left_text ⇒ Object
Returns the value of attribute left_text.
9 10 11 |
# File 'lib/potty/widgets/status_bar.rb', line 9 def left_text @left_text end |
#right_text ⇒ Object
Returns the value of attribute right_text.
9 10 11 |
# File 'lib/potty/widgets/status_bar.rb', line 9 def right_text @right_text end |
Instance Method Details
#preferred_height(width) ⇒ Object
18 19 20 |
# File 'lib/potty/widgets/status_bar.rb', line 18 def preferred_height(width) 1 end |
#render(window) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/potty/widgets/status_bar.rb', line 22 def render(window) return unless @rect window.setpos(@rect.y, @rect.x) window.attron(theme[:status]) do # Clear line with background color window.addstr(" " * @rect.width) # Left-aligned if @left_text && !@left_text.empty? window.setpos(@rect.y, @rect.x) max_left = @rect.width / 3 window.addstr(@left_text[0, max_left]) end # Center-aligned if @center_text && !@center_text.empty? center_x = @rect.x + (@rect.width - @center_text.length) / 2 center_x = [center_x, @rect.x].max window.setpos(@rect.y, center_x) window.addstr(@center_text[0, @rect.width]) end # Right-aligned if @right_text && !@right_text.empty? right_x = @rect.x + @rect.width - @right_text.length right_x = [right_x, @rect.x].max window.setpos(@rect.y, right_x) window.addstr(@right_text) end end end |