summaryrefslogtreecommitdiff
path: root/devdocs/elisp/accessing-scroll.html
blob: 03550d55d740aba76d28ca318828d58a8dc0d3f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 <h4 class="subsection">Accessing Scroll Bar Events</h4>  <p>These functions are useful for decoding scroll bar events. </p> <dl> <dt id="scroll-bar-event-ratio">Function: <strong>scroll-bar-event-ratio</strong> <em>event</em>
</dt> <dd><p>This function returns the fractional vertical position of a scroll bar event within the scroll bar. The value is a cons cell <code>(<var>portion</var> . <var>whole</var>)</code> containing two integers whose ratio is the fractional position. </p></dd>
</dl> <dl> <dt id="scroll-bar-scale">Function: <strong>scroll-bar-scale</strong> <em>ratio total</em>
</dt> <dd>
<p>This function multiplies (in effect) <var>ratio</var> by <var>total</var>, rounding the result to an integer. The argument <var>ratio</var> is not a number, but rather a pair <code>(<var>num</var> . <var>denom</var>)</code>—typically a value returned by <code>scroll-bar-event-ratio</code>. </p> <p>This function is handy for scaling a position on a scroll bar into a buffer position. Here’s how to do that: </p> <div class="example"> <pre class="example">(+ (point-min)
   (scroll-bar-scale
      (posn-x-y (event-start event))
      (- (point-max) (point-min))))
</pre>
</div> <p>Recall that scroll bar events have two integers forming a ratio, in place of a pair of x and y coordinates. </p>
</dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Accessing-Scroll.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Accessing-Scroll.html</a>
  </p>
</div>