Add documentation about the hoverable component.

This commit is contained in:
ArthurSonzogni 2022-12-04 11:59:56 +01:00
parent 0d54285e19
commit b9f51844c3
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C

View File

@ -139,8 +139,23 @@ ComponentDecorator Hoverable(bool* hover) {
return [hover](Component component) { return Hoverable(component, hover); }; return [hover](Component component) { return Hoverable(component, hover); };
} }
/// @brief Wrap a component. Two callback can be used to know when the mouse /// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// enter and leave its area. /// mouse.
/// @param on_enter is called when the mouse hover the component.
/// @param on_leave is called when the mouse leave the component.
/// @ingroup component
///
/// ### Example
///
/// ```cpp
/// auto button = Button("exit", screen.ExitLoopClosure());
/// int on_enter_cnt = 0;
/// int on_leave_cnt = 0;
/// button |= Hoverable(
/// [&]{ on_enter_cnt++; },
/// [&]{ on_leave_cnt++; }
// );
/// ```
ComponentDecorator Hoverable(std::function<void()> on_enter, ComponentDecorator Hoverable(std::function<void()> on_enter,
std::function<void()> on_leave) { std::function<void()> on_leave) {
return [on_enter, on_leave](Component component) { return [on_enter, on_leave](Component component) {
@ -148,6 +163,20 @@ ComponentDecorator Hoverable(std::function<void()> on_enter,
}; };
} }
/// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// mouse.
/// @param component the wrapped component.
/// @param on_change is called when the mouse enter or leave the component.
/// @ingroup component
///
/// ### Example
///
/// ```cpp
/// auto button = Button("exit", screen.ExitLoopClosure());
/// bool hovered = false;
/// auto button_hoverable = Hoverable(button,
// [&](bool hover) { hovered = hover;});
/// ```
Component Hoverable(Component component, std::function<void(bool)> on_change) { Component Hoverable(Component component, std::function<void(bool)> on_change) {
return Hoverable( return Hoverable(
component, // component, //
@ -156,8 +185,18 @@ Component Hoverable(Component component, std::function<void(bool)> on_change) {
); );
} }
/// @brief Wrap a component. Two callback can be used to know when the mouse /// @brief Wrap a component. Gives the ability to know if it is hovered by the
/// enter and leave its area. /// mouse.
/// @param on_change is called when the mouse enter or leave the component.
/// @ingroup component
///
/// ### Example
///
/// ```cpp
/// auto button = Button("exit", screen.ExitLoopClosure());
/// bool hovered = false;
/// button |= Hoverable([&](bool hover) { hovered = hover;});
/// ```
ComponentDecorator Hoverable(std::function<void(bool)> on_change) { ComponentDecorator Hoverable(std::function<void(bool)> on_change) {
return [on_change](Component component) { return [on_change](Component component) {
return Hoverable(component, on_change); return Hoverable(component, on_change);