holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,74 +1,70 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
"golang.org/x/image/font"
|
||||
)
|
||||
import "git.vezzani.net/ben/games/common/ux/v1"
|
||||
|
||||
type xAlign int
|
||||
type yAlign int
|
||||
|
||||
const (
|
||||
AlignCente xAlign = iota
|
||||
AlignLeft
|
||||
AlignRight
|
||||
)
|
||||
|
||||
const (
|
||||
AlignCenter yAlign = iota
|
||||
AlignTop
|
||||
AlignBottom
|
||||
)
|
||||
|
||||
type Button struct {
|
||||
mouseHandler
|
||||
block
|
||||
Label string
|
||||
OnClick func() error
|
||||
OnRightClick func() error
|
||||
Style struct {
|
||||
MouseDownColor *color.Color
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Button) HandleClick(_ MouseState) error {
|
||||
if b.OnClick == nil {
|
||||
return nil
|
||||
}
|
||||
return b.OnClick()
|
||||
}
|
||||
|
||||
func (b *Button) getFont() font.Face {
|
||||
if b.block.block.Font == nil {
|
||||
return ux.FontFace
|
||||
}
|
||||
|
||||
return *b.block.block.Font
|
||||
}
|
||||
|
||||
func (b *Button) backgroundColor() color.Color {
|
||||
var c *color.Color
|
||||
if b.block.block.BackgroundColor != nil {
|
||||
c = b.block.block.BackgroundColor
|
||||
} else {
|
||||
c = &ux.BackgroundColor
|
||||
}
|
||||
|
||||
if (b.mouseState.RightDown || b.mouseState.LeftDown) && b.Style.MouseDownColor != nil {
|
||||
c = b.Style.MouseDownColor
|
||||
}
|
||||
|
||||
return *c
|
||||
}
|
||||
|
||||
func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||
|
||||
vector.StrokeRect(image, xz, yz, w, h, 1, b.backgroundColor(), true)
|
||||
|
||||
return nil
|
||||
}
|
||||
//
|
||||
//import (
|
||||
// "image/color"
|
||||
//)
|
||||
//
|
||||
//type xAlign int
|
||||
//type yAlign int
|
||||
//
|
||||
//const (
|
||||
// AlignCente xAlign = iota
|
||||
// AlignLeft
|
||||
// AlignRight
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// AlignCenter yAlign = iota
|
||||
// AlignTop
|
||||
// AlignBottom
|
||||
//)
|
||||
//
|
||||
//type Button struct {
|
||||
// mouseHandler
|
||||
// block
|
||||
// Label string
|
||||
// OnClick func() error
|
||||
// OnRightClick func() error
|
||||
// Style struct {
|
||||
// MouseDownColor *color.Color
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func (b *Button) HandleClick(_ MouseState) error {
|
||||
// if b.OnClick == nil {
|
||||
// return nil
|
||||
// }
|
||||
// return b.OnClick()
|
||||
//}
|
||||
//
|
||||
//
|
||||
//func (b *Button) getFont() font.Face {
|
||||
// if b.block.Font == nil {
|
||||
// return ux.FontFace
|
||||
// }
|
||||
//
|
||||
// return *b.block.block.Font
|
||||
//}
|
||||
//
|
||||
//func (b *Button) backgroundColor() color.Color {
|
||||
// var c *color.Color
|
||||
// if b.block.block.BackgroundColor != nil {
|
||||
// c = b.block.block.BackgroundColor
|
||||
// } else {
|
||||
// c = &ux.BackgroundColor
|
||||
// }
|
||||
//
|
||||
// if (b.mouseState.RightDown || b.mouseState.LeftDown) && b.Style.MouseDownColor != nil {
|
||||
// c = b.Style.MouseDownColor
|
||||
// }
|
||||
//
|
||||
// return *c
|
||||
//}
|
||||
//
|
||||
//func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||
//
|
||||
// vector.StrokeRect(image, xz, yz, w, h, 1, b.backgroundColor(), true)
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user