Re: How to find the column and row of a basic tableField
PS - Here are two word problems to view this type of algorithm in a bigger context beyond just software UI. Not too scary or difficult; our ancestors could solve similar problems, and so can kids in school. Older problem: You are in charge of preparing animal enclosures for a market. The marketplace has several pens that respectively hold 20, 15, 30, and 25 goats and will be filled in that order. If 42 goats are expected, how many of the pens will be needed? Newer problem: Your app has a field with tabWidths of 200, 150, 300, and 250 (or the equivalent tabStops). The user's clickH minus left edge of the field and margin is 420. Assuming field hScroll is 0 and standard borders, which column did the user click? (Then write an LC function to solve for any clickH and tabStops.) Great exercise for an intermediate LC student to solve WITHOUT having previously seen solution source code! I'm fond of this type of problem. Best wishes, Curry Kenworthy Custom Software Development "Better Methods, Better Results" LiveCode Training and Consulting http://livecodeconsulting.com/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Probably has to do with margins. Bob S On Apr 2, 2020, at 11:42 PM, Håkan Liljegren via use-livecode mailto:use-livecode@lists.runrev.com>> wrote: It works for tables with or without date but doesn’t handle tables with variable row heights as that was not the case at the moment. To get it pixel-perfect I needed to compensate the row calculation with 5 pixels and the column with -2 as you can see in my code. Does anyone know why? Is it the same reason that if you set the margins of a field to 0 you often get the first line clipped? Keep Safe! :-Håkan ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
With risk of going slightly off-topic, but also showing yet another code example. I had exactly this problem some time ago and came up with the following solution: getProp clickedRowCol # calc Row => TODO: Handle row with variable row heights put the clickV - the top of me - the borderWidth of me - the effective topMargin of me + 5 into tY put tY div the effective textHeight of me + 1 into tLine #Calc column : TODO : Handle other text aligns put the tabstops of me into tTabs put the number of items in tTabs into tNumCols put item -1 of tTabs into tLastTab put tLastTab - item -2 of tTabs into tTabWidth put the left of me + the borderWidth of me +the effective leftMargin of me - 2 into tLeft if (the ClickH - tleft) > tLastTab then # Click right of last column return tLine, (the ClickH - tLastTab - tLeft) div tTabWidth + tNumCols + 1 else put the ClickH - tLeft into tClickPos put "," & tClickPos after tTabs sort items of tTabs numeric ascending return tLine, itemOffset(tClickPos, tTabs) end if end clickedRowCol You can try it by adding the following mouseUp code: on mouseUp answer "You clicked at " & the clickH, the clickV && "= (Row,Col)" && the clickedRowCol of me end mouseUp It works for tables with or without date but doesn’t handle tables with variable row heights as that was not the case at the moment. To get it pixel-perfect I needed to compensate the row calculation with 5 pixels and the column with -2 as you can see in my code. Does anyone know why? Is it the same reason that if you set the margins of a field to 0 you often get the first line clipped? Keep Safe! :-Håkan ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Thank you. I feel so much Better educated. (Sarcasm intended)!! Sean Cole Pi Digital ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Pi: > you make these statement but give no example code to show it. This > is damned infuriating as it keeps us hunting around in the dark. On the contrary, as I've mentioned and as you know, "SEVERAL people immediately provided sample code." You were using sarcasm at the time to walk back disproven previous statements, but you never politely asked me for anything that I noticed. Nevertheless you received a ton of code from other helpful souls before I even saw your sarcastic remarks. I think it's clear how you are playing this socially, but that's OK - the facts speak loud and clear. You have many code samples, relieving any actual need for damnation or infuriation, and we also have a listing of correct verifiable facts for those who care about real info and don't want confusion. Putting out a stream of wrong statements never solves anything! I like to do the opposite, because wrong info hurts people. Stay safe. :) Best wishes, Curry K. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Curry This winds me up a treat! Your point number 6: > It has been available as a one-line function call without rolling your own > since at least 2012 with SpreadLib. is totally unreasonable if you are claiming there IS a one line use case but ONLY if we buy into some spreadsheet library. That’s not the same in any way as something available natively. SpreadLib wasn’t mentioned in any previous solutions in these threads. And 3&4: > 3. Can we figure out which field column was clicked? YES! > > 4. Have we had this ability (#3) for a long time? YES! Since LC/RR 1.0 at > least. Again, as before in the other thread, you make these statement but give no example code to show it. This is damned infuriating as it keeps us hunting around in the dark. It’s great that you have this wealth of knowledge and information and that you ‘like to prevent headaches before they happen’. But making statements with no examples to back them up is only adding to my headache and doesn’t feel particularly ethical overall. It’s just hoarding the knowledge you have without properly educating us pathetic fake news mongers underneath you. Telling us it can be done is no help when we would benefit from your ability to teach practically. Knowledge is power. For with it you can empower others. Many thanks and get well soon. Sean > On 2 Apr 2020, at 19:14, Curry Kenworthy via use-livecode > wrote: > > > We don't need to confuse people - it DOES cause damage, because readers often > trust confident/prolific statements without realizing which ones are flawed, > and they act upon bad information. It often falls to consultants and trainers > like myself to help individuals fix the resulting problems later. I guess > that's good for business, but as an ethical person I also like to prevent > headaches for others before they happen. I can't in good conscience let > incorrect info slip by unchallenged. > > Despite a lot of good info posted, there has been also considerable > intentional "spin" on this topic in various threads, as well as several > outright inaccurate claims, all of which could easily be confusing, so here's > an ACCURATE FACTS RECAP (for all related threads) that people who desire real > info can easily verify as factually correct and trust as reliable and > objective: > > 1. Can fields display inline images? YES! A large number of images can be > displayed. > > 2. Can fields display checkboxes? Only CUSTOM designed ones, which can work > well. > > 3. Can we figure out which field column was clicked? YES! > > 4. Have we had this ability (#3) for a long time? YES! Since LC/RR 1.0 at > least. > > 5. Is finding which column something people commonly know or can figure out? > Not sure, but SEVERAL people immediately provided sample code. (This was > attempted as a strawman claim, it was not my claim, but hilariously > backfired.) Actually there are at least THREE different approaches, two of > which are generally applicable and the other also valid and interesting but > specialized to certain content requirements. I'm not counting additional > handy approach(es) that rely on an existing implementation of one of these > three. > > 6. Does finding which column via tabstops require a "convoluted" solution > with lots of code? HECK NO; that's rubbish! It has been available as a > one-line function call without rolling your own since at least 2012 with > SpreadLib. Also available with other libraries. And while rough sample > functions have been posted here, some of us specialize in more efficient > techniques and have much sleeker code. > > 7. Does finding which column require using the simple table field setting > with cell edit enabled? NO! Not at all. The wording of the subject line might > confuse people, but this was later clarified by Bernd regarding his helpful > code sample. > > 8. Is using a datagrid somehow more trouble than setting up a field for > desired table features? Depends on the approach, but IRRELEVANT to the > original issue of WHETHER finding which column was available on regular > fields. (In context of recent discussions, this was another strawman argument > introduced to reframe the discussion and walk back previous incorrect claims.) > > The reality is that multiple solutions are available to choose from, there > are precoded solutions and sample code available, and each approach has some > pros and cons. Do NOT be confused by "fans" of an approach (usually DG) who > exaggerate and cherry-pick (or just make confident assertions) to sway > others. They may sound confident, but the actual facts don't change based on > who has the time and energy to be more talkative. Datagrids are fairly easy > to set up, but the flip side is that they also more complex and subject to > the limitations and consequences of that complexity. Those familiar with KISS > and optimization will understand such considerations; well-documented in >
Re: How to find the column and row of a basic tableField
We don't need to confuse people - it DOES cause damage, because readers often trust confident/prolific statements without realizing which ones are flawed, and they act upon bad information. It often falls to consultants and trainers like myself to help individuals fix the resulting problems later. I guess that's good for business, but as an ethical person I also like to prevent headaches for others before they happen. I can't in good conscience let incorrect info slip by unchallenged. Despite a lot of good info posted, there has been also considerable intentional "spin" on this topic in various threads, as well as several outright inaccurate claims, all of which could easily be confusing, so here's an ACCURATE FACTS RECAP (for all related threads) that people who desire real info can easily verify as factually correct and trust as reliable and objective: 1. Can fields display inline images? YES! A large number of images can be displayed. 2. Can fields display checkboxes? Only CUSTOM designed ones, which can work well. 3. Can we figure out which field column was clicked? YES! 4. Have we had this ability (#3) for a long time? YES! Since LC/RR 1.0 at least. 5. Is finding which column something people commonly know or can figure out? Not sure, but SEVERAL people immediately provided sample code. (This was attempted as a strawman claim, it was not my claim, but hilariously backfired.) Actually there are at least THREE different approaches, two of which are generally applicable and the other also valid and interesting but specialized to certain content requirements. I'm not counting additional handy approach(es) that rely on an existing implementation of one of these three. 6. Does finding which column via tabstops require a "convoluted" solution with lots of code? HECK NO; that's rubbish! It has been available as a one-line function call without rolling your own since at least 2012 with SpreadLib. Also available with other libraries. And while rough sample functions have been posted here, some of us specialize in more efficient techniques and have much sleeker code. 7. Does finding which column require using the simple table field setting with cell edit enabled? NO! Not at all. The wording of the subject line might confuse people, but this was later clarified by Bernd regarding his helpful code sample. 8. Is using a datagrid somehow more trouble than setting up a field for desired table features? Depends on the approach, but IRRELEVANT to the original issue of WHETHER finding which column was available on regular fields. (In context of recent discussions, this was another strawman argument introduced to reframe the discussion and walk back previous incorrect claims.) The reality is that multiple solutions are available to choose from, there are precoded solutions and sample code available, and each approach has some pros and cons. Do NOT be confused by "fans" of an approach (usually DG) who exaggerate and cherry-pick (or just make confident assertions) to sway others. They may sound confident, but the actual facts don't change based on who has the time and energy to be more talkative. Datagrids are fairly easy to set up, but the flip side is that they also more complex and subject to the limitations and consequences of that complexity. Those familiar with KISS and optimization will understand such considerations; well-documented in Computer Science. Fields have their pros and cons too. Be aware that you have choices, and which solution is superior depends on your project requirements. Finally, while having a pre-coded solution is nice (and we've had some for years) people shouldn't be misled into thinking this is an extremely difficult problem. The math algorithm is simple to understand. Not rocket science by any stretch of the imagination; in fact, this is much closer to real-world problems encountered thousands of years ago in the Bronze Age or perhaps even earlier in the Neolithic. Literally somewhere between Jericho and Sumer in the level of progress and difficulty. The math is not complicated - it makes a good student learning exercise. If people think this is really hard, society may be in trouble! :) This and other topics with some inaccurate claims have inspired me. When I get caught up, along with other things eventually I'll launch a Facts vs Myths/Fake News web page to help newbies sort out reliable information about LiveCode features. Accuracy is important and must not be lost among all the "politics" and opinions of discussions. Take care, all! Be safe about quality code, accurate info, and virus precautions/social distancing. Best wishes, Curry Kenworthy Custom Software Development "Better Methods, Better Results" LiveCode Training and Consulting http://livecodeconsulting.com/ ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to
Re: How to find the column and row of a basic tableField
Specialising in missing the point as I do, I've posted something here: http://forums.livecode.com/viewtopic.php?f=7=33859 Richmond. On 2.04.20 1:52, Pi Digital via use-livecode wrote: Thanks Bernd. This only works if there is already data in the field. If you put empty into the field it produces no results. In those instances you are forced to get an x,y clickLoc and use the tabstops and textHeight to hard code the result. The revTableLibrary was last modified in 2015 from your recommendations and pulls. Notable is the ones in revCalculateCellLoc and revCalculateCellRect. Interestingly in revCalculateCellLoc there is a couple of lines that set cREVTable[“currentxcell”] and [“currentycell”] of the object. Using: Put cRevTable[“currentxcell”],cRevTable[“currentycell”] into tCellIndex Works a charm. To make this work you do need to have cellEdit enabled but to avoid having it actually enable editing the text, in the mouseup just have a ‘select nothing’ to immediately exit the field. That way you only return the xy index and can use other means to add in or collect cell data. This is far less convoluted and exactly what I was looking for. None of this faffing around with huge lines of code. LiveCode is supposed to be EASY and almost instinctive. This is pretty close. It’s a real shame that these are not visible in the property inspector as standard properties and not even in the customProperties cRevTable until you have clicked into one of the cells in runtime when it populate the custom set. It’s even more of a shame that this is not documented anywhere, in the dictionary, guide, lessons, tutorials. It’s practically lost to obscurity in the forums too only being found if I search for currentxcell specifically. I only found it by hacking through all of the object library code of the IDE stacks. This definitely make the table field object far more useful, though. Sean Cole Pi Digital Productions Ltd ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Sean, The idea for the script I posted was to be independent of the Livecode provided tableField. My use case was that tab-delimited data was provided in a _regular_ field and the user clicks on a cell and the developer wants to know which cell was clicked to take action upon that information. That is what modTableField is all about. modTableField has an option for the user to fill/change cells within the provided tab-delimited matrix. http://berndniggemann.on-rev.com/mtf/modTableField.zip To make such a field you use the standard field and set its hGrid and vGrid to true. The revtablelibrary frontscript knows nothing about such a field and keeps out of it. If however you want to use the built-in tableField to let the user enter data (that is what I gather from your comment) be aware that revTableField is not free of bugs. https://quality.livecode.com/show_bug.cgi?id=21679 That bug may be of interest to you if you want to let the user enter information at arbitrary not yet created cells in a revTableField But then again I may not understand your use case. If I can be of help feel free to mail me. Kind regards Bernd ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
I made two mistakes there. First: Put cRevTable[“currentxcell”],cRevTable[“currentycell”] into tCellIndex Should be: Put the cRevTable[“currentxcell”] of me , the cRevTable[“currentycell”] of me into tCellIndex And: select nothing Should be: select empty Oops Sean Cole Pi Digital Productions ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to find the column and row of a basic tableField
Thanks Bernd. This only works if there is already data in the field. If you put empty into the field it produces no results. In those instances you are forced to get an x,y clickLoc and use the tabstops and textHeight to hard code the result. The revTableLibrary was last modified in 2015 from your recommendations and pulls. Notable is the ones in revCalculateCellLoc and revCalculateCellRect. Interestingly in revCalculateCellLoc there is a couple of lines that set cREVTable[“currentxcell”] and [“currentycell”] of the object. Using: Put cRevTable[“currentxcell”],cRevTable[“currentycell”] into tCellIndex Works a charm. To make this work you do need to have cellEdit enabled but to avoid having it actually enable editing the text, in the mouseup just have a ‘select nothing’ to immediately exit the field. That way you only return the xy index and can use other means to add in or collect cell data. This is far less convoluted and exactly what I was looking for. None of this faffing around with huge lines of code. LiveCode is supposed to be EASY and almost instinctive. This is pretty close. It’s a real shame that these are not visible in the property inspector as standard properties and not even in the customProperties cRevTable until you have clicked into one of the cells in runtime when it populate the custom set. It’s even more of a shame that this is not documented anywhere, in the dictionary, guide, lessons, tutorials. It’s practically lost to obscurity in the forums too only being found if I search for currentxcell specifically. I only found it by hacking through all of the object library code of the IDE stacks. This definitely make the table field object far more useful, though. Sean Cole Pi Digital Productions Ltd ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode