We can use pane.vertical_scroll to manipulate the scrolling so it always shows the last line, useful for having a pane that shows some log or command output. However, this value needs to be equal to the lines written minus the height of the pane, which is easy to get if it's set on initialisation, but it is not if the pane is dynamic and supposed to fill the available height.
The height is calculated by preferred_height, but that receives input from its caller that we can't easily ascertain. The result of this calculation is kept private.
To correctly use vertical_scroll, we need to implement the following:
if pane.height and state.line_counter > pane.height:
pane.vertical_scroll = state.line_counter - pane.height
Which works for the fixed height case and can be simplified to: max(0, state.line_counter - pane.height) if we had some attribute available that has the current height of the pane, regardless of whether it's fixed or dynamically sized.
We can use
pane.vertical_scroll
to manipulate the scrolling so it always shows the last line, useful for having a pane that shows some log or command output. However, this value needs to be equal to the lines written minus the height of the pane, which is easy to get if it's set on initialisation, but it is not if the pane is dynamic and supposed to fill the available height.The height is calculated by
preferred_height
, but that receives input from its caller that we can't easily ascertain. The result of this calculation is kept private.To correctly use vertical_scroll, we need to implement the following:
Which works for the fixed height case and can be simplified to:
max(0, state.line_counter - pane.height)
if we had some attribute available that has the current height of the pane, regardless of whether it's fixed or dynamically sized.But see also the related bug.