Showing tag results for Code

Aug 13, 2003
Post comments count0
Post likes count0

Scrollbars part 8 – Integral interactive resizing

Raymond Chen

Enforcing integrality solves the fractional-line problem, but notice that when you grab the top or bottom edge and resize the window, the resize feedback doesn't match the actual window you get back if you drag the window to a non-integral size. (You may need to turn off full window drag to see this effect more...

Code
Aug 11, 2003
Post comments count0
Post likes count0

Scrollbars part 7 – Integrality

Raymond Chen

If you play around with resizing the window, you can get a fractional line to appear at the bottom of the screen. This is not normally a problem until you scroll to the very end of the list, say, by pressing the key, at which point an ugly blank space appears at the bottom. This ugly blank space is particularl...

Code
Aug 11, 2003
Post comments count0
Post likes count0

Answers to exercises

Raymond Chen

What is the significance of the cast in the computation of ? It isn't. I got the question wrong. The real question should have been "What is the significance of the cast in the computation of ?" The answer is to ensure that the computation is performed with signed integers throughout. ...

Code
Aug 7, 2003
Post comments count0
Post likes count0

A subtlety in the keyboard code

Raymond Chen

I neglected to call it out explicitly in the text for Part 5:  Notice that I use cRepeat to determine how many lines/pages to scroll.  This allows us to scroll the correct amount even if we are falling behind on input processing and are missing some autorepeats.

Code
Aug 7, 2003
Post comments count0
Post likes count0

Scrollbars bart 6 – The wheel

Raymond Chen

The mouse wheel is tricky because the mouse wheel UI guidelines indicate that you should scroll by a user-specified amount for each "click" of the mouse, where one click is mouse units (called a "detent"). There are two subtle points about the above requirement: First, that the amount of scrolling is a user ...

Code
Aug 5, 2003
Post comments count0
Post likes count0

Keyboard accessibility for scrollbars

Raymond Chen

Note that so far, the scrollbar is accessible only with the mouse. Our next step is to add keyboard access to the scrollbar. Fortunately, this is not all that difficult. We merely map some keystrokes to equivalent scrollbar actions. Note that this doesn't make our sample program fully accessible; this just m...

Code
Aug 5, 2003
Post comments count0
Post likes count0

Answer to previous exercise on proportional scrollbars

Raymond Chen

If you look at the WM_VSCROLL message, you'll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won't be able to use the scroll thumb to get to the ones at the end. Try it: Change the value of g_cItems to 100000 and watch what happens. The fix is to ignore the passed to the message and instead ge...

Code
Jul 31, 2003
Post comments count0
Post likes count0

Scrollbars, part 4: Adding a proportional scrollbar

Raymond Chen

To obtain a proportional scrollbar, you need to tell Windows the minimum and maximum values covered by the scrollbar, the current scrollbar position, and the size of the scrollbar thumb (called the "page size"). One annoyance of the way scrollbars are set up is that the maximum value is attainable. This differs...

Code
Jul 30, 2003
Post comments count0
Post likes count0

Answer to yesterday's exercise

Raymond Chen

iMin is the lowest-index element which intersects the paint rectangle, so a simple truncating division produces the desired index. The formula for iMax can be interpreted two ways. One is that it is the roundup of the first invisible line. Recall the rectangles are exclusive of the endpoint, s...

Code
Jul 29, 2003
Post comments count0
Post likes count0

Scrollbars, part 3: Optimizing the paint cycle

Raymond Chen

Observe that we paint all 100 lines in our paint handler, even though most of them aren't visible. This is a problem if there are a large number of items, or if painting an item is time-consuming. So instead, we optimize our paint cycle so as to paint only the elements which intersect the pain...

Code