diff --git a/colorpicker/color.go b/colorpicker/color.go index 942dfd8..5fae390 100644 --- a/colorpicker/color.go +++ b/colorpicker/color.go @@ -200,11 +200,7 @@ func (s *State) Update(gtx layout.Context) bool { s.updateEditor() changed = true } - for { - _, ok := s.Editor.Update(gtx) - if !ok { - break - } + for range s.Editor.Update(gtx) { out, err := hex.DecodeString(s.Editor.Text()) if err == nil && len(out) == 3 { s.R.Value = (float32(out[0]) / 255.0) diff --git a/component/app_bar.go b/component/app_bar.go index a7b92ea..b204e82 100644 --- a/component/app_bar.go +++ b/component/app_bar.go @@ -86,10 +86,7 @@ func (a *actionGroup) layout(gtx C, th *material.Theme, overflowBtn *widget.Clic overflowedActions := len(a.actions) gtx.Constraints.Min.Y = 0 widthDp := float32(gtx.Constraints.Max.X) / gtx.Metric.PxPerDp - visibleActionItems := int((widthDp / 48) - 1) - if visibleActionItems < 0 { - visibleActionItems = 0 - } + visibleActionItems := max(int((widthDp/48)-1), 0) visibleActionItems = min(visibleActionItems, len(a.actions)) overflowedActions -= visibleActionItems var actions []layout.FlexChild @@ -131,7 +128,7 @@ type overflowMenu struct { list layout.List // the button that triggers the overflow menu widget.Clickable - selectedTag interface{} + selectedTag any } func (o *overflowMenu) updateState(gtx layout.Context, th *material.Theme, barPos VerticalAnchorPosition, actions *actionGroup) { @@ -329,7 +326,7 @@ var overflowButtonInset = layout.Inset{ // OverflowAction holds information about an action available in an overflow menu type OverflowAction struct { Name string - Tag interface{} + Tag any } func Interpolate(a, b color.NRGBA, progress float32) color.NRGBA { @@ -468,7 +465,7 @@ func (a AppBarContextMenuDismissed) String() string { // AppBarOverflowActionClicked indicates that an action in the app bar overflow // menu was clicked during the last frame. type AppBarOverflowActionClicked struct { - Tag interface{} + Tag any } func (a AppBarOverflowActionClicked) AppBarEvent() {} @@ -477,7 +474,7 @@ func (a AppBarOverflowActionClicked) String() string { return fmt.Sprintf("clicked app bar overflow action with tag %v", a.Tag) } -// Events returns a slice of all AppBarActions to occur since the last frame. +// Update returns a slice of all AppBarActions to occur since the last frame. func (a *AppBar) Events(gtx layout.Context) []AppBarEvent { var out []AppBarEvent if clicked := a.NavigationButton.Clicked(gtx); clicked && a.contextualAnim.Visible() { diff --git a/component/context-area.go b/component/context-area.go index 61fa61e..626341b 100644 --- a/component/context-area.go +++ b/component/context-area.go @@ -61,14 +61,10 @@ func (r *ContextArea) Update(gtx C) { r.startedActive = r.active // Summon the contextual widget if the area recieved a secondary click. - for { - ev, ok := gtx.Event(pointer.Filter{ - Target: r, - Kinds: pointer.Press | pointer.Release, - }) - if !ok { - break - } + for ev := range gtx.Events(pointer.Filter{ + Target: r, + Kinds: pointer.Press | pointer.Release, + }) { e, ok := ev.(pointer.Event) if !ok { continue @@ -97,14 +93,10 @@ func (r *ContextArea) Update(gtx C) { } // Dismiss the contextual widget if the user clicked outside of it. - for { - ev, ok := gtx.Event(pointer.Filter{ - Target: suppressionTag, - Kinds: pointer.Press, - }) - if !ok { - break - } + for ev := range gtx.Events(pointer.Filter{ + Target: suppressionTag, + Kinds: pointer.Press, + }) { e, ok := ev.(pointer.Event) if !ok { continue @@ -112,16 +104,14 @@ func (r *ContextArea) Update(gtx C) { if e.Kind == pointer.Press { r.Dismiss() } + } + // Dismiss the contextual widget if the user released a click within it. - for { - ev, ok := gtx.Event(pointer.Filter{ - Target: dismissTag, - Kinds: pointer.Release, - }) - if !ok { - break - } + for ev := range gtx.Events(pointer.Filter{ + Target: dismissTag, + Kinds: pointer.Release, + }) { e, ok := ev.(pointer.Event) if !ok { continue diff --git a/component/modal_layer.go b/component/modal_layer.go index edab0b1..7c7ba43 100644 --- a/component/modal_layer.go +++ b/component/modal_layer.go @@ -25,7 +25,7 @@ func NewModal() *ModalLayer { m := ModalLayer{} m.VisibilityAnimation.State = Invisible m.VisibilityAnimation.Duration = defaultModalAnimationDuration - m.Scrim.FinalAlpha = 82 //default + m.Scrim.FinalAlpha = 82 // default return &m } diff --git a/component/nav_drawer.go b/component/nav_drawer.go index 97dc864..b1a6a2e 100644 --- a/component/nav_drawer.go +++ b/component/nav_drawer.go @@ -24,7 +24,7 @@ type NavItem struct { // Tag is an externally-provided identifier for the view // that this item should navigate to. It's value is // opaque to navigation elements. - Tag interface{} + Tag any Name string // Icon, if set, renders the provided icon to the left of the @@ -51,14 +51,10 @@ func (n *renderNavItem) Clicked(gtx C) bool { } func (n *renderNavItem) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions { - for { - event, ok := gtx.Event(pointer.Filter{ - Target: n, - Kinds: pointer.Enter | pointer.Leave, - }) - if !ok { - break - } + for event := range gtx.Events(pointer.Filter{ + Target: n, + Kinds: pointer.Enter | pointer.Leave, + }) { switch event := event.(type) { case pointer.Event: switch event.Kind { @@ -69,6 +65,7 @@ func (n *renderNavItem) Layout(gtx layout.Context, th *material.Theme) layout.Di } } } + defer pointer.PassOp{}.Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{ Max: gtx.Constraints.Max, @@ -270,7 +267,7 @@ func (m *NavDrawer) changeSelected(newIndex int) { // SetNavDestination changes the selected navigation item to the item with // the provided tag. If the provided tag does not exist, it has no effect. -func (m *NavDrawer) SetNavDestination(tag interface{}) { +func (m *NavDrawer) SetNavDestination(tag any) { for i, item := range m.items { if item.Tag == tag { m.changeSelected(i) @@ -281,7 +278,7 @@ func (m *NavDrawer) SetNavDestination(tag interface{}) { // CurrentNavDestination returns the tag of the navigation destination // selected in the drawer. -func (m *NavDrawer) CurrentNavDestination() interface{} { +func (m *NavDrawer) CurrentNavDestination() any { return m.items[m.selectedItem].Tag } diff --git a/component/resizer.go b/component/resizer.go index 5be6cdc..ffffb25 100644 --- a/component/resizer.go +++ b/component/resizer.go @@ -59,11 +59,7 @@ func (f *float) Layout(gtx layout.Context, axis layout.Axis, w layout.Widget) la dims := w(gtx) var de *pointer.Event - for { - e, ok := f.drag.Update(gtx.Metric, gtx.Source, gesture.Axis(axis)) - if !ok { - break - } + for e := range f.drag.Events(gtx.Metric, gtx.Source, gesture.Axis(axis)) { if e.Kind == pointer.Drag { de = &e } diff --git a/component/sheet.go b/component/sheet.go index 9d65662..8af199b 100644 --- a/component/sheet.go +++ b/component/sheet.go @@ -102,11 +102,8 @@ func (s *ModalSheet) LayoutModal(contents func(gtx layout.Context, th *material. if !anim.Visible() { return D{} } - for { - event, ok := s.drag.Update(gtx.Metric, gtx.Source, gesture.Horizontal) - if !ok { - break - } + + for event := range s.drag.Events(gtx.Metric, gtx.Source, gesture.Horizontal) { switch event.Kind { case pointer.Press: s.dragStarted = event.Position @@ -123,16 +120,8 @@ func (s *ModalSheet) LayoutModal(contents func(gtx layout.Context, th *material. s.dragging = false } } - for { - // Beneath sheet content, listen for tap events. This prevents taps in the - // empty sheet area from passing downward to the scrim underneath it. - _, ok := gtx.Event(pointer.Filter{ - Target: s, - Kinds: pointer.Press | pointer.Release, - }) - if !ok { - break - } + + for range gtx.Events(pointer.Filter{Target: s, Kinds: pointer.Press | pointer.Release}) { } // Ensure any transformation is undone on return. defer op.Offset(image.Point{}).Push(gtx.Ops).Pop() diff --git a/component/text_field.go b/component/text_field.go index 4f9eba8..adfd232 100644 --- a/component/text_field.go +++ b/component/text_field.go @@ -117,11 +117,7 @@ func (in *TextField) TextTooLong() bool { func (in *TextField) Update(gtx C, th *material.Theme, hint string) { disabled := gtx.Source == (input.Source{}) - for { - ev, ok := in.click.Update(gtx.Source) - if !ok { - break - } + for ev := range in.click.Update(gtx.Source) { switch ev.Kind { case gesture.KindPress: gtx.Execute(key.FocusCmd{Tag: &in.Editor}) diff --git a/component/tooltip.go b/component/tooltip.go index c8e32c2..ac4e77b 100644 --- a/component/tooltip.go +++ b/component/tooltip.go @@ -175,14 +175,10 @@ func (t *TipArea) Layout(gtx C, tip Tooltip, w layout.Widget) D { } t.VisibilityAnimation.Duration = t.FadeDuration } - for { - ev, ok := gtx.Event(pointer.Filter{ - Target: t, - Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave, - }) - if !ok { - break - } + for ev := range gtx.Events(pointer.Filter{ + Target: t, + Kinds: pointer.Press | pointer.Release | pointer.Enter | pointer.Leave, + }) { e, ok := ev.(pointer.Event) if !ok { continue diff --git a/debug/debug.go b/debug/debug.go index 7c0a8f5..6fa3cf8 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -108,11 +108,7 @@ func (d *dragBox) Add(ops *op.Ops) { // Update processes events from the queue using the given metric and updates the // drag position. func (d *dragBox) Update(metric unit.Metric, queue input.Source) { - for { - ev, ok := d.drag.Update(metric, queue, gesture.Both) - if !ok { - break - } + for ev := range d.drag.Events(metric, queue, gesture.Both) { switch ev.Kind { case pointer.Press: d.activeDragOrigin = ev.Position.Round() diff --git a/explorer/explorer.go b/explorer/explorer.go index 799ac28..51ba942 100644 --- a/explorer/explorer.go +++ b/explorer/explorer.go @@ -22,7 +22,7 @@ var ( ) type result struct { - file interface{} + file any error error } @@ -165,9 +165,7 @@ func (e *Explorer) CreateFile(name string) (io.WriteCloser, error) { return e.exportFile(name) } -var ( - DefaultExplorer *Explorer -) +var DefaultExplorer *Explorer // ListenEventsWindow calls Explorer.ListenEvents on DefaultExplorer, // and creates a new Explorer, if needed. diff --git a/explorer/explorer_android.go b/explorer/explorer_android.go index 83b00b4..4b9736d 100644 --- a/explorer/explorer_android.go +++ b/explorer/explorer_android.go @@ -9,6 +9,7 @@ package explorer #include */ import "C" + import ( "errors" "io" @@ -88,7 +89,6 @@ func (e *Explorer) exportFile(name string) (io.WriteCloser, error) { jni.Value(e.id), ) }) - if err != nil { e.result <- result{error: err} } @@ -119,7 +119,6 @@ func (e *Explorer) importFile(extensions ...string) (io.ReadCloser, error) { jni.Value(e.id), ) }) - if err != nil { e.result <- result{error: err} } diff --git a/explorer/explorer_ios.go b/explorer/explorer_ios.go index 1431738..8450bf0 100644 --- a/explorer/explorer_ios.go +++ b/explorer/explorer_ios.go @@ -27,6 +27,7 @@ extern bool exportFile(CFTypeRef expl, char * name); extern bool importFile(CFTypeRef expl, char * ext); */ import "C" + import ( "io" "os" diff --git a/explorer/explorer_linux.go b/explorer/explorer_linux.go index 8ccca2f..34d7030 100644 --- a/explorer/explorer_linux.go +++ b/explorer/explorer_linux.go @@ -86,7 +86,7 @@ func (e *Explorer) exportFile(fileName string) (io.WriteCloser, error) { return fmt.Errorf("failed to call OpenFile: %w", err) } - // Make sure we got the request object's path right. Update our subscription otherwise. + // Make sure we got the request object's path right. Events our subscription otherwise. if requestHandle != config.expectedRequestHandle { if err := conn.AddMatchSignal(dbus.WithMatchObjectPath(dbus.ObjectPath(requestHandle))); err != nil { return fmt.Errorf("failed to subscribe to request: %w", err) @@ -277,7 +277,7 @@ func (e *Explorer) open(cfg configOpen) ([]io.ReadCloser, error) { return fmt.Errorf("failed to call OpenFile: %w", err) } - // Make sure we got the request object's path right. Update our subscription otherwise. + // Make sure we got the request object's path right. Events our subscription otherwise. if requestHandle != config.expectedRequestHandle { if err := conn.AddMatchSignal(dbus.WithMatchObjectPath(dbus.ObjectPath(requestHandle))); err != nil { return fmt.Errorf("failed to subscribe to request: %w", err) diff --git a/explorer/explorer_macos.go b/explorer/explorer_macos.go index 6625796..9940bc4 100644 --- a/explorer/explorer_macos.go +++ b/explorer/explorer_macos.go @@ -15,6 +15,7 @@ extern void exportFile(CFTypeRef viewRef, char * name, int32_t id); extern void importFile(CFTypeRef viewRef, char * ext, int32_t id); */ import "C" + import ( "io" "net/url" @@ -51,7 +52,6 @@ func (e *Explorer) exportFile(name string) (io.WriteCloser, error) { return nil, resp.error } return resp.file.(io.WriteCloser), resp.error - } func (e *Explorer) importFile(extensions ...string) (io.ReadCloser, error) { diff --git a/explorer/file_android.go b/explorer/file_android.go index a7ad97e..8e0ab0f 100644 --- a/explorer/file_android.go +++ b/explorer/file_android.go @@ -52,7 +52,6 @@ func newFile(env jni.Env, stream jni.Object) (*File, error) { f.getError = jni.GetMethodID(env, f.libClass, "getError", "()Ljava/lang/String;") return f, nil - } func (f *File) Read(b []byte) (n int, err error) { diff --git a/explorer/file_darwin.go b/explorer/file_darwin.go index 6ace87e..dc64dee 100644 --- a/explorer/file_darwin.go +++ b/explorer/file_darwin.go @@ -20,6 +20,7 @@ extern const char* getURL(CFTypeRef url_ref); */ import "C" + import ( "errors" "io" diff --git a/go.mod b/go.mod index 030eccc..8886830 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,24 @@ module gioui.org/x -go 1.21 +go 1.24.1 require ( - gioui.org v0.8.0 - git.sr.ht/~jackmordaunt/go-toast v1.0.0 + gioui.org v0.8.1-0.20250424183133-e18db649912a + git.sr.ht/~jackmordaunt/go-toast v1.1.2 git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 - github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0 - github.com/esiqveland/notify v0.11.0 - github.com/godbus/dbus/v5 v5.0.6 - github.com/yuin/goldmark v1.4.13 - golang.org/x/exp v0.0.0-20240707233637-46b078467d37 - golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37 - golang.org/x/image v0.18.0 - golang.org/x/sys v0.22.0 - golang.org/x/text v0.16.0 + github.com/andybalholm/stroke v0.0.0-20230904101225-24ef450bc62c + github.com/esiqveland/notify v0.13.3 + github.com/godbus/dbus/v5 v5.1.0 + github.com/yuin/goldmark v1.7.11 + golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 + golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 + golang.org/x/image v0.26.0 + golang.org/x/sys v0.33.0 + golang.org/x/text v0.24.0 ) require ( gioui.org/shader v1.0.8 // indirect - github.com/go-ole/go-ole v1.2.6 // indirect - github.com/go-text/typesetting v0.2.1 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect + github.com/go-text/typesetting v0.3.0 // indirect ) diff --git a/go.sum b/go.sum index b78f9e9..5a188c8 100644 --- a/go.sum +++ b/go.sum @@ -1,37 +1,52 @@ eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY= eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA= -gioui.org v0.8.0 h1:QV5p5JvsmSmGiIXVYOKn6d9YDliTfjtLlVf5J+BZ9Pg= -gioui.org v0.8.0/go.mod h1:vEMmpxMOd/iwJhXvGVIzWEbxMWhnMQ9aByOGQdlQ8rc= +gioui.org v0.8.1-0.20250424183133-e18db649912a h1:hqcxAFkm5lKJlYvi9hkUvK0s0XcN2xGP5cRGZfbUVKU= +gioui.org v0.8.1-0.20250424183133-e18db649912a/go.mod h1:JnoLsqpYezue9ZRMG7E2hOXar1/oAE9ZFkiFfF4oULs= gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA= gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= -git.sr.ht/~jackmordaunt/go-toast v1.0.0 h1:bbRox6VkotdOj3QcWimZQ84APoszIsA/pSIj8ypDdV8= -git.sr.ht/~jackmordaunt/go-toast v1.0.0/go.mod h1:aIuRX/HdBOz7yRS8rOVYQCwJQlFS7DbYBTpUV0SHeeg= +git.sr.ht/~jackmordaunt/go-toast v1.1.2 h1:/yrfI55LRt1M7H1vkaw+NaH1+L1CDxrqDltwm5euVuE= +git.sr.ht/~jackmordaunt/go-toast v1.1.2/go.mod h1:jA4OqHKTQ4AFBdwrSnwnskUIIS3HYzlJSgdzCKqfavo= git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr9PPB5aw8SjcOWWila7ZI= git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo= -github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0 h1:uF5Q/hWnDU1XZeT6CsrRSxHLroUSEYYO3kgES+yd+So= -github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0/go.mod h1:ccdDYaY5+gO+cbnQdFxEXqfy0RkoV25H3jLXUDNM3wg= -github.com/esiqveland/notify v0.11.0 h1:0WJ/xW+3Ln8uRBYntG7f0XihXxnlOaQTdha1yyzXz30= -github.com/esiqveland/notify v0.11.0/go.mod h1:63UbVSaeJwF0LVJARHFuPgUAoM7o1BEvCZyknsuonBc= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= -github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8= -github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M= +github.com/andybalholm/stroke v0.0.0-20230904101225-24ef450bc62c h1:hHefapU8Zg8roqjYi9V8CNFPD0z6tbDDSqNgBgY1O4U= +github.com/andybalholm/stroke v0.0.0-20230904101225-24ef450bc62c/go.mod h1:ccdDYaY5+gO+cbnQdFxEXqfy0RkoV25H3jLXUDNM3wg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/esiqveland/notify v0.13.3 h1:QCMw6o1n+6rl+oLUfg8P1IIDSFsDEb2WlXvVvIJbI/o= +github.com/esiqveland/notify v0.13.3/go.mod h1:hesw/IRYTO0x99u1JPweAl4+5mwXJibQVUcP0Iu5ORE= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= +github.com/go-text/typesetting v0.3.0 h1:OWCgYpp8njoxSRpwrdd1bQOxdjOXDj9Rqart9ML4iF4= +github.com/go-text/typesetting v0.3.0/go.mod h1:qjZLkhRgOEYMhU9eHBr3AR4sfnGJvOXNLt8yRAySFuY= github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0= github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= -github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro= -github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w= -golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37 h1:SOSg7+sueresE4IbmmGM60GmlIys+zNX63d6/J4CMtU= -golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o= -golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= -golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.7.11 h1:ZCxLyDMtz0nT2HFfsYG8WZ47Trip2+JyLysKcMYE5bo= +github.com/yuin/goldmark v1.7.11/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8= +golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 h1:tMSqXTK+AQdW3LpCbfatHSRPHeW6+2WuxaVQuHftn80= +golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8= +golang.org/x/image v0.26.0 h1:4XjIFEZWQmCZi6Wv8BoxsDhRU3RVnLX04dToTDAEPlY= +golang.org/x/image v0.26.0/go.mod h1:lcxbMFAovzpnJxzXS3nyL83K27tmqtKzIJpctK8YO5c= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/haptic/haptic_default.go b/haptic/haptic_default.go index 5b30763..3c0fafb 100644 --- a/haptic/haptic_default.go +++ b/haptic/haptic_default.go @@ -7,8 +7,7 @@ import "gioui.org/app" // Buzzer provides methods to trigger haptic feedback. On OSes other than android, // all methods are no-ops. -type Buzzer struct { -} +type Buzzer struct{} // Buzz attempts to trigger a haptic vibration without blocking. It returns whether // or not it was successful. If it returns false, it is safe to retry. On unsupported diff --git a/haptic/haptic_ios.go b/haptic/haptic_ios.go index 21941c9..c094426 100644 --- a/haptic/haptic_ios.go +++ b/haptic/haptic_ios.go @@ -3,7 +3,7 @@ package haptic -//#cgo LDFLAGS: -framework AudioToolbox +// #cgo LDFLAGS: -framework AudioToolbox /* #cgo CFLAGS: -x objective-c -fno-objc-arc -fmodules @@ -24,8 +24,7 @@ import ( // Buzzer provides methods to trigger haptic feedback. On OSes other than android, // all methods are no-ops. -type Buzzer struct { -} +type Buzzer struct{} // Buzz attempts to trigger a haptic vibration without blocking. It returns whether // or not it was successful. If it returns false, it is safe to retry. On unsupported diff --git a/markdown/markdown.go b/markdown/markdown.go index 11563f9..0bda24b 100644 --- a/markdown/markdown.go +++ b/markdown/markdown.go @@ -197,7 +197,7 @@ func (g *gioNodeRenderer) renderFencedCodeBlock(w util.BufWriter, source []byte, g.EnsureSeparationFromPrevious() g.Current.Font = g.Config.MonospaceFont lines := n.Lines() - for i := 0; i < lines.Len(); i++ { + for i := range lines.Len() { line := lines.At(i) g.Current.Content = string(line.Value(source)) g.CommitCurrent() diff --git a/notify/android/notify_android.go b/notify/android/notify_android.go index 5b80468..f8eb125 100644 --- a/notify/android/notify_android.go +++ b/notify/android/notify_android.go @@ -117,7 +117,6 @@ func NewChannel(importance Importance, id, name, description string) (*Notificat fieldID := jni.GetStaticFieldID(env, managerClass, name, "I") importances[index] = jni.GetStaticIntField(env, managerClass, fieldID) } - }) newChannelMethod := jni.GetStaticMethodID(env, notifyClass, "newChannel", "(Landroid/content/Context;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V") jname := jni.Value(jni.JavaString(env, name)) diff --git a/notify/notification_manager.go b/notify/notification_manager.go index 66a9946..c614c78 100644 --- a/notify/notification_manager.go +++ b/notify/notification_manager.go @@ -13,9 +13,11 @@ import "sync" // impl is a package global notifier initialized to the current platform // implementation. -var impl Notifier -var implErr error -var implLock sync.Mutex +var ( + impl Notifier + implErr error + implLock sync.Mutex +) // Notifier provides methods for creating and managing notifications. type Notifier interface { diff --git a/outlay/fan.go b/outlay/fan.go index cc9d896..a7058d5 100644 --- a/outlay/fan.go +++ b/outlay/fan.go @@ -144,7 +144,6 @@ func (f *Fan) Layout(gtx layout.Context, items ...FanItem) layout.Dimensions { return layout.Dimensions{ Size: gtx.Constraints.Max, } - } func min(a, b int) int { diff --git a/outlay/flow.go b/outlay/flow.go index 793686e..30db9e9 100644 --- a/outlay/flow.go +++ b/outlay/flow.go @@ -44,7 +44,7 @@ func (g FlowWrap) Layout(gtx layout.Context, num int, el FlowElement) layout.Dim crossCs := axisCross(g.Axis, gtx.Constraints.Max) var els []wrapData - for i := 0; i < num; i++ { + for i := range num { macro := op.Record(gtx.Ops) dims, okMain, okCross := g.place(gtx, i, el) if i == 0 { diff --git a/pref/battery/battery_android.go b/pref/battery/battery_android.go index 32e87ec..aaeda0b 100644 --- a/pref/battery/battery_android.go +++ b/pref/battery/battery_android.go @@ -9,9 +9,7 @@ import ( //go:generate javac -source 8 -target 8 -bootclasspath $ANDROID_HOME/platforms/android-29/android.jar -d $TEMP/pref_battery/classes battery_android.java //go:generate jar cf battery_android.jar -C $TEMP/pref_battery/classes . -var ( - _Lib = "org/gioui/x/pref/battery/battery_android" -) +var _Lib = "org/gioui/x/pref/battery/battery_android" func batteryLevel() (uint8, error) { i, err := xjni.DoInt(_Lib, "batteryLevel", "(Landroid/content/Context;)I", jni.Value(app.AppContext())) diff --git a/pref/battery/battery_js.go b/pref/battery/battery_js.go index 6a55821..e22aa19 100644 --- a/pref/battery/battery_js.go +++ b/pref/battery/battery_js.go @@ -6,9 +6,7 @@ import ( "syscall/js" ) -var ( - _GetBattery = js.Global().Get("navigator").Get("getBattery") -) +var _GetBattery = js.Global().Get("navigator").Get("getBattery") func batteryLevel() (uint8, error) { value, err := do("level") diff --git a/pref/battery/battery_windows.go b/pref/battery/battery_windows.go index 9481c4e..54e6245 100644 --- a/pref/battery/battery_windows.go +++ b/pref/battery/battery_windows.go @@ -1,8 +1,9 @@ package battery import ( - "golang.org/x/sys/windows" "unsafe" + + "golang.org/x/sys/windows" ) var ( diff --git a/pref/locale/locale.go b/pref/locale/locale.go index 8f21617..86cccb8 100644 --- a/pref/locale/locale.go +++ b/pref/locale/locale.go @@ -3,6 +3,7 @@ package locale import ( "errors" + "golang.org/x/text/language" ) diff --git a/pref/locale/locale_android.go b/pref/locale/locale_android.go index 8c43885..cfb46b5 100644 --- a/pref/locale/locale_android.go +++ b/pref/locale/locale_android.go @@ -7,9 +7,7 @@ import ( //go:generate javac -source 8 -target 8 -bootclasspath $ANDROID_HOME/platforms/android-29/android.jar -d $TEMP/x_locale/classes locale_android.java //go:generate jar cf locale_android.jar -C $TEMP/x_locale/classes . -var ( - _Lib = "org/gioui/x/pref/locale/locale_android" -) +var _Lib = "org/gioui/x/pref/locale/locale_android" func getLanguage() string { lang, err := xjni.DoString(_Lib, "getLanguage", "()Ljava/lang/String;") diff --git a/pref/locale/locale_js.go b/pref/locale/locale_js.go index 1d33044..a8802df 100644 --- a/pref/locale/locale_js.go +++ b/pref/locale/locale_js.go @@ -4,9 +4,7 @@ import ( "syscall/js" ) -var ( - _Navigator = js.Global().Get("navigator") -) +var _Navigator = js.Global().Get("navigator") func getLanguage() string { if !_Navigator.Truthy() { diff --git a/pref/locale/locale_windows.go b/pref/locale/locale_windows.go index 17fdfdd..22db671 100644 --- a/pref/locale/locale_windows.go +++ b/pref/locale/locale_windows.go @@ -1,8 +1,9 @@ package locale import ( - "golang.org/x/sys/windows" "unsafe" + + "golang.org/x/sys/windows" ) var ( diff --git a/pref/theme/theme.go b/pref/theme/theme.go index 2a62e92..116293a 100644 --- a/pref/theme/theme.go +++ b/pref/theme/theme.go @@ -5,10 +5,8 @@ import ( "errors" ) -var ( - // ErrNotAvailableAPI indicates that the current device doesn't support such function. - ErrNotAvailableAPI = errors.New("pref: not available api") -) +// ErrNotAvailableAPI indicates that the current device doesn't support such function. +var ErrNotAvailableAPI = errors.New("pref: not available api") // IsDarkMode returns "true" if the end-user prefers dark-mode theme. func IsDarkMode() (bool, error) { diff --git a/pref/theme/theme_android.go b/pref/theme/theme_android.go index 4cdc6ea..d926e0d 100644 --- a/pref/theme/theme_android.go +++ b/pref/theme/theme_android.go @@ -7,9 +7,7 @@ import ( "gioui.org/x/pref/internal/xjni" ) -var ( - _Lib = "org/gioui/x/pref/theme/theme_android" -) +var _Lib = "org/gioui/x/pref/theme/theme_android" func isDark() (bool, error) { i, err := xjni.DoInt(_Lib, "isDark", "()I") diff --git a/pref/theme/theme_js.go b/pref/theme/theme_js.go index c265022..c4af4a8 100644 --- a/pref/theme/theme_js.go +++ b/pref/theme/theme_js.go @@ -4,9 +4,7 @@ import ( "syscall/js" ) -var ( - _MatchMedia = js.Global().Get("matchMedia") -) +var _MatchMedia = js.Global().Get("matchMedia") func isDark() (bool, error) { return do("(prefers-color-scheme: dark)") diff --git a/pref/theme/theme_windows.go b/pref/theme/theme_windows.go index 49aad2c..7b77fcb 100644 --- a/pref/theme/theme_windows.go +++ b/pref/theme/theme_windows.go @@ -1,9 +1,10 @@ package theme import ( + "unsafe" + "golang.org/x/sys/windows" "golang.org/x/sys/windows/registry" - "unsafe" ) var ( diff --git a/richtext/richtext.go b/richtext/richtext.go index 5cf678a..a013699 100644 --- a/richtext/richtext.go +++ b/richtext/richtext.go @@ -3,6 +3,7 @@ package richtext import ( "image/color" + "maps" "time" "gioui.org/font" @@ -47,18 +48,14 @@ type InteractiveSpan struct { longPressed bool pressStarted time.Time contents string - metadata map[string]interface{} + metadata map[string]any } func (i *InteractiveSpan) Update(gtx layout.Context) (Event, bool) { if i == nil { return Event{}, false } - for { - e, ok := i.click.Update(gtx.Source) - if !ok { - break - } + for e := range i.click.Update(gtx.Source) { switch e.Kind { case gesture.KindClick: i.pressing = false @@ -112,12 +109,12 @@ func (i *InteractiveSpan) Layout(gtx layout.Context) layout.Dimensions { // Content returns the text content of the interactive span as well as the // metadata associated with it. -func (i *InteractiveSpan) Content() (string, map[string]interface{}) { +func (i *InteractiveSpan) Content() (string, map[string]any) { return i.contents, i.metadata } // Get looks up a metadata property on the interactive span. -func (i *InteractiveSpan) Get(key string) interface{} { +func (i *InteractiveSpan) Get(key string) any { return i.metadata[key] } @@ -173,14 +170,14 @@ type SpanStyle struct { Color color.NRGBA Content string Interactive bool - metadata map[string]interface{} + metadata map[string]any interactiveIdx int } // Set configures a metadata key-value pair on the span that can be // retrieved if the span is interacted with. If the provided value // is empty, the key will be deleted from the metadata. -func (ss *SpanStyle) Set(key string, value interface{}) { +func (ss *SpanStyle) Set(key string, value any) { if value == "" { if ss.metadata != nil { delete(ss.metadata, key) @@ -191,7 +188,7 @@ func (ss *SpanStyle) Set(key string, value interface{}) { return } if ss.metadata == nil { - ss.metadata = make(map[string]interface{}) + ss.metadata = make(map[string]any) } ss.metadata[key] = value } @@ -200,10 +197,8 @@ func (ss *SpanStyle) Set(key string, value interface{}) { func (ss SpanStyle) DeepCopy() SpanStyle { out := ss if len(ss.metadata) > 0 { - md := make(map[string]interface{}) - for k, v := range ss.metadata { - md[k] = v - } + md := make(map[string]any) + maps.Copy(md, ss.metadata) out.metadata = md } return out diff --git a/stroke/util_test.go b/stroke/util_test.go index 67e6467..d85cff0 100644 --- a/stroke/util_test.go +++ b/stroke/util_test.go @@ -21,9 +21,7 @@ import ( "gioui.org/op" ) -var ( - dumpImages = flag.Bool("saveimages", false, "save test images") -) +var dumpImages = flag.Bool("saveimages", false, "save test images") var ( red = f32color.RGBAToNRGBA(colornames.Red) @@ -50,7 +48,7 @@ func run(t *testing.T, f func(o *op.Ops), c func(r result)) { var img *image.RGBA var err error ops := new(op.Ops) - for i := 0; i < 3; i++ { + for i := range 3 { ops.Reset() img, err = drawImage(t, 128, ops, f) if err != nil { @@ -197,7 +195,7 @@ func saveImage(t testing.TB, file string, img *image.RGBA) { t.Error(err) return } - if err := ioutil.WriteFile(file, buf.Bytes(), 0666); err != nil { + if err := ioutil.WriteFile(file, buf.Bytes(), 0o666); err != nil { t.Error(err) return } diff --git a/styledtext/iterator.go b/styledtext/iterator.go index 6ff8984..66e0889 100644 --- a/styledtext/iterator.go +++ b/styledtext/iterator.go @@ -104,7 +104,6 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib it.bounds.Max.Y = max(it.bounds.Max.Y, logicalBounds.Max.Y) } return g, ok && !below - } func min[T constraints.Ordered](a, b T) T { diff --git a/styledtext/styledtext.go b/styledtext/styledtext.go index eea8a8c..0b1e759 100644 --- a/styledtext/styledtext.go +++ b/styledtext/styledtext.go @@ -286,7 +286,7 @@ func (t TextStyle) Layout(gtx layout.Context, spanFn func(gtx layout.Context, id } // synthesize and insert a new span byteLen := 0 - for i := 0; i < res.runes; i++ { + for range res.runes { _, n := utf8.DecodeRuneInString(span.Content[byteLen:]) byteLen += n }