Initial commit

This commit is contained in:
Trevor Slocum 2022-06-08 16:35:42 -07:00
commit 1b8a1f536a
15 changed files with 672 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Trevor Slocum <trevor@rocketnine.space>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# etk - Ebitengine Tool Kit
[![GoDoc](https://code.rocketnine.space/tslocum/godoc-static/raw/branch/master/badge.svg)](https://docs.rocketnine.space/code.rocketnine.space/tslocum/etk)
[![Donate via LiberaPay](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
[![Donate via Patreon](https://img.shields.io/badge/dynamic/json?color=%23e85b46&label=Patreon&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F5252223)](https://www.patreon.com/rocketnine)
[Ebitengine](https://github.com/hajimehoshi/ebiten) tool kit for creating graphical user interfaces
**Note:** This library is still in development. Breaking changes may be made until v1.0 is released.
[IME](https://en.wikipedia.org/wiki/Input_method) is not yet supported.
## Documentation
Documentation is available via [godoc](https://docs.rocketnine.space/code.rocketnine.space/tslocum/etk).
## Support
Please share issues and suggestions [here](https://code.rocketnine.space/tslocum/etk/issues).

46
box.go Normal file
View File

@ -0,0 +1,46 @@
package etk
import (
"image"
"sync"
)
type Box struct {
rect image.Rectangle
children []Widget
sync.Mutex
}
func NewBox() *Box {
return &Box{}
}
func (b *Box) Rect() image.Rectangle {
b.Lock()
defer b.Unlock()
return b.rect
}
func (b *Box) SetRect(r image.Rectangle) {
b.Lock()
defer b.Unlock()
b.rect = r
}
func (b *Box) Children() []Widget {
b.Lock()
defer b.Unlock()
return b.children
}
func (b *Box) AddChild(w ...Widget) {
b.Lock()
defer b.Unlock()
b.children = append(b.children, w...)
}

90
button.go Normal file
View File

@ -0,0 +1,90 @@
package etk
import (
"image"
"image/color"
"log"
"code.rocketnine.space/tslocum/messeji"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"github.com/hajimehoshi/ebiten/v2"
)
// TODO
var mplusNormalFont font.Face
func init() {
tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
if err != nil {
log.Fatal(err)
}
const dpi = 72
mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 32,
DPI: dpi,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
}
type Button struct {
*Box
label *messeji.TextField
}
func NewButton(label string, onSelected func()) *Button {
textColor := Style.ButtonTextColor
if textColor == nil {
textColor = Style.TextColor
}
l := messeji.NewTextField(mplusNormalFont)
l.SetText(label)
l.SetForegroundColor(textColor)
l.SetBackgroundColor(color.RGBA{0, 0, 0, 0})
l.SetHorizontal(messeji.AlignCenter)
l.SetVertical(messeji.AlignCenter)
return &Button{
Box: NewBox(),
label: l, // TODO
}
}
func (b *Button) SetRect(r image.Rectangle) {
b.Box.rect = r
b.label.SetRect(r)
}
func (b *Button) HandleMouse() (handled bool, err error) {
return false, nil
}
func (b *Button) HandleKeyboard() (handled bool, err error) {
return false, nil
}
func (b *Button) Draw(screen *ebiten.Image) error {
// TODO background color
// Draw background.
screen.SubImage(b.rect).(*ebiten.Image).Fill(Style.ButtonBgColor)
// Draw label.
b.label.Draw(screen)
// Draw border.
const borderSize = 4
screen.SubImage(image.Rect(b.rect.Min.X, b.rect.Min.Y, b.rect.Max.X, b.rect.Min.Y+borderSize)).(*ebiten.Image).Fill(Style.BorderColor)
screen.SubImage(image.Rect(b.rect.Min.X, b.rect.Max.Y-borderSize, b.rect.Max.X, b.rect.Max.Y)).(*ebiten.Image).Fill(Style.BorderColor)
screen.SubImage(image.Rect(b.rect.Min.X, b.rect.Min.Y, b.rect.Min.X+borderSize, b.rect.Max.Y)).(*ebiten.Image).Fill(Style.BorderColor)
screen.SubImage(image.Rect(b.rect.Max.X-borderSize, b.rect.Min.Y, b.rect.Max.X, b.rect.Max.Y)).(*ebiten.Image).Fill(Style.BorderColor)
return nil
}

4
doc.go Normal file
View File

@ -0,0 +1,4 @@
/*
Package etk provides an Ebitengine tool kit for creating graphical user interfaces.
*/
package etk

33
examples/flex/game.go Normal file
View File

@ -0,0 +1,33 @@
//go:build example
// +build example
package main
import (
"code.rocketnine.space/tslocum/etk"
"github.com/hajimehoshi/ebiten/v2"
)
type game struct {
}
func newGame() *game {
g := &game{}
return g
}
func (g *game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
etk.Layout(outsideWidth, outsideHeight)
return outsideWidth, outsideHeight
}
func (g *game) Update() error {
return etk.Update()
}
func (g *game) Draw(screen *ebiten.Image) {
err := etk.Draw(screen)
if err != nil {
panic(err)
}
}

39
examples/flex/main.go Normal file
View File

@ -0,0 +1,39 @@
//go:build example
// +build example
package main
import (
"code.rocketnine.space/tslocum/etk"
"github.com/hajimehoshi/ebiten/v2"
)
func main() {
ebiten.SetWindowTitle("etk showcase")
g := newGame()
b1 := etk.NewButton("Button 1", nil)
b2 := etk.NewButton("Button 2", nil)
topFlex := etk.NewFlex()
topFlex.AddChild(b1, b2)
b3 := etk.NewButton("Button 3", nil)
b4 := etk.NewButton("Button 4", nil)
b5 := etk.NewButton("Button 5", nil)
bottomFlex := etk.NewFlex()
bottomFlex.AddChild(b3, b4, b5)
rootFlex := etk.NewFlex()
rootFlex.SetVertical(true)
rootFlex.AddChild(topFlex, bottomFlex)
etk.SetRoot(rootFlex)
err := ebiten.RunGame(g)
if err != nil {
panic(err)
}
}

33
examples/showcase/game.go Normal file
View File

@ -0,0 +1,33 @@
//go:build example
// +build example
package main
import (
"code.rocketnine.space/tslocum/etk"
"github.com/hajimehoshi/ebiten/v2"
)
type game struct {
}
func newGame() *game {
g := &game{}
return g
}
func (g *game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
etk.Layout(outsideWidth, outsideHeight)
return outsideWidth, outsideHeight
}
func (g *game) Update() error {
return etk.Update()
}
func (g *game) Draw(screen *ebiten.Image) {
err := etk.Draw(screen)
if err != nil {
panic(err)
}
}

39
examples/showcase/main.go Normal file
View File

@ -0,0 +1,39 @@
//go:build example
// +build example
package main
import (
"code.rocketnine.space/tslocum/etk"
"github.com/hajimehoshi/ebiten/v2"
)
func main() {
ebiten.SetWindowTitle("etk showcase")
g := newGame()
b1 := etk.NewButton("Button 1", nil)
b2 := etk.NewButton("Button 2", nil)
topFlex := etk.NewFlex()
topFlex.AddChild(b1, b2)
b3 := etk.NewButton("Button 3", nil)
b4 := etk.NewButton("Button 4", nil)
b5 := etk.NewButton("Button 5", nil)
bottomFlex := etk.NewFlex()
bottomFlex.AddChild(b3, b4, b5)
rootFlex := etk.NewFlex()
rootFlex.SetVertical(true)
rootFlex.AddChild(topFlex, bottomFlex)
etk.SetRoot(rootFlex)
err := ebiten.RunGame(g)
if err != nil {
panic(err)
}
}

110
flex.go Normal file
View File

@ -0,0 +1,110 @@
package etk
import (
"image"
"log"
"github.com/hajimehoshi/ebiten/v2"
)
type Flex struct {
*Box
vertical bool
lastRect image.Rectangle
}
func NewFlex() *Flex {
return &Flex{
Box: NewBox(),
}
}
func (f *Flex) SetRect(r image.Rectangle) {
f.Lock()
defer f.Unlock()
f.Box.rect = r
// TODO
for _, child := range f.children {
child.SetRect(r)
}
}
func (f *Flex) SetVertical(v bool) {
f.Lock()
defer f.Unlock()
if f.vertical == v {
return
}
f.vertical = v
f.reposition()
}
func (f *Flex) HandleMouse() (handled bool, err error) {
return false, nil
}
func (f *Flex) HandleKeyboard() (handled bool, err error) {
return false, nil
}
func (f *Flex) Draw(screen *ebiten.Image) error {
f.Lock()
defer f.Unlock()
if !f.rect.Eq(f.lastRect) {
f.reposition()
f.lastRect = f.rect
}
for _, child := range f.children {
err := child.Draw(screen)
if err != nil {
return err
}
}
return nil
}
func (f *Flex) reposition() {
l := len(f.children)
r := f.rect
if f.vertical {
childHeight := float64(r.Dy()) / float64(l)
minY := r.Min.Y
for i, child := range f.children {
maxY := r.Min.Y + int(childHeight*float64(i+1))
if i == l-1 {
maxY = r.Max.Y
}
log.Println(i, maxY, image.Rect(r.Min.X, minY, r.Max.X, maxY))
child.SetRect(image.Rect(r.Min.X, minY, r.Max.X, maxY))
minY = maxY
}
return
}
childWidth := float64(r.Dx()) / float64(l)
minX := r.Min.X
for i, child := range f.children {
maxX := r.Min.X + int(childWidth*float64(i+1))
if i == l-1 {
maxX = r.Max.X
}
log.Println(i, maxX, image.Rect(minX, r.Min.Y, maxX, r.Max.Y))
child.SetRect(image.Rect(minX, r.Min.Y, maxX, r.Max.Y))
minX = maxX
}
}

91
game.go Normal file
View File

@ -0,0 +1,91 @@
package etk
import (
"fmt"
"image"
"github.com/hajimehoshi/ebiten/v2"
)
var root Widget
var (
lastWidth, lastHeight int
)
func SetRoot(w Widget) {
root = w
}
func Layout(outsideWidth, outsideHeight int) {
if root == nil {
panic("no root widget specified")
}
if outsideWidth != lastWidth || outsideHeight != lastHeight {
root.SetRect(image.Rect(0, 0, outsideWidth, outsideHeight))
lastWidth, lastHeight = outsideWidth, outsideHeight
}
}
func Update() error {
if root == nil {
panic("no root widget specified")
}
var mouseHandled bool
var keyboardHandled bool
var err error
children := root.Children()
for _, child := range children {
if !mouseHandled {
mouseHandled, err = child.HandleMouse()
if err != nil {
return fmt.Errorf("failed to handle widget mouse input: %s", err)
}
}
if !keyboardHandled {
keyboardHandled, err = child.HandleKeyboard()
if err != nil {
return fmt.Errorf("failed to handle widget keyboard input: %s", err)
}
}
if mouseHandled && keyboardHandled {
return nil
}
}
if !mouseHandled {
_, err = root.HandleMouse()
if err != nil {
return fmt.Errorf("failed to handle widget mouse input: %s", err)
}
}
if !keyboardHandled {
_, err = root.HandleKeyboard()
if err != nil {
return fmt.Errorf("failed to handle widget keyboard input: %s", err)
}
}
return nil
}
func Draw(screen *ebiten.Image) error {
if root == nil {
panic("no root widget specified")
}
err := root.Draw(screen)
if err != nil {
return fmt.Errorf("failed to draw widget: %s", err)
}
children := root.Children()
for _, child := range children {
err = child.Draw(screen)
if err != nil {
return fmt.Errorf("failed to draw widget: %s", err)
}
}
return nil
}

20
go.mod Normal file
View File

@ -0,0 +1,20 @@
module code.rocketnine.space/tslocum/etk
go 1.18
require (
code.rocketnine.space/tslocum/messeji v1.0.0
github.com/hajimehoshi/ebiten/v2 v2.3.3
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd
)
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/jezek/xgb v1.0.1 // indirect
golang.org/x/exp/shiny v0.0.0-20220609121020-a51bd0440498 // indirect
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
golang.org/x/text v0.3.7 // indirect
)

90
go.sum Normal file
View File

@ -0,0 +1,90 @@
code.rocketnine.space/tslocum/messeji v1.0.0 h1:GRZ8/ExI/syR3+0UH3cMjnJFhJnGxQOMSMoCf/v7XLM=
code.rocketnine.space/tslocum/messeji v1.0.0/go.mod h1:o3MnboWYp/W/ZsYCzga4t/pyzLfXnf6iK8R3KBJuHIM=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220320163800-277f93cfa958/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661 h1:1bpooddSK2996NWM/1TW59cchQOm9MkoV9DkhSJH1BI=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220516021902-eb3e265c7661/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/hajimehoshi/bitmapfont/v2 v2.2.0 h1:E6vzlchynZj6OVohVKFqWkKW348EmDW62K5zPXDi7A8=
github.com/hajimehoshi/bitmapfont/v2 v2.2.0/go.mod h1:Llj2wTYXMuCTJEw2ATNIO6HbFPOoBYPs08qLdFAxOsQ=
github.com/hajimehoshi/ebiten/v2 v2.3.3 h1:v72UzprVvWGE+HGcypkLI9Ikd237fqzpio5idPk9KNI=
github.com/hajimehoshi/ebiten/v2 v2.3.3/go.mod h1:vxwpo0q0oSi1cIll0Q3Ui33TVZgeHuFVYzIRk7FwuVk=
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.3/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.1.0/go.mod h1:9i0oYbpJ8BhVGkXDKdXKfFthX1JUNfXjeTp944W8TGM=
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jezek/xgb v1.0.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=
github.com/jezek/xgb v1.0.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp/shiny v0.0.0-20220609121020-a51bd0440498 h1:mJjyic/dxHcz1W6IUE8zf6+RltuO8+9mS45tTtb4F6k=
golang.org/x/exp/shiny v0.0.0-20220609121020-a51bd0440498/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220321031419-a8550c1d254a/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd h1:9NbNcTg//wfC5JskFW4Z3sqwVnjmJKHxLAol1bW2qgw=
golang.org/x/image v0.0.0-20220601225756-64ec528b34cd/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd h1:x1GptNaTtxPAlTVIAJk61fuXg0y17h09DTxyb+VNC/k=
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 h1:z8Hj/bl9cOV2grsOpEaQFUaly0JWN3i97mo3jXKJNp0=
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

22
style.go Normal file
View File

@ -0,0 +1,22 @@
package etk
import "image/color"
type Attributes struct {
TextColor color.Color
BorderColor color.Color
ButtonTextColor color.Color
ButtonBgColor color.Color
ButtonBgColorDisabled color.Color
}
var Style = &Attributes{
TextColor: color.RGBA{0, 0, 0, 255},
BorderColor: color.RGBA{0, 0, 0, 255},
ButtonBgColor: color.RGBA{255, 255, 255, 255},
ButtonBgColorDisabled: color.RGBA{110, 110, 110, 255},
}

16
widget.go Normal file
View File

@ -0,0 +1,16 @@
package etk
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
type Widget interface {
Rect() image.Rectangle
SetRect(r image.Rectangle)
HandleMouse() (handled bool, err error)
HandleKeyboard() (handled bool, err error)
Draw(screen *ebiten.Image) error
Children() []Widget
}