Issue with field margins when building a custom control based on a scrolling list field.

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Issue with field margins when building a custom control based on a scrolling list field.

Post by jacque » Wed Aug 02, 2023 5:46 pm

I haven't been following this closely but would the selectedLoc function be useful?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Issue with field margins when building a custom control based on a scrolling list field.

Post by bn » Wed Aug 02, 2023 10:21 pm

Simon Knight wrote:
Wed Aug 02, 2023 5:08 pm

I have just noticed this happens if border and margins are both set to zero (text is 11) :


What logic is being employed and why?

Also just found this command :

Code: Select all

function getTopOfFirstLine
   return item 2 of the formattedRect of Line 1 of field "MyNewList"
end getTopOfFirstLine
S
Simon,

at margins 0 text is alway cut off by 1 pixel.

Code: Select all

function getTopOfFirstLine
   return item 2 of the formattedRect of Line 1 of field "MyNewList"
end getTopOfFirstLine
You should have told me that about 10 years ago...

It does seem to do the trick, I just never knew/found this although I did play around with formattedRect quite a bit.

This is the current version the mouseDoubleUp handler for field "myNewList". No need for function getTopOfLine.
This handler seems to take care of it all. (note I added a conditional to catch doubleClick above first line, it would otherwise place an editorField into line 0)

Code: Select all

on mouseDoubleDown pButtonNumber
   // Enter edit mode
   // Get the line no of the clicked row
   
   put the effective textHeight of me into tCellHt
   put the borderWidth of me into tBorderWidth //only applies to the outer boarder not the thin lines
   put the leftMargin of me into tLeftMargin -- changed to leftMargin
   
   put item 2 of the formattedRect of line 1 of me into tTopOfLines
   
   put item 2 of (the mouseloc) into tMouseYcoOrd
   
   // catch if doubleClick is above first line, otherwise it would create a LineEditor for line 0
   if tMouseYcoOrd < tTopOfLines then
      exit mouseDoubleDown
   end if
   
   put  tMouseYcoOrd-(tTopOfLines - the vScroll of me) into tMouseYPosnInField
   // Calculate the line number
   put (tMouseYPosnInField)/tCellHt  into tLineNo
   put the floor of tLineNo + 1 into tLineNo
   
   put "Line number : " & tLineNo into field "Details"
   
   put tTopOfLines + ((tLineNo - 1)*tCellHt) - the vScroll of me +1  into tLineTop
   
   put the scrollbarWidth of me into tScrollBarWidth
   if not the vScrollBar of me then
      put 0 into tScrollbarWidth
   else
      subtract 1 from tScrollbarWidth
   end if
   
   // size and position the field used for editing
   set the height of field "LineEditor" to tCellHt - 1
   
   set the width of field "LineEditor" to (the width of me)-(2*tBorderWidth) - tScrollbarWidth
   set the top of field "LineEditor" to tLineTop
   Set the left of field "LineEditor" to (the left of me + tBorderWidth)
   set the textsize of field "LineEditor" to the effective textsize of me
   
   set the margins of field "LineEditor" to tLeftMargin,5,0,0 --left, top, right, bottom
   
   put line tLineNo of me into tLineText
   
   // Store line number and text in custom variables
   set the uEditingLineNo of field "LineEditor" to tLineNo
   
   put the short name of me into tMyName
   set the uParentFieldName of field "LineEditor" to tMyName
   
   // Populate the field and make visible
   put tLineText into field "LineEditor"
   
   set the visible of field "LineEditor" to true
   focus on field "LineEditor"
   
end mouseDoubleDown
Kind regards
Bernd

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

Re: Issue with field margins when building a custom control based on a scrolling list field.

Post by bn » Wed Aug 02, 2023 10:27 pm

Simon Knight wrote:
Wed Aug 02, 2023 4:44 pm
I have just seen this in the dictionary
If the object's showBorder property is false, the borderWidth property has no effect.
I don't think it is correct at least on version 10 .
Just wondering if I should post a documentation bug report.
Simon
For me the borderWidth setting is in effect regardless of the status of "showBorder" in LC 9.6.9 confirming your observation.
It is definitely a documentation bug. The behavior may have changed with the rewrite in LC 7 series.
I would report it.
Kind regards
Bernd

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Issue with field margins when building a custom control based on a scrolling list field.

Post by Simon Knight » Thu Aug 03, 2023 8:09 am

You should have told me that about 10 years ago...
:D

I wonder when the command was introduced ?

I found it by going down the list of field properties / commands looking for other issues like the Borderwidth error.
There are several where the syntax example either does not work, throws an error or does not appear to apply to a field object.

So I was surprised that calling the formatted rectangle of line n did work as I expected it to be another documentation error.


Simon
best wishes
Skids

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Issue with field margins when building a custom control based on a scrolling list field.

Post by Simon Knight » Thu Aug 03, 2023 6:30 pm

Thank you for all your inputs. The final version of the control is on the attached stack.

best wishes

Simon
ListFieldDemonstration_Modified.livecode.zip
DemoStack
(4.7 KiB) Downloaded 85 times
best wishes
Skids

Post Reply

Return to “Talking LiveCode”