Commit Graph

1777 Commits

Author SHA1 Message Date
Larry Clapp 34273940a0 widget,widget/material: add selection to the editor
- Allow dragging to be on both horizontal and vertical axes at once.
- Split Editor.caret.pos into caret.start and caret.stop. caret.start is
  the old caret.pos, and is both the position of the caret, and also the
  start of selected text. caret.end is the end of the selected text.
  Start can be after end, e.g. after after Shift-DownArrow.
- Update caret.end after a mouse drag, and various shifted keys
  (Shift-UpArrow, Shift-DownArrow, etc).
- Change Shortcut-C to copy only the selected text, not the whole editor
  text.
- Add Shortcut-X to copy and delete selected text, and Shortcut-A to
  select all text.
- The various Insert/Delete/etc functions now overwrite or delete the
  selection, as appropriate.
- Change MoveCaret to accept a distance for selection end, as well.
  Change SetCaret to accept a selection end offset.
- Add SelectionLen to get the selection length, Selection to get
  selection offsets, SelectedText to get the selected text, and
  ClearSelection to clear the selection.
- Add a rudimentary selection unit test, and extend the deleteWord unit
  test with some text selection cases.
- Add SelectionColor to material.EditorStyle, which defaults to
  Theme.Palette.ContrastBg.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2021-01-24 09:44:52 +01:00
Larry Clapp e78bd15564 widget: refactoring to prep for editor selection
- Move caret from editBuffer.caret to Editor.caret.pos.ofs and related
  refactoring. Move other fields in Editor.caret into Editor.caret.pos.
- Refactor several functions to change a position passed into them,
  rather than changing e.rr.caret directly.
- Add editBuffer.Seek().
- Remove editBuffer.dump().
- Change Editor.Move to MoveCaret.
- Add Editor.SetCaret.
- Updated tests.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2021-01-24 09:44:41 +01:00
Elias Naur cc63a3aeb7 io/router: don't send pointer.Cancel events to disappearing handlers
As a follow-up to gioui.org/commit/24f69bf4, this change makes it so
that merely adding a pointer.InputOp doesn't trigger redraws when
the pointer is hovered over its area.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-23 12:00:50 +01:00
Elias Naur 84b586ae6c gpu: don't automatically clear screen before rendering
Gio UI may be overlaid on top of custom graphics such as in the glfw example.
That will only work if Gio doesn't clear the screen (to white).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 18:33:34 +01:00
Elias Naur 686d680ea3 io/key,io/pointer: forbid nil tags for InputOps
Forcing a non-nil tag ensures that all handler tags are either unique,
or intentionally equal. Additionally, a nil tag has special meaning in
FocusOps.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:38:25 +01:00
Elias Naur 4f45d9a567 io/router: rename Router.Add to the more specific Queue
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:36:14 +01:00
Elias Naur 24f69bf4bb io/router: don't trigger redraw for handler reset events
key.InputOp and pointer.InputOp handlers are reset on first registration
through a key.FocusEvent{false} or pointer.Cancel, respectively.

However, the mere act of registering a handle shouldn't result in a
redraw. This is particularly true for misconfigured handlers where a new
tag is supplied every frame, resulting in continously redrawing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:34:51 +01:00
Elias Naur e70a16c345 io/router/key: add explicit tag to FocusOp; make last SoftKeyboardOp apply
The target of FocusOp is too subtle; be explicit instead and remove
any doubt.

Multiple SoftKeyboardOp in a single frame is rare, but if they do occur,
they should behave as if they were from separate frames: the last one
applies.

As a side-effect the key event router can be much simplified.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:34:51 +01:00
Elias Naur 95953b2ae0 io/router: remove redundant field
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 12:10:59 +01:00
pierre a928c07a1c layout: added offset for last visible item to List
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-21 18:31:41 +01:00
Elias Naur 74eb0a4a34 gpu/shaders: clamp clip coverage to [0.0, 1.0]
Fixes the "bleaching" artifacts of the painting program by ~wrnrlr.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-21 12:39:02 +00:00
Elias Naur d0d6c6c38e internal/glimpl: hook up glTexStorage2D on iOS
The glTexStorage2D is part of OpenGL ES 3, but wasn't its function
pointer wasn't initialized on iOS.

Fixes a crash on startup on iOS devices and simulators.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-21 11:40:31 +01:00
pierre b24df0aa6e widget/material: use clip.UniformRRect
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-21 10:30:00 +01:00
pierre 9bede80a3d layout: added number of visible children to List
Also fixed an edge case where the first visible child was off by 1 when it was just fully hidden.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-20 21:05:14 +01:00
Elias Naur cd47a158a2 op/clip: move Rect to shapes.go
It's a specialized shape like the others.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-19 20:31:29 +01:00
Chris Waldon d93874005c op/clip: document dimensions of Border.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-01-19 20:30:51 +01:00
Chris Waldon 9231ff47ef widget: make border draw within widget dims as documented
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-01-19 20:22:11 +01:00
Elias Naur d6886737a5 op: change Defer to only restore transformation state
It turns out restoring all operation state from the moment Defer
is executed is too much; for example, a right-click pop-up needs
the transformation, but not the current clip.

Change Defer to only restore the transformation, and reset all
other state.

Other combinations may be needed in future; we'll deal with them then,
possibly by exposing the load state mask.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-19 20:04:30 +01:00
Egon Elbre eea1dbc176 widget/material: add hover to Switch
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:10 +01:00
Egon Elbre bc6798c4ca widget/material: add hovered to RadioButton
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:06 +01:00
Egon Elbre 0b736990a9 widget/material: add hover to CheckBox
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:01 +01:00
Egon Elbre 468bd6f53a widget/material: add hover to Button
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:56:57 +01:00
Egon Elbre 93ebd51531 gesture,widget: add hovered property
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:56:52 +01:00
Elias Naur 99bfa6a33c internal/f32color: revert incorrect NRGBA to linear color change
Egon Elbre convinced me commit 01d5e72291 was incorrect, because
in the NRGBA colorspace the alpha value is linear, not gamma adjusted.

Updates gio#192

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-16 09:58:04 +01:00
Elias Naur 01d5e72291 internal/f32color: correct pre-multipled color conversion
Tweak a test color to avoid an off-by-1 rounding error after changing
the conversion formula.

Fixes gio#192

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-15 16:02:39 +01:00
pierre 85c0a7d803 widget/material: added support for Vertical axis to Slider
Adding an axis to the Float widget, allows positioning the Slider one not only horizontally but also vertically.
Also update the fill ops while there.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-14 17:42:58 +01:00
Elias Naur f86703e4b0 op: introduce Defer for deferring CallOps
Updates gio#164

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-14 15:53:49 +01:00
pierre e088833caf layout: simplified Axis methods
Removed the Main and Cross Axis methods in favor of Convert.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-14 11:04:06 +01:00
Elias Naur d331dd2de8 op: rename StackOp/Push/Pop to StateOp/Save/Load
The semantics were relaxed in a previous commit; this change renames
to operations accordingly.

API change. Use gofmt to adjust your code accordingly:

gofmt -r 'op.Push(a).Pop() -> op.Save(a).Load()'
gofmt -r 'op.Push(a) -> op.Save(a)'
gofmt -r 'v.Pop() -> v.Load()'
gofmt -r 'op.StackOp -> op.StateOp'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 21:28:59 +01:00
Elias Naur ae2c74ec13 op: relax Push/Pop to Save/Restore semantics
A previous change implemented save/restore semantics where a saved
state can be restored anywhere, not just in a stack-like manner.

This change similarly relaxes the exported Push/Pop operations; the next
change will rename them accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 20:53:47 +01:00
Elias Naur f7902f299b op: implement StackOp in terms of general save/load of state
Push/Pop only allows saving and restoring operation state in a
stack-like manner. We're going to need restoring arbitrary state
for implementing deferred operations.

Generalize state save/restore and implement Push and Pop on top of
that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 20:53:25 +01:00
Egon Elbre f114acdb02 widget: use correct color in Icon
iconvg seems to expect a linear premultiplied color.

Fixes gio#132

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-11 14:32:28 +01:00
pierre 0e3e446393 layout: added Axis methods
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-11 14:32:28 +01:00
Elias Naur f7f94c93fe app/internal/window: [android] re-apply view state lost on rotate etc.
Android can re-create our Activity and GioView at any time, losing view
and activity state such as the current cursor. Further, setting state
while there is no GioView attached is lost.

Track the current and unapplied state, and apply it when a GioView is
available.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 14:48:01 +01:00
Elias Naur acef4e6e2d app/internal/window: [android] move switching to main thread to Go
There's runOnMain alread; use that for show|hideTextInput instead
of an ad-hoc switch.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 13:14:43 +01:00
Elias Naur f311a54ffb app/internal/window: [android] remove redundant context argument
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 12:42:10 +01:00
Elias Naur 5155893781 app: drop return value from Window.driverDo
It's not used anymore.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 11:35:22 +01:00
Elias Naur beb046ac42 ap/internal/window: make cached JNI method descriptors global
We're about to remove all references to window from runOnMain callbacks.
The JNI methods are constant and can be moved out of window.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-10 11:22:42 +01:00
Elias Naur 759b796283 app: treat Invalidate more like InvalidateOp
Using Window.Invalidate for animation with, say

var w Window
var e FrameEvent

w.Invalidate()
e.Frame(...)

stops and immediately starts animation mode which is inefficient
and may cause jitter in the redraw timing.

InvalidateOp is the efficient and sure way to achieve smooth animation,
and Invalidate only exists for external events where there is nowhere to
add an InvalidateOp.

We can do better, so this change makes Invalidate almost as efficient as
InvalidateOp by checking for Invalidates at the same time we check for
InvalidateOps.

Note that we can't avoid the inefficiency in all cases, for example
when the calls above are swapped,

e.Frame(...)
w.Invalidate()

the Invalidate may not be registered before the check during Frame.

While here, add a note to Invalidate that it's meant for externally
triggered redraws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-08 20:17:08 +01:00
Elias Naur 5f6fa25209 app/internal/window: [wasm] have at most one animation callback in flight
Track whether requestAnimationCallback has been called when SetAnimating
changes the animated state of the window. Multiple callbacks result in wasteful
redraws.

Without this change, my browser becomes unresponsive when Window.Invalidate
is called every frame. Calling Invalidate every frame is a misuse (InvalidateOp
should be used for animation), but it's nice to have reasonable behaviour.

This change might also fix the issues described in
https://github.com/gioui/gio/pull/7.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-08 10:41:07 +01:00
Inkeliz b430786f9b app/internal/window: [wasm] fix insets on Firefox
Insets must not be included if the `visualViewport` isn't available.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-01-07 09:51:46 +01:00
Inkeliz 07715a8125 cmd/gogio: remove windres dependency
Now, it's possible to compile to Windows (`-target windows`) without
having `windres`. The PNG icon, manifest and version info will be
generated and include using `gogio`.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2021-01-07 09:49:26 +01:00
pierre c030065af7 app: fixed swapped horizontal scrolling directions on Windows
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-06 09:42:11 +01:00
Sebastien Binet 7bfdafb7b1 gpu: handle closure test for stroked path
Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-03 14:03:23 +01:00
Elias Naur 72a3248041 gpu: implement GPU profiling for compute
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-03 13:27:59 +01:00
Elias Naur 8662790f10 gpu: remove unused field
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-03 13:05:10 +01:00
Elias Naur bb9252f9d4 gpu: cache path data for compute
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-02 20:18:05 +01:00
Elias Naur 23f710910f gpu: reclaim stale images in atlas texture before resizing
Issue found by Anthony Starks.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-02 18:28:41 +01:00
Sebastien Binet 5045a9e877 gpu: handle rounding errors when splitting quads
This CL handles rounding errors arising when splitting quads into linear
segments.
Rounding errors would lead to a pair of quad triplets (from,ctl,to) not
exactly matching.
ie: to(n-1) wouldn't exactly match from(n).

Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-02 12:54:32 +01:00
Sebastien Binet 8676a73a91 internal/rendertest: use a YIQ-based algorithm to compare images
This PR implements an image comparison algorithm in the NTSC YIQ color
space, as described in:

  Measuring perceived color difference using YIQ NTSC
  transmission color space in mobile applications.
  Yuriy Kotsarenko, Fernando Ramos.

An electronic version is available at:

- http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf

This should allow the image comparison to be a tad more robust than
comparing plain uint8 pixel values.

Signed-off-by: Sebastien Binet <s@sbinet.org>
2021-01-02 12:54:29 +01:00