PolyList and variable itemHeight to fit text in an item

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

Post Reply
tomsve
Posts: 46
Joined: Tue Jan 20, 2015 5:01 pm

PolyList and variable itemHeight to fit text in an item

Post by tomsve » Sun Apr 16, 2023 9:28 pm

I'm trying to use itemPointer to change the itemHeight of an individual item in the PolyList, so it can fit the text in it (they all have a text . However, it seems to change all of the items in the list, not the individual item.

This is the code I use for testing.

Code: Select all

   set the itemPointer of widget "plList" to 1
   set the itemHeight of widget "plList" to 100
Is it even possible? Any ideas?

Thanks and regards.

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: PolyList and variable itemHeight to fit text in an item

Post by SWEdeAndy » Mon Apr 17, 2023 7:41 am

tomsve wrote:
Sun Apr 16, 2023 9:28 pm
Is it even possible?
No, unfortunately not, as far as I know. The PolyList and PolyGrid don't have variable item/row height yet. I think there's an enhancement request in for that. You'll have to use the good old datagrid to get variable row height.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: PolyList and variable itemHeight to fit text in an item

Post by stam » Mon Apr 17, 2023 10:06 am

SWEdeAndy wrote:
Mon Apr 17, 2023 7:41 am
tomsve wrote:
Sun Apr 16, 2023 9:28 pm
Is it even possible?
No, unfortunately not, as far as I know. The PolyList and PolyGrid don't have variable item/row height yet. I think there's an enhancement request in for that. You'll have to use the good old datagrid to get variable row height.
There is much that the venerable DataGrid2 does much better than the newcomers - I just wish it was better encapsulated like PoyList and PolyGrid are, and had the clever multi-column facility of PolyList.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: PolyList and variable itemHeight to fit text in an item

Post by bn » Mon Apr 17, 2023 3:29 pm

Hi Tom,

If all you want is to fit more text into e.g. the top item then you can tweak the Polygrid to show more text without changing the overall appearence too much.

Assume you drag out a new Polylist in the IDE (I am using 9.6.9) and you want to change text in "Title" to accomodate more text than currently fits.
You could change "Title" to multiline and change its height and position.
This affects all items of the polygrid but barely shows.

Use this script to apply the necessary changes(I did not find an easier way)

Code: Select all

on mouseUp
   local tDataLayoutA, tItemContentA
   
   ## change top text item "Title" of standard widget "Polylist" as in IDE (9.6.9)
   
   put the dataLayout of widget 1 into tDataLayoutA
   put 0 into tDataLayoutA[2]["top"]
   put 60 into tDataLayoutA[2]["height"]
   put "text-multiline" into tDataLayoutA[2]["content-type"]
   set the dataLayout of widget 1 to tDataLayoutA
   
   ## change text of first item and set text of "Title"
   set the itemPointer of widget"PolyList" to 1
   put the itemContent of widget"PolyList" into tItemContentA
   
   put "New content" & cr & "new line is much longer than fits" into tItemContentA["title"] ## with cr
   -- put "New content new line is much longer than fits" into tItemContentA["title"] ## auto wrap
   set the itemContent of widget"PolyList" to tItemContentA
   
   ## increase itemHeight slightly to make room for multiline text
   set the itemHeight of widget"PolyList" to 50
end mouseUp
It looks a bit intimidating but that seems to work for small tweaks. (DataGrid is also not the easiest to tweak)

But maybe that is not what you are after then it was a nice exercise in configuring a Polygrid.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: PolyList and variable itemHeight to fit text in an item

Post by bn » Mon Apr 17, 2023 9:11 pm

Hi Tom,

I had a look at the Polygrid using the Properties Inspector. You can set all the paramters I've set via script manually using the Properties Inspector.

Kind regards
Bernd

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: PolyList and variable itemHeight to fit text in an item

Post by marksmithhfx » Tue May 02, 2023 12:04 pm

SWEdeAndy wrote:
Mon Apr 17, 2023 7:41 am
that. You'll have to use the good old datagrid to get variable row height.
Andreas, do you happen to know of a code example that demonstrates how to get variable row height in the data grid? I've been wanting to add that to my Organize app for eons but just didn't know it was possible.

Thanks
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: PolyList and variable itemHeight to fit text in an item

Post by SWEdeAndy » Tue May 02, 2023 12:45 pm

marksmithhfx wrote:
Tue May 02, 2023 12:04 pm
Andreas, do you happen to know of a code example that demonstrates how to get variable row height in the data grid? I've been wanting to add that to my Organize app for eons but just didn't know it was possible.
I seem to remember using a LiveCode lesson on how to make a messenger-type app as a basis, when I needed to make a messenger-type feature once, but I can't find that one now.

But I found this one that might even better suit your needs:
https://lessons.livecode.com/m/datagrid ... ne-heights
(how-do-i-create-a-form-with-variable-line-heights)
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: PolyList and variable itemHeight to fit text in an item

Post by marksmithhfx » Tue May 02, 2023 12:51 pm

SWEdeAndy wrote:
Tue May 02, 2023 12:45 pm
But I found this one that might even better suit your needs:
https://lessons.livecode.com/m/datagrid ... ne-heights
(how-do-i-create-a-form-with-variable-line-heights)
Thanks Andreas for reminding me about this one :oops: I posted about it in the message section of the lesson back in 2020 but never got around to trying it... where does the time fly? (However my procrastination may have a benefit as Elanor added a modification in 2021 which she said may make the process clearer. I hope!!)

Cheers,
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

cealansmith
Posts: 1
Joined: Tue Jul 30, 2024 4:22 am

Re: PolyList and variable itemHeight to fit text in an item

Post by cealansmith » Tue Jul 30, 2024 4:26 am

It looks like using DataGrid might be the best solution for achieving variable row heights. The example provided by Andreas on how to create a form with variable line heights could be quite useful. Has anyone tried this approach recently? Does it work well for dynamically adjusting item heights based on content?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PolyList and variable itemHeight to fit text in an item

Post by Klaus » Tue Jul 30, 2024 9:00 am

DO NOT DELETE THE POST ABOVE YET!
Heather needs to take a look first!

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 161
Joined: Tue Feb 23, 2010 10:53 pm

Re: PolyList and variable itemHeight to fit text in an item

Post by bobcole » Wed Jul 31, 2024 12:47 am

In a DataGrid, creating a field with variable height is fairly easy if you have an example to follow.
The following assumes you have a DataGrid already and just want to make a field to have variable height.

Using the Pointer tool, double click on the DataGrid to bring up the Property Inspector.
Click on the second icon (Data Grid) and then click on the button "Edit Script" of the Row Behavior.
In the code, you will see the LayoutControl handler. The LayoutControl handler is what you need to modify.

I took this code from somewhere else, I don't remember where.
Here is the LayoutControl from my app which has words (in item 1) and their definitions (in item 3).
The field "Definition" is the field I want to have as a variable height.
The constants (+6, -5, etc.) may have to adjusted for your app.

Code: Select all

	
on LayoutControl pControlRect, pWorkingRect
   local theFieldRect
      
   ## Expand the field to fill the available width
   put the rect of field "Definition" of me into theFieldRect
   put item 3 of pControlRect - 5 into item 3 of theFieldRect
   set the rect of field "Definition" of me to theFieldRect
   
   ## Now resize the field to fit its content
   put item 2 of theFieldRect \
         + the formattedheight of field "Definition" of me + 6 \
         - the bottommargin of field "Definition" of me \
         into item 4 of theFieldRect
   set the rect of field "Definition" of me to theFieldRect
   
   ## Now update the bounding rect to match total the height 
   ## you want this row to have (note there is an additional 4 
   ## pixels added to the bottom
   put item 4 of theFieldRect + 4 into item 4 of pControlRect
   
   set the rect of graphic "Background" of me to pControlRect 
end LayoutControl
That is it; it works. Let me know if it doesn't work for you.
Bob

Post Reply