Page 1 of 2
Accordion Functionality
Posted: Mon Sep 21, 2015 3:26 am
by ADSamz
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?
Re: Accordion Functionality
Posted: Mon Sep 21, 2015 4:43 am
by dunbarx
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
Re: Accordion Functionality
Posted: Mon Sep 21, 2015 9:29 pm
by AndyP
Re: Accordion Functionality
Posted: Mon Sep 21, 2015 11:22 pm
by dunbarx
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
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 4:40 am
by strongbow
Has anyone seen this:
https://livecode.com/elements-accordion/
and if/which LC version it might be in??
cheers
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 10:33 am
by richmond62
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.

Re: Accordion Functionality
Posted: Sun Nov 10, 2024 11:24 am
by richmond62
-
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.
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 11:42 am
by richmond62
-
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.
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 6:02 pm
by bn
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
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 8:02 pm
by richmond62
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'.
https://youtu.be/-14L7wDwuGc
Re: Accordion Functionality
Posted: Sun Nov 10, 2024 10:23 pm
by jacque
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.
Re: Accordion Functionality
Posted: Mon Nov 11, 2024 12:11 am
by strongbow
Hmm, thanks Jacque, hadn't thought about styling the tree view, must have a look!
cheers!
Re: Accordion Functionality
Posted: Mon Nov 25, 2024 3:32 pm
by bn
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
Re: Accordion Functionality
Posted: Mon Nov 25, 2024 3:57 pm
by richmond62
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.
Re: Accordion Functionality
Posted: Mon Nov 25, 2024 9:56 pm
by strongbow
[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!!