Commit Graph

136 Commits

Author SHA1 Message Date
Elias Naur c3574cdabd widget/material: Make checkbox/radio buttons icon modifiable
Signed-off-by: songpv <pvsong10@icloud.com>
2020-08-10 21:33:20 +02:00
Elias Naur 6ab43aba3e all: implement staticcheck suggestions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-19 10:47:17 +02:00
Chris Waldon ae07c5f470 widget/material: handle elliptical icon buttons
This commit changes the ink-drawing code so that IconButtons that
are not perfectly circular will still ink fully. Previously, an
elliptical icon would only animate a circular sub-region.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-07-18 08:46:38 +02:00
Elias Naur 773939fe1d widget/material: avoid excessive trigonometry in Loader.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-11 14:35:15 +02:00
Elias Naur 713770f808 widget: defer op.StackOp in Editor.PaintCaret
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 20:34:15 +02:00
Elias Naur c76b42e486 op/clip,widget: add clip.Border and widget.Border
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 19:55:37 +02:00
Elias Naur d572aa23ac op/clip: split Rect into pixel-aligned Rect and rounded RRect
The pixel-aligned Rect is more efficient and easier to use in the common case
of layout clipping.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 18:33:00 +02:00
Elias Naur 4818538ef8 op/clip: unexport Rect.Op
It wasn't used anywhere outside Rect.Add.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 17:29:31 +02:00
Elias Naur 29f820caaa widhet/material: change minimum Loader size to be a default
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-09 15:54:39 +02:00
Elias Naur 692d6ab221 widget/material: add Loader for indeterminate progress widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-07-08 22:52:58 +02:00
Elias Naur 6ef1ff7cfb widget/material: remove Inset from ButtonLayoutStyle
ButtonLayout is for custom button content; insets belong to the
custom content, not the button.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-30 20:44:35 +02:00
Elias Naur 851255f7a6 widget: tolerate nil shader in Editor movement methods
Fixes gio#142

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-28 22:34:58 +02:00
Gordon Klaus 5368743478 widget,widget/material: add Float and Slider
Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-22 12:17:35 +02:00
Elias Naur 878131189b all: remove redundant op.TransformOp.Offset
Use op.Offset instead, or create and manipulate a f32.Affine2D.

API change. Update your code with a gofmt rule:

	gofmt -r 'op.TransformOp{}.Offset -> op.Offset'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-21 22:41:56 +02:00
Elias Naur 9e3d3b6f58 text,font/gofont: replace text.Collection with slice of FontFaces
A slice of FontFace pairs are simpler, and thread safe in case a client
wants to append or modify the font collection.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-21 21:44:28 +02:00
tainted-bit 5c0f190849 widget: add optional password masking to Editor
This change adds optional password masking to the Editor. To enable
this feature, set the new Mask field to a non-zero rune. Every rune
in the Editor's contents will be replaced by the mask rune in the
visual display, except for newlines. The actual contents of the
editor can still be accessed with Len, Text, and SetText.

Fixes gio#80

Signed-off-by: tainted-bit <sourcehut@taintedbit.com>
2020-06-21 10:54:41 +02:00
Elias Naur a21aefa8b7 widget: remove Editor references to text.Line.Len and text.Glyph.Rune
In preparation for adding editor masking, Editor can't rely on the
Rune and Len fields of the laid out text.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 18:33:31 +02:00
Elias Naur ffec83a001 widget: add Editor tests
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 16:50:45 +02:00
Elias Naur dcbbcbb543 widget: introduce Editor.moveLines
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 16:50:45 +02:00
Elias Naur ef21a7ace1 widget: maintain Editor caret position
Only call layoutCaret when the text layout changes, adjust position
for caret movement.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 16:50:30 +02:00
Elias Naur 8f31f8da2c widget: move Editor caret information to sub-struct
In preparation for maintaining the caret position.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 12:26:24 +02:00
Elias Naur 4eb66d2707 widget: fix caret comparison in editBuffer.move
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 12:25:24 +02:00
Elias Naur e316f42964 widget: reset Editor x offset on mouse initiated caret movement
The caret x-offset tracks residual horizontal offset for arrow key
movements. Caret movement by the mouse should reset the residual.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 12:07:05 +02:00
Elias Naur 2f23a326b8 widget: return float32 coordinates from Editor.CaretCoords
Don't leak the implementation details of the caret coordinates.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 11:47:46 +02:00
Elias Naur 810be77412 widget: remove unused parameter from Editor.moveCoord
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-20 11:45:52 +02:00
Elias Naur 596e321610 all: make unit.Converter concrete and rename to Metric
An interface for scaling dp and sp is overkill, at least for all
current uses. Make it a concrete struct type, and rename it to the
shorter and more precise Metric.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-17 11:47:14 +02:00
Chris Waldon 9f6e09317d widget/material: add disabled state support to all widgets
This commit configures all remaining widgets to draw themselves in a disabled state
when their layout.Context is disabled. A description of the
strategy employed by each follows:

- Checkbox and RadioButton: Draws the icon component in a lighter color. Currently the label text is left
in its default color.
- ProgressBar: The "progress" color is lightened, but not as much as the background color. This makes the current progress value still readable.
- Editor: The cursor is no longer drawn and the text is lightened.
- Switch: The track is unchanged, but the circular "thumb" component is lightened.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-06-15 09:53:49 +02:00
tainted-bit 2dc19a3695 widget: use byte length when comparing with caret position
Fixes misaligned carets when the Editor text contains code points
represented by multiple UTF-8 bytes. Line lengths should be
measured in bytes instead of glyphs for caret positioning.

Signed-off-by: tainted-bit <sourcehut@taintedbit.com>
2020-06-12 17:14:31 +02:00
Elias Naur 5fe3785bbd widget/material: make Switch disabled color configurable
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-10 20:20:36 +02:00
Elias Naur 6380baacb6 all: move Now from system.Config to system.FrameEvent
Then, make layout.Context.Now a field, copied from FrameEvent.Now.

API change:

	gofmt -r 'gtx.Now() -> gtx.Now'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 23:23:08 +02:00
Elias Naur a24a2c9fb6 widget/material: fade out inkwells a little longer than their expansions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 22:29:43 +02:00
Elias Naur 0715c801e2 widget,widget/material: convert Switch to use Clickable
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 22:12:41 +02:00
Elias Naur f7fea02312 widget: immediately fade out cancelled button press inkwells
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 21:51:39 +02:00
Elias Naur ce56464923 widget,gesture: fade out cancelled inkwells
While here, adjust inkwell sizes to match gtx.Constraints.Min.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 23:50:00 +02:00
Elias Naur 36f4267a6c widget/material: fade in inkwells
When a clickable is pressed and dragged any enclosing List will grab and
cancels the press. To minimize visual dicontinuity, smoothly fade in the
inkwell.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 22:07:02 +02:00
Elias Naur 0444caa9e3 gesture,widget: drop press markers on gesture cancel
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 21:44:57 +02:00
Chris Waldon cc5f8fcffe widget/material: add support for disabled buttons
This leverages the new semantics of a disabled layout.Context
to draw all of the button types in a disabled state.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-06-08 10:16:50 +02:00
Elias Naur 8761550839 widget: fix Enum.Changed to reset changed status
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 17:06:03 +02:00
Elias Naur b07d34354e text,widget/material: make font collections explicit
Before this change, package font implemented a global font registry,
with the usual problems of package global state.

This change deletes the global registry and introduces the text.Collection
type for representing a list of fonts and their faces. Collection exports
Lookup that finds the closest match and its face.

The existing FontRegistry is renamed to Cache to reflect its new limited
functionality: a cache of shapes and measurements on top of a Collection.

Then, material.NewTheme is changed to take a Collection and initialize
a Cache.

Updates gio#19 because multiple windows require a separate (writable) Cache per
window, while (read-only) Collections may be shared.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 16:27:43 +02:00
Elias Naur c19ed05342 op: change CallOp to be a return value from MacroOp.Stop
Converting

	macro := op.Record(ops)
	...
	macro.Stop()

	macro.Add()

to

	macro := op.Record(ops)
	...
	call := macro.Stop()

	call.Add(ops)

Which is more general (call.Add can take a different ops than the op.Record
that started it), and enforced the order between Stop and the subsequent Add.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 12:07:20 +02:00
Thomas Bruyelle ae8a377cda 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>
2020-06-02 10:39:56 +02:00
Pierre.Curto bade277876 widget: Clickable: added support for NumClicks
Clickable.Clicks() now returns the number of clicks.

Signed-off-by: Pierre.Curto <pierre.curto@gmail.com>
2020-06-02 10:26:14 +02:00
Elias Naur 3ef841bd07 widget: make Clickable.Clicked use a pointer receiver
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 10:19:50 +02:00
Elias Naur ad93e32128 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>
2020-05-24 19:48:33 +02:00
Elias Naur f2df7c1458 widget: change Enum.Layout to follow layout protocol
Respect constraints and return dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:52:48 +02:00
Elias Naur 31d722d9eb 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>
2020-05-24 13:50:03 +02:00
Elias Naur 4898e1a691 widget: add Button.Clicks for retrieving clicks
An earlier change unexported the Button.Update method that exposed raw pointer
input not available from the boolean Button.Clicked method. Introduce Click
and Button.Clicks to replace it, and implement Clicked in terms of it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:20:00 +02:00
Elias Naur 8d838e89f5 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>
2020-05-24 13:19:34 +02:00
Elias Naur d017c722f5 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() {...}
	btn.Layout(...)

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

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>
2020-05-24 13:03:23 +02:00
Elias Naur c791f59351 widget: simplify Editor event flushing
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 12:53:09 +02:00