Commit Graph

39 Commits

Author SHA1 Message Date
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 b331407e81 text: add io.Reader Layout method to Shaper
use them for Editor, which is no longer required to construct a string
for laying out its content.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-13 21:38:54 +01:00
Elias Naur 16d2a3ac0a text: remove String, Layout and add Glyph
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>
2020-01-13 19:54:11 +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 3f6a1c34d3 text: correct Shaper comment about the default face
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-13 13:52:33 +01:00
Werner Laurensse e76726d4f7 text/shaper: Add Metrics method to Shaper struct.
Signed-off-by: Werner Laurensse <werner@alman.ax>
2019-12-15 20:23:13 +01:00
Elias Naur 0768fbe590 text: convert clip.Ops to op.CallOp
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>
2019-12-12 00:45:36 +01:00
Werner Laurensse 4bcb4ec8b6 text: add Metrics method to Face interface. font/opentype: implement Metrics method for Font struct.
Signed-off-by: Werner Laurensse <werner@alman.ax>
2019-11-24 20:01:33 +01:00
Elias Naur 682d2810d3 text: remove SingleLine from LayoutOptions
Low level text layout should not deal with filtering newlines.

Updates gio#61

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 20:01:40 +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 3a440c07c6 text: don't panic on missing default font
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-15 10:07:10 +02:00
Elias Naur edf0d8ef99 font/opentype,text/opentype: move package
Opentype parsing, layout and shaping will be used by subpackages to package
font. Move the opentype package accordingly.

Remove the Must helper function; programs will no longer use the opentype
package in the normal case.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-13 18:23:30 +02:00
Elias Naur d33461dd80 text: match Bold weight to CSS, add Variant and Typeface 2019-10-13 18:23:30 +02:00
Elias Naur 481cca5781 text: use the first registered font as the default in Shaper
Before this change, the default font was the one registered with an empty
Typeface.

We're about to use the correct names for fonts, so change Shaper to
fallback to the first registered typeface instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-13 18:23:30 +02:00
Elias Naur ff3fc7a24a widget,text: move Label and Editor from text to widget package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur a5b22860ac text: replace Editor.Event with Editor.Event and add Text to SubmitEvent
THe single-stepping Event was done so that SubmitEvents didn't have to
copy the text out if it wasn't needed.

This is a dubious optimization, because SubmitEvents are only generated
when Editor.Submit is true, in which case it is highly likely the user
wants the text.

Furthermore, I expect Editors with Submit enabled to be relatively short,
in the order of a message field in a chat program.

Finally, Editor will need support for undo at some point. Supporting undo
means we can support a lightweight SubmitEvent that points to an older Editor
state.

All in all (1) we gain a simpler Events method, and (2) we can allow the user
to call it before or after Editor.Layout. Before this change any the events were
gone after Layout was called.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur d8e3d1077c text: maintain valid Editor scroll offset
No functional changes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur bc8ad61b54 text: remove themable properties from Editor and Label
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur dbb62ae0f6 text: remove padding from Editor
Before this change, the Editor computed a suitable padding for itself
from its font and text. Varying the padding according to the particular
font and text doesn't seem worth it and interferes with higher level widgets'
ability to overlay hints and the like on top of the editor.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur f35fe407b3 text: tighten clip bounds for Editor and Label
We're about to remove the extra padding from Editor. To do that, the
clipping must account for text drawing that lie outside the viewport.

With accurate clip bounds, use it for Label as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur bef7c39e4c text: replace Family with Shaper, add Font, Face
There is now a single shaping implementation, Shaper, for all fonts, replacing
Family that only covered a single typeface.

A typeface is identified by a name, where the empty string denotes the
default typeface.

Font is introduced to specify a particular font from the typeface, style,
weight and size.

Face is changed to an interface for a particular layout and shaping method.
The text/shape package is renamed to text/opentype and contains a Face
implementation based on golang.org/x/image/font/sfnt.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur ea404bc8fc text: refactor Editor
To prepare for separating drawing from state tracking, refactor
Editor so that only its top level Layout method touches font
parameters and materials.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:04:34 +02:00
Elias Naur ef5cf5b724 op/paint: return ClipOp from Path.End
Instead of adding an implicit ClipOp, return a ClipOp ready to use, freeing the
caller from recording a macro.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 14:01:46 +02:00
Elias Naur 163d9037e6 text: fix editBuffer.runeBefore
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-10 15:27:02 +02:00
Elias Naur afeaa247c8 text: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-06 13:03:19 +02:00
Elias Naur 225c73f012 text: move Label.it to a local variable
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-06 12:29:35 +02:00
Elias Naur 1b44594411 text/shape: reduce garbage a bit
The sfnt.Buffer embedded in the opentype type caused instances of
it to escape. Move the buffer to Family to avoid that.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-05 22:53:37 +02:00
Elias Naur 2097c6475d text/shape: remove Family.Reset by introducing LRU caches
It was easy to forget Family.Reset, and the per-frame caching strategy is
probably too aggressive. Use a static size for the caches and evict
according to a least recently used policy.

Reset is then no longer required, and we can delete it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-05 22:27:32 +02:00
Elias Naur 0b637f549d text: rename Face to Family and let Face denote a family configuration
While here, rename Family.Path to Shape which a more precise term.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-05 22:27:32 +02:00
Elias Naur b4a52d3010 text: make text size implicit
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-05 11:22:26 +02:00
Elias Naur f230036cad text: re-phrase and clarify Label.MaxLines comment
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-04 19:18:05 +02:00
Elias Naur 6dad034b22 op/paint: rename PathBuilder to Path
There was no "Path" to "Build", so let's just use the simpler name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-03 13:35:38 +02:00
Elias Naur 3784ece6dd all: rename package ui to unit
Package ui is now only about units except for the Config.Now method.
Remove Now and rename Config to Converter. Add layout.Config to
replace the old ui.Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur 1d3360699e text/shape: move package measure
Text shaping is a common name for what package measure does. Rename
it to "shape" and move it below the text package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur beaec661d2 op/paint: move paint package below the op package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur 8cf35a1f97 op: add package op for operations
Extract operation types from package ui into package op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur e7a97bf176 io/event: move event types from package ui to its own package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 15:18:08 +02:00
Elias Naur 7a259e68f7 io: give event packages a common prefix
Packages that provide support for external events such as pointer, key and
system are only the beginning. Future packages are expected for clipboard
access, drag and drop, gps positions and so on.

To keep the number of top-level packages under control, move such I/O packages
to the new `io` directory.

The `system` package name was the previous solution to keeping the number of
top-level packages under control: I named it `system` instead of the narrower
`profile` because I expected to put all the less common events into it, turning
`system` into a "package util" smell.

With `io`, package system can be renamed to `profile`.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 14:50:55 +02:00
Elias Naur 22cd88df9f all: rename the gioui.org/ui module to gioui.org
The "ui" is redundant and stutters.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 12:37:06 +02:00