Skip to content

Commit

Permalink
use wydget.Entry to set a minimum width for entry fields
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 21, 2024
1 parent 2c47e66 commit c25be1d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
27 changes: 17 additions & 10 deletions fyneui/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"github.com/ftl/hellocontest/core"
core_callinfo "github.com/ftl/hellocontest/core/callinfo"
core_entry "github.com/ftl/hellocontest/core/entry"
"github.com/ftl/wydget"
)

const (
minWidthExchange = 100
minWidthTheirCall = 150
)

type EntryController interface {
Expand Down Expand Up @@ -53,7 +59,7 @@ type entry struct {

// their data
theirLabel *widget.Label
theirCall *widget.Entry
theirCall *wydget.Entry
theirExchangesParent *fyne.Container
theirExchanges []fyne.CanvasObject

Expand Down Expand Up @@ -99,7 +105,8 @@ func setupEntry(canvas func() fyne.Canvas) *entry {

// entry row: input
result.theirLabel = widget.NewLabel("Their:")
result.theirCall = widget.NewEntry()
result.theirCall = wydget.NewEntry()
result.theirCall.MinWidth = minWidthTheirCall
result.theirCall.PlaceHolder = "Call"
result.addFieldEntryEventHandler(core.CallsignField, result.theirCall)
result.theirExchangesParent = container.NewHBox()
Expand Down Expand Up @@ -153,7 +160,7 @@ func (e *entry) onModeSelect(modeLabel string) {
// TODO implement
}

func (e *entry) addFieldEntryEventHandler(field core.EntryField, w *widget.Entry) {
func (e *entry) addFieldEntryEventHandler(field core.EntryField, w *wydget.Entry) {
w.OnChanged = func(s string) {
e.onEntryChanged(field, s)
}
Expand Down Expand Up @@ -182,9 +189,9 @@ func (e *entry) setupExchangeEntry(fields []core.ExchangeField, parent *fyne.Con

*entries = make([]fyne.CanvasObject, len(fields))
for i, field := range fields {
entry := widget.NewEntry()
entry := wydget.NewEntry()
entry.SetPlaceHolder(field.Short)
entry.Resize(fyne.NewSize(200, 0))
entry.MinWidth = minWidthExchange
(*entries)[i] = entry
parent.Add(entry)
e.addFieldEntryEventHandler(field.Field, entry)
Expand Down Expand Up @@ -271,15 +278,15 @@ func (e *entry) SetMyExchange(index int, text string) {
if i < 0 || i >= len(e.myExchanges) {
return
}
e.myExchanges[i].(*widget.Entry).SetText(text)
e.myExchanges[i].(*wydget.Entry).SetText(text)
}

func (e *entry) SetTheirExchange(index int, text string) {
i := index - 1
if i < 0 || i >= len(e.theirExchanges) {
return
}
e.theirExchanges[i].(*widget.Entry).SetText(text)
e.theirExchanges[i].(*wydget.Entry).SetText(text)
}

func (e *entry) SetPredictedExchange(index int, text string) {
Expand Down Expand Up @@ -378,7 +385,7 @@ func (e *entry) fieldToWidget(field core.EntryField) fyne.CanvasObject {
panic("this is never reached")
}

func (e *entry) fieldToEntry(field core.EntryField) *widget.Entry {
func (e *entry) fieldToEntry(field core.EntryField) *wydget.Entry {
switch field {
case core.CallsignField:
return e.theirCall
Expand All @@ -388,10 +395,10 @@ func (e *entry) fieldToEntry(field core.EntryField) *widget.Entry {
switch {
case field.IsMyExchange():
i := field.ExchangeIndex() - 1
return e.myExchanges[i].(*widget.Entry)
return e.myExchanges[i].(*wydget.Entry)
case field.IsTheirExchange():
i := field.ExchangeIndex() - 1
return e.theirExchanges[i].(*widget.Entry)
return e.theirExchanges[i].(*wydget.Entry)
}
return nil
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ftl/hellocontest

go 1.22.3
go 1.23.3

// replace github.com/ftl/cabrillo => ../cabrillo

Expand All @@ -21,7 +21,7 @@ go 1.22.3
// replace fyne.io/fyne/v2 => ../fyne

require (
fyne.io/fyne/v2 v2.5.2
fyne.io/fyne/v2 v2.5.3
github.com/ftl/cabrillo v0.2.2
github.com/ftl/clusterix v0.1.0
github.com/ftl/conval v0.7.7
Expand All @@ -30,6 +30,7 @@ require (
github.com/ftl/hamradio v0.2.11
github.com/ftl/rigproxy v0.2.6
github.com/ftl/tci v0.3.2
github.com/ftl/wydget v0.0.0-20241221133158-be3cc2568e32
github.com/golang/protobuf v1.5.2
github.com/gotk3/gotk3 v0.6.3
github.com/pkg/errors v0.9.1
Expand All @@ -47,7 +48,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/ftl/localcopy v0.0.0-20190616142648-8915fb81f0d9 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a // indirect
github.com/fyne-io/glfw-js v0.0.0-20241126112943-313d8a0fe1d0 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
Expand All @@ -61,7 +62,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rymdport/portal v0.2.6 // indirect
github.com/rymdport/portal v0.3.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/objx v0.5.0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
fyne.io/fyne/v2 v2.5.2 h1:eSyGTmSkv10yAdAeHpDet6u2KkKxOGFc14kQu81We7Q=
fyne.io/fyne/v2 v2.5.2/go.mod h1:26gqPDvtaxHeyct+C0BBjuGd2zwAJlPkUGSBrb+d7Ug=
fyne.io/fyne/v2 v2.5.3 h1:k6LjZx6EzRZhClsuzy6vucLZBstdH2USDGHSGWq8ly8=
fyne.io/fyne/v2 v2.5.3/go.mod h1:0GOXKqyvNwk3DLmsFu9v0oYM0ZcD1ysGnlHCerKoAmo=
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -99,10 +99,12 @@ github.com/ftl/rigproxy v0.2.6 h1:umsoOET+VWpWc3jSXz+FoZq5zwuodrigiOiwZyafr3o=
github.com/ftl/rigproxy v0.2.6/go.mod h1:PrBUiqLwu/6zL44+uOz4lgmOfnis4FIvJDhxDNXoi60=
github.com/ftl/tci v0.3.2 h1:1Qdgprldiv7/DQvuK96OHMVqb+SDunqbxTHDcWsE5Tk=
github.com/ftl/tci v0.3.2/go.mod h1:3B8x8FI/kBbUwbWnz725tTiiiNfJpIL9cQ67TnjW3aU=
github.com/ftl/wydget v0.0.0-20241221133158-be3cc2568e32 h1:3bknFisq3nKKRGWH9JQMFAOa0U+rzyjmURwwfDTBPvY=
github.com/ftl/wydget v0.0.0-20241221133158-be3cc2568e32/go.mod h1:RWYHAGiTS0u9KrYYZkngdHFxA+xUW7C16H5OrLX9mJA=
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe h1:A/wiwvQ0CAjPkuJytaD+SsXkPU0asQ+guQEIg1BJGX4=
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe/go.mod h1:d4clgH0/GrRwWjRzJJQXxT/h1TyuNSfF/X64zb/3Ggg=
github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a h1:ybgRdYvAHTn93HW79bLiBiJwVL4jVeyGQRZMgImoeWs=
github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a/go.mod h1:gsGA2dotD4v0SR6PmPCYvS9JuOeMwAtmfvDE7mbYXMY=
github.com/fyne-io/glfw-js v0.0.0-20241126112943-313d8a0fe1d0 h1:/1YRWFv9bAWkoo3SuxpFfzpXH0D/bQnTjNXyF4ih7Os=
github.com/fyne-io/glfw-js v0.0.0-20241126112943-313d8a0fe1d0/go.mod h1:gsGA2dotD4v0SR6PmPCYvS9JuOeMwAtmfvDE7mbYXMY=
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 h1:hnLq+55b7Zh7/2IRzWCpiTcAvjv/P8ERF+N7+xXbZhk=
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2/go.mod h1:eO7W361vmlPOrykIg+Rsh1SZ3tQBaOsfzZhsIOb/Lm0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -280,8 +282,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/rymdport/portal v0.2.6 h1:HWmU3gORu7vWcpr7VSwUS2Xx1HtJXVcUuTqEZcMEsIg=
github.com/rymdport/portal v0.2.6/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4=
github.com/rymdport/portal v0.3.0 h1:QRHcwKwx3kY5JTQcsVhmhC3TGqGQb9LFghVNUy8AdB8=
github.com/rymdport/portal v0.3.0/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
Expand Down

0 comments on commit c25be1d

Please sign in to comment.