Source: shellfish-ui/ui/WindowTitle.shui

shellfish-ui/ui/WindowTitle.shui

/*******************************************************************************
This file is part of the Shellfish UI toolkit.
Copyright (c) 2021 - 2024 Martin Grimme <martin.grimme@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************************************/

require "shellfish/ui";

/**
 * Element representing a standard titlebar for Window elements.
 *
 * @memberof ui
 * @name WindowTitle
 * @class
 * @extends html.Box
 *
 * @property {string} icon - (default: `""`) The icon name of the window icon.
 * @property {bool} showClose - (default: `true`) If `true`, the close button is shown.
 * @property {bool} showMaximize - (default: `true`) If `true`, the maximize button is shown.
 * @property {bool} showMinimize - (default: `true`) If `true`, the minimize button is shown.
 * @property {ui.Window} target - (default: parent window) The target window to modify.
 * @property {string} text - (default: `""`) The window title.
 */
Box {
    id: titlebar

    property target: parent.parent

    property icon: ""
    property text: ""
    property showMinimize: true
    property showMaximize: true
    property showClose: true

    /**
     * Is triggered when the user pressed the minimize button.
     * @memberof ui.WindowTitle.prototype
     * @name minimize
     * @event
     */
    event minimize
    /**
     * Is triggered when the user pressed the close button.
     * @memberof ui.WindowTitle.prototype
     * @name close
     * @event
     */
    event close

    fillWidth: true
    height: theme.itemHeightMedium
    color: target.selected ? theme.highlightBackgroundColor
                           : theme.secondaryBackgroundColor

    Object {
        id: buttonProfile
        property color: target.selected ? theme.highlightColor
                                        : theme.primaryColor
    }

    Box {
        position: "free"
        fill: true
        layout: "center-row"

        Label {
            visible: titlebar.icon !== ""
            marginLeft: theme.paddingSmall
            color: target.selected ? theme.highlightColor
                                : theme.primaryColor
            text: "[icon:" + titlebar.icon + "]"
        }

        Label {
            marginLeft: theme.paddingSmall
            fillWidth: true
            overflowBehavior: "ellipsis"
            color: target.selected ? theme.highlightColor
                                : theme.primaryColor
            text: titlebar.text
        }

        Button {
            visible: titlebar.showMinimize
            labelProfile: buttonProfile
            width: bboxHeight
            fillHeight: true
            flat: true
            icon: "core-window-minimize"

            onPointerDown: (ev) => { ev.accepted = true; }

            onClick: (ev) =>
            {
                titlebar.minimize();
                ev.accepted = true;
            }
        }

        Button {
            visible: titlebar.showMaximize && target.resizable
            labelProfile: buttonProfile
            width: bboxHeight
            fillHeight: true
            flat: true
            icon: "core-window-maximize"

            onPointerDown: (ev) => { ev.accepted = true; }

            onClick: (ev) =>
            {
                target.maximized = ! target.maximized;
                ev.accepted = true;
            }
        }

        Button {
            visible: titlebar.showClose
            labelProfile: buttonProfile
            width: bboxHeight
            fillHeight: true
            flat: true
            icon: "core-window-close"

            onPointerDown: (ev) => { ev.accepted = true; }

            onClick: (ev) =>
            {
                titlebar.close();
                ev.accepted = true;
            }
        }
    }


}