unit: add Metric.DpToSp and Metric.SpToDp

It's sometimes necessary to specify padding or spacing based on
the text size.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2022-06-09 18:13:45 +03:00
committed by Elias Naur
parent bf6371c8e9
commit 72669e19bc
2 changed files with 51 additions and 10 deletions
+32
View File
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Unlicense OR MIT
package unit_test
import (
"testing"
"gioui.org/unit"
)
func TestMetric_DpToSp(t *testing.T) {
m := unit.Metric{
PxPerDp: 2,
PxPerSp: 3,
}
{
exp := m.Dp(5)
got := m.Sp(m.DpToSp(5))
if got != exp {
t.Errorf("DpToSp conversion mismatch %v != %v", exp, got)
}
}
{
exp := m.Sp(5)
got := m.Dp(m.SpToDp(5))
if got != exp {
t.Errorf("SpToDp conversion mismatch %v != %v", exp, got)
}
}
}