add BufferWidget#initialize, #render, add a BufferWidget to Window
This commit is contained in:
parent
8c8cae552c
commit
0244338e94
@ -1,5 +1,18 @@
|
||||
require "widget"
|
||||
|
||||
class BufferWidget
|
||||
|
||||
include Widget
|
||||
|
||||
def initialize(buffer, font)
|
||||
@buffer = buffer
|
||||
@font = font
|
||||
end
|
||||
|
||||
def render
|
||||
(0...@buffer.size).each do |i|
|
||||
draw_text(@font, 0, @height - @font.line_height * (i + 1), @buffer[i], 1, 1, 1, 1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -20,6 +20,8 @@ class Window
|
||||
def initialize
|
||||
Window.register(self)
|
||||
super
|
||||
@font = Font.new(Runtime.find(:font, "DejaVuSansMono"), 20)
|
||||
@buffer_widget = BufferWidget.new(Buffer.new, @font)
|
||||
end
|
||||
|
||||
def close
|
||||
@ -27,6 +29,12 @@ class Window
|
||||
end
|
||||
|
||||
def render
|
||||
@buffer_widget.draw
|
||||
end
|
||||
|
||||
def resize(x, y, width, height)
|
||||
super
|
||||
@buffer_widget.resize(x, y, width, height)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user