Hello,
I'm working on a field with a vertical scroller, that wraps its very long text. User has to zoom the text, i.e. changing font size.
No problem for changing font size using a slider control.
Text is automatically wrapped in the field, so changing font size change current text position displayed. How can set again the displayed text at the same point previous changing font size?
Field text position
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Field text position
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Field text position
Hi.
Is there a cursor blinking in the field when you resize? I can think of a way to do this if there is, though I have not tried it, Something along the lines of (pseudocode):
load the selectedLine into a custom property whenever the user clicks in the field
resize with the slider
scroll to the selectedLine with the new textSize showing
If not, the initial scroll of the field is something that might be loaded instead, and the scale of the new textSize could be used to scale the new scroll value. The lineHeight may need to come into play, but this seems doable.
Craig Newman
Is there a cursor blinking in the field when you resize? I can think of a way to do this if there is, though I have not tried it, Something along the lines of (pseudocode):
load the selectedLine into a custom property whenever the user clicks in the field
resize with the slider
scroll to the selectedLine with the new textSize showing
If not, the initial scroll of the field is something that might be loaded instead, and the scale of the new textSize could be used to scale the new scroll value. The lineHeight may need to come into play, but this seems doable.
Craig Newman
Re: Field text position
Hi MaxV,
this works on locked fields. In testing I set the scrollbar start value to 11 and end value to 36. Could not come up with easier code. Would be interested in more straight forward approaches though.
Kind regards
Bernd
Code: Select all
local sNoOfLines, sNoOfWords
on scrollbarDrag pValue
lock screen
set the textsize of field 1 to pValue
-- this selects first word of in topmost visible paragraph and keeps track of it, unblock to activate
-- select word 1 of line sNoOfLines of field 1
-- put item 2 of the formattedRect of word 1 of line sNoOfLines of field 1 into tTop
-- this selects a word in topmost visible line and keeps track of it, block if you want above code active
select word sNoOfWords of field 1
put item 2 of the formattedRect of word sNoOfWords of field 1 into tTop
put the top of field 1 - tTop into tDiff
set the vScroll of field 1 to the vScroll of field 1 - tDiff
select empty -- block to see which word was selected
unlock screen
end scrollbarDrag
on mouseDown
put the formattedText of field 1 into tFormatted
put the vScroll of field 1 + the topMargins of field 1 + the borderWidth of field 1 into tVScroll
put the effective textHeight of field 1 into tTextHeight
put tVScroll div tTextHeight + 1 into tLine
put the number of words of line 1 to (tLine - 1) of tFormatted + 1 into sNoOfWords
put the number of lines of word 1 to sNoOfWords of field 1 into sNoOfLines
end mouseDown
Kind regards
Bernd
Re: Field text position
Thank you bn for you suggestion, vscroll is the key!
I added this code to the scrollbar that set textsize (field "testo" is the field that changes Font size):
In the end I just put the vScroll at the same percent before text resizing. 
I added this code to the scrollbar that set textsize (field "testo" is the field that changes Font size):
Code: Select all
on mouseUp
put (the effective textheight of fld "testo") * (the number of lines in fld "testo") into totalscroll
put the vscroll of field "testo" into currScroll
put currScroll / totalScroll into percentscroll
set the textSize of field "testo" to the thumbpos of me
# now totalscroll is changed I need to recalculate it
put (the effective textheight of fld "testo") * (the number of lines in fld "testo") into totalscroll
set the vscroll of fld "testo" to trunc( totalScroll * percentScroll )
end mouseUp

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Field text position
Hi MaxV,
good you found a solution for your task. Just mind you that the hard part of my solution was to be consistent and precise when changing font sizes. As to not confuse the user when his text is in/decreased in size.
Kind regards
Bernd
good you found a solution for your task. Just mind you that the hard part of my solution was to be consistent and precise when changing font sizes. As to not confuse the user when his text is in/decreased in size.
Kind regards
Bernd