diff --git a/shell/plugins/panels/weather/Model.js b/shell/plugins/panels/weather/Model.js index 4b66dfafaa6d..c16fb72904dc 100644 --- a/shell/plugins/panels/weather/Model.js +++ b/shell/plugins/panels/weather/Model.js @@ -267,6 +267,27 @@ function iconForOpenMeteoCode(code, night) { return iconForCode(119, night) } +// Width of the hero row so the temperature block and the stats column do not +// meet: left margin, temperature, the gap between the halves, the stats +// column, right margin. Labels such as Russian ОЩУЩАЕТСЯ are much wider than +// FEELS, and at the 480px floor they land on top of the °C. +function heroNeededWidth(leftMargin, temperatureWidth, gap, statsWidth, rightMargin) { + return leftMargin + temperatureWidth + gap + statsWidth + rightMargin +} + +// Card content width before KeyboardPanel.fittedContentWidth caps it to the +// screen. Short labels stay at the floor; longer ones grow the card by the +// hero width plus the card's own chrome. +function heroContentWidth(baseWidth, neededWidth, chrome) { + return Math.max(baseWidth, neededWidth + chrome) +} + +// Place name drawn inside the stats column. A name wider than the column +// elides; a shorter one keeps its own width. +function locationLabelWidth(textWidth, columnWidth, pinWidth, spacing) { + return Math.min(textWidth, columnWidth - pinWidth - spacing) +} + function iconForCode(code, night) { var c = parseInt(String(code || "0"), 10) switch (c) { @@ -312,6 +333,9 @@ if (typeof module !== "undefined") { bareTempForDay: bareTempForDay, dayIcon: dayIcon, iconForOpenMeteoCode: iconForOpenMeteoCode, - iconForCode: iconForCode + iconForCode: iconForCode, + heroNeededWidth: heroNeededWidth, + heroContentWidth: heroContentWidth, + locationLabelWidth: locationLabelWidth } } diff --git a/shell/plugins/panels/weather/Panel.qml b/shell/plugins/panels/weather/Panel.qml index 0daf3795430a..b86c76c85305 100644 --- a/shell/plugins/panels/weather/Panel.qml +++ b/shell/plugins/panels/weather/Panel.qml @@ -72,6 +72,9 @@ Panel { // Parsed wttr.in j1 response. Kept on failure so stale data stays visible. property var report: null + // Width the hero row needs so the temperature and the stats column never + // overlap (labels are much wider in some languages, e.g. Russian). + property real heroNeededWidth: 0 property var dailyForecastReport: null // Configured location, read from the weather.json state file (owned by @@ -545,7 +548,7 @@ Panel { // popup follows wherever the widget is placed. centerOnBar: false focusTarget: panel.loadedContent - contentWidth: panel.fittedContentWidth(Style.space(480)) + contentWidth: panel.fittedContentWidth(Model.heroContentWidth(Style.space(480), root.heroNeededWidth, panel.padding * 2 + Style.space(4))) contentHeight: panel.fittedContentHeight(panel.loadedContentHeight) content: PanelKeyCatcher { @@ -577,6 +580,13 @@ Panel { width: parent.width height: Math.max(heroLeft.height, heroRight.height) + // left margin + temperature block + gap + stats column + right margin + Binding { + target: root + property: "heroNeededWidth" + value: Model.heroNeededWidth(Style.space(16), heroLeft.implicitWidth, Style.space(24), heroRight.width, Style.space(20)) + } + Row { id: heroLeft anchors.left: parent.left @@ -636,6 +646,7 @@ Panel { spacing: Style.space(12) Row { + id: locationRow visible: !root.editingLocation && root.reportLocation !== "" spacing: Style.space(6) @@ -647,6 +658,7 @@ Panel { } Text { + id: locationPin text: "" // nf-fa-map_marker color: Qt.darker(root.bar.foreground, 1.4) font.family: root.bar.fontFamily @@ -656,6 +668,9 @@ Panel { Text { textFormat: Text.PlainText text: (root.reportLocation || "").toUpperCase() + // Long place names are elided instead of spilling past the panel. + width: Model.locationLabelWidth(implicitWidth, heroRight.width, locationPin.width, locationRow.spacing) + elide: Text.ElideRight color: Qt.darker(root.bar.foreground, 1.4) font.family: root.bar.fontFamily font.pixelSize: Style.font.body diff --git a/test/shell.d/weather-test.sh b/test/shell.d/weather-test.sh index bcc292d55671..377631bf6420 100644 --- a/test/shell.d/weather-test.sh +++ b/test/shell.d/weather-test.sh @@ -121,6 +121,53 @@ assertEqual( weather.iconForCode(389, false), 'weather picks hourly forecast icon nearest noon' ) + +// #17630: the °C and the stats column share one row. These widths stand in +// for the measured halves (a hero temperature, and stat labels as wide as +// Russian ОЩУЩАЕТСЯ / ВЕТЕР / ВЛАЖНОСТЬ). The card opens up so the halves +// and the gap still fit; short labels stay on the 480px floor. The screen +// cap stays in KeyboardPanel.fittedContentWidth, which this width feeds. +function heroOverlaps(contentWidth, spec) { + const inner = contentWidth - spec.chrome + const temperatureRight = spec.leftMargin + spec.temperatureWidth + const statsLeft = inner - spec.rightMargin - spec.statsWidth + return temperatureRight + spec.gap > statsLeft +} + +const longStats = { + baseWidth: 480, + chrome: 32, + leftMargin: 16, + temperatureWidth: 200, + gap: 24, + statsWidth: 360, + rightMargin: 20 +} +const longWidth = weather.heroContentWidth( + longStats.baseWidth, + weather.heroNeededWidth(longStats.leftMargin, longStats.temperatureWidth, longStats.gap, longStats.statsWidth, longStats.rightMargin), + longStats.chrome +) +assert(!heroOverlaps(longWidth, longStats), 'long language stats stay clear of the temperature unit') +assert(longWidth > longStats.baseWidth, 'long language stats widen the weather panel past 480') + +const shortStats = Object.assign({}, longStats, { statsWidth: 120 }) +const shortWidth = weather.heroContentWidth( + shortStats.baseWidth, + weather.heroNeededWidth(shortStats.leftMargin, shortStats.temperatureWidth, shortStats.gap, shortStats.statsWidth, shortStats.rightMargin), + shortStats.chrome +) +assert(!heroOverlaps(shortWidth, shortStats), 'short language stats stay clear of the temperature unit') +assertEqual(shortWidth, shortStats.baseWidth, 'short language stats keep the 480px weather panel') + +const statsColumn = 360 +const pinWidth = 14 +const locationSpacing = 6 +const locationRoom = statsColumn - pinWidth - locationSpacing +const longLocation = weather.locationLabelWidth(900, statsColumn, pinWidth, locationSpacing) +assert(longLocation <= locationRoom, 'long location names elide inside the stats column') +assert(longLocation > 0, 'an elided location name still shows') +assertEqual(weather.locationLabelWidth(40, statsColumn, pinWidth, locationSpacing), 40, 'short location names keep their own width') JS test_tmp=$(mktemp -d)