Commit Graph

175 Commits

Author SHA1 Message Date
Elias Naur 0d49eb3f4b ui/layout: drop CrossAxisAlignment value Stretch
It doesn't carry its own weight; client can just as easily adjust
the Constraints themselves.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 20:13:10 +02:00
Elias Naur 10ef4576e7 ui/layout: drop Flex.MainAxisSize setting and MainAxisSize type
The setting doesn't bear its own weight; it's simpler for the client
to adjust the constraints itself.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 19:15:17 +02:00
Elias Naur c7e85efc27 ui/layout: ensure that flex weights add to 1
Before this change, the weight applied to the space left, not the
total space available after rigid children.

While here, ensure that weight sums > 1 are capped to the available
space.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 19:06:27 +02:00
Elias Naur 449c2b844a ui/layout: drop FlexMode
The type and argument to Flex.Flexible does not carry its weight;
It is just as easy to expand the constraint directly.

While we're here, rename the flex argument to weight which is clearer.
2019-07-11 18:44:44 +02:00
Elias Naur fe4a61ec89 ui/layout: make List more friendly to for loops
With this change, a List l can be iterated with

    for l.Init(...); l.More(); l.Next() {
        l.Elem(..., l.Constraints(), l.Index())
    }

instead of

   l.Init(...)
   for {
       i, cs, ok := l.Next()
       if !ok {
               break
       }
       l.End(..., cs, i))
    }

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 18:07:16 +02:00
Elias Naur f4461721e3 ui/app: tweak monitor scale
Don't apply monitor scale to wayland font sizes, since it detects
the user scale itself.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 15:08:25 +02:00
Elias Naur 478d56102a ui/app: introduce Insets for system decoration insets
Insets is like image.Rectangle, but with properly named fields
and ui.Value instead of raw ints to make use with the layout
package easier.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 14:33:38 +02:00
Elias Naur 15c4ce9e22 ui/app,cmd/gio: support edge-to-edge layout on Android
Implement recomendations from
https://developer.android.com/preview/features/gesturalnav#java

While here, give up on providing translucent top and bottom bars on
Android 4.4 and below. It's simpler to use the app drawn system
backgrounds from 5.0 and newer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 13:05:29 +02:00
Elias Naur 896f5a77dd ui/layout: don't stretch Align child
Let the caller decide whether the constraints should be stretched.

Also unexport Constraint (not Constraints) methods, they weren't
pulling their weight.

Finally, don't force cross axis constraint minimum to 0 in List.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 09:18:56 +02:00
Elias Naur 4fadf71992 ui/pointer: split AreaOp into RectAreaOp and EllipseAreaOp
Now that the pass through mode is moved into its own PassOp op,
it doesn't make sense to collect all area types into one exported
type.

Add RectAreaOp and EllipseAreaOp for clients; the internal
representation is still a single op. It can be changed later without
breaking clients.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 22:55:16 +02:00
Elias Naur f44ccec043 ui/pointer: simplify pointer pass through
Get rid of the confused LayerOp and the transparent property from
AreaOp. Add an explicit PassOp to specify whether pointer events
pass-through the current area.

Let AreaOp swallow events even when no handlers are active for the
area. That behaviour is less surprising and allow clients to disable
a widget by keeping its areas but leave out its handlers.

Simplify the pointer.HitResult enum to just a bool: hit or no hit.

Finally, simplify the pointer queue by tracking parent areas and
node with indices.
2019-07-10 22:43:03 +02:00
Elias Naur f90ef91b19 ui: fix comment for TransformOp 2019-07-10 20:47:42 +02:00
Elias Naur 32aae18293 ui,ui/app: convert Config to an interface
To keep the interface slim, remove the helper methods and shorten
the essential method, Pixels, to Px.

Add and use unexported Config implementation in the app package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 17:20:55 +02:00
Elias Naur 320579814f ui: rename Config.Val to Pixels
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 14:00:44 +02:00
Elias Naur ad4215a7eb ui: use ints for unit conversions to pixels
The dp and sp units are approximate and mostly used for layout
dimensions that operate in whole pixels. This change alters the
Config methods to return pixels in ints instead of floats, which
results in smoother use for layout and emphasize the inexactness of
the device independent units.

Clients can still access to raw PxPrDp and PxPrSp factors from
Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 13:31:06 +02:00
Elias Naur 25af3e3701 ui/layout: replace Sized struct with simpler Constraint.Exact method
While here, add String methods to ui.Value and ui.Unit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 11:18:45 +02:00
Elias Naur 4ec352727e ui/layout: remove unused isInf
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 17:05:38 +02:00
Elias Naur b1af8aa75e ui/widget: introduce Image.Scale
And use a constant 72 DPI for the default scale, to ensure consistent
image sizes across display densities.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 16:00:02 +02:00
Elias Naur ca24026ffd ui/widget: preserve image aspect in Image.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 14:39:08 +02:00
Elias Naur 99be31bc26 ui/layout: convert Sized and Insets to use ui.Value
Layout objects are usually ephemereal, but when saved and re-used
between frames their measurements are not updated with varying pixel
density and font scaling.

Go back to storing unconverted ui.Values instead of raw pixels,
and convert them at each use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 11:28:41 +02:00
Elias Naur 8a34469211 Revert "ui/app: (iOS) treat the \n character as a return key chord"
It's not the way of the soft keyboards.

This reverts commit a0c04cb3b2.
2019-07-08 19:04:57 +02:00
Elias Naur f7ea448256 ui/app: (android) fix length of C string copy
The data dir string is returned to Go as a byte array of the UTF-8
encoded string, but it is not NUL terminated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 16:15:45 +02:00
Elias Naur b494b3c8c0 ui/app: remove IsAlive
IsAlive races with the StageDead event: if the client checks IsAlive
after the stage is updated to StageDead but before having received
the StageDead it will exit the event loop, blocking the StageDead
to ever arrive.

Remove IsAlive and let the client rely only on the StageDead to exit
its event loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 15:46:48 +02:00
Elias Naur 51905c0aad ui/text: ignore all newlines in single line editors
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 14:59:32 +02:00
Elias Naur 84cd3fcdca ui/text: handle stop and scroll immediately
In case an event is returned, don't aggregate state changes in Next.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 00:07:51 +02:00
Elias Naur 2292fd0c63 ui/app: implement window insets for iOS
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 23:50:16 +02:00
Elias Naur c884b7d4f0 ui/app: introduce DrawEvent.Insets and add Android implementation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 23:30:38 +02:00
Elias Naur 3897832842 ui/app: use log level info for stderr
It's not given that output to stderr is caused by an error
condition.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 19:32:26 +02:00
Elias Naur ab13a2ee73 ui/text: add Editor.Focus method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 18:23:50 +02:00
Elias Naur a0c04cb3b2 ui/app: (iOS) treat the \n character as a return key chord
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 17:54:50 +02:00
Elias Naur 47c6ea2dd2 ui/app: (iOS) redirect standard Go logger to NSLog
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 17:43:40 +02:00
Elias Naur 5f42e2e804 ui/app: (android) set close-on-exit flag on dup'ed log file descriptors
The file descriptors are probably overwritten on exec anyway, but at
least our intent is clear.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 16:47:38 +02:00
Elias Naur 1a417d353c ui/app: fix a few C signatures and a comment typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 16:33:11 +02:00
Elias Naur f110c26e3f ui/input: hide soft keyboard when focus is lost
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 15:52:09 +02:00
Elias Naur 31418eefbe ui/key: rename TextInputClosed to TextInputClose
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 15:52:09 +02:00
Elias Naur 2c5b7496d2 ui/text: apply correct material for cursor
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 00:48:00 +02:00
Elias Naur f56e082cc7 ui/app: introduce DataDir for application-specific data files
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 00:39:13 +02:00
Elias Naur 2d89a914e9 ui/app: tweak comment
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-06 16:09:01 +02:00
Elias Naur 38ec6a8831 ui/draw: rename ColorOp.Col to Color 2019-07-05 17:14:57 +02:00
Elias Naur 0f576cf625 ui/text: use default colors to guard against empty materials
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-05 17:11:17 +02:00
Elias Naur 86bc3e612d ui/text: use BlockOp as materials
Before this change, clients were expected to set up the current
material (color or image) before laying out Labels and Editors.
This was done to avoid garbage from a hypothetical material
interface covering both colors and images.

However, some widgets need more than one material: the Editor had
HintImage for the hint text material.

This change implements generalized materials through blocks:
anywhere a material is expected, a ui.BlockOp is is assumed to
contain the operation(s) needed for setting the desired material.

This way we avoid allocations (interfaces) and keep the
abstraction over material types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-05 16:52:13 +02:00
Elias Naur 30a558d10d ui/app: fix race condition between Window.Redraw and Draw
A Window.Redraw called after the client has completed building a
frame and before Window.Draw resets the redraw flag is effectively
ignored. Move the flag reset earlier to just before the client is
asked to build the frame, to ensure that no state updates are lost.

Tighten and simplify the locking while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-04 16:31:48 +02:00
Elias Naur f1dffa155c ui/text: add ChangeEvent and rename Submit to SubmitEvent
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-04 15:06:50 +02:00
Elias Naur 252514af9d all: update dependencies
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-03 20:26:19 +02:00
Elias Naur 475bccb722 ui: add checks for unmatched Ops.Begin/End
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-02 20:12:06 +02:00
Elias Naur e862761e17 ui/input: keep default focus on earliest focusable
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-02 19:36:45 +02:00
Elias Naur 33fc35f58d ui/draw: switch to color.RGBA for colors
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-02 14:56:48 +02:00
Elias Naur 683df6345b ui/layout: fix Flex spacing
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-01 19:22:06 +02:00
Elias Naur d720fa6233 ui/text: add Hint and HintImage to Editor
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-01 13:36:54 +02:00
Elias Naur 0546683720 ui/text: add LayoutOptions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-30 23:58:05 +02:00