Some updates
This commit is contained in:
110
wdgt_buffer.go
Normal file
110
wdgt_buffer.go
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright © Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
// The Buffer widget is a widget that is manually setup by the user
|
||||
type BufferWidget struct {
|
||||
id string
|
||||
style tcell.Style
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
visible bool
|
||||
active bool
|
||||
focusable bool
|
||||
|
||||
buffer *Buffer
|
||||
|
||||
keyMap KeyMap
|
||||
|
||||
timeMap *TimeMap
|
||||
}
|
||||
|
||||
var _ Widget = (*BufferWidget)(nil)
|
||||
|
||||
func NewBufferWidget(id string, s tcell.Style) *BufferWidget {
|
||||
ret := &BufferWidget{}
|
||||
ret.Init(id, s)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (w *BufferWidget) Init(id string, s tcell.Style) {
|
||||
w.id = id
|
||||
w.style = s
|
||||
w.visible = true
|
||||
w.timeMap = BlankTimeMap()
|
||||
w.keyMap = BlankKeyMap()
|
||||
w.buffer = NewBuffer()
|
||||
}
|
||||
|
||||
func (w *BufferWidget) Id() string { return w.id }
|
||||
func (w *BufferWidget) HandleResize(ev *tcell.EventResize) {
|
||||
}
|
||||
|
||||
func (w *BufferWidget) SetKeyMap(km KeyMap, def bool) { w.keyMap = km }
|
||||
func (w *BufferWidget) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
||||
func (w *BufferWidget) RemoveFromKeyMap(km KeyMap) {
|
||||
for k := range km.Keys {
|
||||
w.keyMap.Remove(k)
|
||||
}
|
||||
for r := range km.Runes {
|
||||
w.keyMap.RemoveRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *BufferWidget) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
}
|
||||
return w.keyMap.Handle(ev)
|
||||
}
|
||||
func (w *BufferWidget) HandleTime(ev *tcell.EventTime) { w.timeMap.Handle(ev) }
|
||||
func (w *BufferWidget) Draw(screen tcell.Screen) { w.buffer.Draw(w.x, w.y, screen) }
|
||||
func (w *BufferWidget) Active() bool { return w.active }
|
||||
func (w *BufferWidget) SetActive(a bool) { w.active = a }
|
||||
func (w *BufferWidget) Visible() bool { return w.visible }
|
||||
func (w *BufferWidget) SetVisible(a bool) { w.visible = a }
|
||||
func (w *BufferWidget) Focusable() bool { return w.focusable }
|
||||
func (w *BufferWidget) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *BufferWidget) SetX(x int) { w.x = x }
|
||||
func (w *BufferWidget) SetY(y int) { w.y = y }
|
||||
func (w *BufferWidget) GetX() int { return w.x }
|
||||
func (w *BufferWidget) GetY() int { return w.y }
|
||||
func (w *BufferWidget) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *BufferWidget) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *BufferWidget) GetW() int { return w.buffer.Width() }
|
||||
func (w *BufferWidget) GetH() int { return w.buffer.Height() }
|
||||
func (w *BufferWidget) SetW(wd int) { w.w = wd }
|
||||
func (w *BufferWidget) SetH(h int) { w.h = h }
|
||||
func (w *BufferWidget) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
|
||||
func (w *BufferWidget) WantW() int { return w.buffer.Width() }
|
||||
func (w *BufferWidget) WantH() int { return w.buffer.Height() }
|
||||
|
||||
func (w *BufferWidget) MinW() int { return w.buffer.Width() }
|
||||
func (w *BufferWidget) MinH() int { return w.buffer.Height() }
|
||||
|
||||
func (w *BufferWidget) GetBuffer() *Buffer { return w.buffer }
|
||||
Reference in New Issue
Block a user