weatherClock Bangle.js 2 layout compatibility

On Bangle.js 2 there still was a layout overlap issue for wind text.
This commit fixes it. Tested for different input lengths in emulator, also for Bangle.js.
master
lunctis-viribus 2021-12-12 10:15:44 +01:00 committed by GitHub
parent 6b2f8e98d3
commit c5a598d75e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 11 deletions

View File

@ -73,12 +73,10 @@ var clockLayout = new Layout( {
{type: "img", filly: 1, id: "weatherIcon", src: sunIcon}, {type: "img", filly: 1, id: "weatherIcon", src: sunIcon},
{type: "v", fillx:1, c: [ {type: "v", fillx:1, c: [
{type: "h", c: [ {type: "h", c: [
{type: "txt", font: "10%", id: "temp", label: "000"}, {type: "txt", font: "10%", id: "temp", label: "000 °C"},
{type: "txt", font: "10%", id: "tempUnit", label: "°C"},
]}, ]},
{type: "h", c: [ {type: "h", c: [
{type: "txt", font: "10%", id: "wind", label: "00"}, {type: "txt", font: "10%", id: "wind", label: "00 km/h"},
{type: "txt", font: "10%", id: "windUnit", label: "km/h"},
]} ]}
] ]
}, },
@ -106,18 +104,15 @@ function draw() {
if(weatherJson && weatherJson.weather){ if(weatherJson && weatherJson.weather){
var currentWeather = weatherJson.weather; var currentWeather = weatherJson.weather;
const temp = locale.temp(currentWeather.temp-273.15).match(/^(\D*\d*)(.*)$/); const temp = locale.temp(currentWeather.temp-273.15).match(/^(\D*\d*)(.*)$/);
clockLayout.temp.label = temp[1]; clockLayout.temp.label = temp[1] + " " + temp[2];
clockLayout.tempUnit.label = temp[2];
clockLayout.weatherIcon.src = chooseIcon(currentWeather.txt); clockLayout.weatherIcon.src = chooseIcon(currentWeather.txt);
const wind = locale.speed(currentWeather.wind).match(/^(\D*\d*)(.*)$/); const wind = locale.speed(currentWeather.wind).match(/^(\D*\d*)(.*)$/);
clockLayout.wind.label = wind[1] + " ".repeat(wind[2].length-1); clockLayout.wind.label = wind[1] + " " + wind[2] + " " + (currentWeather.wrose||'').toUpperCase();
clockLayout.windUnit.label = wind[2] + " " + (currentWeather.wrose||'').toUpperCase(); var currentWeather = weatherJson.weather;
} }
else{ else{
clockLayout.temp.label = "Err"; clockLayout.temp.label = "Err";
clockLayout.tempUnit.label = "";
clockLayout.wind.label = "No Data"; clockLayout.wind.label = "No Data";
clockLayout.windUnit.label = "";
clockLayout.weatherIcon.src = errIcon; clockLayout.weatherIcon.src = errIcon;
} }
clockLayout.clear(); clockLayout.clear();