mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user