Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions colorpicker/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions component/app_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {}
Expand All @@ -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() {
Expand Down
38 changes: 14 additions & 24 deletions component/context-area.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,31 +93,25 @@ 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
}
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
Expand Down
2 changes: 1 addition & 1 deletion component/modal_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 8 additions & 11 deletions component/nav_drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
6 changes: 1 addition & 5 deletions component/resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 4 additions & 15 deletions component/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
6 changes: 1 addition & 5 deletions component/text_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
12 changes: 4 additions & 8 deletions component/tooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
)

type result struct {
file interface{}
file any
error error
}

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions explorer/explorer_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package explorer
#include <stdlib.h>
*/
import "C"

import (
"errors"
"io"
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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}
}
Expand Down
1 change: 1 addition & 0 deletions explorer/explorer_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern bool exportFile(CFTypeRef expl, char * name);
extern bool importFile(CFTypeRef expl, char * ext);
*/
import "C"

import (
"io"
"os"
Expand Down
4 changes: 2 additions & 2 deletions explorer/explorer_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion explorer/explorer_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion explorer/file_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions explorer/file_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern const char* getURL(CFTypeRef url_ref);

*/
import "C"

import (
"errors"
"io"
Expand Down
Loading