Skip to content

Conversation

Jhynjhiruu
Copy link

@Jhynjhiruu Jhynjhiruu commented Oct 8, 2025

Per discussion in Discord, here's a test implementation of rendering text in ComponentGraphics, along with an implementation for HTML5.

I based the API almost entirely on how SVGGraphics does it, so this may need to be reworked before it's merged (hence, draft PR). I added a new FontStyle(size:Null<Int>, family:Null<String>, anchor:Null<String>) draw command to set the style, and then Text(x:Float, y:Float, t:String) to actually draw the text. My implementation of the function in ComponentGraphicsBase has signature fontStyle(size:Null<Int>, family:Null<String> = null, anchor:Null<String> = null), since I assumed based on mostly nothing that people would want to change the font size most commonly. SVGGraphics reuses StrokeStyle and FillStyle to render the text, which is fine as an API but I don't know if that poses any implementation challenges for other backends.

Example usage:

componentGraphics.strokeStyle(Color.fromString("black"), 5);
componentGraphics.fillStyle(Color.fromString("white"));
for (node in _nodes) {
    componentGraphics.circle(node._xy.x, node._xy.y, 20);
}

componentGraphics.strokeStyle(null);
componentGraphics.fillStyle(Color.fromString("black"));
componentGraphics.fontStyle(10, "Sans Serif", "middle");
for (node in _nodes) {
    componentGraphics.text(node._xy.x, node._xy.y, 'node${node._id}');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant