[plt-scheme] flowing text into two text% objects

From: Leslie Gerhat (thoroughbred_phoenix at yahoo.com)
Date: Thu Nov 29 12:12:36 EST 2007



We need to create a single text% object and display it in two
editor-canvas%es, and have them scroll relative to each other.  Our code thus far is below.  We can get the one text% object to the two editor-canvas%es, and we can scroll them independently. However, we can't get the two editor-canvas%es to scroll relative to each other. Any ideas about how to go about doing this?


Thank you,

Leslie Gerhat

(require (lib "class.ss")

"mred.ss" "mred"))


(define lorem-ipsum

  "Lorem ipsum
dolor sit amet, consectetuer adipiscing elit. Mauris ultrices. Ut rutrum lacus
quis tortor. Cras commodo massa vel nisl.

Phasellus porta malesuada nulla. Cras quis tortor.
Pellentesque ut urna. Integer ipsum elit, pulvinar sollicitudin, pulvinar et,
feugiat nec, turpis. Aliquam accumsan. Aenean bibendum turpis at nisl. Aliquam
in augue et felis bibendum vulputate. Nunc non arcu.


Donec erat arcu, tempor sit amet, posuere sit amet, dignissim
ac, enim. Donec eget tellus. Suspendisse hendrerit arcu posuere magna. Sed non
purus eu libero molestie consectetuer. Nunc id ligula vel ipsum cursus
consectetuer. Nullam tristique porttitor lorem. Sed odio dolor, venenatis in,
mollis eu, elementum id, enim. Sed varius varius leo.

Mauris eleifend nonummy est. Morbi ut mi. Curabitur eget

Phasellus leo urna, volutpat sed, laoreet vel, semper ac,

Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas.


Fusce ut massa ac risus porta eleifend. Mauris non enim.
Pellentesque consequat, lacus quis tempus sollicitudin, lectus elit tempor
orci, a tempor dolor felis et nunc. Sed eget nunc quis metus tempus mattis.

Donec aliquet euismod velit. Nullam sit amet eros. Mauris
dui. Aliquam ligula enim, commodo vitae, imperdiet quis, convallis id, ante.

Curabitur sit amet metus quis nulla euismod tincidunt.
Integer interdum. Vestibulum bibendum, velit imperdiet faucibus ullamcorper,
libero eros ornare sem, sed commodo justo quam a sem. Vestibulum nunc.

In tincidunt pede at pede. Duis ante lacus, sodales ac,
lacinia vel, commodo at, ipsum. Phasellus malesuada. Ut malesuada dolor.
Quisque dolor ante, blandit in, faucibus id, laoreet nec, libero.


Vestibulum adipiscing mollis nisi. Aliquam nec sem eget
tortor suscipit mattis. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas. Phasellus et massa. Sed nunc nulla,
lobortis quis, tincidunt sed, fringilla at, enim. Ut varius pharetra erat.
Phasellus pharetra nulla sed felis. Nulla facilisi. Vestibulum vulputate nisi a
quam. Suspendisse fringilla odio vitae purus. Sed dapibus nonummy justo.
Integer mollis ligula vel odio sollicitudin euismod. Fusce vel turpis. Aliquam
semper lacinia diam.

Mauris fermentum, pede nec rhoncus vehicula, lorem turpis
cursus diam, a tempor ligula justo vulputate tortor. Sed sodales orci ut metus.
Sed et tortor.")


(define f (new frame%

(label "Foo")

               (min-width 800)

(min-height 400)



(define v (new vertical-pane%

(parent f)))


(define h (new horizontal-pane%

(parent v)



(define txt (new text%

                 (auto-wrap #t)



(define left (new editor-canvas%

(parent h)

(editor txt)

(style '(hide-vscroll))

(min-width 300)

(min-height 350)

(scrolls-per-page 1)



(define space (new horizontal-panel%

(parent h)

(min-width 100)))


(define right (new editor-canvas%

(parent h)

(editor txt)

(min-width 300)

(min-height 350)))


(define start (box 0))

(define end (box 0))


(define b (new button%

(parent v)

(label "Extent")


(lambda (w e)

(define last (send txt last-position))

(printf "~a~n" last)

(send txt get-visible-position-range start end #f)

(printf "~a, ~a~n"

(unbox start)

                          (unbox end))))))


(send f show #t)




(send txt insert lorem-ipsum)

;; Scroll the text to the top; this gets everything.

(send txt scroll-to-position 0 #f 'same 'none)

At Tue, 13 Nov 2007 17:15:58 -0800 (PST), Leslie Gerhat wrote:
> We are creating an eBook reader program and are having some
 difficulties with 
> our GUI.   In particular, we would like the area which displays the
 text to 
> look like a book with two text% objects corresponding to the right
 and left 
> pages.  We have created these two objects; however we are unable to
 fill them 
> appropriately.  We need to feed text into the left text% object until
> snips are no longer visible.  At that point, we need to start filling
> right text% object.  Then, once the user has read these two columns,
 they need 
> to be able to "turn the page" and repeat the fill processes with the
 next "two 
> pages" of text.   We have tried breaking our single string of text
 into list 
> objects representing a "page," but because we are using a
 proportional font, 
> the number of characters per "page" is inconsistent and we have no
 good way of 
> generating these list objects.  We also considered making each word
 or newline 
> into a structure, carrying a field
>  corresponding to the word's index in the complete text.  However, we
 ran into 
> issues when trying to put these into the text% object.  Specifically,
> couldn't figure out how to tell whether or not the word was visible.
  We tried 
> to use the (get-visible-position-range) function, but it
> doesn't actually return an integer value that can be compared to the
> current position.  We are looking for any advice with our approach to
> problem.  Thank you in advance for your help.
> Leslie Gerhat

Be a better sports nut!  Let your teams follow you 
with Yahoo Mobile. Try it now.  http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071129/d3ebc8df/attachment.html>

Posted on the users mailing list.