layout

package
v0.1.119 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis added in v0.1.111

type Axis uint8

Axis is the Horizontal or Vertical direction.

const (
	AxisUnspecified Axis = iota
	AxisHorizontal
	AxisVertical
)

func (Axis) IsSpecified added in v0.1.111

func (a Axis) IsSpecified() bool

func (Axis) TakeOrElse added in v0.1.111

func (a Axis) TakeOrElse(def Axis) Axis

TakeOrElse returns this Dp if Specified, otherwise executes the block.

type ContentScale

type ContentScale interface {
	// Scale returns the scale factor to apply to the source to fit the destination.
	Scale(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor
}

ContentScale defines how to scale the source content to fit the destination space.

var (
	// ContentScaleNone maintains the source size.
	ContentScaleNone ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return ScaleFactor{ScaleX: 1.0, ScaleY: 1.0}
	})

	// ContentScaleFillBounds scales the source to fill the destination bounds, potentially changing the aspect ratio.
	ContentScaleFillBounds ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return computeFillScale(srcSize, dstSize)
	})

	// ContentScaleFillWidth scales the source to fill the destination width, maintaining the aspect ratio.
	ContentScaleFillWidth ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return computeFillWidth(srcSize, dstSize)
	})

	// ContentScaleFillHeight scales the source to fill the destination height, maintaining the aspect ratio.
	ContentScaleFillHeight ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return computeFillHeight(srcSize, dstSize)
	})

	// ContentScaleFit scales the source to fit within the destination bounds, maintaining the aspect ratio.
	// The source will be completely visible.
	ContentScaleFit ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return computeFitScale(srcSize, dstSize)
	})

	// ContentScaleCrop scales the source to fill the destination bounds, maintaining the aspect ratio.
	// The source may be cropped.
	ContentScaleCrop ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		return computeCropScale(srcSize, dstSize)
	})

	// ContentScaleInside scales the source to fit within the destination bounds only if the source is larger than the destination.
	// Otherwise, it maintains the source size.
	ContentScaleInside ContentScale = contentScaleFunc(func(srcSize, dstSize layoutnode.LayoutDimensions) ScaleFactor {
		if srcSize.Size.X <= dstSize.Size.X && srcSize.Size.Y <= dstSize.Size.Y {
			return ScaleFactor{ScaleX: 1.0, ScaleY: 1.0}
		}
		return computeFitScale(srcSize, dstSize)
	})
)

type LayoutCoordinates

type LayoutCoordinates interface {
	// IsAttached returns true if the layout is currently attached to the composition.
	IsAttached() bool

	// Size returns the size of this layout in pixels.
	Size() unit.IntSize

	// PositionInRoot returns the position of this layout relative to the root.
	PositionInRoot() geometry.Offset

	// PositionInWindow returns the position of this layout in window coordinates.
	PositionInWindow() geometry.Offset

	// LocalPositionOf converts a position from another LayoutCoordinates to this one.
	LocalPositionOf(sourceCoordinates LayoutCoordinates, relativeToSource geometry.Offset) geometry.Offset

	// VisibleBounds returns the visible bounds of this layout in local coordinates.
	VisibleBounds() geometry.Rect

	// BoundsInWindow returns the bounds of this layout in window coordinates.
	BoundsInWindow() geometry.Rect
}

LayoutCoordinates provides access to the position and size of a layout.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/LayoutCoordinates.kt

type ScaleFactor

type ScaleFactor struct {
	ScaleX float32
	ScaleY float32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL