From f704ab6a454b8d70079964dcc0f10dce87e61db3 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Fri, 17 Jul 2026 20:59:00 -0300 Subject: [PATCH] fix(amm): contain compact navbar controls --- apps/amm/qml/NavBar.qml | 115 ++++++++++++++++-------------- apps/amm/tests/qml/tst_NavBar.qml | 49 +++++++++++++ 2 files changed, 110 insertions(+), 54 deletions(-) create mode 100644 apps/amm/tests/qml/tst_NavBar.qml diff --git a/apps/amm/qml/NavBar.qml b/apps/amm/qml/NavBar.qml index 3c06f91..1501f0a 100644 --- a/apps/amm/qml/NavBar.qml +++ b/apps/amm/qml/NavBar.qml @@ -1,6 +1,4 @@ import QtQuick 2.15 -import QtQuick.Layouts 1.15 - import Logos.Theme import Logos.Wallet @@ -11,6 +9,7 @@ Item { property int currentIndex: 0 readonly property var tabs: ["Trade", "Liquidity"] + readonly property bool compactLayout: width < 480 // Wallet wiring, passed down from Main.qml. property var backend: null @@ -36,72 +35,80 @@ Item { color: Theme.palette.borderSecondary } - RowLayout { - anchors.fill: parent - anchors.leftMargin: 20 - anchors.rightMargin: 20 + // App identity + Text { + id: appTitle + + objectName: "navAppTitle" + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.verticalCenter: parent.verticalCenter + visible: root.width >= 600 + text: "Logos AMM" + color: Theme.palette.text + font.pixelSize: 17 + font.weight: Font.Bold + } + + // Tab pills stay centered independently of title and wallet widths. + Row { + anchors.centerIn: parent spacing: 4 - // App identity - Text { - text: "Logos AMM" - color: Theme.palette.text - font.pixelSize: 17 - font.weight: Font.Bold - } + Repeater { + model: root.tabs - Item { Layout.fillWidth: true } + delegate: Rectangle { + required property int index + required property string modelData + readonly property bool active: root.currentIndex === index - // Tab pills - Row { - spacing: 4 + objectName: "navTab" + index + height: 36 + width: tabLabel.implicitWidth + (root.compactLayout ? 16 : 28) + radius: 18 + color: active ? Theme.palette.backgroundSecondary : "transparent" - Repeater { - model: root.tabs + Behavior on color { ColorAnimation { duration: 150 } } - delegate: Rectangle { - readonly property bool active: root.currentIndex === index - - height: 36 - width: tabLabel.implicitWidth + 28 - radius: 18 - color: active ? Theme.palette.backgroundSecondary : "transparent" + Text { + id: tabLabel + anchors.centerIn: parent + text: modelData + color: active ? Theme.palette.text : Theme.palette.textSecondary + font.pixelSize: root.compactLayout ? 13 : 14 + font.weight: active ? Font.Medium : Font.Normal Behavior on color { ColorAnimation { duration: 150 } } + } - Text { - id: tabLabel - anchors.centerIn: parent - text: modelData - color: active ? Theme.palette.text : Theme.palette.textSecondary - font.pixelSize: 14 - font.weight: active ? Font.Medium : Font.Normal - - Behavior on color { ColorAnimation { duration: 150 } } - } - - MouseArea { - anchors.fill: parent - cursorShape: Qt.PointingHandCursor - onClicked: { - root.currentIndex = index - root.tabChanged(index) - } + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: { + root.currentIndex = index + root.tabChanged(index) } } } } + } - // Wallet / account control on the far right. - WalletControl { - id: accountControl - Layout.leftMargin: 12 - wallet: root.backend - accountModel: root.accountModel - viewportWidth: root.width - watchCall: function(result, success, failure) { - logos.watch(result, success, failure) - } + // Wallet / account control on the far right. + WalletControl { + id: accountControl + + anchors.right: parent.right + anchors.rightMargin: root.compactLayout ? 8 : 20 + anchors.verticalCenter: parent.verticalCenter + width: implicitWidth + height: implicitHeight + compact: root.compactLayout + wallet: root.backend + accountModel: root.accountModel + viewportWidth: root.width + watchCall: function(result, success, failure) { + logos.watch(result, success, failure) } } } diff --git a/apps/amm/tests/qml/tst_NavBar.qml b/apps/amm/tests/qml/tst_NavBar.qml new file mode 100644 index 0000000..385c779 --- /dev/null +++ b/apps/amm/tests/qml/tst_NavBar.qml @@ -0,0 +1,49 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import QtTest + +import "../../qml" as Amm + +Item { + id: root + + width: 320 + height: 56 + + Component { + id: navComponent + + Amm.NavBar { + width: root.width + height: root.height + } + } + + TestCase { + name: "NavBar" + when: windowShown + + function test_compactControlsStayInsideViewport() { + const nav = createTemporaryObject(navComponent, root) + verify(nav) + const trade = findChild(nav, "navTab0") + const liquidity = findChild(nav, "navTab1") + const wallet = findChild(nav, "walletConnectButton") + verify(trade) + verify(liquidity) + verify(wallet) + + const controls = [trade, liquidity, wallet] + for (let index = 0; index < controls.length; ++index) { + const position = controls[index].mapToItem(nav, 0, 0) + verify(position.x >= 0) + verify(position.x + controls[index].width <= nav.width) + } + verify(trade.mapToItem(nav, trade.width, 0).x + <= liquidity.mapToItem(nav, 0, 0).x) + verify(liquidity.mapToItem(nav, liquidity.width, 0).x + <= wallet.mapToItem(nav, 0, 0).x) + } + } +}