From 15c9618700dc681e6b94e83a1aaeea6cbcd0c2c2 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 10 May 2024 13:17:02 -0400 Subject: separate label widget and style constants --- gui/widget/image.go | 3 +++ gui/widget/label.go | 31 +++++++++++++++++++++++++++++++ gui/widget/style.go | 10 ++++++++++ gui/widget/widget.go | 43 ------------------------------------------- 4 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 gui/widget/label.go create mode 100644 gui/widget/style.go delete mode 100644 gui/widget/widget.go diff --git a/gui/widget/image.go b/gui/widget/image.go index c5712c4..daf76aa 100644 --- a/gui/widget/image.go +++ b/gui/widget/image.go @@ -3,6 +3,7 @@ package widget import ( "sync" + xdraw "golang.org/x/image/draw" "image" "image/draw" @@ -10,6 +11,8 @@ import ( "volute/gui/win" ) +var interpolator = xdraw.ApproxBiLinear + func Image(imChan <-chan image.Image, r image.Rectangle, env gui.Env, wg *sync.WaitGroup) { defer wg.Done() defer close(env.Draw()) diff --git a/gui/widget/label.go b/gui/widget/label.go new file mode 100644 index 0000000..cc2010f --- /dev/null +++ b/gui/widget/label.go @@ -0,0 +1,31 @@ +package widget + +import ( + "sync" + "image" + "image/draw" + + "volute/gui" + "volute/gui/text" + "volute/gui/win" +) + +func Label(str string, r image.Rectangle, env gui.Env, wg *sync.WaitGroup) { + defer wg.Done() + defer close(env.Draw()) + + redraw := func(drw draw.Image) image.Rectangle { + text.Draw([]byte(str), drw, r, BLACK, WHITE) + return r + } + + env.Draw() <- redraw + for event := range env.Events() { + switch event := event.(type) { + case win.WiFocus: + if event.Focused { + env.Draw() <- redraw + } + } + } +} diff --git a/gui/widget/style.go b/gui/widget/style.go new file mode 100644 index 0000000..b2bd3f9 --- /dev/null +++ b/gui/widget/style.go @@ -0,0 +1,10 @@ +package widget + +import "image/color" + +var ( + FOCUS_COLOR = color.RGBA{179, 217, 255, 255} + GREEN = color.RGBA{51, 102, 0, 255} + BLACK = color.Gray{0} + WHITE = color.Gray{255} +) diff --git a/gui/widget/widget.go b/gui/widget/widget.go deleted file mode 100644 index 84e7175..0000000 --- a/gui/widget/widget.go +++ /dev/null @@ -1,43 +0,0 @@ -package widget - -import ( - "sync" - - xdraw "golang.org/x/image/draw" - "image" - "image/color" - "image/draw" - - "volute/gui" - "volute/gui/text" - "volute/gui/win" -) - -var ( - FOCUS_COLOR = color.RGBA{179, 217, 255, 255} - GREEN = color.RGBA{51, 102, 0, 255} - BLACK = color.Gray{0} - WHITE = color.Gray{255} - - interpolator = xdraw.ApproxBiLinear -) - -func Label(str string, r image.Rectangle, env gui.Env, wg *sync.WaitGroup) { - defer wg.Done() - defer close(env.Draw()) - - redraw := func(drw draw.Image) image.Rectangle { - text.Draw([]byte(str), drw, r, BLACK, WHITE) - return r - } - - env.Draw() <- redraw - for event := range env.Events() { - switch event := event.(type) { - case win.WiFocus: - if event.Focused { - env.Draw() <- redraw - } - } - } -} -- cgit v1.2.3