Commit Graph

48 Commits

Author SHA1 Message Date
Elias Naur e460e4f4bf widget,widget/material: move Image and Icon to widget package
There is nothing theme-specific about displaying images and icons,
so move the types from the material package to the generic widget
package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 12:22:32 +02:00
Elias Naur fa7f9d3ba8 widget/material: report icons dimensions after running Icon.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-02 20:56:33 +02:00
Elias Naur b1aed3eae0 Revert "widget/material: propagate ButtonLayout minimum constraints to content"
This reverts commit 52ccc183b5.

Reason for revert:

This doesn't seem like a good idea after all. The reason for the change was to
propagate the minimum constraints to the button content. But in the simplest case,
a label, stretching the button will make the label stretch as well, leaving the label
top-aligned.

We'll revisit this issue if a real use-case comes up.
2020-04-16 19:57:19 +02:00
metaclips da01fbdea7 widget/material: add ProgressBar
Add progress indicator support to material widget

Signed-off-by: metaclips <utimichael9@gmail.com>
2020-04-02 21:05:13 +02:00
Elias Naur 27d81b8c7e widget/material: re-center Button label
A previous change propagated the minimum layout constraints to Button's
content, which made Button no longer center its label when stretched.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-27 16:40:13 +01:00
Elias Naur 52ccc183b5 widget/material: propagate ButtonLayout minimum constraints to content
The previous change fixed a regression where minimum constraints larger than 0
would not affect the button. This change moves the minimum constraints one
level lower so the content widget will see them as well. The wrapping
layout.Center ensures that any misbehaving widgets still end up centered.

Add a test to lock in the new behaviour and the previous fix.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-25 17:52:02 +01:00
metaclips f7a23ad46a widget/material: draw button to max width with ButtonLayout
This patch allows support to draw button to maximum width using ButtonLayout.
2020-03-25 17:41:01 +01:00
metaclips 5d7fbd761f widget/material: add ButtonLayout
Add ButtonLayout for adding button behaviour and style to arbitrary content such
as a combined icon-and-text button.
Fixes #43

Signed-off-by: metaclips <utimichael9@gmail.com>
2020-03-22 13:20:32 +01:00
Elias Naur 148a2828e7 layout: don't force Expanded Stack children larger than their minimum
Instead, honor the constraints after laying out both Stacked and
Expanded children.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 14:06:25 +01:00
Elias Naur bfb50cef5d all: remove unused fields, functions and add missing error handling
Credit to staticcheck.io.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 22:26:54 +01:00
Larry Clapp 0dd77be975 widget/material: allow button Inset to be customizable
Signed-off-by: Larry Clapp <larry@theclapp.org>
2020-02-17 15:37:08 +01:00
Elias Naur 69dfd2e3a5 op/paint: add support for efficient ImageOp subimages
The new field ImageOp.Rect is initialized to cover the entire source
image, but can be modified to draw only a section of it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-13 13:15:32 +01:00
Elias Naur 4c220f4554 text: simplify text layout and shaping API
First, replace LayoutOptions with an explicit maximum width parameter.  The
single-field option struct doesn't carry its weight, and I don't think we'll
see more global layout options in the future. Rather, I expect options to cover
spans of text or be part of a Font.

Second, replace the unit.Converter with an scaled text size. It's simpler and
allow the Editor and similar widgets to easily detect whether their cached
layouts are stale. Package text no longer depends on package unit, which is
now dealt with at the widget-level only.

Finally, remove the Size field from Font. It was a design mistake: a Font is
assumed to cover all sizes, as evidenced by the FontRegistry disregarding
Size when looking up fonts.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-03 23:32:55 +01:00
Elias Naur fb7337f794 layout: replace Align with a Layout method on Direction
It's one less type (Align) and shorter:

Before:

	layout.Align(layout.Center).Layout(...)

After

	layout.Center.Layout(...)

It is also safer: since `layout.Align(...)` was a casting operation,
the Go compiler would not complain about an incompatible constant.

For example, the widget/material package contained a wrong cast:

	layout.Align(layout.Start)

which should have been

	layout.Align(layout.W)

After this change, attempting `layout.Start.Layout(...)` result
in a compile error.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-02 17:13:02 +01:00
Elias Naur e25b1639b9 text: make Shaper an interface
And rename out the caching implementation to FontRegistry.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-13 14:48:31 +01:00
Elias Naur 7814da47a0 layout: simplify Stack API
Similar to what a previous commit did for Flex, this change simplifies
Stack to just one Layout call:

	layout.Stack{}.Layout(gtx,
		layout.Stacked(func() {...}),
		layout.Expanded(func() {...}),
	)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-12 00:45:36 +01:00
Elias Naur f60a5c7ac3 layout: simplify Flex API to a single Layout call
With the simplification of MacroOp, it is now possible to simplify
the Flex API to just a single Layout method, similar to List:

	layout.Flex{}.Layout(gtx,
		layout.Rigid(func() { ... }),
		layout.Flexed(0.5, func() { ... }),
	)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-12 00:45:36 +01:00
Elias Naur edc81ea0bb op: remove operation list argument from MacroOp.Add
The ability to invoke other operation lists belongs in the new CallOp.

While we're here, make MacroOp.Add use a pointer receiver to match the
other methods.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-12 00:45:36 +01:00
Elias Naur 16cc51ee8a io/pointer: unify area ops into a single AreaOp
Make Rect and Ellipse constructors of AreaOp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-18 15:03:11 +01:00
Elias Naur 7299d1c875 op/clip: replace Rect and RoundRect with Rect type
Remembering the order of the corners in the RoundRect is difficult,
which suggest that RoundRect should be a struct with named fields.

Do that, and make Rect the special case where corner radii are all
zero.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-18 14:33:28 +01:00
Elias Naur 778b7e6398 widget/material: rename material.go to theme.go
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:55:05 +01:00
Elias Naur 65c783179d clip: change Rect argument to f32.Rectangle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:42:19 +01:00
Elias Naur 4f30b985eb op/clip: add RoundRect
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:30:07 +01:00
Elias Naur e864ac3fc3 op/clip: split clip operations into its own package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:07:00 +01:00
Elias Naur 9c0fc631bd widget/material: use theme TextSize for Editors
Thanks to Werner Laurensse for noticing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-07 18:45:53 +01:00
Elias Naur 7256bdae38 app/internal/windows: don't draw window background on Windows
Avoids flickering between GPU content and the CPU drawn background
color.

gofmt -w -s . now we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-06 17:28:14 +01:00
Elias Naur 1defd4e759 widget/material: clean up package docs, add license, rename file
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-06 11:46:52 +01:00
Alexander Arin 089ae31f0c widgets, widgets/material: add RadioButton & Enum
Signed-off-by: Alexander Arin <fralx@yandex.ru>
2019-11-06 11:02:28 +01:00
Elias Naur 82e51019e1 widget/material: document package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-06 10:57:17 +01:00
Alexander Arin 0f5b94a483 widget,widget/material: add CheckBox 2019-11-04 00:31:12 +01:00
Alexander Arin 2a06f3d3b2 widget/material: move Icon to its own file and add Color; add CornerRadius to Button 2019-11-04 00:29:21 +01:00
Elias Naur 4107485902 widget,widget/material: remove disabled drawing modes
Determining the enabled state of a widget from whether its Clicked method has
been called only works for button-like widgets. For example, it's not clear a
Clicked method is appropriate for a CheckBox.

Remove the feature for now, and let's find a better design in the future.

As a nice side effect, we can now process events in Layout methods, so that
buttons react to user input even when Clicked is not called.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 14:48:22 +01:00
Elias Naur 9a6bdee813 widget/material: adjust Button insets to match Android
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 20:51:16 +01:00
Elias Naur 0504c27e46 widget/material: respect height minimum constraint in Button.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-23 09:56:34 +02:00
Elias Naur 3a60a384e6 widget/material: respect min width in Button.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 12:58:05 +02:00
Elias Naur 86f45f813e widget/material: fix IconButton padding
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 09:34:26 +02:00
Elias Naur 78963bdaae widget/material: add and use Icon.Layout method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 09:21:23 +02:00
Elias Naur bf6741f2d6 widget/material: accept nil icon in IconButton.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-17 20:50:02 +02:00
Elias Naur 3ec0948bba widget/material: don't scale image when constrained
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-17 14:10:49 +02:00
Elias Naur 7835d6999f widget/material: don't use translucency for disabled icon buttons
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 21:11:16 +02:00
Elias Naur e2d0b3cfca layout: invert baseline to measure positive distance from bottom
With an inverted baseline, the zero value results in the widget
baseline aligned to its bottom.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 00:49:52 +02:00
Elias Naur 160408ec03 widget/material: use constraint minimums for background fills 2019-10-15 23:33:31 +02:00
Elias Naur 8da2c9dbb4 widget/material: change Image to take an ImageOp, not an image.Image
Using ImageOps directly avoids the image copy by NewImageOp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 18:17:30 +02:00
Elias Naur 74407a50d5 op/paint: add NewImageOp, unexport ImageOp fields
With public ImageOp fields there was no way to mark an image.Image as modified.
Replace them with NewImageOp that always make a copy, and use the opportunity
to ensure the copy is ready to upload to a GPU texture.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 18:06:50 +02:00
Elias Naur 2e22edbb99 widget/material: remove unused function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 17:41:32 +02:00
Elias Naur 0559393633 widget/material: don't use transparency for disabled buttons
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 15:08:13 +02:00
Elias Naur 8cd4c2e5de widget/material: use font.Default
And simplify NewTheme to take no arguments.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-13 18:23:39 +02:00
Elias Naur abb99eca5c theme/material: add the material theme
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:36:25 +02:00