C

Qt Quick Ultralite swipe_game Demo

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

import QtQuick 2.0
import StyleModule 1.0

/*
    A simple button with text.
    If not overwritten, the button adjusts its width to the length of the text
*/

MouseArea {
    id: root

    // NOTE: overwrite the Style value assignments if you want to use the component outside of this project

    property color borderColor: pressed ? Style.colorHighlight : Style.colorLines
    property int borderWidth: Style.lineSize
    property color backgroundColor: Style.colorButtonBackground
    property int radius: Style.buttonRadius
    property color textColor: Style.colorText
    property alias font: label.font
    property alias text: label.text

    implicitHeight: Style.buttonHeight
    implicitWidth: Math.max(height * 2, label.width + Style.buttonTextMargins * 2)

    Rectangle {
        id: border

        anchors.fill: parent

        radius: root.radius
        color: root.borderColor

        Rectangle {
            id: background

            anchors.fill: parent
            anchors.margins: root.borderWidth

            radius: root.radius
            color: root.backgroundColor

            Text {
                id: label

                anchors.centerIn: parent
                color: root.textColor
            }
        }
    }
}