feat: Add support for Monkey C (#1081)

This commit is contained in:
Philipp Meier 2024-08-16 14:27:59 +02:00 committed by GitHub
parent da3fe791df
commit 84fcef1f2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 77 additions and 0 deletions

View File

@ -462,6 +462,7 @@ Meson
Mint
Mlatu
ModuleDef
MonkeyC
MoonScript
MsBuild
Mustache

View File

@ -1042,6 +1042,13 @@
"extensions": ["def"],
"line_comment": [";"]
},
"MonkeyC": {
"name": "Monkey C",
"extensions": ["mc"],
"line_comment": ["//"],
"multi_line_comments": [["/*", "*/"]],
"quotes": [["\\\"", "\\\""]]
},
"MoonBit": {
"line_comment": ["//"],
"quotes": [["\\\"", "\\\""]],

69
tests/data/monkeyc.mc Normal file
View File

@ -0,0 +1,69 @@
// 69 lines 41 code 18 comments 10 blanks
// Slightly modified template from the "Garmin.monkey-c" VS Code extension.
import Toybox.Application;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class WatchFaceView extends WatchUi.WatchFace {
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc as Dc) as Void {
setLayout(Rez.Layouts.WatchFace(dc));
}
/*
Called when this View is brought to the foreground. Restore
the state of this View and prepare it to be shown. This includes
loading resources into memory.
*/
function onShow() as Void {
}
// Update the view
function onUpdate(dc as Dc) as Void {
// Get the current time and format it correctly
var timeFormat = "$1$:$2$";
var clockTime = System.getClockTime();
var hours = clockTime.hour;
if (!System.getDeviceSettings().is24Hour) {
if (hours > 12) {
hours = hours - 12;
}
} else {
if (getApp().getProperty("UseMilitaryFormat")) {
timeFormat = "$1$$2$";
hours = hours.format("%02d");
}
}
var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);
// Update the view
var view = View.findDrawableById("TimeLabel") as Text;
view.setColor(getApp().getProperty("ForegroundColor") as Number);
view.setText(timeString);
View.onUpdate(dc); // Call the parent onUpdate function to redraw the layout
}
/*
Called when this View is removed from the screen. Save the
state of this View here. This includes freeing resources from
memory.
*/
function onHide() as Void {
}
// The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() as Void {
}
// Terminate any active timers and prepare for slow updates.
function onEnterSleep() as Void {
}
}