mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-09-06 13:34:36 +02:00
go fmt ./...
This commit is contained in:
@@ -2,14 +2,14 @@ package UI
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/rect"
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
)
|
||||
|
||||
//MultiLabel is also a LabelInterface
|
||||
@@ -20,24 +20,24 @@ type MultiLabel struct {
|
||||
Color *color.Color
|
||||
CanvasHWND *sdl.Surface
|
||||
//TextSurf *sdl.Surface
|
||||
MaxWidth int
|
||||
Bold bool
|
||||
MaxWidth int
|
||||
Bold bool
|
||||
}
|
||||
|
||||
func NewMultiLabel() *MultiLabel{
|
||||
func NewMultiLabel() *MultiLabel {
|
||||
l := &MultiLabel{}
|
||||
l.Color = &color.Color{83,83,83,255}
|
||||
l.Color = &color.Color{83, 83, 83, 255}
|
||||
l.Width = 135
|
||||
l.Height = 100
|
||||
l.Bold = false
|
||||
l.Bold = false
|
||||
return l
|
||||
}
|
||||
|
||||
func (self *MultiLabel) Init(text string, font_obj *ttf.Font,col *color.Color) {
|
||||
func (self *MultiLabel) Init(text string, font_obj *ttf.Font, col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
|
||||
|
||||
self.Text = text
|
||||
self.FontObj = font_obj
|
||||
|
||||
@@ -46,12 +46,11 @@ func (self *MultiLabel) Init(text string, font_obj *ttf.Font,col *color.Color) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *MultiLabel) SetCanvasHWND( canvas *sdl.Surface) {
|
||||
func (self *MultiLabel) SetCanvasHWND(canvas *sdl.Surface) {
|
||||
self.CanvasHWND = canvas
|
||||
}
|
||||
|
||||
|
||||
func (self *MultiLabel) SetColor(col *color.Color){
|
||||
func (self *MultiLabel) SetColor(col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
@@ -61,14 +60,13 @@ func (self *MultiLabel) GetText() string {
|
||||
return self.Text
|
||||
}
|
||||
|
||||
|
||||
func (self *MultiLabel) SetText(text string) {
|
||||
self.Text = text
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *MultiLabel) SetBold(b bool) {
|
||||
self.Bold = b
|
||||
self.Bold = b
|
||||
|
||||
}
|
||||
|
||||
@@ -77,22 +75,22 @@ func (self *MultiLabel) DrawCenter(bold bool) {
|
||||
}
|
||||
|
||||
func (self *MultiLabel) Draw() {
|
||||
font.SetBold(self.FontObj,self.Bold) // avoing same font tangling set_bold to others
|
||||
self.blit_text(self.CanvasHWND, self.Text,self.PosX,self.PosY,self.FontObj)
|
||||
font.SetBold(self.FontObj, self.Bold) // avoing same font tangling set_bold to others
|
||||
self.blit_text(self.CanvasHWND, self.Text, self.PosX, self.PosY, self.FontObj)
|
||||
}
|
||||
|
||||
// difference to Label
|
||||
func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int, fnt *ttf.Font) {
|
||||
func (self *MultiLabel) blit_text(surf *sdl.Surface, text string, pos_x, pos_y int, fnt *ttf.Font) {
|
||||
words := make([][]string, 0)
|
||||
temp := strings.Split(text,"\n")
|
||||
for _,v := range temp {
|
||||
t := strings.Split(v," ")
|
||||
words = append(words,t)
|
||||
temp := strings.Split(text, "\n")
|
||||
for _, v := range temp {
|
||||
t := strings.Split(v, " ")
|
||||
words = append(words, t)
|
||||
}
|
||||
|
||||
space,_ := font.Size(fnt," ")
|
||||
space, _ := font.Size(fnt, " ")
|
||||
max_width := self.Width
|
||||
x,y := pos_x,pos_y
|
||||
x, y := pos_x, pos_y
|
||||
|
||||
row_total_width := 0
|
||||
lines := 0
|
||||
@@ -101,33 +99,33 @@ func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int
|
||||
if len(words) > 4 {
|
||||
tmp = words[:4]
|
||||
}
|
||||
|
||||
for _,line := range tmp {
|
||||
|
||||
for _, line := range tmp {
|
||||
word_height := 0
|
||||
tmp2 := line
|
||||
if len(line) > 12 {
|
||||
tmp2 = line[:12]
|
||||
}
|
||||
|
||||
for _,word := range tmp2 {
|
||||
word_surface := font.Render(fnt,word,true,self.Color,nil)
|
||||
word_width := surface.GetWidth(word_surface)
|
||||
word_height = surface.GetHeight(word_surface)
|
||||
|
||||
for _, word := range tmp2 {
|
||||
word_surface := font.Render(fnt, word, true, self.Color, nil)
|
||||
word_width := surface.GetWidth(word_surface)
|
||||
word_height = surface.GetHeight(word_surface)
|
||||
row_total_width += word_width
|
||||
if row_total_width+space >= max_width {
|
||||
x = pos_x
|
||||
y = y+word_height
|
||||
y = y + word_height
|
||||
row_total_width = word_width
|
||||
if lines == 0 {
|
||||
lines = lines + word_height
|
||||
}else {
|
||||
} else {
|
||||
lines = lines + word_height
|
||||
}
|
||||
}
|
||||
}
|
||||
rect_ := rect.Rect(x,y,self.Width,self.Height)
|
||||
surface.Blit(surf,word_surface,&rect_,nil)
|
||||
word_surface.Free()
|
||||
x += (word_width+space)
|
||||
rect_ := rect.Rect(x, y, self.Width, self.Height)
|
||||
surface.Blit(surf, word_surface, &rect_, nil)
|
||||
word_surface.Free()
|
||||
x += (word_width + space)
|
||||
}
|
||||
x = pos_x
|
||||
y += word_height
|
||||
@@ -135,6 +133,5 @@ func (self *MultiLabel) blit_text(surf *sdl.Surface,text string, pos_x,pos_y int
|
||||
}
|
||||
|
||||
self.Height = lines
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user