Nearby positioning helpers.
For creating dropdowns, tooltips, confirmation dialogs, modals, badges, and other attached UI that should stay anchored to an element.
Use:
above/1,below/1,on_left/1, andon_right/1for nearby content that escapes the normal layout while staying anchored to a host elementin_front/1for overlays painted over the host slotbehind_content/1for placeholders, highlights, and decorative layers behind the host content
Escaping The Layout
Nearby.above/1, Nearby.below/1, Nearby.on_left/1, Nearby.on_right/1,
and Nearby.in_front/1 all let content escape the normal layout while staying
anchored to a host element.
Rows and columns still place the host normally. Nearby content does not take up layout space in that row or column. That makes nearby useful for things like dropdown menus and tooltips that should stay attached to a control without pushing later siblings around.
Complex background elements
Nearby.behind_content/1 is a little different: it lives between background
and the element content. Use it to create placeholders, highlights, or any UI
tree as decorative layers behind the host content.
Alignment
Nearby alignment comes from the nearby root element itself.
above/1andbelow/1use horizontal alignment from the nearby root, for examplealign_left(),center_x(), oralign_right()on_left/1andon_right/1use vertical alignment from the nearby root, for examplealign_top(),center_y(), oralign_bottom()in_front/1andbehind_content/1use both axes
Clipping
Nearby escape content is not clipped by ancestor hosts by default. Add
Emerge.UI.clip_nearby/0 on a host or scroll container when you want that
host to clip nearby escapes too.
Paint Order
Same-host nearby content follows definition order, so later nearby attrs on the same host paint above earlier nearby attrs when they overlap.
Between different hosts, nearby follows the same paint order used by normal content. Nearby on later sibling branches paints above nearby on earlier sibling branches, and nearby attached to an ancestor host paints above nearby attached deeper in that host subtree.
Example
See the dropdown example in
guides/tutorials/describe_ui.md
for a fuller nearby composition walkthrough.
Summary
Functions
Place an element above the current one without affecting layout flow.
Render an element behind the current one.
Place an element below the current one without affecting layout flow.
Render an element in front of the current one.
Place an element on the left of the current one without affecting layout flow.
Place an element on the right of the current one without affecting layout flow.
Types
@type overlay_attr() :: {:above, Emerge.UI.element()} | {:below, Emerge.UI.element()} | {:on_left, Emerge.UI.element()} | {:on_right, Emerge.UI.element()} | {:in_front, Emerge.UI.element()} | {:behind, Emerge.UI.element()}
@type t() :: overlay_attr()
Functions
@spec above(Emerge.UI.element()) :: {:above, Emerge.UI.element()}
Place an element above the current one without affecting layout flow.
Horizontal alignment comes from the nearby root, so align_left(),
center_x(), and align_right() control how the nearby element lines up with
the host.
@spec behind_content(Emerge.UI.element()) :: {:behind, Emerge.UI.element()}
Render an element behind the current one.
behind_content/1 paints between the host background and the host content. It
is useful for placeholders, highlights, and decorative backing layers.
@spec below(Emerge.UI.element()) :: {:below, Emerge.UI.element()}
Place an element below the current one without affecting layout flow.
Horizontal alignment comes from the nearby root, so align_left(),
center_x(), and align_right() control how the nearby element lines up with
the host.
@spec in_front(Emerge.UI.element()) :: {:in_front, Emerge.UI.element()}
Render an element in front of the current one.
in_front/1 paints over the host slot. width(fill()) and height(fill())
fill the host slot, while explicit sizes can overflow it.
@spec on_left(Emerge.UI.element()) :: {:on_left, Emerge.UI.element()}
Place an element on the left of the current one without affecting layout flow.
Vertical alignment comes from the nearby root, so align_top(), center_y(),
and align_bottom() control how the nearby element lines up with the host.
@spec on_right(Emerge.UI.element()) :: {:on_right, Emerge.UI.element()}
Place an element on the right of the current one without affecting layout flow.
Vertical alignment comes from the nearby root, so align_top(), center_y(),
and align_bottom() control how the nearby element lines up with the host.