rebol [ Title: "Demo scroll-panel style" File: %demo-scroll-panel.r Date: 26-Aug-2008 Version: 1.0.3 Needs: [View] Author: "Anton Rolls" Language: 'English Purpose: {Show how to use the scroll-panel style} Usage: {} History: [ 1.0.0 [16-Oct-2003 {First version} "Anton"] 1.0.1 [29-Nov-2005 {made window resizeable and mapped that to the scroll-panel, removed scrollers for resizing the scroll-panel} "Anton"] 1.0.2 [30-Nov-2005 {replaced the gif images to have more of a chance of working on View 1.2.1} "Anton"] 1.0.3 [26-Aug-2008 {Added text and made the layouts a bit more informative and clearer (I hope), added auto-resizing code (commented), and scroller reset code} "Anton"] ] ToDo: { - DONE?: demo using a face directly - (try to get backwards compatibility with View 1.2.1) - SCROLLER is not present on View 1.2.1 - make a backwards compatibility file and call it or include it from here } Notes: {} ] query/clear system/words use [site][ site: select load-thru http://www.rebol.net/reb/index.r [folder "Anton"] clear find site %index.r do load-thru site/library/include.r ;print mold query/clear system/words include [ site/gui/scroll-panel.r [scroll-panel-style] ] ] ;print mold query/clear system/words ;use [window initial-window-size pos my-scroll-panel initial-spec][ initial-window-size: 449x485 ; <-- just make this smaller than or equal to the size that snugly fits the scroll-panel with its subface's initial layout view/new/options window: center-face layout [ ;size (initial-window-size) styles scroll-panel-style h1 "scroll-panel" pos: at ; Store current position (as a way of getting my-scroll-panel/offset before my-scroll-panel has been created) my-scroll-panel: scroll-panel ;max-initial-size (initial-window-size - pos - 20x20) ;max-initial-size 471x438 subface (initial-spec: [ ;backdrop effect [merge gradcol 0.220.255 0.0.100] ; this slows down updates a lot backcolor 210.210.192 ; kind of "olive paper" colour origin 20x20 h3 "Initial layout." btn "Change subface" [ my-scroll-panel/subface: layout/offset (alternative-spec: [ backcolor 190.200.210 ; "steely blue" colour h3 "Alternative layout." btn "Change subface back" [ my-scroll-panel/subface: initial-spec do bind [hscroll/data: vscroll/data: 0] my-scroll-panel ; Reset the scrollers to 0 (top-left) show my-scroll-panel ] text as-is "Scroll-panels can be nested.^/Inside this scroll-panel is another scroll-panel (below):" styles scroll-panel-style scroll-panel 280x140 subface [ backeffect [gradient 210.190.190 220.220.180] h2 "Inner scroll-panel" orange vh3 "Here are some example images." image logo.gif across image help.gif image info.gif image exclamation.gif ] edge [size: 1x1 color: black] ]) 0x0 ; Auto-size the scroll-panel to fit the new subface (two ways): ; 1. ;my-scroll-panel/size: none ;my-scroll-panel/resubface my-scroll-panel/subface ;show my-scroll-panel/parent-face ; 2. A simpler way: ;my-scroll-panel/size: -1x-1 ; autosize width and height ;show my-scroll-panel/parent-face ; Otherwise, it will remain the same size, so just SHOW. ; but first, let us also reset the scroll position to 0x0 do bind [hscroll/data: vscroll/data: 0] my-scroll-panel ; Reset the scrollers to 0 (top-left) show my-scroll-panel ] style text text as-is text {Here is a scroll-panel.} text {It can contain a face of any size, showing as much of it as will fit.} text {The horizontal and vertical scrollers only appear when necessary.} text {The scroll-panel can be resized freely. (Try resizing this window.)} text {It responds to scroll-wheel, is focusable, and, when focused,^/scrolls on arrow keys and page-up/down keys.} text {Focus is shown by changing the edge color to a blueish (default) colour.} text {scroll-wheel-handler can be used to allow control^/by scroll-wheel when other faces are focused.} text {When clicking on text inside a scroll-panel, the focus may^/be taken from the scroll-panel by the text,^/so the scroll-panel will no longer respond to key presses.} text {It's possible to either make the TEXTs inactive by setting^/their FEEL to NONE, or to modify their ENGAGE^/function to reroute specific key events to the^/scroll-panel. This is a bit of a hack, not well defined,^/but may work for your situation.} ]) edge [size: 2x2 color: black] do [focus my-scroll-panel] ; set focus for key events (including scroll-wheel events) ] 'resize window/feel: make window/feel [ detect: func [face event][ if event/type = 'resize [ my-scroll-panel/size: face/size - my-scroll-panel/offset - 20x20 ; <- 20x20 is origin show my-scroll-panel ] event ; allow event to continue ] ] do-events ;] ; end of use ;print mold query/clear system/words