aboutsummaryrefslogtreecommitdiffstats
path: root/style/options.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-03-03 14:22:43 -0500
committerSam Anthony <sam@samanthony.xyz>2026-03-03 14:22:43 -0500
commit0a0b9b8cc9cdc0ffe1819de0266dd1e3c3eb564f (patch)
treeead2723b26a2dcb1d1db80efc01390579056d4fc /style/options.go
parent8858a54b5ddb3a2d8a42ecb1a837c02800bc934f (diff)
downloadgui-0a0b9b8cc9cdc0ffe1819de0266dd1e3c3eb564f.zip
style: unit conversion
Implemented the golang.org/x/exp/shiny/unit.Converter interface on style.Style.
Diffstat (limited to 'style/options.go')
-rw-r--r--style/options.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/style/options.go b/style/options.go
new file mode 100644
index 0000000..c1514c0
--- /dev/null
+++ b/style/options.go
@@ -0,0 +1,62 @@
+package style
+
+import (
+ "golang.org/x/image/font"
+ "golang.org/x/image/font/gofont/goregular"
+ "golang.org/x/image/font/opentype"
+)
+
+var defaultOptions = options{
+ font: goregular.TTF,
+ FaceOptions: opentype.FaceOptions{
+ DefaultFontSize,
+ DefaultDpi,
+ DefaultHinting,
+ },
+}
+
+// Option is a functional option to Style constructor, New.
+type Option func(*options)
+
+type options struct {
+ font []byte
+ opentype.FaceOptions
+}
+
+func parseOpts(opts ...Option) options {
+ o := defaultOptions
+ for i := range opts {
+ opts[i](&o)
+ }
+ return o
+}
+
+// Font option sets the font source to use. It takes TTF or OTF data
+// (see golang.org/x/image/font/opentype.Parse).
+func Font(src []byte) Option {
+ return func(o *options) {
+ o.font = src
+ }
+}
+
+// FontSize option sets the font size in points (1/72").
+func FontSize(size float64) Option {
+ return func(o *options) {
+ o.FaceOptions.Size = size
+ }
+}
+
+// Dpi option sets the dots per inch resolution of the display.
+func Dpi(dpi float64) Option {
+ return func(o *options) {
+ o.FaceOptions.DPI = dpi
+ }
+}
+
+// Hinting options selects how to quantize a vector font's glyph
+// nodes.
+func Hinting(h font.Hinting) Option {
+ return func(o *options) {
+ o.FaceOptions.Hinting = h
+ }
+}