[erlang-questions] wxErlang question 6 - Image display

zxq9 zxq9@REDACTED
Tue Jul 11 03:17:13 CEST 2017


On 2017年07月08日 土曜日 15:14:05 Joe Armstrong wrote:
> Images
> 
> wxWidgets is breaking the principle of least astonishment

Indeed. Most of all with regard to semantics. "Window", "frame", "image", "bitmap" and so on all mean slightly different things than we expect. The semantic hurdles were my greatest annoyance with WX, and still are.

>     Image = wxImage:new("image.jpg", []),
>     wxSizer:add(Vbox, Image, ...)
> 
> But oh dear - this doesn't work.
> 
> I Googled a bit - and it appears I have to mess with paint events and
> graphics contexts and so on.
> 
> But why? - why break the principle of least atonishment.
> 
> Is it possible to dispay an Image in a Panel *without* handling graphics context
> and paint events?

I remember encountering this problem... and I placed the solution into a library (which I've been doing gradually with quite a few things to make them more Erlangish). Looking it up, I see that I had been using wxBitmap to display jpegs and pngs.

The relevant code:

https://github.com/zxq9/zxWidgets/blob/master/src/zxw.erl#L101-L114

That function is a shortcut for displaying a PNG image button, but I believe the basic bits worked for displaying an image inside a sizer also.

Until now I've only dabbled with abstracting away a few annoyances into my little widget wrapper lib. Within about a month or so I'll be back working on it quite deliberately. I'll let you know how it goes. My goal is to prevent myself from having to constantly write pages of extremely long functions just to get a few generic things on the screen (like grids of input fields, basic data displays where we know basically an X-columns wide set of information like [{Label, Data}] but don't want it to look like a Calc spreadsheet, etc.).

-Craig



More information about the erlang-questions mailing list