Topic: Appgraphics Scrollbar

Jeff,

Would it be possible to provide a simple example of the use of a scrollbar in appgraphics?

It's not clear to me how the Callback routine is implemented to activate scrolling and what the passed variables are?

It's listed in SF contents as a Subroutine but it's passed as a parameter to create a scroll bar.  Should it be a function?

Thanks again,

Frank

Re: Appgraphics Scrollbar

Frank,

I apologize for the delay.  There was a brief discussion of scroll bars in point 3 of this post that lays out a bit of what is supposed to happen.

Basically, one of the scroll bar arguments is a subroutine that is called whenever the scroll bar position changes.  This subroutine should accept a single integer that represents the scroll bar's current position.  The position range, by default, should be 1-100, but it can be changed by calling setscrollrange to represent whatever you'd like. 

AppGraphics might work differently than other toolkits in regards to scrolling.  Again, AppGraphics is pretty low-level, meaning the application is responsible for creating any type of scrolling effect.  When the scroll bar position changes, the application would have to draw the window contents based on the scroll position, in contrast to the contents being larger than the current window and our scroll bars moving the contents of the window.  It might take a bit of getting used to, but it works in a manner similar to AppGraphic's resizing methodology.

I had though I had an already-working scroll demonstration, but apparently I do not.  Let me build an example for you over the next day or two.

Jeff Armstrong
Approximatrix, LLC

Re: Appgraphics Scrollbar

Frank,

Here's a simple example of using a scrollbar:

program main
use appgraphics
implicit none

    integer::myscreen
    integer::scrollbar
    integer, volatile::scroll_position
    integer::i, j
    character(len=4)::text
    
    myscreen = initwindow(200, 500, closeflag=.TRUE.)
    
    scrollbar = createscrollbar(185, 0, 15, 500, SCROLL_VERTICAL, scrolled)
    call setscrollrange(scrollbar, 0, 200)
    
    scroll_position = 0
    call settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 20)
    call setviewport(0, 0, 184, 500, .TRUE.)
    
    do while(.TRUE.)    
        call clearviewport()
        
        j = 0
        do i = 5, 480, 25
            Write(text, '(I4)') scroll_position+j
            call outtextxy(10, i, text)
            j = j + 1
        end do
        
        call loop()
    end do
    
    call closewindow(myscreen)

contains

    subroutine scrolled(p)
    implicit none
    
        integer::p
        
        scroll_position = p
        
        call stopidle()
        
    end subroutine scrolled

end program main

You can see that the scrollbar callback, scrolled, receives a scroll position, sets a scoped variable, and ends idling to force a redraw. You might notice that the drawing region isn't actually bigger than the window.  The application is responsible for determining what to draw within that space based on the current position of a scroll bar.  It's a somewhat lower level of scrolling than people might be used to dealing with in other toolkits.

Jeff Armstrong
Approximatrix, LLC

Re: Appgraphics Scrollbar

Jeff,

Thank you for providing an example of the implementation of a scroll-bar.

This example was very helpful and clarified the passing of a variable in the createscrollbar() subroutine.
It was not obvious to me that passing a subroutine 'scrolled' as a parameter did not have to itself contain the passed parameter 'p'.

scrollbar = createscrollbar(185, 0, 15, 500, SCROLL_VERTICAL, scrolled)

As in,

contains

    subroutine scrolled(p)
    implicit none
        integer::p,i,j

        scroll_position = p

        call stopidle()

    end subroutine scrolled

A word of caution.  I tried moving the inner text display Do-Loop of the Do While()-End Do that displays the scrolled text to the subroutine scrolled(p) instead and it did not work as you would expect. Jeff's approach is the correct one.

!-- Incorrect implementation
    subroutine scrolled(p)
        implicit none
        integer::p,i,j

        scroll_position = p

        call stopidle()

        j = 0
        do i = 5, 480, 25
            scroll_position = getscrollposition (scrollbar)
            Write(text, '(I4)') scroll_position+j
            call outtextxy(10, i, text)
            j = j + 1
        end do
    end subroutine scrolled

Thanks again,

Frank

Re: Appgraphics Scrollbar

Frank,

Ah, I see the point of confusion.  I'll take a peek at the documentation and see if it can be improved.

Jeff Armstrong
Approximatrix, LLC