ref: f24232dac52e gio/widget/bool.go -rw-r--r-- 751 bytes
gesture,widget: add hovered property

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
widget,widget/material: convert Switch to use Clickable

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget,gesture: fade out cancelled inkwells

While here, adjust inkwell sizes to match gtx.Constraints.Min.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ae8a377c — Thomas Bruyelle 1 year, 3 months ago
op: add op.Push and op.Record funcs

The funcs replace stack.Push and macro.Record, which become private.
This makes stack and macro faster to write, in particular for stacks
where you can just write the following line to save and restore the
state :

  defer op.Push(ops).Pop()

This usage requires Push to return a pointer (since Pop has a pointer
receiver), or else the code doesn't compile.

For consistancy, I tried to do the same for op.Record, but this implied
to turn all the MacroOp fields into pointers, and this caused some
panics. As a result, op.Record doesn't return a pointer.

An other side effect pointed by Larry Clapp: StackOp and MacroOp are not
re-usable any more, you have to allocate a new one for each usage, using
the described funcs above.

Signed-off-by: Thomas Bruyelle <thomas.bruyelle@gmail.com>
widget: redefine Enum.Changed and Bool.Changed to consider only user interaction

Ignore programmatic value changes to avoid feedback loops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget: change Bool.Layout to follow layout protocol

Just like Clickable, Bool.Layout should respect constraints and
return its dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget,widget/material: rename widget.Click to widget.Press

Press tracks pointer presses, not clicks, and we're about to add a Click
type that does.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget,widget/material: only process events in Layout methods

Before this change, events were typically processed twice or more per
widget: once in the Layout method for refreshing the visual state, and
once per method that queries for state changes.

One example is widget.Clickable that processed events in both its Layout
and Clicked method.

This change establishes the convention that events are processed once, in
the Layout method. There are several advantages to that approach:

- Query methods such as Clickable.Clicked no longer need a layout.Context.
- State updates from events only occur in Layout.
- Widgets are simplified because they won't need a separate processEvents
(or similar) method and won't forget to call it from methods other than Layout.
- Useless calls to gtx.Events are avoided (gtx.Events only returns events
for the first call each frame for a given event.Tag).

The disadvantage is that state updates from input events will not appear
before Layout. For example, in the call sequence

	var btn *widget.Clickable

	if btn.Clicked() {...}

the Clicked call will not detect an incoming click until the frame after it

This is ok because

- The Gio event router automatically dispatches an extra frame after events
arrive, bounding the latency from events to queries such as Clicked to
at most one frame (~17 ms).
- The potential extra frame of latency does not apply to Layout methods as long
as they process events before drawing. In other words, the visual feedback
from input events are not delayed because of this change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: change Widget to take explicit Context and return explicit Dimensions

Change the definition of Widget from the implicit

        type Widget func()

to the explicit functional

        type Widget func(gtx layout.Context) layout.Dimensions

The advantages are numerous:

- Clearer connection between the incoming context and the output dimensions.
- Returning the Dimensions are impossible to omit.
- Contexts passed by value, so its fields can be exported
and freely mutated by the program.

The only disadvantage is the longer function literals and the many "returns".
What tipped the scales in favour of the explicit Widget variant is that type
aliases can dramatically shorten the literals:

	type (
		C = layout.Context
		D = layout.Dimensions

	widget := func(gtx C) D {

Note that the aliases are not part of the Gio API and it is up to each user
whether they want to use them.

Finally the Go proposal for lightweight function literals,
https://github.com/golang/go/issues/21498, may remove the disadvantage
completely in future.

Context becomes a plain struct with only public fields, and its Reset is
replaced by a NewContext convenience constructor.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget: report whether Value changed after Enum.Update and Bool.Update

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget/material: add Switch widget

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget: rename CheckBox to Bool

We're about to introduce the Switch widget that re-uses the same
state type as CheckBox. The Bool name covers both uses.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
widget,widget/material: export CheckBox.Checked

Similar to the previous change to Enum, expose the current state of
the CheckBox. Rename the Checked method to just Update and get rid
of the SetChecked method.

Fixes gio#100

Signed-off-by: Elias Naur <mail@eliasnaur.com>
4ac3a7fd — Alexander Arin 1 year, 10 months ago
widget: add SetChecked method to CheckBox

Signed-off-by: Alexander Arin <fralx@yandex.ru>
0f5b94a4 — Alexander Arin 1 year, 10 months ago
widget,widget/material: add CheckBox