last_light/game/ui/window.go

62 lines
1 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-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 UIWindow struct {
id uuid.UUID
2024-05-06 20:43:35 +03:00
title *engine.Text
box engine.Rectangle
2024-04-24 17:11:33 +03:00
}
func CreateWindow(x, y, width, height int, title string, style tcell.Style) *UIWindow {
2024-04-24 17:11:33 +03:00
w := new(UIWindow)
titleLen := utf8.RuneCountInString(title)
titlePos := (width / 2) - int(titleLen/2)
2024-04-24 17:11:33 +03:00
2024-05-06 20:43:35 +03:00
w.title = engine.CreateText(x+titlePos, y, int(titleLen), 1, title, style)
2024-04-24 17:11:33 +03:00
2024-05-06 20:43:35 +03:00
w.box = engine.CreateRectangle(
2024-04-24 17:11:33 +03:00
x, y, width, height,
'┌', '─', '┐',
'│', ' ', '│',
'└', '─', '┘',
false, true, style,
)
return w
}
func (w *UIWindow) UniqueId() uuid.UUID {
return w.id
}
func (w *UIWindow) MoveTo(x int, y int) {
2024-04-24 17:11:33 +03:00
}
2024-05-06 21:47:20 +03:00
func (w *UIWindow) Position() engine.Position {
2024-04-24 17:11:33 +03:00
return w.box.Position()
}
2024-05-06 21:47:20 +03:00
func (w *UIWindow) Size() engine.Size {
return engine.SizeOf(0, 0)
2024-04-24 17:11:33 +03:00
}
func (w *UIWindow) Draw(v views.View) {
w.box.Draw(v)
w.title.Draw(v)
}
func (w *UIWindow) Input(e *tcell.EventKey) {
}