Julie's Document Website / Delphi Menu Engine / Dev Journal / Scripting Expansions
Publish Date
2025-26-05 19:29:00 +0200 UTC
Author
Julie

Scripting Expansions

25-05-2025

Script expansions

I added scheduling functions! setInterval(cb, delay, interval) and setTimeout(cb, delay) are now supported. But keep in mind, they take in delays and intervals in ticks, not milliseconds. Both of these functions return an ID integer that represents their task ID.

There is of course an accompanying clearTimeout(taskId) to cancel both interval and timeout tasks.

This was all made possible with the scheduling API I added to the DocumentView. This quick little API allows you to schedule tasks that run after a certain amount of ticks or are run over and over. Once the view itself is closed, the tasks are closed and don't execute.

Custom Events

I also added support for custom events, which I thought might be a good way for plugins to communicate with menus written with JS, or just a good way to communicate with menus, really.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
DocumentView view = /* .. idk */;
Document document = view.getDocument();

// Create the event object itself, the only parameter needed, 
// being the event's type
CustomEvent event = document.newCustomEvent("something-happened");

// The "Map.of" can be any map of string to object that contains data 
// for the event.
event.initEvent(null, false, false, Map.of("data", 1, "data2", false));

// Then finally, dispatch the event
document.dispatchEvent(event);

// Sidenote: you can access those map properties like this:
Object data = event.getProperty("data");

Other

There isn't really any other changes, I fixed a weird jerk that would happen when you set a text node's text content to a text with a different size. For less than a tick, it would be squished or stretched out before correcting.

This was happening because the renderer's callback for a text node's content being modified would directly update that text node's render object. But the actual layout update would happen when the view's tick method was called, much later. This difference caused a half second of the text looking smushed or stretched before being updated again.