Files
gio-patched/unit/unit_test.go
T
Egon Elbre e9bce02b24 unit: add PxToDp and PxToSp
PxToDp and PxToSp are useful when you are trying to calculate
text-size or widget size based on dynamically sized container.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2023-01-01 10:19:50 -06:00

49 lines
740 B
Go

// 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)
}
}
{
exp := unit.Dp(5)
got := m.PxToDp(m.Dp(5))
if got != exp {
t.Errorf("PxToDp conversion mismatch %v != %v", exp, got)
}
}
{
exp := unit.Sp(5)
got := m.PxToSp(m.Sp(5))
if got != exp {
t.Errorf("PxToSp conversion mismatch %v != %v", exp, got)
}
}
}