Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

2.1 KB
Raw Blame
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import app.nectarlink

// A settings-style row: optional icon, title and description, and a
// trailing control placed in `trailing`.
Item {
    id: row
    property string iconPath
    property string title
    property string description
    property bool stackBelow: false
    default property alias trailing: trailingSlot.data

    readonly property bool stackTrailing: stackBelow || (trailingSlot.childrenRect.width > row.width * 0.52 && row.width > 0)

    implicitHeight: stackTrailing
        ? texts.implicitHeight + trailingSlot.childrenRect.height + 34
        : Math.max(56, texts.implicitHeight + 20, trailingSlot.childrenRect.height + 16)

    Icon {
        id: icon
        visible: row.iconPath.length > 0
        anchors.left: parent.left
        anchors.verticalCenter: row.stackTrailing ? texts.verticalCenter : parent.verticalCenter
        path: row.iconPath
        color: Theme.surfaceContentVariant
    }
    Column {
        id: texts
        anchors.left: icon.visible ? icon.right : parent.left
        anchors.leftMargin: icon.visible ? 14 : 0
        anchors.right: row.stackTrailing ? parent.right : trailingSlot.left
        anchors.rightMargin: row.stackTrailing ? 0 : 16
        y: row.stackTrailing ? 12 : Math.round((row.height - height) / 2)
        spacing: 2
        Txt {
            width: parent.width
            text: row.title
            role: "title"
            size: 14
            wrapMode: Text.WordWrap
            elide: Text.ElideNone
        }
        Txt {
            visible: row.description.length > 0
            width: parent.width
            text: row.description
            role: "bodySmall"
            muted: true
            wrapMode: Text.WordWrap
            elide: Text.ElideNone
        }
    }
    Item {
        id: trailingSlot
        anchors.left: row.stackTrailing ? texts.left : undefined
        anchors.right: row.stackTrailing ? undefined : parent.right
        y: row.stackTrailing ? (texts.y + texts.implicitHeight + 10) : Math.round((row.height - height) / 2)
        width: childrenRect.width
        height: childrenRect.height
    }
}