Commit Graph

131 Commits

Author SHA1 Message Date
Chris Waldon 77eed223ac widget/material: fix scrollbar indicator partially off-screen bug
This commit fixes a problem that could force the scroll indicator to
lay itself out outside of its configured bounds. This occurred when
the scroll indicator size was increased to meet the minimum size
configured on the style type while the scrollbar was near the end
of the list. The increased size did not take the start position
of the scroll indicator into account, which made the indicator begin
in the correct place, but extend beyond the end of its track.

This commit alters the logic to ensure that the scroll indicator can
never extend beyond the end of its track.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-09-14 06:42:22 +02:00
Chris Waldon da09aabbe8 widget/material: clamp fromListPosition end coordinate
Previously, it was possible for fromListPosition to return
an end coordinate greater than 1, which would make scroll
indicators using those coordinates render beyond the
boundaries of their scroll tracks. One could argue that
this is a bug in the scroll indicator, but I don't think
this method should return data outside of its documented
range.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-09-14 06:42:15 +02:00
Walter Werner SCHNEIDER 8701c253c3 material: update label type scales to match the MD spec
Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
2021-09-01 14:30:27 +02:00
Elias Naur 6e9bb7b91c widget,widget/material: remove Color field from Icon
Icons are meant to be shared among multiple widgets, but their Color
state may end up with unexpected values after use. Replace the state
with and explicit argument to Layout.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-07-28 14:19:39 +02:00
Chris Waldon b3918ce40f widget/material: ensure List accounts for scrollbar size in dims
This commit ensures that the dimensions returned by material.List
include the size of the scrollbar when the scrollbar is set to
the Occupy AnchorStrategy.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-13 16:43:38 +02:00
Chris Waldon 78235baaa5 widget/material: ensure List handles zero minimum constraints
This change ensures that the scrollbar anchors to the proper edge of the
content even when the list was drawn with a zero minimum constraint.

Without this, the layout.Direction used to anchor the scrollbar will choose
to use the minimum size and anchor it to the opposite edge of the content.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-13 15:09:26 +02:00
Chris Waldon 0e60935856 widget/material: ensure scrollbars can be dragged from list end
The scrollbar implementation prior to this change only adjusted
list.Position.Offset. This works in all circumstances except when
list.Position.BeforeEnd=false. If the position indicates that the
scroll position is at the end of the list, the offset is ignored.

This change ensures that manually dragging the scrollbar always
causes BeforeEnd to be set to true. If the drag ends with the
scrollbar at the end of the list, BeforeEnd will be set
automatically by the next list.Layout call, so this doesn't
prevent the list from optimizing for that case in general.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-07 15:51:00 +02:00
Chris Waldon 941aeaae91 widget{,/material}: add List types with scrollbars
To use these lists instead of layout.List, callers simply need to
change declarations of layout.List to widget.List, and to change
calls to layout.List.Layout to material.List(th,&list).Layout.

So this:

    var list layout.List
    list.Layout(gtx, 10, func(gtx C, index int) D {
        return material.Body1(th, fmt.Sprintf("%d", index)).Layout(gtx)
    })

Becomes:

    var list widget.List
    material.List(th, &list).Layout(gtx, 10, func(gtx C, index int) D {
        return material.Body1(th, fmt.Sprintf("%d", index)).Layout(gtx)
    })

Naturally, the material.ListStyle type supports tweaking the scrollbar's
appearance and behavior.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-07-05 16:08:30 +02:00
pierre 2e991f31be widget: make Icon honour its constraints
This is a breaking change as Icon.Layout no longer requests a size.

Before:
  sz := unit.Dp(20)
  ic.Layout(gtx, sz)

After:
  sz := gtx.Metric.Px(unit.Dp(20))
  gtx.Constraints.Min = image.Pt(sz, 0)
  ic.Layout(gtx)

Fixes gio#240

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-07-01 13:15:08 +02:00
Elias Naur a87206c364 widget/material: add ProgressCircle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-26 18:05:34 +02:00
Elias Naur d5b70c439c widget/material: draw Loader completely inside its bounds
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-05-19 19:35:36 +02:00
Egon Elbre b9f2e0fb41 widget/material: use clip.Circle to draw circles
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-03-14 10:08:58 +01:00
Elias Naur 2bd539d2de widget/material: use simpler clip.Rect for Clickable clip region
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-03 20:04:46 +01:00
Elias Naur b39d1bdac7 widget: handle hovering of the empty Enum key
Before this change, a radio button with the empty key ("") would be
displayed as hovering if no other button were.

It's still not possible to have no radio buttons selected when one of
them is the empty key. If that's becomes necessary, Enum.Value can be
converted to a *string.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-03 18:12:39 +01:00
Elias Naur de7a5985d5 widget/material: remove bogus minimum cosntraint from checkable
checkable.layout forces the label to take up at least constraints.min
space. However, for min == max, the total checkbox plus label would then
overflow. The minimum constraint doesn't seem necessary anymore, so drop
it.

Remove a superfluous layout.W layout as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-03 17:32:31 +01:00
Chris Waldon 6682f75db9 widget/material: use more readable editor default selection color
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2021-02-06 07:51:56 +01:00
Larry Clapp 34273940a0 widget,widget/material: add selection to the editor
- Allow dragging to be on both horizontal and vertical axes at once.
- Split Editor.caret.pos into caret.start and caret.stop. caret.start is
  the old caret.pos, and is both the position of the caret, and also the
  start of selected text. caret.end is the end of the selected text.
  Start can be after end, e.g. after after Shift-DownArrow.
- Update caret.end after a mouse drag, and various shifted keys
  (Shift-UpArrow, Shift-DownArrow, etc).
- Change Shortcut-C to copy only the selected text, not the whole editor
  text.
- Add Shortcut-X to copy and delete selected text, and Shortcut-A to
  select all text.
- The various Insert/Delete/etc functions now overwrite or delete the
  selection, as appropriate.
- Change MoveCaret to accept a distance for selection end, as well.
  Change SetCaret to accept a selection end offset.
- Add SelectionLen to get the selection length, Selection to get
  selection offsets, SelectedText to get the selected text, and
  ClearSelection to clear the selection.
- Add a rudimentary selection unit test, and extend the deleteWord unit
  test with some text selection cases.
- Add SelectionColor to material.EditorStyle, which defaults to
  Theme.Palette.ContrastBg.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2021-01-24 09:44:52 +01:00
pierre b24df0aa6e widget/material: use clip.UniformRRect
Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-21 10:30:00 +01:00
Egon Elbre eea1dbc176 widget/material: add hover to Switch
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:10 +01:00
Egon Elbre bc6798c4ca widget/material: add hovered to RadioButton
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:06 +01:00
Egon Elbre 0b736990a9 widget/material: add hover to CheckBox
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:57:01 +01:00
Egon Elbre 468bd6f53a widget/material: add hover to Button
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-01-18 10:56:57 +01:00
pierre 85c0a7d803 widget/material: added support for Vertical axis to Slider
Adding an axis to the Float widget, allows positioning the Slider one not only horizontally but also vertically.
Also update the fill ops while there.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-14 17:42:58 +01:00
Elias Naur d331dd2de8 op: rename StackOp/Push/Pop to StateOp/Save/Load
The semantics were relaxed in a previous commit; this change renames
to operations accordingly.

API change. Use gofmt to adjust your code accordingly:

gofmt -r 'op.Push(a).Pop() -> op.Save(a).Load()'
gofmt -r 'op.Push(a) -> op.Save(a)'
gofmt -r 'v.Pop() -> v.Load()'
gofmt -r 'op.StackOp -> op.StateOp'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 21:28:59 +01:00
pierre 8a148ad6a1 widget/material: updated Switch comments.
Signed-off-by: pierre <pierre.curto@gmail.com>
2020-12-23 00:36:25 +01:00
Walter Werner SCHNEIDER 83d23ab507 all: sort and group imports
Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
2020-12-17 08:55:09 +01:00
Egon Elbre e383e6d6be widget/material: better disabled color calculation
Use desaturation in combination with alpha multiplication.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-12-16 19:15:17 +01:00
Egon Elbre 296303210f widget/material: remove padding from Slider
Remove padding from the sides of the Slider to align them with
other components.

However, since sliders still need to be used with fingers try to
enforce a minimum finger height, if there is sufficient room.
The sides don't need similar treatment since after grabbing it's
possible to move the finger beyond the touch area, without losing
interaction.

To not enforce finger size, the theme can be adjusted:

    theme.FingerSize = unit.Px(0)

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-12-14 15:56:56 +01:00
Egon Elbre bd7bb4d5d2 widget/material: use float32 for progress
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-12-11 18:28:59 +01:00
Sebastien Binet be89f8b945 all: introduce Outline and Stroke builders
This CL introduces 2 new path builders:
- Outline which takes a PathSpec to be outlined
- Stroke which takes a PathSpec and a stroke style, to stroke a path.

typically, code like this:

  var p clip.Path
  ...
  p.Outline().Add(o)

should be replaced with:

  var p clip.Path
  ...
  clip.Outline{Path: p.End()}.Op().Add(o)

similarly, stroking should be modified from:

  var p clip.Path
  ...
  p.Stroke(width, clip.StrokeStyle{...}).Add(o)

to:

  var p clip.Path
  ...
  clip.Stroke{Path: p.End(), Style: clip.StrokeStyle{Width:...}}.Op().Add(o)

here are tentative 'rf' scripts (see rsc.io/rf for more details):

  ```
  ex {
  	import "gioui.org/op";
  	import "gioui.org/op/clip";

  	var p clip.Path;
  	var o *op.Ops;

  	p.Outline().Add(o) -> clip.Outline{Path:p.End()}.Op().Add(o);
  }

  ex {
  	import "gioui.org/op";
  	import "gioui.org/op/clip";

  	var o *op.Ops;
  	var p clip.Path;
  	var sty clip.StrokeStyle;
  	var width float32;

  	p.Stroke(width, sty).Add(o) ->   \
	    clip.Stroke{                 \
		Path:p.End(),            \
		Style: clip.StrokeStyle{ \
		    Width: width,        \
	    }}.Op().Add(o);
  }
  ```

Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-12-09 09:44:15 +01:00
Chris Waldon a87a520ae8 widget/material: manage widget colors with Palette type
This introduces a new material.Palette type that captures the color information
necessary to render a widget. This type is embedded in the material.Theme to
make it easier to swap to a different palette for part of the UI by reassinging
the Palette field.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-12-06 23:02:30 +01:00
Egon Elbre 21ef492cc9 all: use color.NRGBA in public API
color.RGBA has two problems with regards to using it.

First the color values need to be premultiplied, whereas most APIs
have non-premultiplied values. This is mainly to preserve color components
with low alpha values.

Second there are two ways to premultiply with sRGB. One is to premultiply
after sRGB conversion, the other is before. This makes using the API more
confusing.

Using color.NRGBA in sRGB makes it align with CSS.e

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-11-19 11:30:11 +01:00
Inkeliz 9469d18907 widget/material: fix hint when Editor is single-line
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2020-11-18 11:42:41 +01:00
Sebastien Binet 8e4940e6a8 widget/material: use stroked path to draw loader widget
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-11-10 15:58:14 +01:00
Sebastien Binet 936eb52b7e all: rename clip.Path.End into clip.Path.Outline
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-11-10 15:58:07 +01:00
Elias Naur 94d242d18c op/paint: remove support for PaintOp.Rect
PaintOp.Rect is the wrong abstraction; it implies a clip operation
better handled by package clip, and not all paints need it (colors).
Furthermore, it's awkward to specify a PaintOp that fills up the
current clip area, regardless of its size.

Redefine PathOp to mean "fill current clip area".

API change. Replace uses of PaintOp.Rect with a TransformOp applied
before the PaintOp.

Leave a TODO for the PathOp infinity area.

Fixes gio#167

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-11-05 16:32:19 +01:00
Chris Waldon 672555d3d0 widget/material: remove unused fill helper
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-10-22 18:57:55 +02:00
Chris Waldon 3d042093a5 widget/material: update buttons to use new paint Fill API
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-10-22 18:57:52 +02:00
Elias Naur 4bab6fcf32 internal/f32color: add colorspace-correct function for alpha scaling
Package material's ad-hoc mulAlpha didn't take the sRGB color-space
into account, which meant that alpha-scaled colors were subtly wrong.
Introduce f32color.MulAlpha and convert all uses to it.

Thanks to René Post for finding and debugging the issue.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-09-28 09:06:40 +02:00
Sebastien Binet d57edbb49d widget/material: use clip.Path.Arc to draw loader
Signed-off-by: Sebastien Binet <s@sbinet.org>
2020-08-27 15:25:23 +02:00
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 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
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