[erlang-questions] wxErlang question 4

Joe Armstrong erlang@REDACTED
Sat Jul 8 12:00:40 CEST 2017


On Sat, Jul 8, 2017 at 11:44 AM, Frank Muller
<frank.muller.erl@REDACTED> wrote:
> Joe, why not:
>
> start() ->
>     Panel = wx:new("Hello"),
>     Vbox = wxBoxSizer:new(?wxVERTICAL),
>     wxWindow:setSizer(Panel, Vbox),
>     Button = wxButton:new(Panel, 10, [{label,"Click"}]),
>     wxSizer:add(Vbox, Button, [{flag, ?wxALL}]),
>     wx:show(Panel).
>
>
> Where you hide the W and Frame inside the Panel.
> They're used only once/twice in your code!!!

Yes - bit I I want a minimal *extensible* solution - wx:new has (as I
understand it) - a
lot of side-effects and returns a reference that i can use to make other things.

I could not (I guess) create two windows with the above.

In my version you can say

    test() ->
          W = wx:new(),
          Frame1 = wxFrame:new(W,-1,"window1"),
          Frame2 = wxFrame:new(W,-1,"window2"),
          ...

and get two windows

Really I'd better naming so I'd say

Frame = lib:make_frame(WinRef),
Panel = lib:make_panel(Frame),
Vbox = lib:make_vbox(Panel, ...)

and strict rules about the order of adding things - I find the heavy
overloading and inheritance
rules terrible to understand

/Joe

>
> /Frank
>
>
> Le sam. 8 juil. 2017 à 11:01, Joe Armstrong <erlang@REDACTED> a écrit :
>>
>> This is my attempt at a minimal program which creates a button
>>
>> start() ->
>>     W = wx:new(),
>>     Frame = wxFrame:new(W, -1, "Hello"),
>>     Panel = wxScrolledWindow:new(Frame),
>>     Vbox = wxBoxSizer:new(?wxVERTICAL),
>>     wxWindow:setSizer(Panel, Vbox),
>>     Button = wxButton:new(Panel, 10, [{label,"Click"}]),
>>     wxSizer:add(Vbox, Button, [{flag, ?wxALL}]),
>>     wxFrame:show(Frame).
>>
>> It
>>    1) gets a reference to the wxWindows Server
>>    2) creates a Frame (which wxWindows calls a window)
>>    3) adds a Panel to the frame
>>        a Panel is a thing you can add controls to
>>    4) creates a Vbox (a box to whose children are arranged  vertically)
>>    5) tells the panel to use the Vbox as it's top level sizer
>>    6) makes a button
>>    7) adds the button to the Vbox
>>    8) displays the frame
>>
>> Questions
>>
>> 1) Is my understanding of the steps you have to do be make a
>>     minimal window with a button correct?
>>
>>     Could the code be clearer (how?)
>>
>>     (actually shorter code might be possible but I want something that is
>>      extensible - so I've used a vbox to which I assume I can add more
>> later)
>>
>>  2)  What are the alternatives to wxScrolledWindow and to wxBoxSizer?
>>
>> Cheers
>>
>> /Joe
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list