VladimirMarkelov / clui

Command Line User Interface (Console UI inspired by TurboVision)
MIT License
669 stars 50 forks source link

[Question] OnClick() event for base_control? #136

Open khaf opened 4 years ago

khaf commented 4 years ago

Hi Vladimir, thanks for this library! It really has the TVision vibe.

I'm trying it to see if it will work for one of my projects, so I'll be filing issues as I encounter them, hope you find them useful. this is the first one:

Is there a reason OnClick() is not implemented for BaseControl?

VladimirMarkelov commented 4 years ago

Hi Khosrow,

You are welcome :)

I do not remember why I decided to do it. A few possible reasons:

First, I might be bitten by Go "inheritance" - I tried to implemented another "generic" method and then I got a bunch of strange errors. Only after I understood that Go inheritance != C++ inheritance, I was able to fix the trouble by removing "generic" code. So I chose a way to add OnClick on top level for controls that needs it.

Second reason: I made a library for my needs and OnClick() looked useless for some controls (e.g, for CheckBox it is not as useful as OnChange as it does not pass the current value of checkbox). For my home projects OnClick for Button was enough.

Third possible reason: my Delphi experience. In Delphi VCL OnClick was not common event, so I am not used to it.

khaf commented 4 years ago

Ah, a fellow Delphi veteran! I see why we seek the same thing.

Go doesn't have inheritance, only composition. Everyone gets it wrong in the first go :)

I take it you don't object to me to do a bit of surgery to fix it?

VladimirMarkelov commented 4 years ago

That was why I wrote inheritance quoted :) - people who came from Delphi/C++ it is not obvious and takes time to grasp the Go way.

While "surgery" does not break what works - I am fine with this 👍