Documentation
¶
Index ¶
- Constants
- Variables
- func DpToGioUnit(u Dp) (gioUnit.Dp, error)
- func DpToGioUnitUnsafe(u Dp) gioUnit.Dp
- func TextUnitToGioDp(tu TextUnit, density float32) (gioUnit.Dp, error)
- func TextUnitToGioSp(tu TextUnit) (gioUnit.Sp, error)
- func TextUnitToGioSpUnsafe(tu TextUnit) gioUnit.Sp
- type Constraints
- func FitPrioritizingHeight(minWidth, maxWidth, minHeight, maxHeight int) Constraints
- func FitPrioritizingWidth(minWidth, maxWidth, minHeight, maxHeight int) Constraints
- func Fixed(width, height int) Constraints
- func FixedHeight(height int) Constraints
- func FixedWidth(width int) Constraints
- func NewConstraints(minWidth, maxWidth, minHeight, maxHeight int) Constraints
- func (c Constraints) Constrain(other Constraints) Constraints
- func (c Constraints) ConstrainHeight(height int) int
- func (c Constraints) ConstrainSize(size IntSize) IntSize
- func (c Constraints) ConstrainWidth(width int) int
- func (c Constraints) Copy(minWidth, maxWidth, minHeight, maxHeight int) Constraints
- func (c Constraints) CopyMaxDimensions() Constraints
- func (c Constraints) HasBoundedHeight() bool
- func (c Constraints) HasBoundedWidth() bool
- func (c Constraints) HasFixedHeight() bool
- func (c Constraints) HasFixedWidth() bool
- func (c Constraints) IsSatisfiedBy(size IntSize) bool
- func (c Constraints) IsZero() bool
- func (c Constraints) MaxHeight() int
- func (c Constraints) MaxWidth() int
- func (c Constraints) MinHeight() int
- func (c Constraints) MinWidth() int
- func (c Constraints) Offset(horizontal, vertical int) Constraints
- func (c Constraints) String() string
- type Density
- type Dp
- func (d Dp) Add(other Dp) Dp
- func (d Dp) CoerceAtLeast(minimumValue Dp) Dp
- func (d Dp) CoerceAtMost(maximumValue Dp) Dp
- func (d Dp) CoerceIn(minimumValue, maximumValue Dp) Dp
- func (d Dp) CompareTo(other Dp) int
- func (d Dp) Div(other float32) Dp
- func (d Dp) DivDp(other Dp) float32
- func (d Dp) DivInt(other int) Dp
- func (d Dp) IsFinite() bool
- func (d Dp) IsSpecified() bool
- func (d Dp) IsUnspecified() bool
- func (d Dp) Negate() Dp
- func (d Dp) String() string
- func (d Dp) Subtract(other Dp) Dp
- func (d Dp) TakeOrElse(def Dp) Dp
- func (d Dp) Times(other float32) Dp
- func (d Dp) TimesInt(other int) Dp
- func (d Dp) Value() float32
- type DpOffset
- func (o DpOffset) Add(other DpOffset) DpOffset
- func (o DpOffset) Copy(x, y Dp) DpOffset
- func (o DpOffset) IsSpecified() bool
- func (o DpOffset) IsUnspecified() bool
- func (o DpOffset) String() string
- func (o DpOffset) Subtract(other DpOffset) DpOffset
- func (o DpOffset) TakeOrElse(block DpOffset) DpOffset
- type DpRect
- type DpSize
- func (s DpSize) Add(other DpSize) DpSize
- func (s DpSize) Center() DpOffset
- func (s DpSize) Copy(width, height Dp) DpSize
- func (s DpSize) Div(other float32) DpSize
- func (s DpSize) DivInt(other int) DpSize
- func (s DpSize) IsSpecified() bool
- func (s DpSize) IsUnspecified() bool
- func (s DpSize) String() string
- func (s DpSize) Subtract(other DpSize) DpSize
- func (s DpSize) TakeOrElse(block DpSize) DpSize
- func (s DpSize) Times(other float32) DpSize
- func (s DpSize) TimesInt(other int) DpSize
- type IntSize
- type LayoutDirection
- type TextUnit
- func (tu TextUnit) AsGioSp() gioUnit.Sp
- func (tu TextUnit) Compare(other TextUnit) int
- func (tu TextUnit) Div(other float32) TextUnit
- func (tu TextUnit) Equals(other TextUnit) bool
- func (tu TextUnit) IsEm() bool
- func (tu TextUnit) IsSp() bool
- func (tu TextUnit) IsSpecified() bool
- func (tu TextUnit) IsUnspecified() bool
- func (tu TextUnit) Merge(other TextUnit) TextUnit
- func (tu TextUnit) String() string
- func (tu TextUnit) TakeOrElse(def TextUnit) TextUnit
- func (tu TextUnit) Times(other float32) TextUnit
- func (tu TextUnit) Type() TextUnitType
- func (tu TextUnit) UnaryMinus() TextUnit
- func (tu TextUnit) Value() float32
- type TextUnitType
Constants ¶
const Infinity = math.MaxInt32
Infinity represents unbounded constraints (max value).
Variables ¶
var DpInfinity = Dp(float32(math.Inf(1)))
DpInfinity represents infinite dp dimension.
var DpOffsetUnspecified = DpOffset{X: DpUnspecified, Y: DpUnspecified}
var DpOffsetZero = DpOffset{X: 0, Y: 0}
var DpSizeUnspecified = DpSize{Width: DpUnspecified, Height: DpUnspecified}
var DpSizeZero = DpSize{Width: 0, Height: 0}
var DpUnspecified = Dp(floatutils.Float32Unspecified)
DpUnspecified is the constant for an unspecified Dp.
var TextUnitUnspecified = TextUnit{/* contains filtered or unexported fields */}
1. `TUnspecified` – sentinel (value, not pointer) TextUnitUnspecified is the sentinel value for an unspecified TextUnit. Kotlin uses a packed value with NaN for Unspecified. val Unspecified = pack(UNIT_TYPE_UNSPECIFIED, Float.NaN)
Functions ¶
func DpToGioUnitUnsafe ¶ added in v0.1.102
func TextUnitToGioDp ¶ added in v0.1.120
func TextUnitToGioSpUnsafe ¶ added in v0.1.102
Types ¶
type Constraints ¶
type Constraints uint64
Constraints represents immutable constraints for measuring layouts. It packs minWidth, maxWidth, minHeight, maxHeight, and a 2-bit focus indicator into a uint64. The bit allocation is dynamic: one dimension gets 13-18 bits, the other gets 13-16 bits.
Focus modes (2 bits):
- 0: MaxFocusHeight - height gets 18 bits, width gets 13 bits
- 1: MinFocusHeight - height gets 16 bits, width gets 15 bits
- 2: MinFocusWidth - width gets 16 bits, height gets 15 bits
- 3: MaxFocusWidth - width gets 18 bits, height gets 13 bits
func FitPrioritizingHeight ¶
func FitPrioritizingHeight(minWidth, maxWidth, minHeight, maxHeight int) Constraints
FitPrioritizingHeight creates constraints favoring height bit allocation.
func FitPrioritizingWidth ¶
func FitPrioritizingWidth(minWidth, maxWidth, minHeight, maxHeight int) Constraints
FitPrioritizingWidth creates constraints favoring width bit allocation.
func Fixed ¶
func Fixed(width, height int) Constraints
Fixed creates constraints for a fixed size in both dimensions.
func FixedHeight ¶
func FixedHeight(height int) Constraints
FixedHeight creates constraints with fixed height and unbounded width.
func FixedWidth ¶
func FixedWidth(width int) Constraints
FixedWidth creates constraints with fixed width and unbounded height.
func NewConstraints ¶
func NewConstraints(minWidth, maxWidth, minHeight, maxHeight int) Constraints
NewConstraints creates a new Constraints object with validation.
func (Constraints) Constrain ¶
func (c Constraints) Constrain(other Constraints) Constraints
Constrain clamps another Constraints to these constraints. The result will satisfy these constraints, but may not satisfy the input constraints.
func (Constraints) ConstrainHeight ¶
func (c Constraints) ConstrainHeight(height int) int
ConstrainHeight clamps the height to these constraints.
func (Constraints) ConstrainSize ¶
func (c Constraints) ConstrainSize(size IntSize) IntSize
ConstrainSize clamps an IntSize to these constraints.
func (Constraints) ConstrainWidth ¶
func (c Constraints) ConstrainWidth(width int) int
ConstrainWidth clamps the width to these constraints.
func (Constraints) Copy ¶
func (c Constraints) Copy(minWidth, maxWidth, minHeight, maxHeight int) Constraints
Copy creates new constraints with optional overrides.
func (Constraints) CopyMaxDimensions ¶
func (c Constraints) CopyMaxDimensions() Constraints
CopyMaxDimensions returns constraints with min dimensions zeroed, preserving max and focus.
func (Constraints) HasBoundedHeight ¶
func (c Constraints) HasBoundedHeight() bool
HasBoundedHeight returns false if maxHeight is Infinity.
func (Constraints) HasBoundedWidth ¶
func (c Constraints) HasBoundedWidth() bool
HasBoundedWidth returns false if maxWidth is Infinity.
func (Constraints) HasFixedHeight ¶
func (c Constraints) HasFixedHeight() bool
HasFixedHeight returns true if there's exactly one valid height.
func (Constraints) HasFixedWidth ¶
func (c Constraints) HasFixedWidth() bool
HasFixedWidth returns true if there's exactly one valid width.
func (Constraints) IsSatisfiedBy ¶
func (c Constraints) IsSatisfiedBy(size IntSize) bool
IsSatisfiedBy checks if a size satisfies these constraints.
func (Constraints) IsZero ¶
func (c Constraints) IsZero() bool
IsZero returns true if maxWidth or maxHeight is 0.
func (Constraints) MaxHeight ¶
func (c Constraints) MaxHeight() int
MaxHeight returns the maximum height in pixels, or Infinity.
func (Constraints) MaxWidth ¶
func (c Constraints) MaxWidth() int
MaxWidth returns the maximum width in pixels, or Infinity.
func (Constraints) MinHeight ¶
func (c Constraints) MinHeight() int
MinHeight returns the minimum height in pixels.
func (Constraints) MinWidth ¶
func (c Constraints) MinWidth() int
MinWidth returns the minimum width in pixels.
func (Constraints) Offset ¶
func (c Constraints) Offset(horizontal, vertical int) Constraints
Offset expands constraints by the given deltas.
func (Constraints) String ¶
func (c Constraints) String() string
String returns a readable representation.
type Density ¶
type Density interface {
// Density returns the logical density of the display.
// This is a scaling factor for the [Dp] unit.
Density() float32
// FontScale returns the current user preference for the scaling factor for fonts.
FontScale() float32
// DpToPx converts [Dp] to pixels. Pixels are used to paint to Canvas.
DpToPx(dp Dp) float32
// DpRoundToPx converts [Dp] to [int] by rounding.
DpRoundToPx(dp Dp) int
// TextUnitToPx converts Sp to pixels. Pixels are used to paint to Canvas.
// Panics if TextUnit other than SP unit is specified.
TextUnitToPx(tu TextUnit) float32
// TextUnitRoundToPx converts Sp to [int] by rounding.
TextUnitRoundToPx(tu TextUnit) int
// IntToDp converts an [int] pixel value to [Dp].
IntToDp(px int) Dp
// IntToSp converts an [int] pixel value to Sp.
IntToSp(px int) TextUnit
// FloatToDp converts a [float32] pixel value to a [Dp].
FloatToDp(px float32) Dp
// FloatToSp converts a [float32] pixel value to a Sp.
FloatToSp(px float32) TextUnit
// DpRectToRect converts a [DpRect] to a [Rect].
DpRectToRect(rect DpRect) geometry.Rect
// DpSizeToSize converts a [DpSize] to a [Size].
DpSizeToSize(size DpSize) geometry.Size
// SizeToDpSize converts a [Size] to a [DpSize].
SizeToDpSize(size geometry.Size) DpSize
// DpToTextUnit converts [Dp] to [TextUnit] (Sp).
DpToTextUnit(dp Dp) TextUnit
// TextUnitToDp converts Sp to [Dp] (non-rounding).
TextUnitToDp(tu TextUnit) Dp
}
Density provides information about the density of the display. Used for the conversions between pixels, Dp, [int] and TextUnit.
func DensityFromLayoutContext ¶ added in v0.1.120
DensityFromLayoutContext creates a Density from a Gio Layout Context. gtx: The Gio Layout Context.
func NewDensity ¶
A density of the screen. Used for convert [Dp] to pixels.
density The logical density of the display. This is a scaling factor for the Dp unit. fontScale Current user preference for the scaling factor for fonts.
type Dp ¶
type Dp float32
Dp is a value class that represents a density-independent pixel.
The value is stored as a float32.
const DpHairline Dp = 0
DpHairline is the constant for a hairline Dp.
func (Dp) CoerceAtLeast ¶
CoerceAtLeast ensures value is at least minimumValue.
func (Dp) CoerceAtMost ¶
CoerceAtMost ensures value is at most maximumValue.
func (Dp) IsSpecified ¶
IsSpecified checks if the Dp is specified (not NaN).
func (Dp) IsUnspecified ¶
IsUnspecified checks if the Dp is unspecified (NaN).
func (Dp) TakeOrElse ¶
TakeOrElse returns this Dp if Specified, otherwise executes the block.
type DpOffset ¶
DpOffset represents a 2D offset using Dp.
func LerpDpOffset ¶
func (DpOffset) IsSpecified ¶
func (DpOffset) IsUnspecified ¶
func (DpOffset) TakeOrElse ¶
type DpRect ¶
DpRect represents a rectangle with Dp coordinates.
func NewDpRectFromOriginSize ¶
NewDpRectFromOriginSize creates a DpRect from origin and size.
type DpSize ¶
DpSize represents a size with Dp dimensions.
func LerpDpSize ¶
func (DpSize) IsSpecified ¶
func (DpSize) IsUnspecified ¶
func (DpSize) TakeOrElse ¶
type LayoutDirection ¶
type LayoutDirection int
LayoutDirection represents the horizontal layout direction of content.
const ( // LayoutDirectionLtr represents left-to-right layout direction. LayoutDirectionLtr LayoutDirection = iota // LayoutDirectionRtl represents right-to-left layout direction. LayoutDirectionRtl )
func (LayoutDirection) String ¶
func (d LayoutDirection) String() string
String returns the string representation of the LayoutDirection.
type TextUnit ¶
type TextUnit struct {
// contains filtered or unexported fields
}
TextUnit packs unit type (Sp/Em) and float value into 64 bits. Struct wrapper prevents `TextUnit(24)` - must use `Sp(24)` or `Em(1.5)`.
func LerpTextUnit ¶
LerpTextUnit linearly interpolates between two TextUnits.
func LerpTextUnitInheritable ¶
func NewTextUnit ¶
func NewTextUnit(value float32, unitType TextUnitType) TextUnit
NewTextUnit creates a new TextUnit. Note: In Kotlin this is constructor `TextUnit(value: Float, type: TextUnitType)`.
func (TextUnit) IsSpecified ¶
2. `IsSpecified` – predicate (method on value receiver) IsSpecified returns true if this is a specified unit type.
func (TextUnit) IsUnspecified ¶
IsUnspecified returns true if this is an unspecified unit type.
func (TextUnit) Merge ¶
4. `Merge` – whole-value replacement for atomic packed types (method on value receiver) Merge returns other if specified, otherwise returns tu.
func (TextUnit) String ¶
5. `String` – stringification (method on value receiver) String returns the string representation of the TextUnit.
func (TextUnit) TakeOrElse ¶
3. `TakeOrElse` – 2-param fallback (method on value receiver) TakeOrElse returns this TextUnit if specified, otherwise returns the default.
func (TextUnit) Type ¶
func (tu TextUnit) Type() TextUnitType
Type returns the TextUnitType of this TextUnit.
func (TextUnit) UnaryMinus ¶
UnaryMinus returns the negation of this TextUnit.
type TextUnitType ¶
type TextUnitType int64
const ( TextUnitTypeUnspecified TextUnitType = 0x00 << 32 TextUnitTypeSp TextUnitType = 0x01 << 32 TextUnitTypeEm TextUnitType = 0x02 << 32 )
func (TextUnitType) String ¶
func (t TextUnitType) String() string