Просмотр исходного кода

Внесение правок в код

SVI 3 лет назад
Родитель
Сommit
24c5b0a085

+ 1 - 1
libtui/v0/screen/scr_cursor/scr_cursor.go

@@ -30,7 +30,7 @@ func NewScrCursor(scr types.IScreen) (*ScrCursor, error) {
 
 // Draw -- отрисовка курсора на экране
 func (sf *ScrCursor) Draw() {
-	sf.scr.Set(sf)
+	sf.scr.SetCell(sf)
 }
 
 // SetPos -- устанавливает позицию курсора с подстройкой фона

+ 2 - 2
libtui/v0/screen/screen.go

@@ -87,8 +87,8 @@ func (sf *Screen) GetCell(posX alias.PosX, posY alias.PosY) types.ICell {
 	return cell
 }
 
-// Set -- устанавливает ячейку на экран
-func (sf *Screen) Set(cell types.ICell) {
+// SetCell -- устанавливает ячейку на экран
+func (sf *Screen) SetCell(cell types.ICell) {
 	x, y := cell.Pos()
 	style := cell.Style()
 	lit := cell.Lit()

+ 5 - 12
libtui/v0/screen/win_debug/win_debug.go

@@ -67,6 +67,7 @@ func (sf *WinDebug) SetPos(x alias.PosX, y alias.PosY) {
 	} else {
 		y += 5
 	}
+	sf.Widget.SetPos(x, y)
 }
 
 // Draw -- перерисовывает окноотладки по требованию
@@ -75,18 +76,10 @@ func (sf *WinDebug) Draw() {
 		return
 	}
 	color := tcell.NewRGBColor(0, 0, 255)
-	style := tcell.StyleDefault
-	style = style.Background(color)
+	// style := tcell.StyleDefault
+	// style = style.Background(color)
 	posX, posY := sf.Pos()
-	for x := posX; x < 30; x++ {
-		for y := posY; y < 5; y++ {
-			// int(x), int(y), style, []rune(" ")[0]
-			cell := cell.NewCell()
-			cell.SetPos(x, y)
-			cell.SetStyle(alias.Style(style))
-			sf.screen.Set(cell)
-		}
-	}
+	sf.Widget.Draw()
 	strOut := fmt.Sprintf("WinDebug.Draw(): pos=%v:%v", posX, posY)
 	color1 := tcell.NewRGBColor(200, 200, 200)
 	style1 := tcell.StyleDefault
@@ -100,6 +93,6 @@ func (sf *WinDebug) drawText(style tcell.Style, text string) {
 		cell := cell.NewCell()
 		cell.SetPos(posX+alias.PosX(adr), posY)
 		cell.SetLit(alias.Lit(r))
-		sf.screen.Set(cell)
+		sf.screen.SetCell(cell)
 	}
 }

+ 5 - 3
libtui/v0/types/icolor.go

@@ -5,7 +5,9 @@ import (
 )
 
 // IColor -- цвет эелемента
-type IColor interface{
+type IColor interface {
 	// Get -- возвращает хранимое значение цвета
-	Get()alias.Color
-}
+	Get() alias.Color
+	// Set -- Устанавливает цвет
+	Set(r, g, b uint8)
+}

+ 3 - 3
libtui/v0/types/iscreen.go

@@ -18,12 +18,12 @@ type IScreen interface {
 	MousePos() (alias.PosX, alias.PosY)
 	// App -- возвращает объект приложения
 	App() IApp
-	// Set -- отрисовывает знакоместо на экране
-	Set(ICell)
+	// SetCell -- отрисовывает знакоместо на экране
+	SetCell(ICell)
 	// Draw -- отрисовывает себя по  требованию
 	Draw()
 	// Clear -- очистка экрана
 	Clear()
 	// GetCell -- возвращает ячейку по указанным координатам
-	GetCell(alias.PosX,alias.PosY)ICell
+	GetCell(alias.PosX, alias.PosY) ICell
 }

+ 2 - 0
libtui/v0/types/iwidget.go

@@ -8,4 +8,6 @@ type IWidget interface {
 	Resize(alias.SizeX, alias.SizeY)
 	// Pos -- возвращает позицию виджета
 	Pos() (alias.PosX, alias.PosY)
+	// SetPos -- устаналвивает позицию виджета на экране
+	SetPos(alias.PosX, alias.PosY)
 }

+ 34 - 10
libtui/v0/widget/widget.go

@@ -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)
+}