last_light/game/ui/ui_label.go

61 lines
1.4 KiB
Go
Raw Normal View History

2024-04-24 17:11:33 +03:00
package ui
import (
2024-05-06 20:43:35 +03:00
"mvvasilev/last_light/engine"
2024-06-06 23:17:22 +03:00
"mvvasilev/last_light/game/systems"
2024-04-24 17:11:33 +03:00
"unicode/utf8"
"github.com/gdamore/tcell/v2"
"github.com/gdamore/tcell/v2/views"
"github.com/google/uuid"
)
type UILabel struct {
id uuid.UUID
2024-05-06 20:43:35 +03:00
text *engine.Text
2024-04-24 17:11:33 +03:00
}
func CreateUILabel(x, y int, width, height int, content string, style tcell.Style) *UILabel {
2024-04-24 17:11:33 +03:00
label := new(UILabel)
label.id = uuid.New()
2024-05-06 20:43:35 +03:00
label.text = engine.CreateText(x, y, width, height, content, style)
2024-04-24 17:11:33 +03:00
return label
}
func CreateSingleLineUILabel(x, y int, content string, style tcell.Style) *UILabel {
2024-04-24 17:11:33 +03:00
label := new(UILabel)
label.id = uuid.New()
2024-05-06 20:43:35 +03:00
label.text = engine.CreateText(x, y, int(utf8.RuneCountInString(content)), 1, content, style)
2024-04-24 17:11:33 +03:00
return label
}
func (t *UILabel) UniqueId() uuid.UUID {
return t.id
}
func (t *UILabel) MoveTo(x int, y int) {
2024-05-06 20:43:35 +03:00
t.text = engine.CreateText(x, y, int(t.text.Size().Width()), int(t.Size().Height()), t.text.Content(), t.text.Style())
2024-04-24 17:11:33 +03:00
}
2024-05-06 21:47:20 +03:00
func (t *UILabel) Position() engine.Position {
2024-04-24 17:11:33 +03:00
return t.text.Position()
}
2024-05-31 23:37:06 +03:00
func (t *UILabel) SetContent(content string) {
t.text = engine.CreateText(t.text.Position().X(), t.text.Position().Y(), int(t.text.Size().Width()), int(t.Size().Height()), content, t.text.Style())
}
2024-05-06 21:47:20 +03:00
func (t *UILabel) Size() engine.Size {
2024-04-24 17:11:33 +03:00
return t.text.Size()
}
func (t *UILabel) Draw(v views.View) {
t.text.Draw(v)
}
2024-06-06 23:17:22 +03:00
func (t *UILabel) Input(inputAction systems.InputAction) {}