package unit
import "gioui.org/unit"
Package unit implements device independent units.
Device independent pixel, or dp, is the unit for sizes independent of the underlying display device.
Scaled pixels, or sp, is the unit for text sizes. An sp is like dp with text scaling applied.
Finally, pixels, or px, is the unit for display dependent pixels. Their size vary between platforms and displays.
To maintain a constant visual size across platforms and displays, always use dps or sps to define user interfaces. Only use pixels for derived values.
Index ¶
- type Dp
- type Metric
- func (c Metric) Dp(v Dp) int
- func (c Metric) DpToSp(v Dp) Sp
- func (c Metric) PxToDp(v int) Dp
- func (c Metric) PxToSp(v int) Sp
- func (c Metric) Sp(v Sp) int
- func (c Metric) SpToDp(v Sp) Dp
- type Sp
Types ¶
type Dp ¶
type Dp float32
Dp represents device independent pixels. 1 dp will have the same apparent size across platforms and display resolutions.
type Metric ¶
type Metric struct { // PxPerDp is the device-dependent pixels per dp. PxPerDp float32 // PxPerSp is the device-dependent pixels per sp. PxPerSp float32 }
Metric converts Values to device-dependent pixels, px. The zero value represents a 1-to-1 scale from dp, sp to pixels.
func (Metric) Dp ¶
Dp converts v to pixels, rounded to the nearest integer value.
func (Metric) DpToSp ¶
DpToSp converts v dp to sp.
func (Metric) PxToDp ¶
PxToDp converts v px to dp.
func (Metric) PxToSp ¶
PxToSp converts v px to sp.
func (Metric) Sp ¶
Sp converts v to pixels, rounded to the nearest integer value.
func (Metric) SpToDp ¶
SpToDp converts v sp to dp.
type Sp ¶
type Sp float32
Sp is like UnitDp but for font sizes.
Source Files ¶
unit.go
- Version
- v0.7.0
- Published
- Jun 16, 2024
- Platform
- darwin/amd64
- Imports
- 1 packages
- Last checked
- 14 seconds ago –
Tools for package owners.