Internationalisation & Multi-watch support

Copied two methods from GarminThermoNest to translate languages and manage different sized icons for the various sizes of watch. Also copied ErrorView for smaller wrapped text for error messages.
This commit is contained in:
Philip Abbey
2023-11-02 21:32:42 +00:00
parent 694f312075
commit 816b0dc890
80 changed files with 1784 additions and 19 deletions

48
source/ScalableView.mc Normal file
View File

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------------
//
// Distributed under MIT Licence
// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE.
//
//-----------------------------------------------------------------------------------
//
// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely
// tested on a Venu 2 device. The source code is provided at:
// https://github.com/house-of-abbey/GarminHomeAssistant.
//
// J D Abbey & P A Abbey, 28 December 2022
//
//
// Description:
//
// A view with added methods to scale from percentages of scrren size to pixels.
//
//-----------------------------------------------------------------------------------
using Toybox.Lang;
using Toybox.WatchUi;
using Toybox.Math;
class ScalableView extends WatchUi.View {
hidden var screenWidth;
function initialize() {
View.initialize();
}
// Convert a fraction expressed as a percentage (%) to a number of pixels for the
// screen's dimensions.
//
// Parameters:
// * dc - Device context
// * pc - Percentage (%) expressed as a number in the range 0.0..100.0
//
// Uses screen width rather than screen height as rectangular screens tend to have
// height > width.
//
function pixelsForScreen(pc as Lang.Float) as Lang.Number {
if (screenWidth == null) {
screenWidth = System.getDeviceSettings().screenWidth;
}
return Math.round(pc * screenWidth) / 100;
}
}