Skip to main content

fit

Function fit 

Source
fn fit(
    current: f64,
    view_width: f64,
    column_x: f64,
    column_width: f64,
    gap: f64,
) -> f64
Expand description

Where the view should sit so a column is visible, moving as little as possible.

Three rules, in order, and the order is the point:

  • A column wider than the view is left-aligned — there is no arrangement that shows all of it, so showing the start beats showing the middle.
  • A column already fully visible does not move the view at all. A scroller that recentres on every focus change makes the whole screen lurch when nothing needed to move.
  • Otherwise the alignment that travels less wins.