2024-04-24 17:11:33 +03:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mvvasilev/last_light/render"
|
|
|
|
"mvvasilev/last_light/util"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/gdamore/tcell/v2/views"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UILabel struct {
|
|
|
|
id uuid.UUID
|
|
|
|
text *render.Text
|
|
|
|
}
|
|
|
|
|
2024-04-27 22:32:05 +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()
|
|
|
|
label.text = render.CreateText(x, y, width, height, content, style)
|
|
|
|
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
2024-04-27 22:32:05 +03:00
|
|
|
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-04-27 22:32:05 +03:00
|
|
|
label.text = render.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
|
|
|
|
}
|
|
|
|
|
2024-04-27 22:32:05 +03:00
|
|
|
func (t *UILabel) MoveTo(x int, y int) {
|
|
|
|
t.text = render.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
|
|
|
}
|
|
|
|
|
|
|
|
func (t *UILabel) Position() util.Position {
|
|
|
|
return t.text.Position()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *UILabel) Size() util.Size {
|
|
|
|
return t.text.Size()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *UILabel) Draw(v views.View) {
|
|
|
|
t.text.Draw(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *UILabel) Input(e *tcell.EventKey) {}
|