mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-26 15:50:22 +02:00
tablet-ui: Added sortOrder property to buttons
By default user created buttons will appear after system buttons.
This commit is contained in:
parent
f40285c688
commit
85e01e3922
16 changed files with 57 additions and 16 deletions
|
@ -30,6 +30,24 @@ Item {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortButtons() {
|
||||||
|
var children = [];
|
||||||
|
for (var i = 0; i < flowMain.children.length; i++) {
|
||||||
|
children[i] = flowMain.children[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
children.sort(function (a, b) {
|
||||||
|
if (a.sortOrder === b.sortOrder) {
|
||||||
|
// subsort by stableOrder, because JS sort is not stable in qml.
|
||||||
|
return a.stableOrder - b.stableOrder;
|
||||||
|
} else {
|
||||||
|
return a.sortOrder - b.sortOrder;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
flowMain.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
// called by C++ code when a button should be added to the tablet
|
// called by C++ code when a button should be added to the tablet
|
||||||
function addButtonProxy(properties) {
|
function addButtonProxy(properties) {
|
||||||
var component = Qt.createComponent("TabletButton.qml");
|
var component = Qt.createComponent("TabletButton.qml");
|
||||||
|
@ -42,6 +60,9 @@ Item {
|
||||||
|
|
||||||
// pass a reference to the tabletRoot object to the button.
|
// pass a reference to the tabletRoot object to the button.
|
||||||
button.tabletRoot = parent.parent;
|
button.tabletRoot = parent.parent;
|
||||||
|
|
||||||
|
sortButtons();
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +242,7 @@ Item {
|
||||||
flowMain.children[index].state = state;
|
flowMain.children[index].state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextItem() {
|
function nextItem() {
|
||||||
setCurrentItemState("base state");
|
setCurrentItemState("base state");
|
||||||
var nextColumnIndex = (columnIndex + 3 + 1) % 3;
|
var nextColumnIndex = (columnIndex + 3 + 1) % 3;
|
||||||
|
|
|
@ -11,6 +11,8 @@ Item {
|
||||||
property bool isActive: false
|
property bool isActive: false
|
||||||
property bool inDebugMode: false
|
property bool inDebugMode: false
|
||||||
property bool isEntered: false
|
property bool isEntered: false
|
||||||
|
property double sortOrder: 100
|
||||||
|
property int stableOrder: 0
|
||||||
property var tabletRoot;
|
property var tabletRoot;
|
||||||
width: 129
|
width: 129
|
||||||
height: 129
|
height: 129
|
||||||
|
|
|
@ -388,10 +388,13 @@ QQuickItem* TabletProxy::getQmlMenu() const {
|
||||||
//
|
//
|
||||||
|
|
||||||
const QString UUID_KEY = "uuid";
|
const QString UUID_KEY = "uuid";
|
||||||
|
const QString STABLE_ORDER_KEY = "stableOrder";
|
||||||
|
static int s_stableOrder = 1;
|
||||||
|
|
||||||
TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _properties(properties) {
|
TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) {
|
||||||
// this is used to uniquely identify this button.
|
// this is used to uniquely identify this button.
|
||||||
_properties[UUID_KEY] = _uuid;
|
_properties[UUID_KEY] = _uuid;
|
||||||
|
_properties[STABLE_ORDER_KEY] = _stableOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
|
void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
|
||||||
|
|
|
@ -194,6 +194,7 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QUuid _uuid;
|
QUuid _uuid;
|
||||||
|
int _stableOrder;
|
||||||
mutable std::mutex _mutex;
|
mutable std::mutex _mutex;
|
||||||
QQuickItem* _qmlButton { nullptr };
|
QQuickItem* _qmlButton { nullptr };
|
||||||
QVariantMap _properties;
|
QVariantMap _properties;
|
||||||
|
@ -206,6 +207,7 @@ protected:
|
||||||
* @property {string} activeText - button caption when button is active
|
* @property {string} activeText - button caption when button is active
|
||||||
* @property {string} activeIcon - url to button icon used when button is active. (50 x 50)
|
* @property {string} activeIcon - url to button icon used when button is active. (50 x 50)
|
||||||
* @property {string} isActive - true when button is active.
|
* @property {string} isActive - true when button is active.
|
||||||
|
* @property {number} sortOrder - determines sort order on tablet. lower numbers will appear before larger numbers. default is 100
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif // hifi_TabletScriptingInterface_h
|
#endif // hifi_TabletScriptingInterface_h
|
||||||
|
|
|
@ -177,7 +177,8 @@
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/bubble-i.svg",
|
icon: "icons/tablet-icons/bubble-i.svg",
|
||||||
text: buttonName
|
text: buttonName,
|
||||||
|
sortOrder: 4
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onBubbleToggled();
|
onBubbleToggled();
|
||||||
|
|
|
@ -253,7 +253,8 @@ var toolBar = (function () {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
activeButton = tablet.addButton({
|
activeButton = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/edit-i.svg",
|
icon: "icons/tablet-icons/edit-i.svg",
|
||||||
text: "EDIT"
|
text: "EDIT",
|
||||||
|
sortOrder: 10
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/goto-i.svg",
|
icon: "icons/tablet-icons/goto-i.svg",
|
||||||
text: buttonName
|
text: buttonName,
|
||||||
|
sortOrder: 8
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/help-i.svg",
|
icon: "icons/tablet-icons/help-i.svg",
|
||||||
text: buttonName
|
text: buttonName,
|
||||||
|
sortOrder: 6
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var enabled = false;
|
var enabled = false;
|
||||||
|
|
|
@ -59,7 +59,8 @@ function onHmdChanged(isHmd) {
|
||||||
} else {
|
} else {
|
||||||
button.editProperties({
|
button.editProperties({
|
||||||
icon: "icons/tablet-icons/switch-i.svg",
|
icon: "icons/tablet-icons/switch-i.svg",
|
||||||
text: "VR"
|
text: "VR",
|
||||||
|
sortOrder: 2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
desktopOnlyViews.forEach(function (view) {
|
desktopOnlyViews.forEach(function (view) {
|
||||||
|
@ -82,7 +83,8 @@ if (headset) {
|
||||||
} else {
|
} else {
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/switch-a.svg",
|
icon: "icons/tablet-icons/switch-a.svg",
|
||||||
text: "SWITCH"
|
text: "SWITCH",
|
||||||
|
sortOrder: 2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onHmdChanged(HMD.active);
|
onHmdChanged(HMD.active);
|
||||||
|
|
|
@ -132,7 +132,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
marketplaceButton = tablet.addButton({
|
marketplaceButton = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/market-i.svg",
|
icon: "icons/tablet-icons/market-i.svg",
|
||||||
text: "MARKET"
|
text: "MARKET",
|
||||||
|
sortOrder: 9
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-butt
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/menu-i.svg",
|
icon: "icons/tablet-icons/menu-i.svg",
|
||||||
text: "MENU"
|
text: "MENU",
|
||||||
|
sortOrder: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function onClicked() {
|
function onClicked() {
|
||||||
var entity = HMD.tabletID;
|
var entity = HMD.tabletID;
|
||||||
Entities.editEntity(entity, {textures: JSON.stringify({"tex.close": HOME_BUTTON_TEXTURE})});
|
Entities.editEntity(entity, {textures: JSON.stringify({"tex.close": HOME_BUTTON_TEXTURE})});
|
||||||
|
@ -29,5 +29,5 @@ var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-butt
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
button.clicked.disconnect(onClicked);
|
button.clicked.disconnect(onClicked);
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
})
|
});
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -40,7 +40,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
icon: "icons/tablet-icons/mic-a.svg",
|
icon: "icons/tablet-icons/mic-a.svg",
|
||||||
text: buttonName,
|
text: buttonName,
|
||||||
activeIcon: "icons/tablet-icons/mic-i.svg",
|
activeIcon: "icons/tablet-icons/mic-i.svg",
|
||||||
activeText: "UNMUTE"
|
activeText: "UNMUTE",
|
||||||
|
sortOrder: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onMuteToggled();
|
onMuteToggled();
|
||||||
|
|
|
@ -493,7 +493,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
text: buttonName,
|
text: buttonName,
|
||||||
icon: "icons/tablet-icons/people-i.svg"
|
icon: "icons/tablet-icons/people-i.svg",
|
||||||
|
sortOrder: 7
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var isWired = false;
|
var isWired = false;
|
||||||
|
|
|
@ -36,7 +36,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/snap-i.svg",
|
icon: "icons/tablet-icons/snap-i.svg",
|
||||||
text: buttonName
|
text: buttonName,
|
||||||
|
sortOrder: 5
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
var button = tablet.addButton({
|
var button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/people-i.svg",
|
icon: "icons/tablet-icons/people-i.svg",
|
||||||
text: "Users"
|
text: "USERS",
|
||||||
|
sortOrder: 11
|
||||||
});
|
});
|
||||||
|
|
||||||
function onClicked() {
|
function onClicked() {
|
||||||
|
|
|
@ -33,7 +33,8 @@ if (Settings.getValue("HUDUIEnabled")) {
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/users-i.svg",
|
icon: "icons/tablet-icons/users-i.svg",
|
||||||
text: "USERS",
|
text: "USERS",
|
||||||
isActive: Menu.isOptionChecked(MENU_ITEM)
|
isActive: Menu.isOptionChecked(MENU_ITEM),
|
||||||
|
sortOrder: 11
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue