dlangui icon indicating copy to clipboard operation
dlangui copied to clipboard

API for showing and resizing custom images is overly complicated

Open FreeSlave opened this issue 9 years ago • 2 comments

Probably I'm missing something, but the current way to set custom image (i.e. not from embedded resources) onto ImageWidget looks like this:

auto imageWidget = new ImageWidget();
auto imageBuf = loadImage(imageFileName);
auto rescaledBuf = new ColorDrawBuf(128,128);
rescaledBuf.drawRescaled(Rect(0,0,rescaledBuf.width,rescaledBuf.height), imageBuf, Rect(0,0,imageBuf.width,imageBuf.height));
auto imageBufRef = DrawBufRef(rescaledBuf);
auto imageDrawable = new ImageDrawable(imageBufRef);
imageWidget.drawable = imageDrawable;

Too many lines and entities for such simple task. Drawable? DrawBufRef? I just want to set image loaded from disk.

The perfect one would be:

auto imageBuf = loadImage(imageFileName).scaled(128,128);
auto imageWidget = new ImageWidget(imageBuf);

FreeSlave avatar Apr 28 '16 23:04 FreeSlave

How about you make a pull request with above code?

aberba avatar May 24 '17 01:05 aberba

I also could not find how to set a custom icon for ImageTextButton.

Actually I think that the image API should be re-worked. The current one is a mess with hierarchy of classes which creates the need in casts in many places. And it's not clear how to work with DrawBuf and DrawBufRefs correctly (to not accidentally change data in image that's used somewhere else). I would prefer images to be structures that implement COW (copy-on-write) instead of classes. Similar to the Qt approach. That way we won't need DrawBufRef. @buggins what do you think?

FreeSlave avatar Oct 11 '17 17:10 FreeSlave