/*******************************************************************************
This file is part of the Shellfish UI toolkit.
Copyright (c) 2023 - 2024 Martin Grimme <martin.grimme@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************************************/
require "shellfish/ui";
/**
* Element representing an expandable menu item with sub menu items. This is an
* alternative to using a regular sub menu and is more suitable for touch screen
* navigation.
*
* @memberof ui
* @name MenuExpander
* @class
* @extends ui.MenuItem
*/
MenuItem {
id: item
container default: contentArea
function collapse()
{
contentArea.visible = false;
}
icon: contentArea.visible ? "core-arrow_down" : "core-arrow_right"
highlighted: (selected || menuOpened) && ! contentArea.visible
height: theme.itemHeightMedium + contentArea.bboxHeight
onClick: ev =>
{
ev.accepted = true;
parent.children().forEach(child =>
{
if (child !== self && child.collapse)
{
child.collapse();
}
});
contentArea.visible = ! contentArea.visible;
}
Box {
position: "free"
width: 2
fillHeight: true
color: theme.primaryColor
}
MouseBox {
id: contentArea
visible: false
fillWidth: true
marginLeft: 2
color: theme.secondaryBackgroundColor
onPointerDown: ev => { ev.accepted = true; }
onClick: ev =>
{
ev.accepted = true;
thisMenu.close();
}
}
}