fix: shape morph expands by static 24dp

We don't have dp and I'm not adding dp everywhere, so assume 1dp == 1px
Also enable radius morph by default
This commit is contained in:
2 * r + 2 * t 2026-05-02 22:34:58 +10:00
parent 8d3a915c49
commit 42446dbb0f
4 changed files with 11 additions and 10 deletions

View file

@ -29,7 +29,7 @@ MouseArea {
const d2 = distSq(width, 0); const d2 = distSq(width, 0);
const d3 = distSq(0, height); const d3 = distSq(0, height);
const d4 = distSq(width, height); const d4 = distSq(width, height);
return Math.sqrt(Math.max(d1, d2, d3, d4)) * (shapeMorph ? 1.16 : 1); return Math.sqrt(Math.max(d1, d2, d3, d4)) + (shapeMorph ? 24 : 0);
} }
property real endRadiusAtPress property real endRadiusAtPress

View file

@ -19,7 +19,7 @@ StyledRect {
property bool isToggle property bool isToggle
property bool isRound property bool isRound
property bool radiusMorph property bool radiusMorph: true
property alias shapeMorph: stateLayer.shapeMorph property alias shapeMorph: stateLayer.shapeMorph
property bool fillWidth // For ButtonRow property bool fillWidth // For ButtonRow
@ -43,7 +43,7 @@ StyledRect {
property color disabledOnColour: Qt.alpha(Colours.palette.m3onSurface, 0.38) property color disabledOnColour: Qt.alpha(Colours.palette.m3onSurface, 0.38)
property bool internalChecked property bool internalChecked
property real shapeMorphExpansion: shapeMorph && pressed ? 1.16 : 1 property real shapeMorphExpansion: shapeMorph && pressed ? 24 : 0 // Apparently it's always 24px no matter the width of the button
readonly property color onColour: disabled ? disabledOnColour : internalChecked ? activeOnColour : inactiveOnColour readonly property color onColour: disabled ? disabledOnColour : internalChecked ? activeOnColour : inactiveOnColour
signal clicked signal clicked

View file

@ -102,8 +102,10 @@ void ButtonRow::relayout() {
for (int i = 0; i < nChildren; ++i) { for (int i = 0; i < nChildren; ++i) {
auto* const child = validChildren[i]; auto* const child = validChildren[i];
auto prevExtraWidth = i > 0 ? getMorphExpansion(validChildren[i - 1], baseWidths[i - 1]) : 0.0; // clang-format off
auto nextExtraWidth = i < nChildren - 1 ? getMorphExpansion(validChildren[i + 1], baseWidths[i + 1]) : 0.0; auto prevExtraWidth = i > 0 ? getMorphExpansion(validChildren[i - 1]) : 0.0;
auto nextExtraWidth = i < nChildren - 1 ? getMorphExpansion(validChildren[i + 1]) : 0.0;
// clang-format on
// Items at edges push by full amount, items in middle push by half // Items at edges push by full amount, items in middle push by half
if (i > 1) if (i > 1)
@ -111,7 +113,7 @@ void ButtonRow::relayout() {
if (i < nChildren - 2) if (i < nChildren - 2)
nextExtraWidth /= 2; nextExtraWidth /= 2;
child->setWidth(baseWidths[i] + getMorphExpansion(child, baseWidths[i]) - prevExtraWidth - nextExtraWidth); child->setWidth(baseWidths[i] + getMorphExpansion(child) - prevExtraWidth - nextExtraWidth);
child->setHeight(maxHeight); child->setHeight(maxHeight);
child->setX(accX); child->setX(accX);
@ -123,9 +125,8 @@ void ButtonRow::relayout() {
setImplicitHeight(maxHeight); setImplicitHeight(maxHeight);
} }
qreal ButtonRow::getMorphExpansion(const QQuickItem* item, qreal width) { qreal ButtonRow::getMorphExpansion(const QQuickItem* item) {
const auto prop = item->property("shapeMorphExpansion"); return item->property("shapeMorphExpansion").toReal();
return width * (prop.isValid() ? prop.toReal() - 1 : 0.0);
} }
} // namespace caelestia::components } // namespace caelestia::components

View file

@ -28,7 +28,7 @@ private slots:
private: private:
void relayout(); void relayout();
static qreal getMorphExpansion(const QQuickItem* item, qreal width); static qreal getMorphExpansion(const QQuickItem* item);
bool m_dirty; bool m_dirty;
qreal m_spacing; qreal m_spacing;