Accordion Functionality

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

ADSamz
Posts: 1
Joined: Mon Sep 21, 2015 3:20 am

Accordion Functionality

Post by ADSamz » Mon Sep 21, 2015 3:26 am

I'm trying to build in accordion functionality to hide expand/collapse content and reposition the other rows accordingly.

e.g.

Odd Row 1
Even Row 1
Odd Row 2
Even Row 2
Odd Row 3
Even Row 3

I'd like to be able to hide all Even Rows when pushing a button then repositioning the odd rows so that the gaps are filled.
Pushing another button would re-expand the Even Rows (and reposition the Odd Rows accordingly).

Right now, I've been scripting this out row by row but there must be a more efficient way that handles the relationships between odd and even more elegantly.

Any suggestions?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Accordion Functionality

Post by dunbarx » Mon Sep 21, 2015 4:43 am

Hi.

There are many ways to do what you want, and you only have to script whatever action might be appropriate once.

Are these lines in a list field? You are already doing this? Can you say how, in broad terms? If it is a field, any reasonable number of lines would be swapped instantly.

Craig Newman

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Accordion Functionality

Post by AndyP » Mon Sep 21, 2015 9:29 pm

Andy .... LC CLASSIC ROCKS!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Accordion Functionality

Post by dunbarx » Mon Sep 21, 2015 11:22 pm

Try this. On a new card, make a field with your test data in it. Make a button, and put this into its script:

Code: Select all

on mouseEnter
   if the optionkey is down then
      get fld 1
      set the origContents of fld 1 to it
      
      repeat with y = 1 to the number of lines of it
         if y mod 2 = 0 then put line y of it & return after evens
         else put line y of it & return after odds
      end repeat
      set the label of me to "Even" -- or "Odd", if you want, when initializing
      set the evenContents of fld 1 to evens
      set the oddContents of fld 1 to odds
   end if
end mouseEnter

on mouseUp
      if the label of me = "Even" then
         set the label of me to "Odd"
         set the text of of fld 1 to the evenContents of fld 1
      else
         set the label of me to "Even"
         set the text of of fld 1 to the oddContents of fld 1
      end if
end mouseUp
There is an initialization required, and I did this with the optionKey gadget. The full contents of the field are stored in a custom property of the field, as well as the even and odd rows in their own custom properties. When you simply click on the button (no optionKey anymore), the two dataSets are alternately loaded. You can always get the original contents back if you need them.

Is that what you were after?

Craig

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Accordion Functionality

Post by strongbow » Sun Nov 10, 2024 4:40 am

Has anyone seen this: https://livecode.com/elements-accordion/

and if/which LC version it might be in??

cheers

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Accordion Functionality

Post by richmond62 » Sun Nov 10, 2024 10:33 am

hide expand/collapse content and reposition the other rows accordingly
I feel that some information was left out there: do you mean in a scrolling list field?

This: https://livecode.com/elements-accordion/

looks like something a bit different as each EXPANDED section is larger than 'just' another line.

AND it is frankly of very little use indeed as it does NOT show how to do that. :?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Accordion Functionality

Post by richmond62 » Sun Nov 10, 2024 11:24 am

Screenshot 2024-11-10 at 12.22.36.png
-
I yaised that prayer no as onie proselytisan effort, mair as an unco shairt text:

"The Lord's Prayer, is the maist kenspeckle prayer in the Christian releegion. It is kent as the Oor Faither an aw (frae the first twa wirds o the prayer) or Pater noster (the Laitin for "Oor Faither")."

https://sco.wikipedia.org/wiki/Lord%27s_Prayer

but I yaised the Inglis vairtie forbye.
Attachments
Squeeze Box.livecode.zip
Stack.
(1.73 KiB) Downloaded 413 times
Last edited by richmond62 on Sun Nov 10, 2024 11:48 am, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Accordion Functionality

Post by richmond62 » Sun Nov 10, 2024 11:42 am

Screenshot 2024-11-10 at 12.38.52.png
-

Code: Select all

on mouseUp
   put empty into fld "F2"
   put 1 into LYNE
   repeat until line LYNE of fld "F1" is empty
      put ((line LYNE of fld "F1") & cr ) after fld "F2"
      add 2 to LYNE
   end repeat
end mouseUp
Of course if you want to make that appear in the same field you'll need to store your original data in either a 'shadow' field (i.e. one your end-user won't see) or some sort of variable/array.
Attachments
Button Box.livecode.zip
Stack.
(1.2 KiB) Downloaded 557 times

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

Re: Accordion Functionality

Post by bn » Sun Nov 10, 2024 6:02 pm

how about:

to hide even numbered lines:

Code: Select all

on mouseUp
   repeat with i = 1 to the number of lines of field 1
      if i mod 2 is 0 then 
         set the hidden of line i of field 1 to true
      end if
   end repeat
end mouseUp
to show all:

Code: Select all

on mouseUp
   set the hidden of line 1 to -1 of field 1 to false
end mouseUp
Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Accordion Functionality

Post by richmond62 » Sun Nov 10, 2024 8:02 pm

OK: as usual Bernd, you come up with the clever stuff . . . BUT:

AHA:

Code: Select all

on mouseUp
   repeat with i = 1 to the number of lines of field "F1"
         set the hidden of line i of field "F1" to false
   end repeat
end mouseUp
I really should apologise as Jimmy Shand's bespoke accordion was a Hohner Morino with an 'o'. :wink:

https://youtu.be/-14L7wDwuGc
Attachments
Shand Merino.livecode.zip
Stack.
(1.17 KiB) Downloaded 506 times
Last edited by richmond62 on Sun Nov 10, 2024 10:54 pm, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Accordion Functionality

Post by jacque » Sun Nov 10, 2024 10:23 pm

strongbow wrote:
Sun Nov 10, 2024 4:40 am
Has anyone seen this: https://livecode.com/elements-accordion/

and if/which LC version it might be in??

cheers
That looks like the Tree View widget. I'm not sure if it is included in all license types but it is an older widget that's been available for a long time.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Accordion Functionality

Post by strongbow » Mon Nov 11, 2024 12:11 am

Hmm, thanks Jacque, hadn't thought about styling the tree view, must have a look!

cheers!

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

Re: Accordion Functionality

Post by bn » Mon Nov 25, 2024 3:32 pm

strongbow wrote:
Sun Nov 10, 2024 4:40 am
Has anyone seen this: https://livecode.com/elements-accordion/

and if/which LC version it might be in??
Hi Alan
I could not find a widget or anything in LC that resembles the Accordion you linked to.

So I decided to build one:

viewtopic.php?f=9&t=39452

Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Accordion Functionality

Post by richmond62 » Mon Nov 25, 2024 3:57 pm

I could not find a widget or anything in LC that resembles the Accordion you linked to.
Maybe LiveCode central would like to tell us where it might be found.

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Accordion Functionality

Post by strongbow » Mon Nov 25, 2024 9:56 pm

[quote=bn post_id=232624 time=1732545171 user_id=1486]
...
So I decided to build one:

viewtopic.php?f=9&t=39452

Kind regards
Bernd
[/quote]

Very nice Bernd, as usual, thanks! :-)

Since you asked about other functionality...:

1. perhaps it'd be nice to be able to expand more than one segment at a time?
2. Could it perhaps deal with any sort of grouped objects as an accordion segment? e.g. if you wanted to place fields + buttons + other controls into one of the groups to show/hide as desired?

Thanks again for your many contributions!!

Post Reply