holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,92 +1,93 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Table struct {
|
||||
mouseHandler
|
||||
block
|
||||
|
||||
ColumnCount int
|
||||
RowCount int
|
||||
|
||||
Cells []Dimensions
|
||||
|
||||
Style struct {
|
||||
}
|
||||
|
||||
mouseOverCell int
|
||||
}
|
||||
|
||||
func (t *Table) HandleClick(ctx context.Context, s MouseState) error {
|
||||
address := t.getAddressUnderMouse()
|
||||
if address < 0 || address >= len(t.Cells) {
|
||||
return fmt.Errorf("cell address under mouse is out of bounds")
|
||||
}
|
||||
|
||||
if clickable, ok := t.Cells[address].(Clickable); ok {
|
||||
return clickable.HandleClick(s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) HandleMouseEnter(ctx context.Context, s MouseState) error {
|
||||
_ = t.mouseHandler.HandleMouseEnter(s)
|
||||
address := t.getAddressUnderMouse()
|
||||
if address < 0 || address >= len(t.Cells) {
|
||||
return fmt.Errorf("cell address under mouse is out of bounds")
|
||||
}
|
||||
|
||||
if mouseable, ok := t.Cells[address].(Mouseable); ok {
|
||||
s.X -=
|
||||
return mouseable.HandleMouseEnter(s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) HandleMouseLeave(ctx context.Context, s MouseState) error {
|
||||
_ = t.mouseHandler.HandleMouseLeave(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) HandleMouseMove(ctx context.Context, s MouseState) error {
|
||||
_ = t.mouseHandler.HandleMouseMove(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) HandleMouseDown(ctx context.Context, s MouseState) error {
|
||||
_ = t.mouseHandler.HandleMouseDown(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) HandleMouseUp(ctx context.Context, s MouseState) error {
|
||||
_ = t.mouseHandler.HandleMouseUp(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) CellSize() (w, h float32) {
|
||||
w, h = t.
|
||||
return w / float32(t.ColumnCount), h / float32(t.RowCount)
|
||||
}
|
||||
|
||||
func (t *Table) CellZero(ctx context.Context, addr int) (x, y float32) {
|
||||
x, y = GetZero(ctx)
|
||||
w, h := t.CellSize(ctx)
|
||||
|
||||
col, row := addr%t.ColumnCount, addr/t.ColumnCount
|
||||
return x + float32(col)*w, y + float32(row) + h
|
||||
}
|
||||
|
||||
func (t *Table) Draw(screen *ebiten.Image, zx, zy float64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) getAddressUnderMouse() int {
|
||||
return int(t.mouseState.Y)*t.RowCount + int(t.mouseState.X)
|
||||
}
|
||||
//
|
||||
//import (
|
||||
// "context"
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/hajimehoshi/ebiten/v2"
|
||||
//)
|
||||
//
|
||||
//type Table struct {
|
||||
// mouseHandler
|
||||
// block
|
||||
//
|
||||
// ColumnCount int
|
||||
// RowCount int
|
||||
//
|
||||
// Cells []Bounds
|
||||
//
|
||||
// Style struct {
|
||||
// }
|
||||
//
|
||||
// mouseOverCell int
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleClick(ctx context.Context, s MouseState) error {
|
||||
// address := t.getAddressUnderMouse()
|
||||
// if address < 0 || address >= len(t.Cells) {
|
||||
// return fmt.Errorf("cell address under mouse is out of bounds")
|
||||
// }
|
||||
//
|
||||
// if clickable, ok := t.Cells[address].(Clickable); ok {
|
||||
// return clickable.HandleClick(s)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleMouseEnter(ctx context.Context, s MouseState) error {
|
||||
// _ = t.mouseHandler.HandleMouseEnter(s)
|
||||
// address := t.getAddressUnderMouse()
|
||||
// if address < 0 || address >= len(t.Cells) {
|
||||
// return fmt.Errorf("cell address under mouse is out of bounds")
|
||||
// }
|
||||
//
|
||||
// if mouseable, ok := t.Cells[address].(Mouseable); ok {
|
||||
// s.X -=
|
||||
// return mouseable.HandleMouseEnter(s)
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleMouseLeave(ctx context.Context, s MouseState) error {
|
||||
// _ = t.mouseHandler.HandleMouseLeave(s)
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleMouseMove(ctx context.Context, s MouseState) error {
|
||||
// _ = t.mouseHandler.HandleMouseMove(s)
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleMouseDown(ctx context.Context, s MouseState) error {
|
||||
// _ = t.mouseHandler.HandleMouseDown(s)
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) HandleMouseUp(ctx context.Context, s MouseState) error {
|
||||
// _ = t.mouseHandler.HandleMouseUp(s)
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) CellSize() (w, h float32) {
|
||||
// w, h = t.
|
||||
// return w / float32(t.ColumnCount), h / float32(t.RowCount)
|
||||
//}
|
||||
//
|
||||
//func (t *Table) CellZero(ctx context.Context, addr int) (x, y float32) {
|
||||
// x, y = GetZero(ctx)
|
||||
// w, h := t.CellSize(ctx)
|
||||
//
|
||||
// col, row := addr%t.ColumnCount, addr/t.ColumnCount
|
||||
// return x + float32(col)*w, y + float32(row) + h
|
||||
//}
|
||||
//
|
||||
//func (t *Table) Draw(screen *ebiten.Image, zx, zy float64) error {
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func (t *Table) getAddressUnderMouse() int {
|
||||
// return int(t.mouseState.Y)*t.RowCount + int(t.mouseState.X)
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user