forked from Shinonome/dots-hyprland
left sidebar: bouncy command buttons
This commit is contained in:
@@ -14,12 +14,13 @@ Rectangle {
|
|||||||
default property alias content: rowLayout.data
|
default property alias content: rowLayout.data
|
||||||
property real spacing: 5
|
property real spacing: 5
|
||||||
property real padding: 5
|
property real padding: 5
|
||||||
|
property int clickIndex: rowLayout.clickIndex
|
||||||
|
|
||||||
property real contentWidth: {
|
property real contentWidth: {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (let i = 0; i < rowLayout.children.length; ++i) {
|
for (let i = 0; i < rowLayout.children.length; ++i) {
|
||||||
if (rowLayout.children[i].baseWidth !== undefined)
|
const child = rowLayout.children[i];
|
||||||
total += rowLayout.children[i].baseWidth;
|
total += child.baseWidth ?? child.implicitWidth ?? child.width;
|
||||||
}
|
}
|
||||||
return total + rowLayout.spacing * (rowLayout.children.length - 1);
|
return total + rowLayout.spacing * (rowLayout.children.length - 1);
|
||||||
}
|
}
|
||||||
@@ -27,23 +28,20 @@ Rectangle {
|
|||||||
topLeftRadius: rowLayout.children.length > 0 ? (rowLayout.children[0].radius + padding) :
|
topLeftRadius: rowLayout.children.length > 0 ? (rowLayout.children[0].radius + padding) :
|
||||||
Appearance?.rounding?.small
|
Appearance?.rounding?.small
|
||||||
bottomLeftRadius: topLeftRadius
|
bottomLeftRadius: topLeftRadius
|
||||||
topRightRadius: {
|
topRightRadius: rowLayout.children.length > 0 ? (rowLayout.children[rowLayout.children.length - 1].radius + padding) :
|
||||||
console.log(rowLayout.children.length > 0 ? (rowLayout.children[rowLayout.children.length - 1].radius + padding) :
|
Appearance?.rounding?.small
|
||||||
Appearance?.rounding?.small)
|
|
||||||
return rowLayout.children.length > 0 ? (rowLayout.children[rowLayout.children.length - 1].radius + padding) :
|
|
||||||
Appearance?.rounding?.small
|
|
||||||
}
|
|
||||||
bottomRightRadius: topRightRadius
|
bottomRightRadius: topRightRadius
|
||||||
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
width: root.contentWidth + padding * 2
|
width: root.contentWidth + padding * 2
|
||||||
implicitHeight: rowLayout.implicitHeight + padding * 2
|
implicitHeight: rowLayout.implicitHeight + padding * 2
|
||||||
|
implicitWidth: root.contentWidth + padding * 2
|
||||||
|
|
||||||
children: [RowLayout {
|
children: [RowLayout {
|
||||||
id: rowLayout
|
id: rowLayout
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: root.padding
|
anchors.margins: root.padding
|
||||||
spacing: root.spacing
|
spacing: root.spacing
|
||||||
property int clickIndex: -1
|
property int clickIndex: -1
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Button {
|
|||||||
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
||||||
property real buttonRadiusPressed: buttonRadius
|
property real buttonRadiusPressed: buttonRadius
|
||||||
property var altAction
|
property var altAction
|
||||||
|
property bool bounce: true
|
||||||
property real baseWidth: 40
|
property real baseWidth: 40
|
||||||
property real baseHeight: 40
|
property real baseHeight: 40
|
||||||
property real clickedWidth: baseWidth + 20
|
property real clickedWidth: baseWidth + 20
|
||||||
@@ -23,8 +24,8 @@ Button {
|
|||||||
property int clickIndex: parentGroup?.clickIndex ?? -1
|
property int clickIndex: parentGroup?.clickIndex ?? -1
|
||||||
|
|
||||||
Layout.fillWidth: (clickIndex - 1 <= parentGroup.children.indexOf(button) && parentGroup.children.indexOf(button) <= clickIndex + 1)
|
Layout.fillWidth: (clickIndex - 1 <= parentGroup.children.indexOf(button) && parentGroup.children.indexOf(button) <= clickIndex + 1)
|
||||||
implicitWidth: button.down ? clickedWidth : baseWidth
|
implicitWidth: (button.down && bounce) ? clickedWidth : baseWidth
|
||||||
implicitHeight: button.down ? clickedHeight : baseHeight
|
implicitHeight: (button.down && bounce) ? clickedHeight : baseHeight
|
||||||
|
|
||||||
Behavior on implicitWidth {
|
Behavior on implicitWidth {
|
||||||
animation: Appearance.animation.clickBounce.numberAnimation.createObject(this)
|
animation: Appearance.animation.clickBounce.numberAnimation.createObject(this)
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ int main(int argc, char* argv[]) {
|
|||||||
id: suggestions
|
id: suggestions
|
||||||
visible: root.suggestionList.length > 0 && messageInputField.text.length > 0
|
visible: root.suggestionList.length > 0 && messageInputField.text.length > 0
|
||||||
property int selectedIndex: 0
|
property int selectedIndex: 0
|
||||||
|
property int clickIndex: -1
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
spacing: 5
|
spacing: 5
|
||||||
|
|
||||||
@@ -283,20 +284,12 @@ int main(int argc, char* argv[]) {
|
|||||||
delegate: ApiCommandButton {
|
delegate: ApiCommandButton {
|
||||||
id: commandButton
|
id: commandButton
|
||||||
colBackground: suggestions.selectedIndex === index ? Appearance.colors.colLayer2Hover : Appearance.colors.colLayer2
|
colBackground: suggestions.selectedIndex === index ? Appearance.colors.colLayer2Hover : Appearance.colors.colLayer2
|
||||||
|
bounce: false
|
||||||
contentItem: RowLayout {
|
contentItem: StyledText {
|
||||||
spacing: 5
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
StyledText {
|
color: Appearance.m3colors.m3onSurface
|
||||||
font.pixelSize: Appearance.font.pixelSize.small
|
horizontalAlignment: Text.AlignHCenter
|
||||||
color: Appearance.m3colors.m3onSurface
|
text: modelData.displayName ?? modelData.name
|
||||||
text: modelData.displayName ?? modelData.name
|
|
||||||
}
|
|
||||||
StyledText {
|
|
||||||
visible: modelData.count !== undefined
|
|
||||||
font.pixelSize: Appearance.font.pixelSize.smaller
|
|
||||||
color: Appearance.m3colors.m3outline
|
|
||||||
text: modelData.count ?? ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onHoveredChanged: {
|
onHoveredChanged: {
|
||||||
@@ -524,20 +517,25 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
Repeater { // Command buttons
|
ButtonGroup {
|
||||||
id: commandRepeater
|
padding: 0
|
||||||
model: commandButtonsRow.commandsShown
|
|
||||||
delegate: ApiCommandButton {
|
Repeater { // Command buttons
|
||||||
id: commandButton
|
model: commandButtonsRow.commandsShown
|
||||||
property string commandRepresentation: `${root.commandPrefix}${modelData.name}`
|
delegate: ApiCommandButton {
|
||||||
buttonText: commandRepresentation
|
property string commandRepresentation: `${root.commandPrefix}${modelData.name}`
|
||||||
onClicked: {
|
buttonText: commandRepresentation
|
||||||
if(modelData.sendDirectly) {
|
onClicked: {
|
||||||
root.handleInput(commandRepresentation)
|
if(modelData.sendDirectly) {
|
||||||
} else {
|
root.handleInput(commandRepresentation)
|
||||||
messageInputField.text = commandRepresentation + " "
|
} else {
|
||||||
messageInputField.cursorPosition = messageInputField.text.length
|
messageInputField.text = commandRepresentation + " "
|
||||||
messageInputField.forceActiveFocus()
|
messageInputField.cursorPosition = messageInputField.text.length
|
||||||
|
messageInputField.forceActiveFocus()
|
||||||
|
}
|
||||||
|
if (modelData.name === "clear") {
|
||||||
|
messageInputField.text = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,20 +308,24 @@ Item {
|
|||||||
}
|
}
|
||||||
delegate: ApiCommandButton {
|
delegate: ApiCommandButton {
|
||||||
id: tagButton
|
id: tagButton
|
||||||
|
|
||||||
colBackground: tagSuggestions.selectedIndex === index ? Appearance.colors.colLayer2Hover : Appearance.colors.colLayer2
|
colBackground: tagSuggestions.selectedIndex === index ? Appearance.colors.colLayer2Hover : Appearance.colors.colLayer2
|
||||||
|
bounce: false
|
||||||
contentItem: RowLayout {
|
contentItem: RowLayout {
|
||||||
|
anchors.centerIn: parent
|
||||||
spacing: 5
|
spacing: 5
|
||||||
StyledText {
|
StyledText {
|
||||||
|
Layout.fillWidth: false
|
||||||
font.pixelSize: Appearance.font.pixelSize.small
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
color: Appearance.m3colors.m3onSurface
|
color: Appearance.m3colors.m3onSurface
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
text: modelData.displayName ?? modelData.name
|
text: modelData.displayName ?? modelData.name
|
||||||
}
|
}
|
||||||
StyledText {
|
StyledText {
|
||||||
|
Layout.fillWidth: false
|
||||||
visible: modelData.count !== undefined
|
visible: modelData.count !== undefined
|
||||||
font.pixelSize: Appearance.font.pixelSize.smaller
|
font.pixelSize: Appearance.font.pixelSize.smaller
|
||||||
color: Appearance.m3colors.m3outline
|
color: Appearance.m3colors.m3outline
|
||||||
|
horizontalAlignment: Text.AlignLeft
|
||||||
text: modelData.count ?? ""
|
text: modelData.count ?? ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -615,22 +619,28 @@ Item {
|
|||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
Repeater { // Command buttons
|
ButtonGroup {
|
||||||
id: commandRepeater
|
padding: 0
|
||||||
model: commandButtonsRow.commandsShown
|
Repeater { // Command buttons
|
||||||
delegate: ApiCommandButton {
|
id: commandRepeater
|
||||||
id: tagButton
|
model: commandButtonsRow.commandsShown
|
||||||
property string commandRepresentation: `${root.commandPrefix}${modelData.name}`
|
delegate: ApiCommandButton {
|
||||||
buttonText: commandRepresentation
|
id: tagButton
|
||||||
colBackground: Appearance.colors.colLayer2
|
property string commandRepresentation: `${root.commandPrefix}${modelData.name}`
|
||||||
|
buttonText: commandRepresentation
|
||||||
|
colBackground: Appearance.colors.colLayer2
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(modelData.sendDirectly) {
|
if(modelData.sendDirectly) {
|
||||||
root.handleInput(commandRepresentation)
|
root.handleInput(commandRepresentation)
|
||||||
} else {
|
} else {
|
||||||
tagInputField.text = commandRepresentation + " "
|
tagInputField.text = commandRepresentation + " "
|
||||||
tagInputField.cursorPosition = tagInputField.text.length
|
tagInputField.cursorPosition = tagInputField.text.length
|
||||||
tagInputField.forceActiveFocus()
|
tagInputField.forceActiveFocus()
|
||||||
|
}
|
||||||
|
if (modelData.name === "clear") {
|
||||||
|
tagInputField.text = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,20 @@ import QtQuick.Controls
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
|
||||||
RippleButton {
|
GroupButton {
|
||||||
id: button
|
id: button
|
||||||
property string buttonText
|
property string buttonText
|
||||||
|
|
||||||
implicitHeight: 30
|
horizontalPadding: 8
|
||||||
leftPadding: 10
|
verticalPadding: 6
|
||||||
rightPadding: 10
|
|
||||||
|
baseWidth: contentItem.implicitWidth + horizontalPadding * 2
|
||||||
|
clickedWidth: baseWidth + 20
|
||||||
|
baseHeight: contentItem.implicitHeight + verticalPadding * 2
|
||||||
|
|
||||||
colBackground: Appearance.colors.colLayer2
|
colBackground: Appearance.colors.colLayer2
|
||||||
colBackgroundHover: Appearance.colors.colLayer2Hover
|
colBackgroundHover: Appearance.colors.colLayer2Hover
|
||||||
colRipple: Appearance.colors.colLayer2Active
|
colBackgroundActive: Appearance.colors.colLayer2Active
|
||||||
|
|
||||||
contentItem: StyledText {
|
contentItem: StyledText {
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
|||||||
Reference in New Issue
Block a user