lez-programs/apps/amm/qml/NavBar.qml
2026-07-17 20:59:00 -03:00

116 lines
3.7 KiB
QML

import QtQuick 2.15
import Logos.Theme
import Logos.Wallet
// Self-contained navigation bar — styling is independent of any view's theme.
// Use currentIndex to read the active tab; tabChanged(index) fires on selection.
Item {
id: root
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
property var accountModel: null
// Address of the account currently selected in the header control.
readonly property string selectedAddress: accountControl.selectedAddress
signal tabChanged(int index)
implicitHeight: 56
Rectangle {
anchors.fill: parent
color: Theme.palette.background
// Bottom separator
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 1
color: Theme.palette.borderSecondary
}
// 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
Repeater {
model: root.tabs
delegate: Rectangle {
required property int index
required property string modelData
readonly property bool active: root.currentIndex === index
objectName: "navTab" + index
height: 36
width: tabLabel.implicitWidth + (root.compactLayout ? 16 : 28)
radius: 18
color: active ? Theme.palette.backgroundSecondary : "transparent"
Behavior on color { ColorAnimation { duration: 150 } }
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 } }
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
root.currentIndex = index
root.tabChanged(index)
}
}
}
}
}
// 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)
}
}
}
}