aboutsummaryrefslogtreecommitdiffstats
path: root/len.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-02-24 17:49:26 -0500
committerSam Anthony <sam@samanthony.xyz>2026-02-24 17:49:26 -0500
commitc99ff181003c565385c21b92ca15161fbdff2bd8 (patch)
treee5f55594cfc6a5912807449166653ff049894293 /len.go
parent1b48ef0a114dfb85f2a5b8c5bed7c2b9bc8b72cc (diff)
downloadgui-c99ff181003c565385c21b92ca15161fbdff2bd8.zip
add layout constraints and abs/rel units
Diffstat (limited to 'len.go')
-rw-r--r--len.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/len.go b/len.go
new file mode 100644
index 0000000..895688d
--- /dev/null
+++ b/len.go
@@ -0,0 +1,25 @@
+package gui
+
+// TODO: add font-size-relative units once a text rendering package is added.
+
+// Length allows distance or size to be expressed in absolute or relative units.
+type Length interface {
+ // Px resolves the Length to pixels for the given parent Env's size in pixels.
+ Px(parent int) int
+}
+
+// Px is a Length expressed in pixels.
+type Px int
+
+// Px implements the Length interface.
+func (p Px) Px(parent int) int { return int(p) }
+
+// Relative is a Length relative to the width or height of the parent Env.
+//
+// Relative(0.10) <=> 10%.
+type Relative float64
+
+// Px implements the Length interface.
+func (r Relative) Px(parent int) int {
+ return int(float64(r) * float64(parent))
+}