kerryb

kerryb

WxEx – Elixir wrappers for macros and records in :wx

I’m not sure how many people are using wxWidgets in Elixir, but in the course of playing around with it I created a small library to expose the Erlang macros and record definitions to Erlang code.

It doesn’t wrap any of the :wx modules, because they can be used directly from Elixir.

I haven’t actually used it in any real projects yet, so if you find anything wrong or missing, feel free to raise an issue.

Thanks to @harrisi for managing to find it before I’d shown it to anyone, and submitting a PR to add OpenGL constants!

#wx

Most Liked

cmo

cmo

I tend to think it should be kept the same because a) is easier to write the code (I have a similar script that allows access to the wx Erlang constants) and b) searching the WxWidget docs is easier when the names are the same.

@kerryb what’s the point of the WxObject wrapper if everything else apart from the constants is Erlang syntax?

christhekeele

christhekeele

For those interested I did recently do this, for all 25,000 lines of related constants, mostly through some multi-cursor editing and find/replace regexes. src/ files here.

kerryb

kerryb

In my opinion you should follow Elixir’s naming convention, so all of the macros and functions should be snake case.

The main reason I didn’t do that was … well, laziness to be honest, but also I’ve used tools before (eg Java and Ruby bridges to Apple’s Cocoa) where having to keep mentally translating the names of things when reading documentation was confusing.

I understand that it’s for a reason, so instead of converting it to snake case I would rather fit it in Elixir’s standards, for example a call like:

wxALIGN_RIGHT()

could be changed to:

wx(:ALIGN_RIGHT)

I do like that idea – it seems nicer than polluting the namespace by importing hundreds of functions into a module.

Maybe you could use more clear example usage here.

Yes, good point – I just pasted some snippets from a code sample I’d converted, assuming that if anyone was interested they’d already be far more familiar with wx than I am. I ought to replace it with a working “hello world” example.

harrisi

harrisi

I’m glad I happened to find it right after you published it! I’ve been meaning to publish something like it, so this saves me some time. Definitely a welcome addition.

As a side note, while I’ve been more focused on the realtime rendering stuff with OpenGL, Metal, Vulkan, and Direct3D, there’s a form builder that would probably be great to integrate better. Micheus, who works on Wings3D, did some work on this but I haven’t really looked into it. Just happened to find it last week and thought it might be interesting.

Eiji

Eiji

Interesting project! In my opinion you should follow Elixir’s naming convention, so all of the macros and functions should be snake case. I understand that it’s for a reason, so instead of converting it to snake case I would rather fit it in Elixir’s standards, for example a call like:

wxALIGN_RIGHT()

could be changed to:

wx(:ALIGN_RIGHT)

There should not be a difference in performance. It should also be easier to document it since instead of lots of functions you would have just for example wx/1 and wx_gl/1 functions. :open_book:

Also I’m not sure if write a __using__ macro makes sense if all you do inside it is just import. :icon_confused:

Here is your first example:

use WxEx
import Bitwise # to allow ORing of flags with |||

panel = :wxPanel.new(frame)
label = :wxStaticText.new(panel, wxID_ANY(), "A label", style: wxALIGN_RIGHT())
sizer = :wxBoxSizer.new(wxHORIZONTAL())
:wxSizer.add(sizer, label, flag: wxALL() ||| wxALIGN_CENTRE(), border: 5)

# etc

but it would not work, because frame was not defined. I understand that it should not be a problem for those who used :wx before, but please keep in mind that many people would like to give it a try by running a “quick” session in iex console and then a copy-paste script is very helpful. :see_no_evil:

Similarly to the second example. Again someone who just want to give it a try would not understand why there is so many :undefined. Maybe you could use more clear example usage here. :thinking:

Anyway it’s interesting project. The source of mix task looks very clear and easy to read. :+1:

Where Next?

Popular in Libraries Top

Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
engineeringdept
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

Sub Categories:

We're in Beta

About us Mission Statement