Adds an accordion or expansion panel into your app.
This is very useful to display controls that are grouped together.
Properties
These are the setter and getter properties for the addAccordion Component.
Example - Complete accordion implementation
class Main extends App
{
onStart()
{
this.main = ui.addLayout( "main", "Linear", "VCenter", 1, 1 )
this.accords = [ "Accordion 1", "Accordion 2", "Accordion 3" ]
this.acc = ui.addAccordion( this.main, this.accords, "", 0.9 )
var secTxt = [
"This is the secondary text 1",
"This is the secondary text 2",
"This is the secondary text 3"
]
this.acc.setSecondaryText( secTxt )
this.acc.setOnTouch( this.onTouch )
this.lay1 = this.acc.getLayout( 0 )
this.txt = ui.addText(this.lay1, "This is a text in the first layout.")
this.lay2 = this.acc.getLayout( 1 )
this.btn = ui.addButton(this.lay2, "Button", "Primary")
this.lay3 = this.acc.getLayout( 2 )
this.tfd = ui.addTextField(this.lay3, "", "Outlined", 0.3)
this.tfd.label = "Enter some text"
}
onTouch(index, expand)
{
var msg = `${this.accords[index]} is ${expand ? "open" : "close"}`
ui.showPopup( msg )
}
}
from hybrid import ui
def OnStart():
global accords
main = ui.addLayout("main", "Linear", "VCenter", 1, 1)
accords = ["Accordion 1", "Accordion 2", "Accordion 3"]
acc = ui.addAccordion(main, accords, "", 0.9)
secTxt = [
"This is the secondary text 1",
"This is the secondary text 2",
"This is the secondary text 3"
]
acc.setSecondaryText(secTxt)
acc.setOnTouch(onTouch)
lay1 = acc.getLayout(0)
txt = ui.addText(lay1, "This is a text in the first layout.")
lay2 = acc.getLayout(1)
btn = ui.addButton(lay2, "Button", "Primary")
lay3 = acc.getLayout(2)
tfd = ui.addTextField(lay3, "", "Outlined", 0.3)
tfd.label = "Enter some text"
def onTouch(index, expand):
msg = f"{accords[index]} is {'open' if expand else 'close'}"
ui.showPopup(msg)
Example - Items manipulation
class Main extends App
{
onStart()
{
this.count = 1;
this.main = ui.addLayout( "main", "Linear", "VCenter", 1, 1 )
this.main.setChildMargins(0, 0.01, 0, 0.01)
var accords = [ "Accordion 1", "Accordion 2", "Accordion 3" ]
this.acc = ui.addAccordion( this.main, accords, "", 0.9 )
this.lay = ui.addLayout(this.main, "Linear", "Horizontal", 0.9)
this.lay.childSpacing = "evenly"
this.btn1 = ui.addButton( this.lay, "Append Item" )
this.btn1.setOnTouch( this.btn1_onTouch )
this.btn2 = ui.addButton( this.lay, "Add Item in index 1" )
this.btn2.setOnTouch( this.btn2_onTouch )
this.btn3 = ui.addButton( this.lay, "Remove Item" )
this.btn3.setOnTouch( this.btn3_onTouch )
}
btn1_onTouch()
{
this.acc.addItem( "New Bottom Title", "New secondary text" )
}
btn2_onTouch()
{
var title = "New Title " + this.count++
this.acc.addItem( title, "New secondary text", 1 )
}
btn3_onTouch()
{
this.acc.removeItemByIndex( 2 )
ui.showPopup( "Second item is removed" )
}
}
from hybrid import ui
def OnStart():
global acc, count
count = 1
main = ui.addLayout("main", "Linear", "VCenter", 1, 1)
main.setChildMargins(0, 0.01, 0, 0.01)
accords = ["Accordion 1", "Accordion 2", "Accordion 3"]
acc = ui.addAccordion(main, accords, "", 0.9)
lay = ui.addLayout(main, "Linear", "Horizontal", 0.9)
lay.childSpacing = "evenly"
btn1 = ui.addButton(lay, "Append Item")
btn1.setOnTouch(btn1_onTouch)
btn2 = ui.addButton(lay, "Add Item in index 1")
btn2.setOnTouch(btn2_onTouch)
btn3 = ui.addButton(lay, "Remove Item")
btn3.setOnTouch(btn3_onTouch)
def btn1_onTouch(event):
acc.addItem("New Bottom Title", "New secondary text")
def btn2_onTouch(event):
title = "New Title " + str(count)
acc.addItem(title, "New secondary text", 1)
count += 1
def btn3_onTouch(event):
acc.removeItemByIndex(2)
ui.showPopup("Second item is removed")
Example - Custom styles
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter")
var items = ["Accordion 1", "Accordion 2", "Accordion 3"]
var texts = ["Description for item 1", "Description for item 2", "Description for item 3"];
this.acc = ui.addAccordion(this.main, items, "", 0.9)
this.acc.setSecondaryText( texts )
this.acc.backColor = "#b2dfdb"
this.acc.textSize1 = 18
this.acc.textSize2 = 14
this.acc.textColor1 = "#00695c"
this.acc.textColor2 = "#009688"
this.acc.cornerRadius = 14
this.acc.expandIcon = "favorite"
}
}
from hybrid import ui
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter")
items = ["Accordion 1", "Accordion 2", "Accordion 3"]
texts = ["Description for item 1", "Description for item 2", "Description for item 3"]
acc = ui.addAccordion(main, items, "", 0.9)
acc.setSecondaryText(texts)
acc.backColor = "#b2dfdb"
acc.textSize1 = 18
acc.textSize2 = 14
acc.textColor1 = "#00695c"
acc.textColor2 = "#009688"
acc.cornerRadius = 14
acc.expandIcon = "favorite"
Methods
The following methods are available on the Accordion object:
Boolean: Values can be `true` or `false`.
Boolean: Sets or returns whether the accordion is disabled or not. True only if all accordion is disable, otherwise false.
Boolean: Returns whether the control is visible or not.
Boolean: Sets or returns whether the accordion is rounded or not.
Number: Fraction of the screen width: [0-1]
Number: Fraction of the screen height. [0-1]
Number: The index at which the accordion item will be added. If `null`, the item will be added at the bottom of the accordion.
Number: The time in milliseconds.
Number: The z-index. A negative value behaves like `sendBackward` method.
Number: The index of the accordion item.
Number: The index of the accordion. You can also pass accordion title.
Number: The index of the corresponding accordion to remove.
Number: The z-index. A positve value behaves like `bringForward` method.
Number: Border-left thickness in pixels.
Number: Top-left corner radius.
Number: Top-right corner radius.
Number: Bottom-left corner radius.
Number: Bottom-right corner radius.
Number: The index of the corresponding accordion.
Number: Fraction of the parent width.
Number: Fraction of the parent height.
Number: Fraction of the component width.
Number: Fraction of the component height. [0-1]
Number: Fraction of the component width. [0-1]
Number: Fraction of the parent width. [0-1]
Number: The x-scale of the component.Values less than `0` is smaller than the normal. While values greater than `1` is greater than the normal.
Number: The y-scale of the component. Values less than `1` is smaller than the normal. While vaues greater than `1` is greater than the normal.
Number: If `index` is provided, the corresponding index will be updated with the new text.
Number: Fraction of the parent height. [0-1]
Number: The index of the corresponding title to updates.
Number: Returns the absolute height of the control in pixels.
Number: Returns the absolute distance of the control from the left in pixels.
Number: Returns the absolute distance of the control from the top in pixels.
Number: Returns the absolute width of the control in pixels.
Number: Sets or returns the border thickness in pixels.
Number: Sets or returns the corner radius of the accordion panel. You can also pass an array of the form [tl, tr, bl, br]. See also setCornerRadius method.
Number: Sets or returns the height of the control as a fraction of the parent control.
Number: Returns the distance of the control from the left.
Number: Sets or returns the opacity of the control.
Number: Sets or returns the angle of rotation in degrees.
Number: Sets or returns the size of the text within the control.
Number: Sets or returns the accordion title text size.
Number: Sets or returns the accordion secondary text size.
Number: Sets and returns the width of the title as fraction. Useful when you have a long title.
Number: Collapse or shrink a corresponding accordion by its index.
Number: Returns the distance of the control from the top.
Number: Sets or returns the width of the control as a fraction of the parent control.
String: comma “,” separated: “one or a combination of the following: `Square`
`Layout type `Linear` or `Absolute`”
String: “Accordion title”
String: “Accordion secondary text”
String: “The type of animation. Here are the available values
`bounce` `flash` `pulse` `rubberBand` `shakeX` `shakeY` `headShake` `swing` `tada` `wobble` `jello` `heartBeat`
`Back Entrances `backInDown` `backInLeft` `backInRight` `backInUp`
`Back Exits `backOutDown` `backOutLeft` `backOutRight` `backOutUp`
`Bouncing Entrances `bounceIn` `bounceInDown` `bounceInLeft` `bounceInRight` `bounceInUp`
`Bouncing exits `bounceOut` `bounceOutDown` `bounceOutLeft` `bounceOutRight` `bounceOutUp`
`Fading entrances `fadeIn` `fadeInDown` `fadeInDownBig` `fadeInLeft` `fadeInLeftBig` `fadeInRight` `fadeInRightBig` `fadeInUp` `fadeInUpBig` `fadeInTopLeft` `fadeInTopRight` `fadeInBottomLeft` `fadeInBottomRight`
`Fading exits `fadeOut` `fadeOutDown` `fadeOutDownBig` `fadeOutLeft` `fadeOutLeftBig` `fadeOutRight` `fadeOutRightBig` `fadeOutUp` `fadeOutUpBig` `fadeOutTopLeft` `fadeOutTopRight` `fadeOutBottomRight` `fadeOutBottomLeft`
`Flippers `flip` `flipInX` `flipInY` `flipOutX` `flipOutY`
`Lightspeed `lightSpeedInRight` `lightSpeedInLeft` `lightSpeedOutRight` `lightSpeedOutLeft`
`Rotating Entrances `rotateIn` `rotateInDownLeft` `rotateInDownRight` `rotateInUpLeft` `rotateInUpRight`
`Rotating Exits `rotateOut` `rotateOutDownLeft` `rotateOutDownRight` `rotateOutUpLeft` `rotateOutUpRight`
`Specials `hinge` `jackInTheBox` `rollIn` `rollOut`
`Zooming Entrances `zoomIn` `zoomInDown` `zoomInLeft` `zoomInRight` `zoomInUp`
`Zooming Exits `zoomOut` `zoomOutDown` `zoomOutLeft` `zoomOutRight` `zoomOutUp`
`Sliding Entrances `slideInDown` `slideInLeft` `slideInRight` `slideInUp`
`Sliding Exits `slideOutDown` `slideOutLeft` `slideOutRight` `slideOutUp`.”
String: “The title of the accordion.”
String: “The mode of the measurements. Values can be `px` or `%`”
String: “The title of the corresponding accordion to remove.”
String: “Border color in hexadecimal form `#rrggbb`”
String: “Border-styles. Values can be `dotted` `dashed` `solid` `double` `groove` `ridge` `inset` and `outset`. Default is `solid`”
String: “Unit. Values are `px` `rem` or `%`.”
String: “The title of the accordion”
String: “A material icon”
String: “`px` or `%`”
String: “The size thickness mode. Can be `px`”
String: “Unit of measurement. Can be `px` or `%` or any css unit of measurement.”
String: “Color of the title text in hexadecimal format `#rrggbb`”
String: “Color of the secondary text in hexadecimal format `#rrggbb`”
String: “The new title text.”
String: A hexadecimal color of the form #rrggbb
String: The path to your image file.
String: Sets or returns the border color. Color is in hexadecimal form #rrggbb
String: Sets or returns the border style. Values can be dotted, dashed, solid, double, groove, ridge, inset and outset. Default is solid.
String: Sets or returns the material icon font for the expand icon.
String: Sets or returns the relative path to the font-family use.
String: Sets or returns the options of the control.
String: Sets or returns the color of the text.
String: Sets or returns the title text color in hexadecimal format #rrggbb
String: Sets or returns the secondary text color in hexadecimal format #rrggbb
String: Returns the type of the control.
String: Sets or returns the visibility of the control.
Object: The parent layout where to add the text.
Object: An array of accordion titles.
Object: The layout to check.
Object: The pointer event object.
Object: The secondary text to display. You can pass arguments as string or array by following the format below.
String: `"Secodary text 1,Secondary text 2,Secondary text 3"`
`Array`: `[ "Secondary text 1", "Secondary text 2", "Secondary text 3" ]`
Object: Returns the parent layout control.
Object: Returns the position of the control. The returned object has left top right and bottom props.
List: Sets or returns the padding of each accordion item. See also setItemPadding method.
List: Sets or returns the margin of the control. Works on controls with Linear parent only. You can also pass a number to set equal margins for all sides.
List: Sets or returns the padding of the control. You can also pass a number to set equal padding for all sides.
List: Sets or returns the secondary text of the accordion items. See also setSecondaryText method.
List: Sets or returns the list of titles for the accordion panel. Each element of the titles array is a string.
function(
title,
index,
event
)
function(
index,
expand
)
acc.addItem
Adds an item to the accordion
acc.animate
Animate the component
acc.bringForward
Bring this component forward by a given z-index
acc.destroy
Destroy the component
acc.getEnabled
Get the enabled state of an accordion item by its index
acc.getEnabledByName
Get the enabled state of an accordion item by its name
acc.getLayout
Get the layout of the corresponding accordion item. This is very useful when you add a control or component that will be displayed when the accordion collapse
acc.getLayoutIndex
Get the index of the corresponding layout
acc.getPosition
Returns the position of the component. The return object is of the form `{ left, top, right, bottom
acc.gone
Destroy the component
acc.hide
Hide the component
acc.popItem
Removes the last accordion item
acc.removeItemByIndex
Removes accordion item by its index
acc.removeItemByName
Removes accordion item by its title name
acc.sendBackward
Bring this component backward by a given z-index
acc.setBorder
Sets the border line for the component container
acc.setCornerRadius
Sets the corner radius of the top and bottom accordion panels
acc.setEnabled
Enable or disable the accordion component or an item in the accordion component
acc.setEnabledByName
Enable or disable an accordion item by its name
acc.setExpandIcon
Sets the expand icon at the right of the accordion
acc.setMargins
Sets the margin of the component
acc.setOnContextMenu
Adds a callback function on right click
acc.setOnTouch
Sets a callback function when the accordion is touch
acc.setPadding
Sets the padding component container
acc.setPosition
Sets the position of the component relative to its parent dimensions
acc.setScale
Sets the x and y scaling of the component
acc.setSecondaryText
Adds a secondary text on the accordion
acc.setSize
Sets the size of the component
acc.setTextColor
Sets the color of the title and the secondary text respectively
acc.setTitleText
Update the accordion title by passing its corresponding index
acc.shiftItem
Removes the first accordion item
acc.show
Show the component