mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-01 15:46:17 -04:00
UI fixes (#461)
This commit is contained in:
parent
48a193579f
commit
226181ffcc
@ -138,7 +138,7 @@ func (l *Layout) Clear() {
|
||||
}
|
||||
|
||||
func (l *Layout) render(target d2render.Surface) error {
|
||||
l.adjustEntryPlacement()
|
||||
l.AdjustEntryPlacement()
|
||||
|
||||
for _, entry := range l.entries {
|
||||
if !entry.widget.isVisible() {
|
||||
@ -295,7 +295,7 @@ func (l *Layout) adjustEntryEvent(entry *layoutEntry, eventX, eventY *int) bool
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *Layout) adjustEntryPlacement() {
|
||||
func (l *Layout) AdjustEntryPlacement() {
|
||||
width, height := l.getSize()
|
||||
|
||||
var expanderCount int
|
||||
|
@ -46,6 +46,9 @@ func createGuiManager() (*manager, error) {
|
||||
|
||||
func (m *manager) SetLayout(layout *Layout) {
|
||||
m.layout = layout
|
||||
if m.layout != nil {
|
||||
m.layout.AdjustEntryPlacement()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *manager) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
||||
|
@ -21,7 +21,6 @@ type widget interface {
|
||||
onMouseButtonClick(event d2input.MouseEvent) bool
|
||||
|
||||
getPosition() (int, int)
|
||||
getOffset() (int, int)
|
||||
setOffset(x, y int)
|
||||
getSize() (int, int)
|
||||
getLayer() int
|
||||
@ -57,10 +56,6 @@ func (w *widgetBase) GetOffset() (int, int) {
|
||||
return w.offsetX, w.offsetY
|
||||
}
|
||||
|
||||
func (w *widgetBase) getOffset() (int, int) {
|
||||
return w.offsetX, w.offsetY
|
||||
}
|
||||
|
||||
func (w *widgetBase) setOffset(x, y int) {
|
||||
w.offsetX = x
|
||||
w.offsetY = y
|
||||
|
@ -27,7 +27,7 @@ type Label struct {
|
||||
Height int
|
||||
Alignment LabelAlignment
|
||||
font *Font
|
||||
imageData d2render.Surface
|
||||
imageData map[string]d2render.Surface
|
||||
Color color.Color
|
||||
}
|
||||
|
||||
@ -37,7 +37,9 @@ func CreateLabel(fontPath, palettePath string) Label {
|
||||
Alignment: LabelAlignLeft,
|
||||
Color: color.White,
|
||||
font: GetFont(fontPath, palettePath),
|
||||
imageData: make(map[string]d2render.Surface),
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@ -60,7 +62,7 @@ func (v *Label) Render(target d2render.Surface) {
|
||||
target.PushTranslation(x, y)
|
||||
defer target.PopN(3)
|
||||
|
||||
target.Render(v.imageData)
|
||||
target.Render(v.imageData[v.text])
|
||||
}
|
||||
|
||||
// SetPosition moves the label to the specified location
|
||||
@ -74,14 +76,14 @@ func (v *Label) GetTextMetrics(text string) (width, height int) {
|
||||
}
|
||||
|
||||
func (v *Label) cacheImage() {
|
||||
if v.imageData != nil {
|
||||
if v.imageData[v.text] != nil {
|
||||
return
|
||||
}
|
||||
width, height := v.font.GetTextMetrics(v.text)
|
||||
v.Width = width
|
||||
v.Height = height
|
||||
v.imageData, _ = d2render.NewSurface(width, height, d2render.FilterNearest)
|
||||
surface, _ := d2render.CreateSurface(v.imageData)
|
||||
v.imageData[v.text], _ = d2render.NewSurface(width, height, d2render.FilterNearest)
|
||||
surface, _ := d2render.CreateSurface(v.imageData[v.text])
|
||||
v.font.Render(0, 0, v.text, v.Color, surface)
|
||||
}
|
||||
|
||||
@ -91,7 +93,6 @@ func (v *Label) SetText(newText string) {
|
||||
return
|
||||
}
|
||||
v.text = newText
|
||||
v.imageData = nil
|
||||
}
|
||||
|
||||
// Size returns the size of the label
|
||||
|
@ -364,6 +364,7 @@ func (m *EscapeMenu) setLayout(id layoutID) {
|
||||
m.currentLayout = id
|
||||
m.layouts[id].currentEl = 0
|
||||
d2gui.SetLayout(m.layouts[id].Layout)
|
||||
m.onHoverElement(0)
|
||||
}
|
||||
|
||||
func (m *EscapeMenu) onUpKey() {
|
||||
|
Loading…
Reference in New Issue
Block a user