View

open class View
extension View: LayoutAnchorsContainer
extension View: Equatable
extension View: Hashable
extension View: SpatialReferenceType

Base class for views in ImagineUI.

Can be instantiated and used as container as-is or subclassed to provide custom behaviour, if required.

  • Whether the layout of this view is suspended. When layout is suspended, the view does not propagates setNeedsLayout invocations to parent views.

    Declaration

    Swift

    public var isLayoutSuspended: Bool { get }
  • Undocumented

    Declaration

    Swift

    public internal(set) var needsLayout: Bool { get }
  • A rotation around the relative transform center of this view, in radians.

    This affects the display and hit test of this view’s entire hierarchy, but might affect constraint resolution in unintuitive ways.

    Defaults U0.

    Declaration

    Swift

    open var rotation: Double { get set }
  • A visual scale for the view relative to the transform center of this view.

    Affects all of this view’s rendering and hit test hierarchy, but might affect constraint resolution in unintuitive ways.

    Defaults UIVector(x: 1, y: 1).

    Declaration

    Swift

    open var scale: UIVector { get set }
  • Whether this view naturally clips its rendering area to be within the bounds of boundsForRedraw() automatically.

    This also affects invalidation requests and queries to isFullyVisibleOnScreen().

    Declaration

    Swift

    open var clipToBounds: Bool { get set }
  • The center of the transform for this view. When a view is scaled and/or rotated, this value specifies the relative center of the transformation.

    A value of .zero rotates/scales around the view’s top-left corner, a value of 0.5 transforms around the center of the view’s bounds, and a value of 1.0 transforms around the bottom-right corner of the view. Values in between transform around the relative intermediaries.

    Defaults to UIVector.zero.

    Declaration

    Swift

    open var relativeTransformCenter: UIVector
  • Gets the full transform matrix for this view’s translation, rotation, and scale.

    This

    Declaration

    Swift

    open var transform: UIMatrix { get }
  • Gets or sets the location of this view with respect to its superview.

    Declaration

    Swift

    public var location: UIVector { get set }
  • Gets or sets the relative bounds of this view as a UIRectangle. Since the bounds are always relative to this view’s coordinate system, its top-left location is always at UIPoint.zero and changes to that coordinate are ignored.

    Declaration

    Swift

    open var bounds: UIRectangle { get set }
  • Gets or sets the size of this view’s bounds.

    Declaration

    Swift

    open var size: UISize { get set }
  • Gets or sets this view’s area, affecting both self.location and self.size.

    Unlike self.bounds, this property supports changes to self.location by specifying different top-left coordinates for the input rectangle.

    Declaration

    Swift

    open var area: UIRectangle { get set }
  • Controls whether this view and its subviews are rendered and interactive on screen.

    Hidden views do not participate in rendering and are not considered for mouse input hit tests.

    Declaration

    Swift

    open var isVisible: Bool { get set }
  • Changes the alpha value of this view, which affects the base transparency of its entire view hierarchy.

    A value of 1.0 indicates a fully opaque view, while 0.0 indicates a fully transparent view.

    Views with transparency still render on screen, but the renderer context is automatically set to a lower global alpha, according to the alpha of the view’s hierarchy.

    Value is capped to be within (0.0, 1.0) range, inclusive.

    Declaration

    Swift

    open var alpha: Double { get set }
  • A list of constraints that are affecting this view.

    Declaration

    Swift

    internal(set) public var constraints: [LayoutConstraint] { get }
  • This view’s intrinsic size.

    If non-nil, it indicates to layout systems that this view has a natural size that it reports is preferred, and content compression/hugging constraints are applied relative to it.

    If nil, content compression/hugging is ignored during constraint layout.

    Declaration

    Swift

    open var intrinsicSize: UISize? { get }
  • Gets the logical superview for this view.

    Declaration

    Swift

    private(set) public weak var superview: View? { get }
  • Gets the list of logical subviews for this view.

    Declaration

    Swift

    private(set) public var subviews: [View] { get }
  • Gets the list of layout guides on this view.

    Layout guides can interact with other layout guides and views in the same hierarchy.

    Declaration

    Swift

    internal(set) public var layoutGuides: [LayoutGuide] { get }
  • A set of area components for this view’s self.area that should be turned into constraints, in layout constraint systems.

    If a value is specified, the constraint system adds a constraint that ties that dimension to the view’s current value as if it was an explicit constraint.

    If not empty, might interact unexpectedly with the constraint system, if other constraints affect a dimension of this view that is constrained by this property.

    Declaration

    Swift

    public var areaIntoConstraintsMask: Set<BoundsConstraintMask> { get set }
  • If true, users can interact with this view or any subview with the mouse, in case a ControlView lies under the mouse within this view’s hierarchy.

    Declaration

    Swift

    public var isInteractiveEnabled: Bool
  • Gets the active control system for the view hierarchy. Used to handle first responder configurations.

    Declaration

    Swift

    public var controlSystem: ControlSystemType? { get }
  • If true, reports that this view, as well as all superviews, have isInteractiveEnabled true.

    Control views that return false for this property are ignored in input management as if they where regular views.

    Declaration

    Swift

    public var isRecursivelyInteractiveEnabled: Bool { get }
  • Undocumented

    Declaration

    Swift

    public init()
  • Recursively renders this view’s hierarchy using a specified renderer and screen-space clip region that can be queried to check the screen-space areas that are being redrawn.

    If this view’s clipToBounds is true, the renderer’s clip region is clipped further with self.boundsForRedraw(), but screenRegion is unaffected.

    Declaration

    Swift

    public final func renderRecursive(in renderer: Renderer, screenRegion: ClipRegionType)
  • Renders this view’s contents on a given renderer.

    This pertains to rendering of this view’s contents, and not any of its subviews.

    Declaration

    Swift

    open func render(in context: Renderer, screenRegion: ClipRegionType)

Layout

  • Method automatically called by View.init() that can be used to create view hierarchies before they are constrained by View.setupConstraints().

    Used as a convenience for generating new view subclasses; view hierarchies can be changed at any point in a view’s lifecycle.

    Declaration

    Swift

    open func setupHierarchy()
  • Method automatically called by View.init() that can be used to create constraints between subviews in this view’s hierarchy after they are created by View.setupHierarchy().

    Used as a convenience for generating new view subclasses; view constraints can be changed at any point in a view’s lifecycle.

    Declaration

    Swift

    open func setupConstraints()
  • Removes all constraints that currently affects this view.

    Declaration

    Swift

    open func removeAffectingConstraints()
  • Recursively invokes performLayout() and performInternalLayout() on all subviews.

    Declaration

    Swift

    open func performLayout()
  • Requests that this view perform its internal layout, while ignoring layout of subviews.

    Declaration

    Swift

    open func performInternalLayout()
  • If true, indicates that this view has an internal layout that is self-contained and can be solved deterministically regardless of the layout state of superviews.

    This makes the Cassowary layout constraint system ignore this view and any subview in its hierarchy during constraint resolution of superviews.

    If a view returns true but contains constraints that relate it to a view outside its hierarchy, an undefined layout behavior can occur.

    Declaration

    Swift

    open func hasIndependentInternalLayout() -> Bool
  • Suspends setNeedsLayout() from affecting this view and its parent hierarchy.

    Sequential calls to suspendLayout() must be balanced with a matching number of resumeLayout(setNeedsLayout:) calls later in order for layout to resume successfully.

    Declaration

    Swift

    open func suspendLayout()
  • Resumes layout, optionally dispatching a setNeedsLayout() call to the view at the end.

    Sequential calls to resumeLayout(setNeedsLayout:) must be balanced with a matching number of earlier suspendLayout() calls in order for layout to resume successfully.

    Declaration

    Swift

    open func resumeLayout(setNeedsLayout: Bool)
  • Performs a given closure while suspending the layout of this view, optionally dispatching a setNeedsLayout() call to the view at the end.

    Layout is resumed whether or not the closure throws before the end of the block.

    Declaration

    Swift

    open func withSuspendedLayout<T>(setNeedsLayout: Bool, _ block: () throws -> T) rethrows -> T
  • Marks this view as requiring a layout pass on the next system’s layout pass loop.

    Also invokes setNeedsLayout() on superviews recursively.

    Declaration

    Swift

    open func setNeedsLayout()
  • Calculates the optimal size for this view, taking in consideration its active constraints, while approaching the target size as much as possible.

    The view’s bounds then changes to match the calculated size, with its location left unchanged.

    This method also calls ‘performLayout()’ afterwards to update its contents.

    Declaration

    Swift

    open func layoutToFit(size: UISize)
  • Calculates the optimal size for this view, taking in consideration its active constraints, while approaching the target size as much as possible. The layout of the view is kept as-is, and no changes to its size are made.

    Declaration

    Swift

    open func layoutSizeFitting(size: UISize) -> UISize

Subviews

  • Adds a given subview as a direct child of this view’s hierarchy.

    Views in nested hierarchies inherit coordinate systems of parent views.

    Precondition

    view is not this view, or any superview from this view.

    Declaration

    Swift

    open func addSubview(_ view: View)
  • Function called after a view has been added as a subview of this view.

    Declaration

    Swift

    open func didAddSubview(_ view: View)
  • Function called before a view is removed as a subview of this view instance.

    Note

    Do not add view to any other view hierarchy within this method.

    Declaration

    Swift

    open func willRemoveSubview(_ view: View)
  • Removes this view from its superview’s hierarchy.

    Constraints that where created that cross the superview’s boundaries are removed, but not constraints that reference this view and/or one of its children exclusively.

    Declaration

    Swift

    open func removeFromSuperview()
  • Called when the superview of this view has changed.

    Declaration

    Swift

    open func superviewDidChange(_ newSuperview: View?)
  • Brings this view to the end of this view’s superview’s subviews list.

    Has implications for display and user interactions, as views that are last on the subviews list get rendered on top, and receive priority for mouse events as a consequence.

    If this view has no superview, nothing is done.

    Declaration

    Swift

    open func bringToFrontOfSuperview()
  • Brings this view to be one subview higher than another sibling view in their common superview’s subviews list.

    Has implications for display and user interactions, as views that are last on the subviews list get rendered on top, and receive priority for mouse events as a consequence.

    If this view has no superview, or it does not share a common superview with siblingView, nothing is done.

    Declaration

    Swift

    open func bringInFrontOfSiblingView(_ siblingView: View)
  • A method that should return the subview from this view hierarchy to which firstBaseline constraints should be attached to.

    If nil, the baseline is derived from this view’s baseline.

    Declaration

    Swift

    open func viewForFirstBaseline() -> View?

Layout Guides

  • Adds a given layout guide to this view’s hierarchy.

    Layout guides can be used as supporting layout areas for constraining views without requiring expensive View instances as guides themselves.

    Declaration

    Swift

    open func addLayoutGuide(_ guide: LayoutGuide)
  • Called when a layout guide is being removed from this view’s hierarchy.

    Note

    Do not add guide to any other view hierarchy within this method.

    Declaration

    Swift

    open func willRemoveLayoutGuide(_ guide: LayoutGuide)

Redraw Invalidation

  • Invalidates the entire redraw boundaries of this view.

    Equivalent to self.invalidate(bounds: self.boundsForRedraw()).

    Declaration

    Swift

    open func invalidate()
  • Invalidates a specified region of this view’s boundaries.

    Declaration

    Swift

    open func invalidate(bounds: UIRectangle)
  • Returns a rectangle that represents the invalidation and redraw area of this view in its local coordinates.

    Defaults to self.bounds on View class.

    Declaration

    Swift

    open func boundsForRedraw() -> UIRectangle
  • Gets the absolute transformation matrix that encodes the exact transform of this view according to all its parent view’s transforms combined.

    This matrix can then be used to transform from/to this view’s local coordinate space.

    Declaration

    Swift

    open func absoluteTransform() -> UIMatrix
  • Transforms a given point from this view’s local coordinate space into another spatial reference’s coordinate space.

    If other is nil, the final point can be interpreted as screen-space, if the root view’s (0, 0) coordinate is on the top-left of a window.

    Declaration

    Swift

    open func convert(point: UIVector, to other: SpatialReferenceType?) -> UIVector
  • Transforms a given point from another spatial reference’s coordinate space to this view’s local coordinate space.

    If other is nil, the initial point can be interpreted as screen-space, if the root view’s (0, 0) coordinate is on the top-left of a window.

    Declaration

    Swift

    open func convert(point: UIVector, from other: SpatialReferenceType?) -> UIVector
  • Transforms a given rectangle from this view’s local coordinate space into another spatial reference’s coordinate space.

    If rotations where applied to the rectangle, the final rectangle is still axis-aligned, but stretched to fit the corners of the rotated rectangle.

    If other is nil, the final rectangle can be interpreted as screen-space, if the root view’s (0, 0) coordinate is on the top-left of a window.

    Declaration

    Swift

    open func convert(bounds: UIRectangle, to other: SpatialReferenceType?) -> UIRectangle
  • Transforms a given rectangle from another spatial reference’s coordinate space to this view’s local coordinate space.

    If rotations where applied to the rectangle, the final rectangle is still axis-aligned, but stretched to fit the corners of the rotated rectangle.

    If other is nil, the initial rectangle can be interpreted as screen-space, if the root view’s (0, 0) coordinate is on the top-left of a window.

    Declaration

    Swift

    open func convert(bounds: UIRectangle, from other: SpatialReferenceType?) -> UIRectangle
  • Convenience for convert(point: point, from: nil).

    Declaration

    Swift

    open func convertFromScreen(_ point: UIVector) -> UIVector

Bounds / Hit testing

  • Performs a hit test operation on the area of this, and all child base views, for the given point that is relative to this view’s coordinate system.

    Returns the first base view that crosses the point.

    The inflatingArea argument can be used to inflate the area of the views to perform less precise hit tests.

    Declaration

    Swift

    open func viewUnder(point: UIVector, inflatingArea: UIVector = .zero) -> View?
  • Performs a hit test operation on the area of this, and all child base views, for the given point that is relative to this view’s coordinate system.

    Returns the first base view that crosses the point and returns true for predicate.

    The inflatingArea argument can be used to inflate the area of the views to perform less precise hit tests.

    Declaration

    Swift

    open func viewUnder(
        point: UIVector,
        inflatingArea: UIVector = .zero,
        predicate: (View) -> Bool
    ) -> View?
  • Returns an enumerable of all views that cross the given point.

    The inflatingArea argument can be used to inflate the area of the views to perform less precise hit tests.

    Declaration

    Swift

    open func viewsUnder(point: UIVector, inflatingArea: UIVector = .zero) -> [View]

    Parameters

    point

    Point to test, relative to this view’s coordinate system.

    inflatingArea

    Used to inflate the area of the views to perform less precise hit tests.

    Return Value

    An array where each view returned crosses the given point.

  • Returns an enumerable of all views that cross the given UIRectangle bounds.

    The inflatingArea argument can be used to inflate the area of the views to perform less precise hit tests.

    The UIRectangle is converted into local bounds for each subview, so distortion may occur and result in inaccurate results for views that are rotated. There are no alternatives for this, currently.

    Declaration

    Swift

    open func viewsUnder(area: UIRectangle, inflatingArea: UIVector = .zero) -> [View]

    Parameters

    point

    rectangle to test, relative to this view’s coordinate system.

    inflatingArea

    Used to inflate the area of the views to perform less precise hit tests.

    Return Value

    An enumerable where each view returned intersects the given UIRectangle

  • Returns true if the given vector point intersects this view’s area when inflated by a specified amount.

    Children views’ bounds do not affect the hit test- it happens only on this view’s bounds area.

    Declaration

    Swift

    open func contains(point: UIVector, inflatingArea: UIVector = .zero) -> Bool

    Parameters

    point

    Point to test

    inflatingArea

    Used to inflate the area of the view to perform less precise hit tests.

  • Returns true if the given UIRectangle intersects this view’s area when inflated by a specified amount.

    Children views’ bounds do not affect the hit test- it happens only on this view’s bounds area.

    Declaration

    Swift

    open func intersects(area: UIRectangle, inflatingArea: UIVector = .zero) -> Bool

    Parameters

    area

    area to test

    inflatingArea

    Used to inflate the area of the view to perform less precise hit tests.

  • Returns true if a given rectangle within this view’s local coordinate system is fully visible on the top-most view of this view’s hierarchy.

    Results are invalid if a view is not contained in a hierarchy that is associated with a visible window area.

    Declaration

    Swift

    open func isFullyVisibleOnScreen(area: UIRectangle) -> Bool
  • Returns true if a given rectangle on another spatial reference is fully visible on the top-most view of this view’s hierarchy.

    If self.clipToBounds == true, the rectangle is checked first against the bounds of this view.

    If the area is contained within this view’s visible area, superview is then queried recursively until a hierarchy’s root view is reached. If all recursive checks of containment are true, the result is true.

    Results are invalid if a view is not contained in a hierarchy that is associated with a visible window area.

    Declaration

    Swift

    open func isFullyVisibleOnScreen(area: UIRectangle, spatialReference: SpatialReferenceType) -> Bool

Content Compression/Hugging configuration

Descendent Checking / Hierarchy

  • Returns true iff self is a non-strict descendant of view (i.e. is the view itself, a subview, or a subview-of-a-subview etc. of view).

    In case self === view, true is returned.

    Declaration

    Swift

    open func isDescendant(of view: View) -> Bool
  • Undocumented

    Declaration

    Swift

    public var layout: LayoutAnchors { get }
  • Returns true if the two given view references are pointing to the same view instance.

    Declaration

    Swift

    public static func == (lhs: View, rhs: View) -> Bool
  • Hashes this view as an identity hash, i.e. based on its pointer value.

    Declaration

    Swift

    public func hash(into hasher: inout Hasher)