Determining What Text is in the Current Scrollview of Field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Determining What Text is in the Current Scrollview of Field
Hi all,
Is there a built-in function that returns what text is in the current view of a scrolling text field? Or do I need to write one on my own?
Thanks!
Tom
Is there a built-in function that returns what text is in the current view of a scrolling text field? Or do I need to write one on my own?
Thanks!
Tom
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Determining What Text is in the Current Scrollview of Fi
Hi.
LC sometimes has just what you need, but I think in this case you need to roll your own.
The tools you will need are "the formattedHeight", the "textHeight", the "scroll", and the like. Here is a start, given a field 1 where you have set the textheight to some value:
Does this make sense? Can you see how to get all the exposed lines with this? Write back if you get stuck, but do try first.
Craig Newman
LC sometimes has just what you need, but I think in this case you need to roll your own.
The tools you will need are "the formattedHeight", the "textHeight", the "scroll", and the like. Here is a start, given a field 1 where you have set the textheight to some value:
Code: Select all
on mouseUp
put trunc(the scroll of fld 1 / the textHeight of fld 1) + 1
end mouseUp
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:58 am, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:57 am, edited 1 time in total.
shiftLock happens
Re: Determining What Text is in the Current Scrollview of Fi
Hi guys,
Thanks for the input. To solve my problem (at least partially), I used the fact that selecting text will move a scrollable text field automatically to select individual characters until the vScroll position was no longer 0+some minimum threshold I decided empirically. The toughest part of this is really just making sure that the function can sneak in like a ninja and get this information without messing with your current selections/focused controls, etc.
Where this doesn't work, however, is in determining the text currently showing on the screen when the vScroll is not 0. But, with a little imagination and a little more time, I will get this done too! Let me know if you have another cooler way of doing this...
Thanks,
Tom
Thanks for the input. To solve my problem (at least partially), I used the fact that selecting text will move a scrollable text field automatically to select individual characters until the vScroll position was no longer 0+some minimum threshold I decided empirically. The toughest part of this is really just making sure that the function can sneak in like a ninja and get this information without messing with your current selections/focused controls, etc.
Code: Select all
function theLastVisibleCharacter theField
put 1 into theLastCharIndex
put 10 into minPickup
--preserve the current view
put the focusedObject into thePreservedFocusedObject
if the selectedText is not empty then
put the selectedChunk into thePreservedSelectedChunk
end if
put the scroll of field theField into thePreservedScroll
lock screen
repeat for each char theChar in field theField
select char theLastCharIndex of field theField
if the VScroll of field theField < minPickup then
add 1 to theLastCharIndex
end if
end repeat
--reset the view to the way it was before I messed with it
focus on thePreservedFocusedObject
if thePreservedSelectedChunk is not empty then
select char (word 2 of thePreservedSelectedChunk) to (word 4 of thePreservedSelectedChunk) of thePreservedFocusedObject
end if
set the vScroll of field theField to thePreservedScroll
unlock screen
return theLastCharIndex
end theLastVisibleCharacter
Thanks,
Tom
Last edited by tjm167us on Tue Mar 15, 2016 6:19 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 4002
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Determining What Text is in the Current Scrollview of Fi
Tom,
you can combine Craigs suggestion with the formattedText of a field (that is the field that has wrapping text converted to text that has a return at each APPARENT line ending.
here is a quick stack
Kind regards
Bernd
you can combine Craigs suggestion with the formattedText of a field (that is the field that has wrapping text converted to text that has a return at each APPARENT line ending.
here is a quick stack
Kind regards
Bernd
- Attachments
-
- whatIsTheVisibleText.livecode.zip
- (2.22 KiB) Downloaded 251 times
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:57 am, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Determining What Text is in the Current Scrollview of Fi
Hello -hh.
Why are you negative?
Anyway, since you are a fan of the mouseCharChunk (a very nice feature), note that the dictionary gives wrong information about what that function returns when over empty space. Whether below the last char or over empty lines between text, the function returns empty, not the chunk expression given. I added a user note about this.
Craig
Why are you negative?
Anyway, since you are a fan of the mouseCharChunk (a very nice feature), note that the dictionary gives wrong information about what that function returns when over empty space. Whether below the last char or over empty lines between text, the function returns empty, not the chunk expression given. I added a user note about this.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 4002
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Determining What Text is in the Current Scrollview of Fi
Hi [-HH],
So no pi in livecode fields...
If I want to do this (and I would think hard to come up with a use case, except maybe pi, but see above), I use the formattedRect of a character. But one has to iterate through the chars of the visible lines to get the first and last character that is visible.
I attach a little stack that shows this. It works but would need more work to use in production grade projects.
Kind regards
Bernd
not really because this is for wrapping text and you would not want a horizontal scrollbar in a text field that wraps the text.You have to correct calculating height if a horizontal scrollbar is present (the fld may have one if it was non-wrapping before) by the height of the hScrollbar
not really. FormattedText is in LiveCode since version 1.0, some changes in 5.5. in the dictionary the note about experimental refers to listStylesthe formattedText is experimental until now.
listStyle property is experimental
That is a problem of LIvecode that can at times be tricky. You have to be aware that a line in a livecode field has a limit ofone has to think about adding (and take into account) spaces, if the text is ONE long word.
section 2.2.9 "LiveCode Memory Limits" Usere guide.65,536 characters storage
No more than 32,786 pixels wide for display
So no pi in livecode fields...
That is tricky. I don't know of a command that gives me the "visible" characters.And a question:
A similar technique may be applied to each line of a non-wrapping field (then we have to correct width calculations by the width of the vScrollbar).
If I want to do this (and I would think hard to come up with a use case, except maybe pi, but see above), I use the formattedRect of a character. But one has to iterate through the chars of the visible lines to get the first and last character that is visible.
I attach a little stack that shows this. It works but would need more work to use in production grade projects.
Kind regards
Bernd
- Attachments
-
- whatIsTheVisibleText_0_2.livecode.zip
- (3.5 KiB) Downloaded 234 times
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:57 am, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:57 am, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 4002
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Determining What Text is in the Current Scrollview of Fi
Hi HH,
thank you for the kind words.
knowing some about your language background (german) one guy jokingly said that the german habit of compounding nouns into one new word, which can be quite long
e.g.
Lichtwellenleiterkabelverlegung
was not that the words are too long but life is just too short for them.
As far as the numbering system of the stacks is concerned: unfortunately I can not count up to 3.
Kind regards
Bernd
PS I am shure Craig did not want to say you are negative in tone or mood but alluded to the - sign in front of your signature [-HH], he made a joke, but I guess Craig will chime in to explain that better than I can.
thank you for the kind words.
knowing some about your language background (german) one guy jokingly said that the german habit of compounding nouns into one new word, which can be quite long
e.g.
Lichtwellenleiterkabelverlegung
was not that the words are too long but life is just too short for them.
As far as the numbering system of the stacks is concerned: unfortunately I can not count up to 3.
Kind regards
Bernd
PS I am shure Craig did not want to say you are negative in tone or mood but alluded to the - sign in front of your signature [-HH], he made a joke, but I guess Craig will chime in to explain that better than I can.
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:56 am, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Determining What Text is in the Current Scrollview of Fi
Dear |hh|
There, now there can be no misunderstanding.
Craig
There, now there can be no misunderstanding.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Determining What Text is in the Current Scrollview of Fi
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:56 am, edited 1 time in total.
shiftLock happens