Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion shell/plugins/panels/weather/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -312,6 +333,9 @@ if (typeof module !== "undefined") {
bareTempForDay: bareTempForDay,
dayIcon: dayIcon,
iconForOpenMeteoCode: iconForOpenMeteoCode,
iconForCode: iconForCode
iconForCode: iconForCode,
heroNeededWidth: heroNeededWidth,
heroContentWidth: heroContentWidth,
locationLabelWidth: locationLabelWidth
}
}
17 changes: 16 additions & 1 deletion shell/plugins/panels/weather/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -636,6 +646,7 @@ Panel {
spacing: Style.space(12)

Row {
id: locationRow
visible: !root.editingLocation && root.reportLocation !== ""
spacing: Style.space(6)

Expand All @@ -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
Expand All @@ -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
Expand Down
47 changes: 47 additions & 0 deletions test/shell.d/weather-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down