Skip to content

ui::BringIntoViewOptions

Header: winui/ui/Element.hpp.

Where in the viewport a scrolling ancestor puts the element Element::start_bring_into_view() reveals. With no ratio on an axis the ancestor scrolls as little as it can (the element's near edge, or its far edge when it sticks out past the far side). A ratio places the same point of the element and of the viewport together: 0 the near edges, 0.5 the centers, 1 the far edges. The offsets are added to where that lands.

Example:

// Center the row vertically in its Scroll, animated.
auto row = std::make_unique<ui::TextControl>("Row 42");
row->start_bring_into_view({.vertical_alignment_ratio = 0.5f, .animation_desired = true});

Field Type Default
horizontal_alignment_ratio OptionalFloat Where across the viewport's width the element lands, 0..1; unset scrolls as little as it can.
vertical_alignment_ratio OptionalFloat Where down the viewport's height the element lands, 0..1; unset scrolls as little as it can.
horizontal_offset float 0.0f DIPs added to the horizontal position the ratio (or the smallest scroll) gives.
vertical_offset float 0.0f DIPs added to the vertical position the ratio (or the smallest scroll) gives.
animation_desired bool false Whether the scroll animates (a Scroll's scroll_to()) or jumps.
target_rect std::optional<Rect> The part of the element to reveal, relative to its own top-left; the whole element when unset.