~eliasnaur/gio#56:
Broken scrolling

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

Any ideas on what could be causing this behaviour?

Kind Regards Werner

Status
REPORTED
Submitter
Werner Laurensse
Assigned to
No-one
Submitted
9 days ago
Updated
7 days ago
Labels
No labels applied.

~eliasnaur 9 days ago

On Sun Nov 3, 2019 at 11:32 PM Werner Laurensse wrote:

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

I'd like to take a look, but I failed to run your program:

$ go version
go version devel +5d000a8b62 Sat Oct 26 08:29:23 2019 +0000 linux/amd64
$ cd $(mktemp -d)
$ git clone https://github.com/wrnrlr/foxtrot
Cloning into 'foxtrot'...
remote: Enumerating objects: 68, done.
remote: Counting objects: 100% (68/68), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 68 (delta 30), reused 62 (delta 24), pack-reused 0
Unpacking objects: 100% (68/68), done.
$ cd foxtrot/
$ go run .
go: github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1: parsing expreduce/go.mod: open /tmp/tmp.D56owJdoY0/foxtrot/expreduce/go.mod: no such file or directory

I also tried to leave out the replace for expreduce:

$ go mod edit -dropreplace github.com/corywalker/expreduce
$ go run .
go: finding github.com/op/go-logging latest
go: finding github.com/golang/freetype latest
go: finding github.com/kavehmz/prime latest
go: finding github.com/corywalker/mathbigext latest
go: finding github.com/orcaman/concurrent-map latest
kernel.go:5:2: 
/home/elias/go/pkg/mod/github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1/expreduce/resources.go:1:1: expected 'package', found version

Werner Laurensse 8 days ago

Hi,

git clone https://github.com/wrnrlr/foxtrot foxtrot cd foxtrot/expreduce

Expreduce comes with expressions that are packed inside its binary

go generate ./... cd .. go run cmd/main.go

Now I did notice that when I open foxtrot from the command line it keeps listening to keyboard input on the terminal? I've previously always opened it from GoLand, so that's a new issue for me. It a bit annoying because most of the editing actually happens with key events. You can still add elements by clicking the plus button and refocusing the placeholder by clicking the space between cells. Its a bit hard to get right because the hit area is a bit too small (2sp).

Anyway if this helps.

On 4 Nov 2019, at 11:56 am, ~eliasnaur outgoing@sr.ht wrote:

On Sun Nov 3, 2019 at 11:32 PM Werner Laurensse wrote:

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

I'd like to take a look, but I failed to run your program:

$ go version go version devel +5d000a8b62 Sat Oct 26 08:29:23 2019 +0000 linux/amd64 $ cd $(mktemp -d) $ git clone https://github.com/wrnrlr/foxtrot Cloning into 'foxtrot'... remote: Enumerating objects: 68, done. remote: Counting objects: 100% (68/68), done. remote: Compressing objects: 100% (40/40), done. remote: Total 68 (delta 30), reused 62 (delta 24), pack-reused 0 Unpacking objects: 100% (68/68), done. $ cd foxtrot/

$ go run . go: github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1: parsing expreduce/go.mod: open /tmp/tmp.D56owJdoY0/foxtrot/expreduce/go.mod: no such file or directory

I also tried to leave out the replace for expreduce:

$ go mod edit -dropreplace github.com/corywalker/expreduce $ go run . go: finding github.com/op/go-logging latest go: finding github.com/golang/freetype latest go: finding github.com/kavehmz/prime latest go: finding github.com/corywalker/mathbigext latest go: finding github.com/orcaman/concurrent-map latest kernel.go:5:2: /ho me/elias/go/pkg/mod/github.com/corywalker/expreduce@v0.0.0-2019090220420 0-0a346d0d4ef1/expreduce/resources.go:1:1: expected 'package', found version

View on the web: https://todo.sr.ht/~eliasnaur/gio/56#comment-4516

Werner Laurensse referenced this from #56 8 days ago

Werner Laurensse 8 days ago

Sorry, there is still something wrong with the repo I have updated. I'll let you know when its fixed.

On 4 Nov 2019, at 7:17 pm, Werner Laurensse werner@alman.ax wrote:

Hi,

git clone https://github.com/wrnrlr/foxtrot foxtrot cd foxtrot/expreduce

Expreduce comes with expressions that are packed inside its binary

go generate ./... cd .. go run cmd/main.go

Now I did notice that when I open foxtrot from the command line it keeps listening to keyboard input on the terminal? I've previously always opened it from GoLand, so that's a new issue for me. It a bit annoying because most of the editing actually happens with key events. You can still add elements by clicking the plus button and refocusing the placeholder by clicking the space between cells. Its a bit hard to get right because the hit area is a bit too small (2sp).

Anyway if this helps.

On 4 Nov 2019, at 11:56 am, ~eliasnaur outgoing@sr.ht wrote:

On Sun Nov 3, 2019 at 11:32 PM Werner Laurensse wrote:

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

I'd like to take a look, but I failed to run your program:

$ go version go version devel +5d000a8b62 Sat Oct 26 08:29:23 2019 +0000 linux/amd64 $ cd $(mktemp -d) $ git clone https://github.com/wrnrlr/foxtrot Cloning into 'foxtrot'... remote: Enumerating objects: 68, done. remote: Counting objects: 100% (68/68), done. remote: Compressing objects: 100% (40/40), done. remote: Total 68 (delta 30), reused 62 (delta 24), pack-reused 0 Unpacking objects: 100% (68/68), done. $ cd foxtrot/

$ go run . go: github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1: parsing expreduce/go.mod: open /tmp/tmp.D56owJdoY0/foxtrot/expreduce/go.mod: no such file or directory

I also tried to leave out the replace for expreduce:

$ go mod edit -dropreplace github.com/corywalker/expreduce $ go run . go: finding github.com/op/go-logging latest go: finding github.com/golang/freetype latest go: finding github.com/kavehmz/prime latest go: finding github.com/corywalker/mathbigext latest go: finding github.com/orcaman/concurrent-map latest kernel.go:5:2: /ho me/elias/go/pkg/mod/github.com/corywalker/expreduce@v0.0.0-2019090220420 0-0a346d0d4ef1/expreduce/resources.go:1:1: expected 'package', found version

View on the web: https://todo.sr.ht/~eliasnaur/gio/56#comment-4516

Werner Laurensse referenced this from #56 8 days ago

Werner Laurensse 8 days ago

Ok, third time is the charm, this should work

Clone repo with submodules

git clone --recurse-submodules https://github.com/wrnrlr/foxtrot

First generate builtin expression

cd foxtrot/expreduce go generate ./...

Run Foxtrot

cd .. go run cmd/main.go

The focus error has magically disappeared. Try executing the following rule:

Plot[Sin[x], {x,0,7}]

Kind Regards Werner

On 4 Nov 2019, at 7:17 pm, Werner Laurensse werner@alman.ax wrote:

Hi,

git clone https://github.com/wrnrlr/foxtrot foxtrot cd foxtrot/expreduce

Expreduce comes with expressions that are packed inside its binary

go generate ./... cd .. go run cmd/main.go

Now I did notice that when I open foxtrot from the command line it keeps listening to keyboard input on the terminal? I've previously always opened it from GoLand, so that's a new issue for me. It a bit annoying because most of the editing actually happens with key events. You can still add elements by clicking the plus button and refocusing the placeholder by clicking the space between cells. Its a bit hard to get right because the hit area is a bit too small (2sp).

Anyway if this helps.

On 4 Nov 2019, at 11:56 am, ~eliasnaur outgoing@sr.ht wrote:

On Sun Nov 3, 2019 at 11:32 PM Werner Laurensse wrote:

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

I'd like to take a look, but I failed to run your program:

$ go version go version devel +5d000a8b62 Sat Oct 26 08:29:23 2019 +0000 linux/amd64 $ cd $(mktemp -d) $ git clone https://github.com/wrnrlr/foxtrot Cloning into 'foxtrot'... remote: Enumerating objects: 68, done. remote: Counting objects: 100% (68/68), done. remote: Compressing objects: 100% (40/40), done. remote: Total 68 (delta 30), reused 62 (delta 24), pack-reused 0 Unpacking objects: 100% (68/68), done. $ cd foxtrot/

$ go run . go: github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1: parsing expreduce/go.mod: open /tmp/tmp.D56owJdoY0/foxtrot/expreduce/go.mod: no such file or directory

I also tried to leave out the replace for expreduce:

$ go mod edit -dropreplace github.com/corywalker/expreduce $ go run . go: finding github.com/op/go-logging latest go: finding github.com/golang/freetype latest go: finding github.com/kavehmz/prime latest go: finding github.com/corywalker/mathbigext latest go: finding github.com/orcaman/concurrent-map latest kernel.go:5:2: /ho me/elias/go/pkg/mod/github.com/corywalker/expreduce@v0.0.0-2019090220420 0-0a346d0d4ef1/expreduce/resources.go:1:1: expected 'package', found version

View on the web: https://todo.sr.ht/~eliasnaur/gio/56#comment-4516

Werner Laurensse referenced this from #56 8 days ago

Werner Laurensse 8 days ago

Oh and I forgot to say you can ignore this error:

builtin_rubi.go:1: running go: exit status 1

On 4 Nov 2019, at 7:17 pm, Werner Laurensse werner@alman.ax wrote:

Hi,

git clone https://github.com/wrnrlr/foxtrot foxtrot cd foxtrot/expreduce

Expreduce comes with expressions that are packed inside its binary

go generate ./... cd .. go run cmd/main.go

Now I did notice that when I open foxtrot from the command line it keeps listening to keyboard input on the terminal? I've previously always opened it from GoLand, so that's a new issue for me. It a bit annoying because most of the editing actually happens with key events. You can still add elements by clicking the plus button and refocusing the placeholder by clicking the space between cells. Its a bit hard to get right because the hit area is a bit too small (2sp).

Anyway if this helps.

On 4 Nov 2019, at 11:56 am, ~eliasnaur outgoing@sr.ht wrote:

On Sun Nov 3, 2019 at 11:32 PM Werner Laurensse wrote:

Hi,

I am building a simple scientific notebook with Gio. It shows a list of cells with a mathematical expression and the result. A user can create a new cell by pressing enter when the focus is on a Placeholder (always above and below a cell).

After I started to handle key input like is done in the widget.Editor with gtx.Events(&p.eventKey) the scrolling of the list of cells stopped working.

The easiest way to reproduce the problem is by running the application, the code can be found at https://github.com/wrnrlr/foxtrot Just press Enter a couple times until the list is bigger than the viewport. It is not possible to scroll anymore, it does not matter wether the focus is on a cell's input editor or a placeholder.

The relevant Placeholder code is found in the placeholder.go file.

I'd like to take a look, but I failed to run your program:

$ go version go version devel +5d000a8b62 Sat Oct 26 08:29:23 2019 +0000 linux/amd64 $ cd $(mktemp -d) $ git clone https://github.com/wrnrlr/foxtrot Cloning into 'foxtrot'... remote: Enumerating objects: 68, done. remote: Counting objects: 100% (68/68), done. remote: Compressing objects: 100% (40/40), done. remote: Total 68 (delta 30), reused 62 (delta 24), pack-reused 0 Unpacking objects: 100% (68/68), done. $ cd foxtrot/

$ go run . go: github.com/corywalker/expreduce@v0.0.0-20190902204200-0a346d0d4ef1: parsing expreduce/go.mod: open /tmp/tmp.D56owJdoY0/foxtrot/expreduce/go.mod: no such file or directory

I also tried to leave out the replace for expreduce:

$ go mod edit -dropreplace github.com/corywalker/expreduce $ go run . go: finding github.com/op/go-logging latest go: finding github.com/golang/freetype latest go: finding github.com/kavehmz/prime latest go: finding github.com/corywalker/mathbigext latest go: finding github.com/orcaman/concurrent-map latest kernel.go:5:2: /ho me/elias/go/pkg/mod/github.com/corywalker/expreduce@v0.0.0-2019090220420 0-0a346d0d4ef1/expreduce/resources.go:1:1: expected 'package', found version

View on the web: https://todo.sr.ht/~eliasnaur/gio/56#comment-4516

Werner Laurensse referenced this from #56 8 days ago

Werner Laurensse 7 days ago

It seems to be a general problem with Gio, not just my program:

package main

import ( fmt gioui.org/font/gofont gioui.org/io/system gioui.org/unit gioui.org/widget/material log

gioui.org/app gioui.org/layout )

var theme *material.Theme

func main() { go func() { w := app.NewWindow() if err := loop(w); err != nil { log.Fatal(err) } }() app.Main() }

func loop(w *app.Window) error { gtx := &layout.Context{ Queue: w.Queue(), } gofont.Register() theme = material.NewTheme() items := []item{item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}} for { e := <-w.Events() switch e := e.(type) { case system.DestroyEvent: return e.Err case system.FrameEvent: gtx.Reset(e.Config, e.Size) inset := layout.UniformInset(unit.Dp(8)) list := &layout.List{Axis: layout.Vertical} inset.Layout(gtx, func() { list.Layout(gtx, len(items), func(i int) { items[i].Layout(i, gtx) }) }) e.Frame(gtx.Ops) } } }

type item struct {}

func (ins *item) Layout(i int, gtx *layout.Context) { theme.Label(unit.Dp(38), fmt.Sprintf(%d, i)).Layout(gtx) }

~eliasnaur 7 days ago

On Wed Nov 6, 2019 at 3:36 PM Werner Laurensse wrote:

It seems to be a general problem with Gio, not just my program:

func loop(w *app.Window) error { gtx := &layout.Context{ Queue: w.Queue(), } gofont.Register() theme = material.NewTheme() items := []item{item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}, item{}} for { e := <-w.Events() switch e := e.(type) { case system.DestroyEvent: return e.Err case system.FrameEvent: gtx.Reset(e.Config, e.Size) inset := layout.UniformInset(unit.Dp(8)) list := &layout.List{Axis: layout.Vertical}

I hadn't had time to look at your larger program, but this line caught my attention: layout.List is a stateful object, so you need to reuse the same List every frame.

Moving the above line to a global variable will make scrolling work:

var list = &layout.List{Axis: layout.Vertical}

Let me know if doing that for your other program solves this issue.

Register here or Log in to comment, or comment via email.