Archived
1
0
Fork 0

Add class Curses::React::Nodes::Line

This commit is contained in:
Braiden Vasco 2017-07-28 11:32:52 +00:00
parent b4ac850343
commit 3a8bbdbe3a
3 changed files with 47 additions and 17 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'curses/react/nodes/text_line'
require 'curses/react/nodes/line'
module Curses
module React
@ -10,6 +11,7 @@ module Curses
case element.type
when :text_line then TextLine.new element, window
when :line then Line.new element, window
else
raise "unknown element type: #{element.type.inspect}"
end

View file

@ -0,0 +1,28 @@
# frozen_string_literal: true
module Curses
module React
module Nodes
class Line
def initialize(element, window)
@element = element
@window = window
end
def props
@element.all_props
end
def draw
children.each(&:draw)
end
def children
props[:children].map do |child_element|
Nodes.create child_element, @window
end
end
end
end
end
end

View file

@ -44,24 +44,24 @@ module Widgets
def render_public_key
Curses::React::Nodes.create(
Curses::React::Element.create(
:text_line,
x: 0,
y: 1,
width: PUBLIC_KEY_LABEL.length,
text: PUBLIC_KEY_LABEL,
),
window,
).draw
Curses::React::Element.create(:line) do
Curses::React::Element.create(
:text_line,
x: 0,
y: 1,
width: PUBLIC_KEY_LABEL.length,
text: PUBLIC_KEY_LABEL,
)
Curses::React::Element.create(
:text_line,
x: PUBLIC_KEY_LABEL.length,
y: 1,
width: props[:width] - PUBLIC_KEY_LABEL.length,
text: props[:public_key],
)
end,
Curses::React::Nodes.create(
Curses::React::Element.create(
:text_line,
x: PUBLIC_KEY_LABEL.length,
y: 1,
width: props[:width] - PUBLIC_KEY_LABEL.length,
text: props[:public_key],
),
window,
).draw
end