Archived
1
0
Fork 0

Render Curses::Window with props

This commit is contained in:
Braiden Vasco 2017-07-25 14:29:01 +00:00
parent 9eb51dbc23
commit 71776fcafb
7 changed files with 54 additions and 48 deletions

View file

@ -71,10 +71,17 @@ private
focus: :menu,
focused: true,
menu: {
logo: {
x: 0,
y: 0,
width: Widgets::Logo::WIDTH,
height: Widgets::Logo::HEIGHT,
}.freeze,
menu: {
x: 0,
y: Widgets::Logo::HEIGHT,
width: Widgets::Logo::WIDTH,
height: Curses.stdscr.maxy - Widgets::Logo::HEIGHT,
focused: true,
@ -90,7 +97,7 @@ private
}.freeze,
chat: {
x: 0,
x: Widgets::Logo::WIDTH,
y: 0,
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH,
height: Curses.stdscr.maxy,
@ -98,7 +105,7 @@ private
focused: false,
info: {
x: 0,
x: Widgets::Logo::WIDTH,
y: 0,
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH,
height: 2,
@ -109,10 +116,10 @@ private
}.freeze,
new_message: {
x: 0,
y: 0,
x: Widgets::Logo::WIDTH,
y: Curses.stdscr.maxy - 1,
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH,
height: Curses.stdscr.maxy - 3,
height: 1,
focused: false,
text: '',
@ -120,10 +127,10 @@ private
}.freeze,
history: {
x: 0,
y: 0,
x: Widgets::Logo::WIDTH,
y: 2,
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH,
height: 1,
height: Curses.stdscr.maxy - 3,
focused: true,
messages: 1.upto(100).map do

View file

@ -35,13 +35,7 @@ class Screen
Curses.timeout = 0 # non-blocking input
Curses.stdscr.keypad = true
@window ||= Widgets::Main.new(
nil,
0,
0,
Curses.stdscr.maxx,
Curses.stdscr.maxy,
)
@window ||= Widgets::Main.new nil
end
def close

View file

@ -3,29 +3,45 @@
module Widgets
class Base
attr_reader :parent
attr_reader :window
attr_reader :width, :height
attr_reader :props
def initialize(parent, x, y, width, height)
def initialize(parent)
@parent = parent
@window = parent ? parent.window.subwin(height, width, y, x) : Curses.stdscr
@width = width
@height = height
@props = {}.freeze
end
def window
@window ||= parent ? parent.window.subwin(height, width, y, x) : Curses.stdscr
end
def trigger(event); end
def props=(value)
raise TypeError, "expected props to be a #{Hash}" unless value.is_a? Hash
raise ArgumentError, 'expected props to be frozen' unless value.frozen?
@window = nil if props[:x] != value[:x] || props[:y] != value[:y] ||
props[:width] != value[:width] || props[:height] != value[:height]
@props = value
end
def x
props[:x]
end
def y
props[:y]
end
def width
props[:width]
end
def height
props[:height]
end
def focused
props[:focused]
end

View file

@ -2,20 +2,12 @@
module Widgets
class Chat < VPanel
def initialize(parent, x, y, width, height)
def initialize(_parent)
super
info_height = 2
message_height = 1
history_height = height - info_height - message_height
info_top = 0
history_top = info_height
message_top = info_height + history_height
@info = Info.new self, x, y + info_top, width, info_height
@history = History.new self, x, y + history_top, width, history_height
@message = NewMessage.new self, x, y + message_top, width, message_height
@info = Info.new self
@history = History.new self
@message = NewMessage.new self
end
def props=(_value)

View file

@ -16,10 +16,6 @@ module Widgets
WIDTH = LOGO.first.length
HEIGHT = LOGO.length
def initialize(parent, x, y, _width, _height)
super parent, x, y, WIDTH, HEIGHT
end
def draw
Style.default.logo window do
LOGO.each_with_index do |s, index|

View file

@ -2,11 +2,11 @@
module Widgets
class Main < Container
def initialize(parent, x, y, width, height)
def initialize(_parent)
super
@sidebar = Widgets::Sidebar.new self, x, y, nil, height
@chat = Widgets::Chat.new self, x + @sidebar.width, y, width - @sidebar.width, height
@sidebar = Widgets::Sidebar.new self
@chat = Widgets::Chat.new self
end
def focus

View file

@ -2,11 +2,11 @@
module Widgets
class Sidebar < Container
def initialize(parent, x, y, _width, height)
super parent, x, y, Logo::WIDTH, height
def initialize(_parent)
super
@logo = Logo.new self, x, y, nil, nil
@menu = Menu.new self, x, @logo.height, @logo.width, height - @logo.height
@logo = Logo.new self
@menu = Menu.new self
end
def focus
@ -18,6 +18,7 @@ module Widgets
def props=(_value)
super
@logo.props = props[:logo]
@menu.props = props[:menu]
end