-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6a00e4
commit e2c32f3
Showing
4 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @file option.h | ||
* @author Forairaaaaa | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-05-20 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
#pragma once | ||
#include "../../../core/transition4d/transition4d.h" | ||
#include "../../base/base.h" | ||
#include <functional> | ||
|
||
namespace SmoothUIToolKit | ||
{ | ||
namespace Widgets | ||
{ | ||
namespace Selector | ||
{ | ||
/** | ||
* @brief Provide selectable option behavior abstraction | ||
* | ||
*/ | ||
class OptionBase | ||
{ | ||
private: | ||
struct OptionBaseData_t | ||
{ | ||
bool isHovering = false; | ||
bool isSelected = false; | ||
}; | ||
OptionBaseData_t _option_base_data; | ||
|
||
public: | ||
inline bool isHovering() { return _option_base_data.isHovering; } | ||
inline void hover() | ||
{ | ||
_option_base_data.isHovering = true; | ||
onHover(); | ||
} | ||
inline void unHover() | ||
{ | ||
_option_base_data.isHovering = false; | ||
onUnHover(); | ||
} | ||
|
||
inline bool isSelected() { return _option_base_data.isSelected; } | ||
inline void select() | ||
{ | ||
_option_base_data.isSelected = true; | ||
onSelect(); | ||
} | ||
inline void unSelect() | ||
{ | ||
_option_base_data.isSelected = false; | ||
onUnSelect(); | ||
} | ||
|
||
public: | ||
virtual void onHover() {} | ||
virtual void onUnHover() {} | ||
virtual void onPressed() {} | ||
virtual void onReleasd() {} | ||
virtual void onClicked() {} | ||
virtual void onSelect() {} | ||
virtual void onUnSelect() {} | ||
}; | ||
} // namespace Selector | ||
} // namespace Widgets | ||
} // namespace SmoothUIToolKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @file selector.cpp | ||
* @author Forairaaaaa | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-05-20 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
#include "selelctor.h" | ||
|
||
using namespace SmoothUIToolKit::Widgets::Selector; | ||
|
||
void SelectorBase::enter(WidgetBase* widget) | ||
{ | ||
if (widget == nullptr) | ||
return; | ||
_selector_base_data.current_widget = widget; | ||
} | ||
|
||
bool SelectorBase::back() | ||
{ | ||
if (_selector_base_data.current_widget->isRoot()) | ||
return false; | ||
_selector_base_data.current_widget = _selector_base_data.current_widget->getParent(); | ||
return true; | ||
} | ||
|
||
void SelectorBase::goLast() | ||
{ | ||
if (getOptionNum() <= 0) | ||
return; | ||
|
||
int new_index = _selector_base_data.selected_option_index - 1; | ||
if (new_index < 0) | ||
new_index = _selector_base_data.move_in_loop ? getOptionNum() - 1 : 0; | ||
|
||
goTo(new_index); | ||
onGoLast(); | ||
} | ||
|
||
void SelectorBase::goNext() | ||
{ | ||
if (getOptionNum() <= 0) | ||
return; | ||
|
||
int new_index = _selector_base_data.selected_option_index + 1; | ||
if (new_index >= getOptionNum()) | ||
new_index = _selector_base_data.move_in_loop ? 0 : getOptionNum() - 1; | ||
|
||
goTo(new_index); | ||
onGoNext(); | ||
} | ||
|
||
void SelectorBase::goTo(int optionIndex) | ||
{ | ||
if (getOptionNum() <= 0) | ||
return; | ||
if (optionIndex < 0 || optionIndex > (getOptionNum() - 1)) | ||
return; | ||
|
||
_selector_base_data.selected_option_index = optionIndex; | ||
onGoTo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @file selelctor.h | ||
* @author Forairaaaaa | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-05-20 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
#pragma once | ||
#include "../../../core/transition4d/transition4d.h" | ||
#include "../../base/base.h" | ||
#include "option.h" | ||
#include <cstddef> | ||
#include <functional> | ||
|
||
namespace SmoothUIToolKit | ||
{ | ||
namespace Widgets | ||
{ | ||
namespace Selector | ||
{ | ||
/** | ||
* @brief Provide widget selector behavior abstraction | ||
* | ||
*/ | ||
class SelectorBase | ||
{ | ||
private: | ||
struct SelectorBaseData_t | ||
{ | ||
WidgetBase* current_widget = nullptr; | ||
bool move_in_loop = true; | ||
int selected_option_index = 0; | ||
}; | ||
SelectorBaseData_t _selector_base_data; | ||
|
||
public: | ||
inline void moveInloop(bool moveInLoop) { _selector_base_data.move_in_loop = moveInLoop; } | ||
inline size_t getOptionNum() { return _selector_base_data.current_widget->getChildren().size(); } | ||
inline int getSelectedOptionIndex() { return _selector_base_data.selected_option_index; } | ||
|
||
public: | ||
/** | ||
* @brief Enter a widget | ||
* | ||
* @param widget | ||
*/ | ||
void enter(WidgetBase* widget); | ||
|
||
/** | ||
* @brief Go back to last widget | ||
* | ||
* @return true | ||
* @return false | ||
*/ | ||
bool back(); | ||
|
||
void goLast(); | ||
|
||
void goNext(); | ||
|
||
void goTo(int optionIndex); | ||
|
||
public: | ||
virtual void onGoLast() {} | ||
virtual void onGoNext() {} | ||
virtual void onGoTo() {} | ||
}; | ||
} // namespace Selector | ||
} // namespace Widgets | ||
} // namespace SmoothUIToolKit |