ux stuff
This commit is contained in:
23
common/elements/v1/block.go
Normal file
23
common/elements/v1/block.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func NewBlock(inline bool) *Block {
|
||||
|
||||
}
|
||||
|
||||
type Block struct {
|
||||
inline bool
|
||||
}
|
||||
|
||||
func (b *Block) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||
|
||||
}
|
||||
|
||||
func (b *Block) OnClick(ctx context.Context, click *ClickEvent) {
|
||||
|
||||
}
|
||||
32
common/elements/v1/button.go
Normal file
32
common/elements/v1/button.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"golang.org/x/image/font"
|
||||
)
|
||||
import "git.vezzani.net/ben/games/common/ux/v1"
|
||||
|
||||
type Button struct {
|
||||
Label string
|
||||
LabelPosition
|
||||
Font *font.Face
|
||||
OnClick func(click *ClickEvent) error
|
||||
}
|
||||
|
||||
func (b *Button) getFont() font.Face {
|
||||
if b.Font == nil {
|
||||
return ux.FontFace
|
||||
}
|
||||
|
||||
return *b.Font
|
||||
}
|
||||
|
||||
func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||
|
||||
}
|
||||
|
||||
func (b *Button) HandleClick(ctx context.Context, clickEvent *ClickEvent) error {
|
||||
return b.OnClick(click)
|
||||
}
|
||||
34
common/elements/v1/element.go
Normal file
34
common/elements/v1/element.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.vezzani.net/ben/games/common/control/v1"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type ClickEvent struct {
|
||||
X, Y int
|
||||
Button control.MouseButton
|
||||
}
|
||||
|
||||
const (
|
||||
ParentKey = "parent_element"
|
||||
)
|
||||
|
||||
type Clickable interface {
|
||||
HandleClick(ctx context.Context, click *ClickEvent) error
|
||||
}
|
||||
|
||||
type Element interface {
|
||||
Draw(ctx context.Context, image *ebiten.Image) error
|
||||
Size() (w, h int32)
|
||||
}
|
||||
|
||||
func GetParent(ctx context.Context) Element {
|
||||
if e, ok := ctx.Value(ParentKey).(Element); ok {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
1
common/elements/v1/menu.go
Normal file
1
common/elements/v1/menu.go
Normal file
@@ -0,0 +1 @@
|
||||
package elements
|
||||
1
common/elements/v1/table.go
Normal file
1
common/elements/v1/table.go
Normal file
@@ -0,0 +1 @@
|
||||
package elements
|
||||
Reference in New Issue
Block a user