Monday, April 17, 2006

After some time implementing and debugging scrolled window support under Cocoa, I now have a solution. In the end, what I needed was two widgets. One which represented the actual scrolled window, and its scrollbars. This widget is "scrolledwindow". It has a width, a height, and two boolean attributes used to control the visibility of the scrollbars (one of these controls the horizontal scrollbar, the other the vertical).

The other widget (scrolledview) represents the area being scrolled. It also has a width and height, which will typically be larger than the scrolled window (why else would you need scrollbars in a scrolledwindow widget if the child was smaller than you are?) It also has the interesting attribute that it implements my box layout paradigm, so, just like a box or a window, scrolledview can have arbitrary children, and support spacers too! To do this, I simply factored out the code in box that performed layout into a class called "boxlayout" and now window, box, and scrolledview inherit this base class.

This is slightly different than the strategy I posted previously. Often this is how software development goes -- ideas are one thing, reality becomes clearer in the implementation.

Here is a screenshot, and the portion of the code in XML markup that corresponds to it (the screenshot is of a scrolledwindow and scrolledview that have the same dimensions; the markup shows a more typical case, with scrolledview larger in size than the scrolledwindow).


<scrolledwindow width="200" height="200" vertical="yes" horizontal="yes">
<scrolledview width="500" height="500">
<spacer/>
<button onclick="return Button1Click();" label="ScrolledWindow Button 1"/>
<spacer/>
<button onclick="return Button2Click();" label="ScrolledWindow Button 2"/>
<spacer/>
</scrolledview>
</scrolledwindow>

0 Comments:

Post a Comment

<< Home