background color of text with metadata

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: background color of text with metadata

Post by dunbarx » Thu Mar 14, 2024 1:58 pm

Paul.

Yipes. I must look more carefully at the dictionary. I looked for "rect", saw the list of native words that contained it, like "formattedRect", and saw that the syntax for that entry read "get the formattedRect of {card | group}". There is also one for widgets.

So I never thought to look at the actual entry, where there was a syntax option "get the formattedRect of chunk of field".

And Bernd obviously knew that. Anyway, with both the topLeft and botRight of a selection available, the solution becomes MUCH simpler.

So, Jeff, overlays?

Craig
Last edited by dunbarx on Thu Mar 14, 2024 2:28 pm, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: background color of text with metadata

Post by bn » Thu Mar 14, 2024 2:12 pm

stam wrote:
Thu Mar 14, 2024 1:57 pm
Bernd, you previous solution is clearly superior - this kludge is fine but scrolling and multiple highlights are an issue... if having to scroll multiple highlights this would quickly escalate into a slow-grinding nightmare!
I quite like what you did with your previous solution... goes to show there is (almost) always a workaround.
I am not recommending this kludge as a working solution. I was just trying to show another kludge. I agree it would be a nightmare to support this for scrolling etc. But I thought it would be a nice exercise in kludging.
I even had a kludged version that used 2 identical fields. The toplevel transparent field for working and the lower field for hilting the words of interest.
Then I synced the scroll. Did not even bother to post that although it kind of worked.

The version I recommend to Jeff is
https://forums.livecode.com/viewtopic.p ... 27#p228705

Just one field with the backgroundColor of the words of interest set and the metadata of the words all in the metadata of line 1 of the field. Not really kludgy, just a bit different way of information storage. A workaround for the problems with contiguous hilites and metadata of the actual words.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: background color of text with metadata

Post by dunbarx » Thu Mar 14, 2024 2:27 pm

Bernd.

Are you an Emily Dickinson fan? I am.

Craig

bamakojeff
Posts: 13
Joined: Tue Dec 06, 2022 6:53 pm

Re: background color of text with metadata

Post by bamakojeff » Thu Mar 14, 2024 2:45 pm

I've been coding for over 40 years, but only started using Livecode a year or so ago, and I feel like I'm in a Livecode master-class! I've been messing with this on and off for two weeks (I do have a day job that occasionally expects actual work out of me!) trying all sorts of different things, and you all came up with a series of solutions (that work!) in a day and a half. Craig figures out how to use overlays and Bernd moves the metadata to the line level (where it does not interfere with setting the bgcolor) but can still be easily accessed for each word in the paragraphs. You guys are brilliant!

I haven't looked at Craig's latest overlay solution, but I have confirmed that storing all the metadata at the line level solves this problem. And it looks like it will do so with minimal changes to the code to make it work. I'll have to convert the underlying files which store the html data to reflect this change, but that's a few lines of perl code for me. ;-)

The data files presently look like
<p><span metadata="1">first_word</span> <span metadata="2">second_word</span></p>
and the code to get the metadata for each word when the user clicks on a word is simply:

Code: Select all

put the metadata of the mouseText into tWordID
With the metadata at line level, the data files will look like
<p metadata="1 2">first_word second_word</p>
and to get the metadata for each word I will use:

Code: Select all

put the number of words of char 1 to word 4 of the mouseChunk of fld "txt" into tNum
put word 2 of the mouseLine in tLine
put word tNum of the metadata of line tLine of fld "txt" into tWordID
and "Bob's your uncle!" (Or "Voila!" if you prefer French.)

I still have to take a look at Craig's new overlay code, but I will check that out next. That would require no changes to my existing code to get the metadata since it doesn't touch the field data at all. But it would require all the new code to create the overlays. I'm also curious how it does performance wise when there is a lot of highlighted text and it's being quickly scrolled.

THANK YOU, gentlemen! I would have banged my heard against this for a long time and maybe never come up with either of these solutions.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: background color of text with metadata

Post by bn » Thu Mar 14, 2024 7:33 pm

Jeff,

I think your solution is straightforward and easy to maintain.
Glad you solved the problem.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: background color of text with metadata

Post by bn » Thu Mar 14, 2024 7:37 pm

dunbarx wrote:
Thu Mar 14, 2024 2:27 pm
Bernd.
Are you an Emily Dickinson fan? I am.
Craig
Actually I was intrigued by the text you chose and looked it up. Then I found the whole poem and liked it very much.

So I was not an Emily Dickinson fan (only heard her name before) but now I like this poem and her name means something to me.
Thanks.

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”