mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-09-06 13:34:36 +02:00
go fmt ./...
This commit is contained in:
@@ -3,29 +3,29 @@ package UI
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
type Textarea struct {
|
||||
Widget
|
||||
BackgroundColor *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
MyWords []string
|
||||
BlitWords []string
|
||||
FontObj *ttf.Font
|
||||
LineNumber int
|
||||
TextLimit int
|
||||
TextFull bool
|
||||
TextIndex int
|
||||
BlitIndex int
|
||||
CanvasHWND *sdl.Surface
|
||||
MyWords []string
|
||||
BlitWords []string
|
||||
FontObj *ttf.Font
|
||||
LineNumber int
|
||||
TextLimit int
|
||||
TextFull bool
|
||||
TextIndex int
|
||||
BlitIndex int
|
||||
}
|
||||
|
||||
func NewTextarea() *Textarea {
|
||||
@@ -34,11 +34,11 @@ func NewTextarea() *Textarea {
|
||||
p.TextLimit = 63
|
||||
p.TextFull = false
|
||||
|
||||
p.MyWords = make([]string,0)
|
||||
p.BlitWords = make([]string,0)
|
||||
p.MyWords = make([]string, 0)
|
||||
p.BlitWords = make([]string, 0)
|
||||
|
||||
p.BackgroundColor = &color.Color{228, 228, 228, 255}
|
||||
|
||||
p.BackgroundColor = &color.Color{228,228,228,255}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (self *Textarea) AddTextIndex() {
|
||||
self.TextIndex += 1
|
||||
if self.TextIndex > len(self.MyWords) {
|
||||
self.TextIndex = len(self.MyWords)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Textarea) ResetMyWords() {
|
||||
@@ -70,84 +70,82 @@ func (self *Textarea) RemoveFromLastText() []string {
|
||||
if len(self.MyWords) > 0 {
|
||||
self.SubTextIndex()
|
||||
if self.TextIndex < len(self.MyWords) {
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex],self.MyWords[(self.TextIndex+1):]...)
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex], self.MyWords[(self.TextIndex+1):]...)
|
||||
}
|
||||
}
|
||||
|
||||
return self.MyWords
|
||||
}
|
||||
|
||||
|
||||
func (self *Textarea) AppendText( alphabet string) {
|
||||
func (self *Textarea) AppendText(alphabet string) {
|
||||
self.AppendAndBlitText(alphabet)
|
||||
}
|
||||
|
||||
func (self *Textarea) AppendAndBlitText(alphabet string) {
|
||||
if self.TextFull == false {
|
||||
|
||||
|
||||
if self.TextIndex <= len(self.MyWords) {
|
||||
self.MyWords = append(self.MyWords[:self.TextIndex],
|
||||
append([]string{alphabet},self.MyWords[self.TextIndex:]...)...)
|
||||
|
||||
append([]string{alphabet}, self.MyWords[self.TextIndex:]...)...)
|
||||
|
||||
self.BlitText()
|
||||
self.AddTextIndex()
|
||||
}
|
||||
|
||||
}else {
|
||||
fmt.Printf("is Full %s\n",strings.Join(self.MyWords,""))
|
||||
|
||||
} else {
|
||||
fmt.Printf("is Full %s\n", strings.Join(self.MyWords, ""))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Textarea) BuildBlitText() {
|
||||
blit_rows := make([][]string,0)
|
||||
blit_rows = append(blit_rows,[]string{})
|
||||
|
||||
w := 0
|
||||
// xmargin := 5
|
||||
endmargin :=15
|
||||
blit_rows := make([][]string, 0)
|
||||
blit_rows = append(blit_rows, []string{})
|
||||
|
||||
w := 0
|
||||
// xmargin := 5
|
||||
endmargin := 15
|
||||
linenumber := 0
|
||||
cursor_row := 0
|
||||
|
||||
|
||||
for i,v := range self.MyWords {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for i, v := range self.MyWords {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
t_width := surface.GetWidth(t)
|
||||
w+=t_width
|
||||
w += t_width
|
||||
|
||||
blit_rows[linenumber] = append(blit_rows[linenumber],v)
|
||||
blit_rows[linenumber] = append(blit_rows[linenumber], v)
|
||||
|
||||
if i == self.TextIndex - 1 {
|
||||
if i == self.TextIndex-1 {
|
||||
cursor_row = linenumber
|
||||
}
|
||||
|
||||
if w + t_width >= self.Width - endmargin {
|
||||
if w+t_width >= self.Width-endmargin {
|
||||
w = 0
|
||||
linenumber += 1
|
||||
blit_rows = append(blit_rows,[]string{})
|
||||
blit_rows = append(blit_rows, []string{})
|
||||
}
|
||||
t.Free()
|
||||
t.Free()
|
||||
}
|
||||
|
||||
if len(blit_rows) == 1 {
|
||||
self.BlitWords = blit_rows[0]
|
||||
self.BlitIndex = self.TextIndex
|
||||
}else if len(blit_rows) == 2 || cursor_row < 2 {
|
||||
} else if len(blit_rows) == 2 || cursor_row < 2 {
|
||||
self.BlitWords = append(blit_rows[0], blit_rows[1]...)
|
||||
self.BlitIndex = self.TextIndex
|
||||
|
||||
}else {
|
||||
|
||||
} else {
|
||||
self.BlitWords = append(blit_rows[cursor_row-1], blit_rows[cursor_row]...)
|
||||
self.BlitIndex = self.TextIndex
|
||||
|
||||
for i,v := range blit_rows {
|
||||
if i == cursor_row - 1 {
|
||||
for i, v := range blit_rows {
|
||||
if i == cursor_row-1 {
|
||||
break
|
||||
}
|
||||
self.BlitIndex -= len(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *Textarea) BlitText() {
|
||||
@@ -165,23 +163,23 @@ func (self *Textarea) BlitText() {
|
||||
|
||||
if len(self.MyWords) > self.TextLimit {
|
||||
self.TextFull = true
|
||||
}else {
|
||||
} else {
|
||||
self.TextFull = false
|
||||
}
|
||||
|
||||
for _,v := range self.BlitWords {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for _, v := range self.BlitWords {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
w += surface.GetWidth(t)
|
||||
|
||||
if w >= self.Width - endmargin && linenumber == 0 {
|
||||
if w >= self.Width-endmargin && linenumber == 0 {
|
||||
linenumber += 1
|
||||
x = self.PosX + xmargin
|
||||
y = self.PosY + surface.GetHeight(t) * linenumber
|
||||
y = self.PosY + surface.GetHeight(t)*linenumber
|
||||
w = 0
|
||||
}
|
||||
|
||||
rect_ := rect.Rect(x,y,0,0)
|
||||
surface.Blit(self.CanvasHWND,t,&rect_,nil)
|
||||
rect_ := rect.Rect(x, y, 0, 0)
|
||||
surface.Blit(self.CanvasHWND, t, &rect_, nil)
|
||||
x += surface.GetWidth(t)
|
||||
t.Free()
|
||||
}
|
||||
@@ -191,42 +189,42 @@ func (self *Textarea) Cursor() {
|
||||
w := 0
|
||||
xmargin := 5
|
||||
endmargin := 15
|
||||
x := self.PosX+xmargin
|
||||
x := self.PosX + xmargin
|
||||
y := self.PosY
|
||||
linenumber := 0
|
||||
|
||||
for _,v := range self.BlitWords[:self.BlitIndex] {
|
||||
t := font.Render(self.FontObj,v,true,&color.Color{8,135,174,255},nil)
|
||||
for _, v := range self.BlitWords[:self.BlitIndex] {
|
||||
t := font.Render(self.FontObj, v, true, &color.Color{8, 135, 174, 255}, nil)
|
||||
w += surface.GetWidth(t)
|
||||
|
||||
if w >= self.Width - endmargin && linenumber == 0 {
|
||||
if w >= self.Width-endmargin && linenumber == 0 {
|
||||
x = self.PosX + xmargin
|
||||
y = self.PosY + surface.GetHeight(t)
|
||||
w = 0
|
||||
linenumber +=1
|
||||
linenumber += 1
|
||||
}
|
||||
|
||||
if w >= self.Width - endmargin*3 && linenumber > 0 {
|
||||
if w >= self.Width-endmargin*3 && linenumber > 0 {
|
||||
x += surface.GetWidth(t)
|
||||
break
|
||||
}
|
||||
x += surface.GetWidth(t)
|
||||
t.Free()
|
||||
t.Free()
|
||||
}
|
||||
|
||||
c_t := font.Render(self.FontObj,"_",true,&color.Color{0,0,0,255},nil)
|
||||
rect_ := rect.Rect(x+1,y-2,0,0)
|
||||
surface.Blit(self.CanvasHWND,c_t,&rect_,nil)
|
||||
c_t.Free()
|
||||
c_t := font.Render(self.FontObj, "_", true, &color.Color{0, 0, 0, 255}, nil)
|
||||
rect_ := rect.Rect(x+1, y-2, 0, 0)
|
||||
surface.Blit(self.CanvasHWND, c_t, &rect_, nil)
|
||||
c_t.Free()
|
||||
}
|
||||
|
||||
func (self *Textarea) Draw() {
|
||||
|
||||
rect_:= rect.Rect(self.PosX,self.PosY,self.Width,self.Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND,&rect_,self.BackgroundColor,4,0,self.BackgroundColor)
|
||||
|
||||
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
|
||||
draw.AARoundRect(self.CanvasHWND, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
|
||||
|
||||
self.BlitText()
|
||||
self.Cursor()
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user