Skip to content

Commit

Permalink
Elide text at the borders of FlatButton
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Feb 9, 2023
1 parent d41062a commit 4b3b0e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/appshell/qml/DevTools/Gallery/GeneralComponentsGallery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,36 @@ Rectangle {
text: "Text with icon"
}

FlatButton {
icon: IconCode.SAVE
text: "Suuuuuuuuuuuuuper long text with icon"
}

FlatButton {
icon: IconCode.SAVE
text: "Elided suuuuuuuuuuuuuper long text with icon"
width: 132
}

FlatButton {
icon: IconCode.SAVE
text: "Text with icon"
orientation: Qt.Horizontal
}

FlatButton {
icon: IconCode.SAVE
text: "Suuuuuuuuuuuuuper long text with icon"
orientation: Qt.Horizontal
}

FlatButton {
icon: IconCode.SAVE
text: "Elided suuuuuuuuuuuuuper long text with icon"
orientation: Qt.Horizontal
width: 132
}

FlatButton {
text: "Just text"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ FocusScope {

objectName: root.text

implicitWidth: contentLoader.implicitWidth + 2 * margins
implicitHeight: Math.max(contentLoader.implicitHeight, ui.theme.defaultButtonSize)
implicitWidth: contentLoader.itemImplicitWidth + 2 * margins
implicitHeight: Math.max(contentLoader.itemImplicitHeight, ui.theme.defaultButtonSize)

opacity: root.enabled ? 1.0 : ui.theme.itemOpacityDisabled

Expand Down Expand Up @@ -176,6 +176,9 @@ FocusScope {
anchors.verticalCenter: parent ? parent.verticalCenter : undefined
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined

readonly property real itemImplicitWidth: item ? item.implicitWidth : 0
readonly property real itemImplicitHeight: item ? item.implicitHeight : 0

sourceComponent: root.contentItem ? root.contentItem : defaultContentComponent
readonly property Component defaultContentComponent: root.isVertical ? verticalContentComponent : horizontalContentComponent
}
Expand All @@ -184,6 +187,7 @@ FocusScope {
id: verticalContentComponent

ColumnLayout {
width: Math.min(implicitWidth, root.width)
spacing: 4

StyledIconLabel {
Expand All @@ -194,6 +198,7 @@ FocusScope {
}

StyledTextLabel {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
text: root.text
font: root.textFont
Expand All @@ -208,6 +213,7 @@ FocusScope {
id: horizontalContentComponent

RowLayout {
width: Math.min(implicitWidth, root.width)
spacing: 8

StyledIconLabel {
Expand All @@ -218,6 +224,7 @@ FocusScope {
}

StyledTextLabel {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
text: root.text
font: root.textFont
Expand Down Expand Up @@ -246,7 +253,7 @@ FocusScope {

PropertyChanges {
target: root
implicitWidth: Math.max(contentLoader.implicitWidth + 2 * root.margins,
implicitWidth: Math.max(contentLoader.itemImplicitWidth + 2 * root.margins,
root.minWidth)
implicitHeight: ui.theme.defaultButtonSize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ Item {
width: titleLoader.width - 8 // 4px padding on each side

text: root.title

onImplicitWidthChanged: {
let i = implicitWidth // workaround for strange binding loop warning
}
}

onClicked: {
Expand Down

0 comments on commit 4b3b0e0

Please sign in to comment.