horizontal scroll?
[1/2] from: hijim::pronet::net at: 1-Aug-2001 18:53
In the script below, whan the find function finds a string at the end of
a line it scrolls some of the text off the screen to the left. It does
better if I change the 2 to 1.1 in the scroll-to function, but it still
scrolls a couple of characters AND it puts the highlighted string at the
bottom of the page instead of the middle. How can I make this stop? I
need to scroll all the way to the left before showing the text.
I simplified the find routine from the one found in editor.r. The same
problem exists in that editor.
Any ideas?
Thanks,
Jim
rebol [Title: "Text Editor"]
a-file: ""
home: does [my-slider/data: 0 scroll-para text-file my-slider
show [text-file my-slider]
]
put: func [a b] [
if text-file <> system/view/focal-face [return]
if not system/view/caret [return]
insert system/view/caret a
system/view/caret: skip system/view/caret b show text-file]
search: func [ss] [
start: system/view/caret text-file/text
txt: find any [system/view/caret text-file/text] ss
focus text-file
if not txt [return]
system/view/highlight-start: txt
system/view/caret: txt
system/view/highlight-end: skip system/view/caret length? ss
scroll-to txt system/view/caret: skip system/view/caret length? ss
show [text-file my-slider]
]
scroll-to: func [txt /local xy] [
xy: (caret-to-offset text-file txt) - text-file/para/scroll
text-file/para/scroll: min 0x0 text-file/size / 2 - xy
my-slider/data: (second xy) / max 1 second size-text text-file
]
wrap-text: func [para /margin size /local count][
insert para "^/^/" "^/^/" ; add two newlines at top
count: 1
if not margin [size: 76] ; default size wraps at 70 characters
replace/all para "^/^/" "^/^/ " ; two newlines and some
spaces
count: 5
remove para "^/^/" "^/^/" ; remove two newlines at top
remove para "^/^/" "^/^/" ; remove two more newlines at top
forall para [
if (first para) = newline [count: 0]
if all [
count >= size
find/reverse para " "
][
para: find/reverse para " "
change para newline
para: insert next para " "
count: 5
]
count: count + 1
]
head para
]
view layout [
backdrop silver * 1.1 across space 0 origin 6
text-file: area para [] 500x400 a-file white white font-name
font-fixed wrap
my-slider: slider 18x400 silver / 1.2 gold [scroll-para text-file
my-slider]
below pad 4 across space 3
key #"^-" [put " " 4] ; tab key enters 4 spaces
button 72x22 green / 1.8 "Open" #"^o" [
file-path: request-file/title/keep "Open File" "Open"
if file-path <> none [
a-file: read/string to-file file-path system/view/focal-face
text-file/text: a-file file-path
f-name/text: copy file-path
home show f-name
]
]
button 72x22 blue / 1.4 "Save" [
if file-path <> none [write first file-path text-file/text]
]
button 72x22 blue / 1.4 "Save As" #"^s" [
file-path: request-file/title/keep "Save File" "Save"
if file-path <> none [write first file-path text-file/text]
]
button 72x22 green / 1.8 "Print" #"^p" [write %//prn wrap-text join
copy a-file #"^L"]
button 72x22 gold "Find" #"^F" [search ss/text]
ss: field 137x22 silver * 1.1 silver * 1.2 font-name font-fixed
return
tt "File: "
f-name: info 258x22 edge none font-name font-fixed
button 72x22 gold "Date" #"" [put to-string now/date length?
to-string now/date]
button 67x22 red "Delete" [
file-path: request-file/title/keep "Delete File" "Delete"
if file-path <> none [delete first file-path text-file/text]
]
button 67x22 red "Quit" #"^q" [unview/all]
return
]
[2/2] from: hijim:pronet at: 2-Aug-2001 19:59
I changed the scroll-to function to
scroll-to: func [txt /local xy] [
xy: (caret-to-offset text-file txt) - text-file/para/scroll
text-file/para/scroll: min 0x0 text-file/size / 1.05 - xy
my-slider/data: (second xy) / max 1 second size-text text-file
]
1.05 instead of 2 eliminates the horizontal scrolling, but it puts the found
text on the bottom line of the display instead of in the center. If there's
a simple way of scrolling the text up 2 or 3 lines, I'd like to know it. I'm
still experimenting, so I may find the answer.
Jim