buggins / dlangui

Cross Platform GUI for D programming language
Boost Software License 1.0
815 stars 121 forks source link

How to open URL with UrlImageTextButton widget? #651

Open bagomot opened 1 year ago

bagomot commented 1 year ago
auto testLink = new UrlImageTextButton("test_link", UIString.fromId("ui.test_link"), "https://google.com", null);

How can I use this code to open the specified url when left clicking on the mouse? I check in Windows, it does nothing by itself. But why then specify the url?

bagomot commented 1 year ago

I solved this problem in this way:

testLink.click = (Widget source) {
import std.process : browse;
browse(source.action.stringParam);
return true;
 };

But is this the right way? I think it should work automatically.

GrimMaple commented 1 year ago

I looked at it. The code does assign the action properly, but it might not be triggered for some reason. Sounds like a bug to me.

GrimMaple commented 1 year ago

I looked at it more closely, and here's what happens: The action itself is assigned properly and it works as the original author intended. The problem is, you need to handle those actions somewhere. Otherwise the action is dispatched, but never handled. An example can be found here: https://github.com/buggins/dlangui/blob/51d1eabb8d9b1265f3253d518c742db51f5cbf5f/examples/example1/src/example1.d#L228

I don't know what to feel about this design. If I were to try and understand the reasoning behind all this, it's to allow you to handle URL clicks in a non-specific way (eg check for malicious websites or whatnot). I'm thinking this is the intended way for it to work and not a bug.

However, I can also understand that it's expected to work in a different way. Maybe, I can kludge in a way for it to work without any special shenanigans required. This would mean a cross-platform way of opening links is required.

I'm promoting this from bug to enchancement though :)

bagomot commented 1 year ago

This would mean a cross-platform way of opening links is required.

This is available in the standard library. Works if the default browser is set in the system. I tested in Windows and Linux (ubuntu, archlinux).