Before this change, the widget.Button.Layout method assumed the caller had set
up the pointer hit area before. Further, the very common rectangular hit
areas needed both an AreaOp and a widget.Button.Layout call.
Make widget.Button less subtle and more useful by setting up a
pointer hit area given by the incoming minimum constraints.
Drop a pointer.AreaOp made redundant by the change.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Setting a ColorOp before calling a widget function is too subtle.
Let the widget manage its color instead.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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>
The Value method both updated the enum value and returned it.
In order to access the current value withoutm, expose the Value
field of the enum and rename the method to Update. As a bonus we
can get rid of the SetValue method as well.
Updates gio#96
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The multitude of widget methods on Theme is unnecessary coupling in that all
possible widgets either have to be included in package material, or be
different than 3rd party widgets:
var th *Theme
// Core widget, calling a method on Theme.
th.Button(...).Layout(...)
// 3rd party widget, calling a function taking a Theme.
datepicker.New(th, ...).Layout(...)
Another reason for the Theme methods was to enable a poor man's
theme replacement, so that you could use the same code for
compatible themes. For example,
mat.Button(...).Layout(...)
would not need to change if the type of mat changed, as long as
the new type had a compatible method Button.
However, that point misses the fact that the mat variable had to
be declared somewhere, naming the theme package:
var mat *material.Theme (or, say, *cocoa.Theme)
A better and complete way to replace a theme is to use import renaming.
For example, to replace the material theme with a hypothetical Windows
theme, replace
import theme "gioui.org/widget/material"
with
import theme "github.com/somebody/windows
This change moves all Theme widget methods to be standalone functions,
and renames the widget style types accordingly.
For example, instead of the method
func (t *Theme) Button(...) Button
there is now a function
func Button(t *Theme, ...) ButtonStyle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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.
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>
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>
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>
It was left over from a previous approach to enable the program
to decide the ordering between calls to Layout vs Clicked.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
- Focused: returns whether editor is focused
- CaretPos: returns the text line & column numbers of the caret.
- CaretCoords: returns the x & y pixel coordinates of the caret.
- NumLines: returns the number of text lines in the editor
Signed-off-by: Larry Clapp <larry@theclapp.org>
Editor's event processing assumes the cached layout is valid, but
it might not be if the program changed the Editor text between calling
Layout and Events.
Fixes#85 (I think)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Now that text layout and shaping operate on concrete sizes and not
units, Editor no longer needs to detect scaling changes. Remove it.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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>
In preparation for using Shaper with an io.Reader, rework the API to not refer
to strings. In particular, introduce Glyph for holding the rune in addition to
the advance. For fast traversing of the underlying text, add Len to Line with
the UTF8 length.
Layout is a useless wrapper around []Line; remove it while we're
here.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Editor.Delete
Editor.Move
Editor.Insert
Move the Editor.command method up above all the functions it calls.
Signed-off-by: Larry Clapp <larry@theclapp.org>
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>
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>
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>
MacroOp is about to lose the ability to run a different operation list
than the one it was recorded on. Text shape caches rely on that property,
and must use the new CallOp operation added for purpose.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
While here, unexport the Queue and Config fields. The NewContext
cosntructor is shorter, and there is no reason to expose the fields
to accidental mutation.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
When you press enter to "submit" an editor widget, don't also append the
newline to the editor text. Enter should be "submit" or "add newline"
but not both.
Also add parens to the Enter check: x && y || z => x && (y || z).
Signed-off-by: Larry Clapp <larry@theclapp.org>