I too often forget to initialize widgets' config and queue. Moving
them from fields to parameters fix that. The change results in a
little more verbosity but cleaner code.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before this change, there was no guarantee that a PopOp matched
the intended PushOp. With a single stack operation, the client is
forced to match pop with the right push.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Move the Record and Stop methods from Ops to MacroOp itself.
Before this change, Ops.Stop stopped the recording of the most
recent macro, which could be a different macro than intended.
After this change, there is no such confusion.
As a bonus, the Ops API becomes less cluttered.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Rename Insets to the verb Inset for consistency with Align.
Uniform is a better description than Equal for the result of
UniformInset.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Exact was too special and can be expressed with RigidConstraints.
RigidConstraints is a better name ("rigid" was in the comment!)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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.
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>
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>
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>
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.
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>
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>
To avoid passing a queue type for each kind of input (pointer, key),
introduce package input for mapping a handler key to all input events.
Future input sources can be added without changes to programs, and
as an added bonus, event ordering is preserved across input sources.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Layouts and path builders are transient and need an ops list for
operation. However, instead of passing the ops list to every method,
pass the list in an init method and store it for subsequent methods.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Split out OpArea from OpHandler to allow stacked areas in a followup.
Replace hit closures with static shapes (rectangles and ellipses) to
avoid allocations. If needed, generic hit functions can be introduced
again later.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Instead of allocating and constructing a clip path, store path data
directly in op lists. Use separate op lists for cached text layout
paths.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to allow OpBlock for invoking ops from multiple (cached)
Ops containers. To allow for drawing state changes to stick after
invoking such a cached block, we can't let OpBlock perform an implicit
save and restore of drawing state.
Instead, introduce OpPush and OpPop for explicit drawing state stack
management.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The layout package switched from interfaces to functions for
composing layouts. The switch made sure that no garbage is
generated for transient layouts such as Align, Inset, Stack, Flex.
Unfortunately, that left the stateful widgets and layouts: as soon
as their layout methods are embedded in a transient layout, a
closure is generated that escapes to the heap.
To avoid garbage for both transient as well as stateful widgets,
replace the functional approach with explicit begin/end methods.
A begin method generally starts an op block and returns the adjusted
constraints. An end method takes computed dimensions, ends its op
block and returns adjusted dimensions.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
With layout.Widget a function instead of an interface, the amount
of per-frame garbage can be drastically reduced.
The layout code ends up slightly more explicit.
As a side benefit, the awkward ordering indexing for Flex and Stack
fit nicely into their new explicit Layout methods.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Pros:
- Much less per-frame garbage
- Allow future preprocessing of ops while building it
- Much fewer interface calls and pointer chasing
- Allow future serialization of ops for remote rendering
Cons:
- Slightly clumsier API
Signed-off-by: Elias Naur <mail@eliasnaur.com>
With an interface instead of anonymous functions, amending an
area's parameters can be done even after adding it to an OpHandler.
This will be useful when we switch to serialized op lists.
Signed-off-by: Elias Naur <mail@eliasnaur.com>