|
@@ -7,8 +7,9 @@ import (
|
|
|
"github.com/gdamore/tcell"
|
|
"github.com/gdamore/tcell"
|
|
|
|
|
|
|
|
"p78git.ddns.net/svi/libtui/alias"
|
|
"p78git.ddns.net/svi/libtui/alias"
|
|
|
- "p78git.ddns.net/svi/libtui/cell"
|
|
|
|
|
"p78git.ddns.net/svi/libtui/color"
|
|
"p78git.ddns.net/svi/libtui/color"
|
|
|
|
|
+ "p78git.ddns.net/svi/libtui/line_cell"
|
|
|
|
|
+ "p78git.ddns.net/svi/libtui/line_cell/cell"
|
|
|
"p78git.ddns.net/svi/libtui/pos"
|
|
"p78git.ddns.net/svi/libtui/pos"
|
|
|
"p78git.ddns.net/svi/libtui/safe_bool"
|
|
"p78git.ddns.net/svi/libtui/safe_bool"
|
|
|
"p78git.ddns.net/svi/libtui/size"
|
|
"p78git.ddns.net/svi/libtui/size"
|
|
@@ -21,12 +22,13 @@ type Widget struct {
|
|
|
screen types.IScreen
|
|
screen types.IScreen
|
|
|
pos types.IPos
|
|
pos types.IPos
|
|
|
size types.ISize
|
|
size types.ISize
|
|
|
- bufCell []types.ICell
|
|
|
|
|
|
|
+ bufLine []*line_cell.LineCell
|
|
|
bgColor types.IColor
|
|
bgColor types.IColor
|
|
|
fgColor types.IColor
|
|
fgColor types.IColor
|
|
|
isVisible types.ISafeBool
|
|
isVisible types.ISafeBool
|
|
|
style alias.Style
|
|
style alias.Style
|
|
|
lit alias.Lit
|
|
lit alias.Lit
|
|
|
|
|
+ isWisible types.ISafeBool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NewWidget -- возвращает новый виджет
|
|
// NewWidget -- возвращает новый виджет
|
|
@@ -39,18 +41,20 @@ func NewWidget(screen types.IScreen) (*Widget, error) {
|
|
|
screen: screen,
|
|
screen: screen,
|
|
|
pos: pos.NewPos(),
|
|
pos: pos.NewPos(),
|
|
|
size: size.NewSize(),
|
|
size: size.NewSize(),
|
|
|
- bufCell: make([]types.ICell, 0),
|
|
|
|
|
|
|
+ bufLine: make([]*line_cell.LineCell, 0),
|
|
|
bgColor: color.NewColor(),
|
|
bgColor: color.NewColor(),
|
|
|
fgColor: color.NewColor(),
|
|
fgColor: color.NewColor(),
|
|
|
isVisible: safe_bool.NewSafeBool(),
|
|
isVisible: safe_bool.NewSafeBool(),
|
|
|
style: 0,
|
|
style: 0,
|
|
|
- lit: alias.Lit([]rune(" ")[0]),
|
|
|
|
|
|
|
+ lit: alias.Lit([]rune("d")[0]),
|
|
|
|
|
+ isWisible: safe_bool.NewSafeBool(),
|
|
|
}
|
|
}
|
|
|
- sf.bgColor.Set(0,0,255)
|
|
|
|
|
- sf.fgColor.Set(0,0,255)
|
|
|
|
|
|
|
+ sf.bgColor.Set(0, 0, 255)
|
|
|
|
|
+ sf.fgColor.Set(0, 255, 0)
|
|
|
color := tcell.Color(sf.bgColor.Get())
|
|
color := tcell.Color(sf.bgColor.Get())
|
|
|
- sf.style = alias.Style(tcell.StyleDefault.Background(color))
|
|
|
|
|
|
|
+ sf.style = alias.Style(tcell.StyleDefault.Background(color).Foreground(tcell.Color(sf.fgColor.Get())))
|
|
|
sf.Resize(15, 5)
|
|
sf.Resize(15, 5)
|
|
|
|
|
+ sf.isVisible.Set()
|
|
|
return sf, nil
|
|
return sf, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -59,9 +63,23 @@ func (sf *Widget) Draw() {
|
|
|
if !sf.isVisible.Get() {
|
|
if !sf.isVisible.Get() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- for _, cell := range sf.bufCell {
|
|
|
|
|
- sf.screen.SetCell(cell)
|
|
|
|
|
|
|
+ for _, line := range sf.bufLine {
|
|
|
|
|
+ line.Draw()
|
|
|
}
|
|
}
|
|
|
|
|
+ /*
|
|
|
|
|
+ cell := cell.NewCell()
|
|
|
|
|
+ cell.SetLit(alias.Lit([]rune("=")[0]))
|
|
|
|
|
+ st0 := tcell.StyleDefault
|
|
|
|
|
+ st0 = st0.Background(tcell.ColorBlue).Foreground(tcell.ColorYellow)
|
|
|
|
|
+ scr := sf.app.Scr()
|
|
|
|
|
+ x0, y0 := sf.Pos()
|
|
|
|
|
+ for x := x0; x < x0+20; x++ {
|
|
|
|
|
+ for y := y0; y < y0+5; y++ {
|
|
|
|
|
+ // cell.SetPos(x, y)
|
|
|
|
|
+ scr.SetCell(int(x), int(y), st0, []rune("`")[0])
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ */
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// FgColor -- возвращает цвет переднего фона
|
|
// FgColor -- возвращает цвет переднего фона
|
|
@@ -81,32 +99,34 @@ func (sf *Widget) Size() (alias.SizeX, alias.SizeY) {
|
|
|
|
|
|
|
|
// Resize -- изменяет размер виджета
|
|
// Resize -- изменяет размер виджета
|
|
|
func (sf *Widget) Resize(sizeX alias.SizeX, sizeY alias.SizeY) {
|
|
func (sf *Widget) Resize(sizeX alias.SizeX, sizeY alias.SizeY) {
|
|
|
- x_, y_ := sf.size.Get()
|
|
|
|
|
- if x_ == sizeX && y_ == sizeY {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
sf.size.Set(sizeX, sizeY)
|
|
sf.size.Set(sizeX, sizeY)
|
|
|
posX, posY := sf.pos.Get()
|
|
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)
|
|
|
|
|
|
|
+ bufLine := make([]*line_cell.LineCell, 0)
|
|
|
|
|
+ fnAddLine := func(_y_ alias.PosY) {
|
|
|
|
|
+ line, err := line_cell.NewLineCell(sf.app)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ sf.app.Scr().Fini()
|
|
|
|
|
+ fmt.Printf("Widget.Resize().fnAddLine(): in crete line_cell, err=\n\t%v\n", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ for dx := posX; dx < posX+alias.PosX(sizeX); dx++ {
|
|
|
|
|
+ cell_ := cell.NewCell()
|
|
|
|
|
+ cell_.SetStyle(sf.style)
|
|
|
|
|
+ cell_.BgColorSet(sf.bgColor.Get())
|
|
|
|
|
+ cell_.FgColorSet(sf.FgColor().Get())
|
|
|
|
|
+ cell_.SetLit(sf.lit)
|
|
|
|
|
+ cell_.SetPos(dx, _y_)
|
|
|
|
|
+ if err = line.AddCell(cell_); err != nil {
|
|
|
|
|
+ sf.app.Scr().Fini()
|
|
|
|
|
+ fmt.Printf("Widget.Resize().fnAddLine(): in crete cell, err=\n\t%v\n", err)
|
|
|
}
|
|
}
|
|
|
- cell_.SetPos(dx+posX, dy+posY)
|
|
|
|
|
- bufCellNew = append(bufCellNew, cell_)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ sf.bufLine = append(sf.bufLine, line)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for dy := posY; dy < posY+alias.PosY(sizeY); dy++ {
|
|
|
|
|
+ fnAddLine(dy)
|
|
|
}
|
|
}
|
|
|
- sf.bufCell = bufCellNew
|
|
|
|
|
|
|
+ sf.bufLine = bufLine
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Pos -- возвращает размера виджета
|
|
// Pos -- возвращает размера виджета
|
|
@@ -117,4 +137,22 @@ func (sf *Widget) Pos() (alias.PosX, alias.PosY) {
|
|
|
// SetPos -- устанавливает позицию виджета на экране
|
|
// SetPos -- устанавливает позицию виджета на экране
|
|
|
func (sf *Widget) SetPos(posX alias.PosX, posY alias.PosY) {
|
|
func (sf *Widget) SetPos(posX alias.PosX, posY alias.PosY) {
|
|
|
sf.pos.Set(posX, posY)
|
|
sf.pos.Set(posX, posY)
|
|
|
|
|
+ for _, line := range sf.bufLine {
|
|
|
|
|
+ line.SetPos(posX, posY)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Show -- показать виджет
|
|
|
|
|
+func (sf *Widget) Show() {
|
|
|
|
|
+ sf.isVisible.Set()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Hide -- скрывает виджет
|
|
|
|
|
+func (sf *Widget) Hide() {
|
|
|
|
|
+ sf.isVisible.Reset()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// IsVisible -- признак видимости окна
|
|
|
|
|
+func (sf *Widget) IsVisible() alias.IsVisible {
|
|
|
|
|
+ return alias.IsVisible(sf.isVisible.Get())
|
|
|
}
|
|
}
|