|
|
@@ -21,12 +21,12 @@ type Widget struct {
|
|
|
screen types.IScreen
|
|
|
pos types.IPos
|
|
|
size types.ISize
|
|
|
- lstCell []types.ICell
|
|
|
+ bufCell []types.ICell
|
|
|
bgColor types.IColor
|
|
|
fgColor types.IColor
|
|
|
isVisible types.ISafeBool
|
|
|
style alias.Style
|
|
|
- lit rune
|
|
|
+ lit alias.Lit
|
|
|
}
|
|
|
|
|
|
// NewWidget -- возвращает новый виджет
|
|
|
@@ -39,15 +39,18 @@ func NewWidget(screen types.IScreen) (*Widget, error) {
|
|
|
screen: screen,
|
|
|
pos: pos.NewPos(),
|
|
|
size: size.NewSize(),
|
|
|
- lstCell: make([]types.ICell, 0),
|
|
|
+ bufCell: make([]types.ICell, 0),
|
|
|
bgColor: color.NewColor(),
|
|
|
fgColor: color.NewColor(),
|
|
|
isVisible: safe_bool.NewSafeBool(),
|
|
|
style: 0,
|
|
|
- lit: []rune(" ")[0],
|
|
|
+ lit: alias.Lit([]rune(" ")[0]),
|
|
|
}
|
|
|
+ sf.bgColor.Set(0,0,255)
|
|
|
+ sf.fgColor.Set(0,0,255)
|
|
|
color := tcell.Color(sf.bgColor.Get())
|
|
|
sf.style = alias.Style(tcell.StyleDefault.Background(color))
|
|
|
+ sf.Resize(15, 5)
|
|
|
return sf, nil
|
|
|
}
|
|
|
|
|
|
@@ -56,8 +59,8 @@ func (sf *Widget) Draw() {
|
|
|
if !sf.isVisible.Get() {
|
|
|
return
|
|
|
}
|
|
|
- for _, cell := range sf.lstCell {
|
|
|
- sf.screen.Set(cell)
|
|
|
+ for _, cell := range sf.bufCell {
|
|
|
+ sf.screen.SetCell(cell)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -83,14 +86,35 @@ func (sf *Widget) Resize(sizeX alias.SizeX, sizeY alias.SizeY) {
|
|
|
return
|
|
|
}
|
|
|
sf.size.Set(sizeX, sizeY)
|
|
|
- for len(sf.lstCell) < int(sizeX)*int(sizeY) {
|
|
|
- cell := cell.NewCell()
|
|
|
- cell.SetStyle(sf.style)
|
|
|
- sf.lstCell = append(sf.lstCell, cell)
|
|
|
+ posX, posY := sf.pos.Get()
|
|
|
+ bufCellNew := make([]types.ICell, 0)
|
|
|
+ lenBuf := len(sf.bufCell)
|
|
|
+ for dx := alias.PosX(0); dx < alias.PosX(sizeX); dx++ {
|
|
|
+ for dy := alias.PosY(0); dy < alias.PosY(sizeY); dy++ {
|
|
|
+ ind := int(dx) * int(dy)
|
|
|
+ var cell_ types.ICell
|
|
|
+ if lenBuf != 0 && lenBuf > ind {
|
|
|
+ cell_ = sf.bufCell[ind]
|
|
|
+ } else {
|
|
|
+ cell_ = cell.NewCell()
|
|
|
+ cell_.SetStyle(sf.style)
|
|
|
+ cell_.BgColorSet(sf.bgColor.Get())
|
|
|
+ cell_.FgColorSet(sf.FgColor().Get())
|
|
|
+ cell_.SetLit(sf.lit)
|
|
|
+ }
|
|
|
+ cell_.SetPos(dx+posX, dy+posY)
|
|
|
+ bufCellNew = append(bufCellNew, cell_)
|
|
|
+ }
|
|
|
}
|
|
|
+ sf.bufCell = bufCellNew
|
|
|
}
|
|
|
|
|
|
// Pos -- возвращает размера виджета
|
|
|
func (sf *Widget) Pos() (alias.PosX, alias.PosY) {
|
|
|
return sf.pos.Get()
|
|
|
}
|
|
|
+
|
|
|
+// SetPos -- устанавливает позицию виджета на экране
|
|
|
+func (sf *Widget) SetPos(posX alias.PosX, posY alias.PosY) {
|
|
|
+ sf.pos.Set(posX, posY)
|
|
|
+}
|