1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-20 03:16:26 -05:00
OpenDiablo2/d2core/d2gui/label.go
Alex Yatskov 6f2c212417
Continued work on GUI (#316)
* Configuration cleanup

* Cleanup

* Continued UI work
2020-02-24 22:35:21 -05:00

42 lines
765 B
Go

package d2gui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type Label struct {
widgetBase
surface d2render.Surface
}
func createLabel(text string, fontStyle FontStyle) (*Label, error) {
font, err := loadFont(fontStyle)
if err != nil {
return nil, err
}
width, height := font.GetTextMetrics(text)
surface, err := d2render.NewSurface(width, height, d2render.FilterNearest)
if err != nil {
return nil, err
}
if err := font.RenderText(text, surface); err != nil {
return nil, err
}
label := &Label{surface: surface}
label.SetVisible(true)
return label, nil
}
func (l *Label) render(target d2render.Surface) error {
return target.Render(l.surface)
}
func (l *Label) getSize() (int, int) {
return l.surface.GetSize()
}