forked from Blendman974/faceclaw
Weather app on glanceboard system card and status bar, and has an image
This commit is contained in:
1 parent
61ede9b2a0
commit
6db913af48
15 files changed
+762
-33
No files matched your search
@@ -6,11 +6,18 @@ import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||
import { centeredTextY, lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import { renderWeatherIcon } from "./weather-icons";
|
||||
|
||||
const PAGE_X = 18;
|
||||
const HEADER_Y = 8;
|
||||
const CURRENT_TOP = 34;
|
||||
/** Minimum x of the description column right of the temperature. */
|
||||
const CURRENT_TEXT_X = 112;
|
||||
/** The current-conditions icon, left of the temperature. */
|
||||
const CURRENT_ICON_SIZE = 40;
|
||||
const CURRENT_ICON_GAP = 10;
|
||||
/** Gap between the temperature and the description column. */
|
||||
const CURRENT_TEXT_GAP = 16;
|
||||
const FORECAST_HEADER_Y = 105;
|
||||
const FORECAST_TOP = 124;
|
||||
/** Forecast rows hold a 20px icon; grow with the font past that. */
|
||||
@@ -70,7 +77,8 @@ export class WeatherLayer implements Layer {
|
||||
);
|
||||
return image;
|
||||
}
|
||||
if (weather.phase === "locating" || weather.phase === "loading") {
|
||||
// A refresh with earlier data in hand keeps showing that data.
|
||||
if ((weather.phase === "locating" || weather.phase === "loading") && !weather.current) {
|
||||
this.drawMessage(image, font, width, height, weather.status);
|
||||
return image;
|
||||
}
|
||||
@@ -94,7 +102,7 @@ export class WeatherLayer implements Layer {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!weather.forecast.length || weather.phase !== "ready") return;
|
||||
if (!weather.forecast.length || !showsForecast(weather)) return;
|
||||
if (event.type === "scroll-up" || event.type === "scroll-down") {
|
||||
this.forecastMenu.setItems(weather.forecast);
|
||||
void this.forecastMenu.handleInput(event);
|
||||
@@ -108,16 +116,24 @@ export class WeatherLayer implements Layer {
|
||||
const medium = getDefaultMediumFont();
|
||||
const small = getDefaultSmallFont();
|
||||
const temperature = current.temperatureF === null ? "--°" : `${Math.round(current.temperatureF)}°F`;
|
||||
image.drawText(large, PAGE_X, CURRENT_TOP + 8, temperature, 245);
|
||||
const temperatureY = CURRENT_TOP + 8;
|
||||
let temperatureX = PAGE_X;
|
||||
if (current.condition) {
|
||||
const icon = renderWeatherIcon(current.condition, current.isDaytime, CURRENT_ICON_SIZE);
|
||||
if (icon) image.drawImage(icon, PAGE_X, temperatureY + (((large.lineHeight - icon.height) / 2) | 0));
|
||||
temperatureX += CURRENT_ICON_SIZE + CURRENT_ICON_GAP;
|
||||
}
|
||||
image.drawText(large, temperatureX, temperatureY, temperature, 245);
|
||||
const textX = Math.max(CURRENT_TEXT_X, temperatureX + Math.ceil(large.measureText(temperature)) + CURRENT_TEXT_GAP);
|
||||
// Description / details / source stack compactly from just below the
|
||||
// header line, so at large font sizes they stay clear of the forecast
|
||||
// table instead of running into it.
|
||||
let cy = 30;
|
||||
image.drawText(
|
||||
medium,
|
||||
CURRENT_TEXT_X,
|
||||
textX,
|
||||
cy,
|
||||
truncateText(medium, current.description || "Current conditions", width - CURRENT_TEXT_X - PAGE_X),
|
||||
truncateText(medium, current.description || "Current conditions", width - textX - PAGE_X),
|
||||
220,
|
||||
);
|
||||
cy += medium.lineHeight + 2;
|
||||
@@ -127,11 +143,12 @@ export class WeatherLayer implements Layer {
|
||||
if (current.windSpeedMph !== null) {
|
||||
details.push(`Wind ${current.windDirection ? `${current.windDirection} ` : ""}${Math.round(current.windSpeedMph)} mph`);
|
||||
}
|
||||
image.drawText(small, CURRENT_TEXT_X, cy, details.join(" ") || "Current forecast", 170);
|
||||
image.drawText(small, textX, cy, details.join(" ") || "Current forecast", 170);
|
||||
cy += lineStep(small);
|
||||
const source = current.observed ? "Observed" : "Forecast";
|
||||
const age = current.timestampMs ? formatAge(Date.now() - current.timestampMs) : "";
|
||||
image.drawText(small, CURRENT_TEXT_X, cy, `${source}${age ? ` ${age}` : ""}`, 105);
|
||||
const updating = weather.phase === "locating" || weather.phase === "loading" ? " · updating" : "";
|
||||
image.drawText(small, textX, cy, `${source}${age ? ` ${age}` : ""}${updating}`, 105);
|
||||
image.drawLine(PAGE_X, FORECAST_HEADER_Y - 7, width - PAGE_X, FORECAST_HEADER_Y - 7, 40);
|
||||
}
|
||||
|
||||
@@ -216,6 +233,12 @@ export class WeatherLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether paint shows the forecast table (ready, or refreshing over earlier data). */
|
||||
function showsForecast(weather: WeatherState): boolean {
|
||||
if (weather.phase === "ready") return true;
|
||||
return (weather.phase === "locating" || weather.phase === "loading") && weather.current !== null;
|
||||
}
|
||||
|
||||
/** Forecast row pitch, including the gap between selection boxes. */
|
||||
function forecastRowHeight(font: UiFont): number {
|
||||
return Math.max(FORECAST_MIN_ROW_HEIGHT, tightRowHeight(font) + 3);
|
||||
|
||||
Reference in new issue
Block a user