ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.64k stars 399 forks source link

Is it possible to have on_enter method for Toggle component? #37

Closed VedantParanjape closed 4 years ago

VedantParanjape commented 4 years ago

Hey, is it possible to add on_enter() for toggle component? Since, this framework doesn't have buttons. Toggle is a pretty good way to emulate buttons.

I am more than happy to contribute for this feature.

VedantParanjape commented 4 years ago

hey, @ArthurSonzogni des mises à jour à ce sujet?

ArthurSonzogni commented 4 years ago

Hi, thanks for opening this! We can add on_enter() in the toggle component. This will match RadioBox and CheckBox. Do you prefer to do the change? Or I can do it.

Do you think we need to add a "Button" component? I can do it too.

VedantParanjape commented 4 years ago

Hi, thanks for opening this! We can add on_enter() in the toggle component. This will match RadioBox and CheckBox. Do you prefer to do the change? Or I can do it.

I will make the change, and can we have a identical API for all component, like in RadioBox on_change() actually checks if user pressed enter, and not if the selection changed.

Do you think we need to add a "Button" component? I can do it too.

With toggle component having a on_enter method, it can emulate a button.

VedantParanjape commented 4 years ago

Hey @ArthurSonzogni, Can we have a identical API for on_change, on_enter for all the components, if yes. I'd like to contribute

Like radio box's on_change is actually on_enter, and some component lack the on_change thing.

Regards, Vedant

ArthurSonzogni commented 4 years ago

We currently have:

Component on_change() on_enter()
Toggle X  
Menu X X
RadioBox X
Input X X
CheckBox X

I think I left on_enter() in Toggle, because this was copy-pasted from Menu.

I don't think we can make enter to trigger on_enter() instead of on_change() for RadioBox and CheckBox, this would prevent us from using the current behavior.

VedantParanjape commented 4 years ago

I don't think we can make enter to trigger on_enter() instead of on_change() for RadioBox and CheckBox, this would prevent us from using the current behavior.

Current behaviour as in ? sorry, i didn't understand your point.

ArthurSonzogni commented 4 years ago

I think I don't want to add on_enter to CheckBox, RadioBox. The "enter" key are already assigned to select an element.

However, the CheckBox/RadioBox implementation do not have any privilege, you can freely build your own. You can even derive from them and just override the OnEvent method like this:

bool MyCheckbox::OnEvent(Event event) {
  if (event == Event::Enter) {
    on_enter();
    return true;
  }
 return CheckBox::OnEvent(event);
}
VedantParanjape commented 4 years ago

Oh great, just what i wanted.

Better docs might have helped, why don't you setup detailed docs using mkdocs on readthedocs.com ?

ArthurSonzogni commented 4 years ago

I have started a "doxygen" branch here: https://github.com/ArthurSonzogni/FTXUI/tree/doxygen

I need to finish it and then we will have a documentation page.

ArthurSonzogni commented 4 years ago

I just uploaded: https://arthursonzogni.com/FTXUI/doc

Not that I still haven't completed the documentation yet.

VedantParanjape commented 4 years ago

Oh this is really good. You could use mkdocs or sphinx for a more material, modern looking docs.

ArthurSonzogni commented 4 years ago

I haven't used sphinx. This might be good option.

I improved the CSS and many more things: https://arthursonzogni.com/FTXUI/doc/

You might have to refresh several times (ctrl + maj + R) 2 times to get it, because this page is running through a ServiceWorker.

VedantParanjape commented 4 years ago

Looks great, but i need to refresh twice, I have extensively used github pages, let me know if you need any help with that.

Regards, Vedant