285 Рефакторинг

This commit is contained in:
prospero78su 2019-05-07 11:21:00 +03:00
parent d3f3c56951
commit e844aaf4ac
12 changed files with 62 additions and 59 deletions

View File

@ -606,7 +606,7 @@ func (c *BaseControl) setClipper() {
x, y, w, h := CalcClipper(c)
c.clipper = &rect{x: x, y: y, w: w, h: h}
}
//HitTest --
func (c *BaseControl) HitTest(x, y int) мКнст.HitResult {
if x > c.x && x < c.x+c.width-1 &&
y > c.y && y < c.y+c.height-1 {

View File

@ -22,7 +22,7 @@ type Button struct {
}
/*
NewButton creates a new Button.
CreateButton creates a new Button.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heigth - are minimal size of the control.
@ -63,7 +63,7 @@ func CreateButton(parent Control, width, height int, title string, scale int) *B
return b
}
// Repaint draws the control on its View surface
//Draw Repaint draws the control on its View surface
func (b *Button) Draw() {
if b.hidden {
return

View File

@ -137,7 +137,7 @@ func Flush() {
term.Flush()
}
// SetSize sets the new Canvas size. If new size does not
// SetScreenSize sets the new Canvas size. If new size does not
// equal old size then Canvas is recreated and cleared
// with default colors. Both Canvas width and height must
// be greater than 2
@ -153,7 +153,7 @@ func SetScreenSize(width int, height int) {
SetClipRect(0, 0, width, height)
}
// Size returns current Canvas size
// ScreenSize returns current Canvas size
func ScreenSize() (width int, height int) {
return canvas.width, canvas.height
}
@ -197,11 +197,11 @@ func SetTextColor(clr term.Attribute) {
func SetBackColor(clr term.Attribute) {
canvas.backColor = clr
}
//TextColor --
func TextColor() term.Attribute {
return canvas.textColor
}
//BackColor --
func BackColor() term.Attribute {
return canvas.backColor
}
@ -280,7 +280,7 @@ func DrawText(x, y int, text string) {
if unicode.Is(unicode.Scripts["Han"], elem.Ch) {
x += 2
} else {
x += 1
x++
}
if firstdrawn && !drawn {
@ -338,7 +338,7 @@ func DrawTextVertical(x, y int, text string) {
SetTextColor(elem.Fg)
SetBackColor(elem.Bg)
drawn := PutChar(x, y, elem.Ch)
y += 1
y++
if firstdrawn && !drawn {
break
}

View File

@ -52,7 +52,7 @@ func CreateCheckBox(parent Control, width int, title string, scale int) *CheckBo
return c
}
// Repaint draws the control on its View surface
//Draw Repaint draws the control on its View surface
func (c *CheckBox) Draw() {
if c.hidden {
return

View File

@ -3,7 +3,7 @@ package clui
import (
term "github.com/nsf/termbox-go"
)
//InitLibrary --
func InitLibrary() bool {
initThemeManager()
initComposer()
@ -11,7 +11,7 @@ func InitLibrary() bool {
return initCanvas()
}
// Close closes console management and makes a console cursor visible
//DeinitLibrary Close closes console management and makes a console cursor visible
func DeinitLibrary() {
term.SetCursor(3, 3)
term.Close()

View File

@ -2,10 +2,11 @@ package clui
import (
"testing"
мКнст "./пакКонстанты"
)
func TestParserEmpty(t *testing.T) {
prs := NewColorParser("", ColorBlack, ColorWhite)
prs := NewColorParser("", мКнст.ColorBlack, мКнст.ColorWhite)
elem := prs.NextElement()
@ -17,20 +18,20 @@ func TestParserEmpty(t *testing.T) {
func TestParserColors(t *testing.T) {
prs := NewColorParser("a<b:green>c<t:red>d<b:>e<t:>fg\nf",
ColorBlack, ColorWhite)
мКнст.ColorBlack, мКнст.ColorWhite)
elems := []TextElement{
{ElemPrintable, 'a', ColorBlack, ColorWhite},
{ElemBackColor, ' ', ColorBlack, ColorGreen},
{ElemPrintable, 'c', ColorBlack, ColorGreen},
{ElemTextColor, 'c', ColorRed, ColorGreen},
{ElemPrintable, 'd', ColorRed, ColorGreen},
{ElemBackColor, 'd', ColorRed, ColorWhite},
{ElemPrintable, 'e', ColorRed, ColorWhite},
{ElemTextColor, 'e', ColorBlack, ColorWhite},
{ElemPrintable, 'f', ColorBlack, ColorWhite},
{ElemPrintable, 'g', ColorBlack, ColorWhite},
{ElemLineBreak, 'g', ColorBlack, ColorWhite},
{ElemPrintable, 'f', ColorBlack, ColorWhite},
{ElemPrintable, 'a', мКнст.ColorBlack, мКнст.ColorWhite},
{ElemBackColor, ' ', мКнст.ColorBlack, мКнст.ColorGreen},
{ElemPrintable, 'c', мКнст.ColorBlack, мКнст.ColorGreen},
{ElemTextColor, 'c', мКнст.ColorRed, мКнст.ColorGreen},
{ElemPrintable, 'd', мКнст.ColorRed, мКнст.ColorGreen},
{ElemBackColor, 'd', мКнст.ColorRed, мКнст.ColorWhite},
{ElemPrintable, 'e', мКнст.ColorRed, мКнст.ColorWhite},
{ElemTextColor, 'e', мКнст.ColorBlack, мКнст.ColorWhite},
{ElemPrintable, 'f', мКнст.ColorBlack, мКнст.ColorWhite},
{ElemPrintable, 'g', мКнст.ColorBlack, мКнст.ColorWhite},
{ElemLineBreak, 'g', мКнст.ColorBlack, мКнст.ColorWhite},
{ElemPrintable, 'f', мКнст.ColorBlack, мКнст.ColorWhite},
}
idx := 0
@ -53,6 +54,6 @@ func TestParserColors(t *testing.T) {
}
el = prs.NextElement()
idx += 1
idx++
}
}

View File

@ -70,7 +70,7 @@ func termboxEventToLocal(ev term.Event) мКнст.Event {
return e
}
// Repaints everything on the screen
//RefreshScreen Repaints everything on the screen
func RefreshScreen() {
comp.BeginUpdate()
term.Clear(мКнст.ColorWhite, мКнст.ColorBlack)
@ -118,7 +118,7 @@ func AddWindow(posX, posY, width, height int, title string) *Window {
return window
}
// Border returns the default window border
//BorderStyle returns the default window border
func (c *Composer) BorderStyle() мКнст.BorderStyle {
return c.windowBorder
}
@ -697,7 +697,7 @@ func (c *Composer) processKey(ev мКнст.Event) {
c.lastKey = term.KeyEsc
}
}
//ProcessEvent --
func ProcessEvent(ev мКнст.Event) {
switch ev.Type {
case мКнст.EventCloseWindow:

View File

@ -1,8 +1,8 @@
package clui
import (
term "github.com/nsf/termbox-go"
мКнст "./пакКонстанты"
term "github.com/nsf/termbox-go"
)
// ThumbPosition returns a scrollbar thumb position depending
@ -263,9 +263,9 @@ func NextControl(parent Control, curr Control, next bool) Control {
if next {
return linear[nIndex]
} else {
return linear[pIndex]
}
return linear[pIndex]
}
// SendEventToChild tries to find a child control that should recieve the evetn

View File

@ -32,7 +32,7 @@ type EditField struct {
onKeyPress func(term.Key, rune) bool
}
// NewEditField creates a new EditField control
// CreateEditField creates a new EditField control
// view - is a View that manages the control
// parent - is container that keeps the control. The same View can be a view and a parent at the same time.
// width - is minimal width of the control.

View File

@ -21,7 +21,7 @@ type Label struct {
}
/*
NewLabel creates a new label.
CreateLabel creates a new label.
view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time.
w and h - are minimal size of the control.

View File

@ -2,11 +2,12 @@ package clui
import (
"testing"
мКнст "./пакКонстанты"
)
func TestListBox(t *testing.T) {
width, height := 10, 5
lbox := CreateListBox(nil, width, height, Fixed)
lbox := CreateListBox(nil, width, height, мКнст.Fixed)
w, h := lbox.Size()
if w != width {

View File

@ -2,6 +2,7 @@ package clui
import (
"testing"
мКнст "./пакКонстанты"
)
func TestEllipsize(t *testing.T) {
@ -46,16 +47,16 @@ func TestCutText(t *testing.T) {
func TestAlignText(t *testing.T) {
cases := []struct {
in, want string
align Align
align мКнст.Align
max, shift int
}{
{"abcdefgh", "abcde", AlignLeft, 5, 0},
{"abcdefgh", "defgh", AlignRight, 5, 0},
{"abcdefgh", "bcdef", AlignCenter, 5, 0},
{"abcdefgh", "abcdefgh", AlignLeft, 10, 0},
{"abcdefgh", "abcdefgh", AlignRight, 10, 2},
{"abcdefgh", "abcdefgh", AlignCenter, 10, 1},
{"abcdefg", "abcdefg", AlignCenter, 10, 2},
{"abcdefgh", "abcde", мКнст.AlignLeft, 5, 0},
{"abcdefgh", "defgh", мКнст.AlignRight, 5, 0},
{"abcdefgh", "bcdef", мКнст.AlignCenter, 5, 0},
{"abcdefgh", "abcdefgh", мКнст.AlignLeft, 10, 0},
{"abcdefgh", "abcdefgh", мКнст.AlignRight, 10, 2},
{"abcdefgh", "abcdefgh", мКнст.AlignCenter, 10, 1},
{"abcdefg", "abcdefg", мКнст.AlignCenter, 10, 2},
}
for _, c := range cases {
@ -69,25 +70,25 @@ func TestAlignText(t *testing.T) {
func TestAlignColorizedText(t *testing.T) {
cases := []struct {
in, want string
align Align
align мКнст.Align
max, shift int
}{
// uncolored cases
{"abcdefgh", "abcde", AlignLeft, 5, 0},
{"abcdefgh", "defgh", AlignRight, 5, 0},
{"abcdefgh", "bcdef", AlignCenter, 5, 0},
{"abcdefgh", "abcdefgh", AlignLeft, 10, 0},
{"abcdefgh", "abcdefgh", AlignRight, 10, 2},
{"abcdefgh", "abcdefgh", AlignCenter, 10, 1},
{"abcdefg", "abcdefg", AlignCenter, 10, 2},
{"abcdefgh", "abcde", мКнст.AlignLeft, 5, 0},
{"abcdefgh", "defgh", мКнст.AlignRight, 5, 0},
{"abcdefgh", "bcdef", мКнст.AlignCenter, 5, 0},
{"abcdefgh", "abcdefgh", мКнст.AlignLeft, 10, 0},
{"abcdefgh", "abcdefgh", мКнст.AlignRight, 10, 2},
{"abcdefgh", "abcdefgh", мКнст.AlignCenter, 10, 1},
{"abcdefg", "abcdefg", мКнст.AlignCenter, 10, 2},
// colored cases
{"abc<t:green>defg", "abc<t:green>defg", AlignCenter, 10, 2},
{"abc<t:green>defgh", "abc<t:green>defgh", AlignRight, 10, 2},
{"abc<t:green>defgh", "abc<t:green>defgh", AlignCenter, 10, 1},
{"<b:blue>ab<b:cyan>cdefgh", "<b:blue>ab<b:cyan>cde", AlignLeft, 5, 0},
{"<b:blue>abcdefgh", "<b:cyan>defgh", AlignRight, 5, 0},
{"<b:blue>abcdefgh", "<b:blue>b<b:cyan>cdef", AlignCenter, 5, 0},
{"abc<t:green>defg", "ab", AlignLeft, 2, 0},
{"abc<t:green>defg", "abc<t:green>defg", мКнст.AlignCenter, 10, 2},
{"abc<t:green>defgh", "abc<t:green>defgh", мКнст.AlignRight, 10, 2},
{"abc<t:green>defgh", "abc<t:green>defgh", мКнст.AlignCenter, 10, 1},
{"<b:blue>ab<b:cyan>cdefgh", "<b:blue>ab<b:cyan>cde", мКнст.AlignLeft, 5, 0},
{"<b:blue>abcdefgh", "<b:cyan>defgh", мКнст.AlignRight, 5, 0},
{"<b:blue>abcdefgh", "<b:blue>b<b:cyan>cdef", мКнст.AlignCenter, 5, 0},
{"abc<t:green>defg", "ab", мКнст.AlignLeft, 2, 0},
}
for _, c := range cases {