Revert "io/router: try all handlers if a key don't match the focus ancestor tree"

This reverts commit 28c206fc78c76b1481fc3ed4c28ce3562ce424ba. The commit
introduced counter-intuitive behaviour as demonstrated by #503. In the
meantime, topmost handlers now receive all unhandled key.Events[0], which
should cover the use-cases that motivated the original commit.

[0] 0dba85f52e5131c03d903c84355fb90cdb978811">https://gioui.org/commit/0dba85f52e5131c03d903c84355fb90cdb978811

Fixes: https://todo.sr.ht/~eliasnaur/gio/503
Signed-off-by: Elias Naur <mail@eliasnaur.com>
text: fix over-reading on truncated EOF

When consuming text from an io.Reader, the shaper could hit an EOF when reading the
text, then still try to check whether it was done by calling ReadByte() followed by
UnreadByte(). The ReadByte() would still return EOF, but the UnreadByte() would then
walk the iterator cursor backwards to the final byte of the text. If and only if the
text was being truncated, this unexpected cursor position could cause the shaper to
conclude that there were additional runes that were truncated, and thus the returned
glyph stream would account for too many runes. This commit provides a test and a fix.

Many thanks to Jack Mordaunt for the excellent bug report leading to this fix.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
app: replace uses of Window.dead with Window.destroy

There doesn't seem to be a need for a two-step shutdown sequence, so a
single channel is enough to trigger destruction of the Window.

References: https://todo.sr.ht/~eliasnaur/gio/497
Signed-off-by: Elias Naur <mail@eliasnaur.com>
app: [linux,windows,wasm] scroll horizontally when shift key is pressed

Adds support for horizontal scroll using mousewheel with a shift key.
Support is added for windows, linux (wayland and x11), js (wasm).

Fixes: https://todo.sr.ht/~eliasnaur/gio/398
Signed-off-by: Mearaj <mearajbhagad@gmail.com>
layout: add resize helpers for constraints

This commit adds two helper methods to layout.Contraints that make it easier to
manipulate the constraints while keeping their invariants. In particular, code
manually manipulating constraints usually fails to correctly ensure that the
max does not become smaller than the min, the min does not exceed the max, and
that no value goes below zero.

It's quite a few lines to check these invariants yourself in every custom layout,
so I think it makes sense to offer helpers for this.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
text: fix 32-bit glyph id packing

This commit fixes a problem in the unpacking of text.GlyphID on 32 bit architectures.
Incorrectly casting to an `int` on those platforms resulted in truncating the faceIndex
to always be zero. To catch mistakes like this in the future, I've added tests for this
problem that should be run by our new 32-bit CI testing.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
ci: run tests for 32-bit architectures

This commit introduces a 32-bit test run to our Linux CI in an attempt
to detect architecture dependent bugs earlier. I was forced to install
the i386 packages in a build step becuase they can only be added after
enabling the architecture. Also GOARCH=386 does not support the race
detector, so I'm not running the tests with race detection enabled for
that GOARCH.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
bcb123a0 — Ilia Demianenko a month ago
app: [Android] Set high refresh rate on startup

Some devices with high refresh rates limit SurfaceView apps to 60hz
and need a specific API call to set it back. Same approach is used by
https://github.com/ajinasokan/flutter_displaymode. The extra work is
skipped on the devices that don't need it.

Signed-off-by: Ilia Demianenko <ilia.demianenko@gmail.com>
widget: update textIterator docs for accuracy

The previous docs claimed that failing to set a textMaterial would result in
invisible glyphs when in reality it results in using whatever the current paint
material is. This could be the paint material from before laying out the glyphs,
or it could be the material for a bitmap glyph. As such, it's better to say that
the color is undefined.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
text: optimize shaper paragraph decoding

This commit removes some inefficiencies from the pre-shaper-cache processing of
text. The text is no longer decoded into runes prior to being tested against the
cache, and the search for newlines uses slightly more efficient iteration operations

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
app: use more efficient window decoration font load

This commit switches to the new Regular() collection method in gofont,
ensuring that the regular face is only ever loaded once.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
font/gofont: allow loading just the regular Go font

This commit introduces a special mechanism to load only the regular version
of the Go font. This is useful for Gio to load a font for drawing window
decorations without forcing applications to load every Go font.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
font/opentype: make reusing font.Face efficient and safe

This commit updates the internal representation of a font to separate the
threadsafe and non-threadsafe operations in a way that enures font.Faces can
be shared by all text shapers in an application. This should ensure that applications
only need to parse fonts a single time, saving a great deal of memory for
applications that open many windows (which each need a different text shaper).

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
widget/material: make ScrollBarStyle.MajorMinLen default to FingerSize

Egon pointed out that the current default is unusable on touch screens in Slack, so this
change should hopefully ensure the indicator is interactable on touch devices.

I considered expanding the minor axis dimensions as well, but I don't know what value to
use. The 38DP default would be enormous on non-mobile displays if we made that the default

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
font/opentype: [API] support font collection loading

This commit adds back support for loading font collections, which we
lost when switching to the harfbuzz-based shaper last January. In
addition, this commit takes advantage of our new font loading library's
metadata facilities to automatically construct text.FontFaces for all
fonts within a collection. This is significantly more ergonomic for
users, and can be used to load single fonts with automatic metadata
detection as well.

I've exposed a opentype.Face.Font() method that can be used to get the
font metadata for a given face as well, though you have to type assert to
see it:

var myFace text.Face
if asOpentype, ok := myFace.(opentype.Face); ok {
    myFont := asOpentype.Font()

The one problem with this approach is that the font variant field always
be automatically populated. Mono font detection is supported, but
other variants like SmallCaps are more complicated and may need to be
expressed differently in the future (smallcaps is a feature that any font
file can have, not necessarily a separate font file). See this [0] upstream
issue for details.

Additionally, in order to avoid import cycles, I've moved the declarations
of font attributes to package font. You can fix your code automatically to
refer to the new definitions by running the following:

    gofmt -w -r 'text.FontFace -> font.FontFace' .
    gofmt -w -r 'text.Variant -> font.Variant' .
    gofmt -w -r 'text.Style -> font.Style' .
    gofmt -w -r 'text.Typeface -> font.Typeface' .
    gofmt -w -r 'text.Font -> font.Font' .
    gofmt -w -r 'text.Regular -> font.Regular' .
    gofmt -w -r 'text.Italic -> font.Italic' .
    gofmt -w -r 'text.Thin -> font.Thin' .
    gofmt -w -r 'text.ExtraLight -> font.ExtraLight' .
    gofmt -w -r 'text.Light -> font.Light' .
    gofmt -w -r 'text.Normal -> font.Normal' .
    gofmt -w -r 'text.Medium -> font.Medium' .
    gofmt -w -r 'text.SemiBold -> font.SemiBold' .
    gofmt -w -r 'text.Bold -> font.Bold' .
    gofmt -w -r 'text.ExtraBold -> font.ExtraBold' .
    gofmt -w -r 'text.Black -> font.Black' .
    gofmt -w -r 'text.Hairline -> font.Thin' .
    gofmt -w -r 'text.UltraLight -> font.ExtraLight' .
    gofmt -w -r 'text.DemiBold -> font.SemiBold' .
    gofmt -w -r 'text.UltraBold -> font.ExtraBold' .
    gofmt -w -r 'text.Heavy -> font.Black' .
    gofmt -w -r 'text.ExtraBlack -> font.Black+50' .
    gofmt -w -r 'text.UltraBlack -> font.ExtraBlack' .

Make sure each affected file imports gioui.org/font.

[0] https://github.com/go-text/typesetting/issues/57

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
app: [Windows] include keyboard modifiers in move, drag, and scroll pointer events

This matches the behavior on Linux and macOS.

Signed-off-by: Dominik Honnef <dominik@honnef.co>
io/semantic: avoid unnecessary pointer indirection

Putting a string in an interface value has to (normally) heap allocate
the string header and string. However, putting the address of a local
string variable in an interface value has the same effect, as this
causes the local variable to escape to the heap.

Signed-off-by: Dominik Honnef <dominik@honnef.co>
go.*,text: update go-text to pick up font transformation caching

This commit picks up improvements in upstream go-text that (among other things)
allow the shaper to reuse a lot of information when shaping the same font face
multiple times (using an LRU cache to keep that information available). I've
tried to pick a reasonable default LRU size of 32 faces.

My simple benchmarks indicate a definitive performance gain and reduction in
memory use across the board, which is especially noticable for complex fonts
like arabic and emoji.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
text,widget: minimize loss of positional precision in shaping

This commit combs through the logic of computing glyph sizes and positions,
attempting to remove all unnecessary rounding and truncation. This is in
an effort to help text display consistently when different-length strings
are displayed near one another.

The specific problem prompting this change was end-aligned text stacked in
rows with a common suffix. If the rows displayed different values, they
would shape such that those final glyphs were at different fractional x
coordinates, and then they would be aligned with rounding that could display
them at different x positions in spite of the fact that both suffixes are
the same glyphs.

By removing rounding from Alignment.Align, the largest problem is fixed, but
I'm also removing other unnecessary loss of precision that can circumstantially
contribute to this sort of visual issue.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>