Page 2 of 2
Re: The clicked item
Posted: Sat Dec 26, 2020 7:19 pm
by dunbarx
Richmond.
I am sure you actually know this, but the clickChunk does indeed know what the "clickWord" is:
Code: Select all
answer char word 2 of the clickChunk to word 4 of the clickChunk of me
Craig
Re: The clicked item
Posted: Sat Dec 26, 2020 7:58 pm
by dunbarx
The challenge is to find, in a line in a field, which item of "xx,xx,xx,xx,xx,xx,xx" was clicked on.
My earlier optimistic assertion that the clickLoc might work may be in trouble. Not a problem with a fixed-width font like Courier. I can get the clickCharLoc, the formattedWidth of the line, and so know the pixel distance of that char from the left side of the field. In a fixed-width font, I can find the item that char lives in.
But not sure how to handle the far more common dynamic-width fonts. I do not want to have to know the pixel width of each char in such fonts, and am not even sure that would be viable in any case. I am trying to find a way forward using all the chunk gadgets, and location and size properties available in LC.
Hmmm. I may start a new challenge thread. My very first.
Craig
ClickItem challenge
Posted: Sat Dec 26, 2020 8:03 pm
by dunbarx
There is no "clickItem" function in LC.
This came from another thread:
http://forums.livecode.com/viewtopic.php?f=19&t=35159
The challenge is to find, in a line in a field, which item of "xx,xx,xx,xx,xx,xx,xx" was clicked on.
Not a problem with a fixed-width font like Courier. I can get the clickCharLoc, the formattedWidth of the line, and so know the pixel distance of that char from the left side of the field. In a fixed-width font, I can find the item that char lives in.
But not sure how to handle the far more common dynamic-width fonts. I do not want to have to know the pixel width of each char in such fonts, and am not even sure that would be viable in any case. I am trying to find a way forward using the chunk gadgets, and location and size properties available in LC.
Craig
Re: ClickItem challenge
Posted: Sat Dec 26, 2020 10:25 pm
by jmburnod
Hi Craig,
If i understand you correctly, this should work
Code: Select all
on mouseup
put word 2 of the clickchunk into tStart
put 0 into tNbItems
repeat with i = tStart down to 1
if char i of fld 1 = "," then add 1 to tNbItems
end repeat
put tNbItems+1
end mouseup
Best
Jean-Marc
Re: The clicked item
Posted: Sat Dec 26, 2020 10:40 pm
by richmond62
I am sure you actually know this
Yes, I do, but it doesn't do a blind bit of good in the OP's case.
If I click on a word in a sentence in the line of a listField ALL I can get back is the line clicked.
So, knowing that is in this case as valuable as knowing that the moon is not made of cheese.
Re: ClickItem challenge
Posted: Sat Dec 26, 2020 10:57 pm
by FourthWorld
Original thread posted in the "MacOS" forum (it's not platform-specific) has been merged with this duplicate thread here. Now people know where to post replies, and future readers can find complete discussions.
Re: The clicked item
Posted: Sun Dec 27, 2020 1:06 am
by jacque
richmond62 wrote: Sat Dec 26, 2020 10:40 pm
I am sure you actually know this
Yes, I do, but it doesn't do a blind bit of good in the OP's case.
If I click on a word in a sentence in the line of a listField ALL I can get back is the line clicked.
So, knowing that is in this case as valuable as knowing that the moon is not made of cheese.
The handler I posted finds the clicked item in a list field.
Re: ClickItem challenge
Posted: Sun Dec 27, 2020 10:45 am
by richmond62
Aksherlly, I can't help seeing this whole discussion as slightly redundant
as
ALL one has to do is deselect the list behavior thing in the field's Prop. palette,
and 'Bingo' the whole thang disappears in a puff of smoke:
Code: Select all
on mouseDown
put empty into fld "fREZ"
put ((the clickLine) & " : ") into fld "fREZ"
put the clickText after fld "fREZ"
end mouseDown
-
Re: ClickItem challenge
Posted: Sun Dec 27, 2020 11:13 am
by jmburnod
A better version of my first try
Code: Select all
on mouseup
put word 2 of the clickchunk into tStart
put word 2 of the clickline into tNoLi
if tStart = empty then exit mouseup
put 0 into tNbItems
repeat with i = tStart down to 1
if char i of fld 1 = cr then exit repeat
if char i of fld 1 = "," then add 1 to tNbItems
end repeat
add 1 to tNbItems
put "You clicked item" && tNbItems & "=" & item tNbItems of line tNoLi of fld "fText" into fld "fDev"
end mouseup
Jean-Marc
Re: ClickItem challenge
Posted: Sun Dec 27, 2020 11:54 am
by bn
This works with locked fields and list fields
Code: Select all
on mouseUp
put the clickCharChunk into tTemp
if tTemp is empty then
put "nothing clicked"
beep
exit mouseUp
end if
put word 2 of tTemp into tTemp
put the number of lines of char 1 to tTemp of me into tLineNo
put the number of chars of line 1 to tLineNo -1 of me into tPrevChars
if tPrevChars > 0 then add 1 to tPrevChars -- add return at end of line
put the number of items of char 1 to tTemp - tPrevChars of line tLineNo of me into tItemNo
put "Item " & tItemNo & " of line " & tLineNo
end mouseUp
Kind regards
Bernd
Re: ClickItem challenge
Posted: Sun Dec 27, 2020 6:25 pm
by dunbarx
Thanks, Bernd.
You know, I got stuck in my thinking. I should have stepped back a bit and simply counted forward, collecting commas along the way, like you did.
Craig
Re: ClickItem challenge
Posted: Mon Dec 28, 2020 1:14 am
by dunbarx
So with blinders off, thanks to others, I think this finds, within a line, the item number in any kind of field, listField or not:
Code: Select all
on mouseUp
put word 2 of the clickCharChunk into x
put word 2 of the clickline into lineClickedOn
put char 1 to word 2 of the clickCharChunk of me into tText
put the number of chars of line 1 to (lineClickedOn - 1) of tText + 1 into upperCount
answer the number of items of char 1 to x - upperCount of the last line of tText
end mouseUp
A little analysis, or a kick from your buddies, is worth a million lines of code.
Craig
Re: ClickItem challenge
Posted: Sun Jan 03, 2021 2:56 am
by Fermin
Oh, how clueless I am!... Until now I didn't see that there was a second page of comments. The last post I saw, at the end of the first page was: [Post by dunbarx " Fri Dec 25, 2020 4:07 pm]
Thank you very much for all those answers. I have tried the latest code from Craig [Post by dunbarx "Mon Dec 28, 2020 12:14 am] and it seems to work very well. And I see that it basically relies on the '
clickline' and '
clickCharChunk' commands as I did in the code I uploaded in [Post by Fermin " Fri Dec 25, 2020 1:19 am]. But I'm going to investigate Craig's work because I find it more direct and professional.
Thank you, again... And you, 2021, please be good to us!
Translated with
www.DeepL.com/Translator (free version)