Skip to content

Commit

Permalink
add popput retracting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed May 9, 2024
1 parent 0462a93 commit 0e22c25
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 21 deletions.
48 changes: 48 additions & 0 deletions src/widgets/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,51 @@ void WidgetBase::reset()
onReset();
iterateChildren([&](WidgetBase* child) { child->reset(); });
}

void WidgetBase::popOut()
{
onPopOut();
iterateChildren([&](WidgetBase* child) { child->popOut(); });
_base_data.isWidgetRetracting = false;
}

void WidgetBase::retract()
{
onRetract();
iterateChildren([&](WidgetBase* child) { child->retract(); });
_base_data.isWidgetRetracting = true;
}

bool WidgetBase::isRetracting()
{
// Self check
if (!isAnimFinish())
return false;
if (!_base_data.isWidgetRetracting)
return false;

// Children check
for (const auto& i : _base_data.children)
{
if (!(i->isRetracting()))
return false;
}
return true;
}

bool WidgetBase::isPoppedOut()
{
// Self check
if (!isAnimFinish())
return false;
if (_base_data.isWidgetRetracting)
return false;

// Children check
for (const auto& i : _base_data.children)
{
if (!(i->isPoppedOut()))
return false;
}
return true;
}
63 changes: 42 additions & 21 deletions src/widgets/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace SmoothUIToolKit
namespace Widgets
{
/**
* @brief Provide tree structure and common props.
* @brief Provide tree structure and common widget logic callbacks for animation
*
*/
class WidgetBase
Expand All @@ -41,11 +41,8 @@ namespace SmoothUIToolKit
// Auto invoke render() after root widget update
bool renderOnUpdate = true;

// // If true, onRender() will be invoked on next render()
// bool needRender = true;

// // If true, onRender() will be invoked on every render()
// bool alwaysRender = false;
// Poped out or retracting
bool isWidgetRetracting = true;
};
Data_t _base_data;

Expand Down Expand Up @@ -140,20 +137,29 @@ namespace SmoothUIToolKit
inline void setVisible(bool isVisible) { _base_data.isVisible = isVisible; }
inline bool isVisible() { return _base_data.isVisible; }

// /**
// * @brief Notice widget is render needed
// *
// */
// inline void needRender() { _base_data.needRender = true; }
// inline bool isNeedRender() { return _base_data.needRender; }

// /**
// * @brief Set the Always Render flag
// *
// * @param alwaysRender
// */
// inline void setAlwaysRender(bool alwaysRender) { _base_data.alwaysRender = alwaysRender; }
// inline bool isAlwaysRender() { return _base_data.alwaysRender; }
/**
* @brief Is popup or any anim is finished
*
* @return true
* @return false
*/
virtual bool isAnimFinish() { return true; }

/**
* @brief Is widget completely retracting
*
* @return true
* @return false
*/
virtual bool isRetracting();

/**
* @brief Is widget completely popped out
*
* @return true
* @return false
*/
virtual bool isPoppedOut();

/* -------------------------------------------------------------------------- */
/* Update */
Expand All @@ -178,6 +184,7 @@ namespace SmoothUIToolKit
/* -------------------------------------------------------------------------- */
/* Common methods */
/* -------------------------------------------------------------------------- */
// Children methods will also be invoked
public:
/**
* @brief Init your shit
Expand All @@ -186,17 +193,31 @@ namespace SmoothUIToolKit
virtual void init();

/**
* @brief Reset anim or whatever
* @brief Reset widget
*
*/
virtual void reset();

/**
* @brief Set your pop out anim maybe
*
*/
virtual void popOut();

/**
* @brief Set your retract anim maybe
*
*/
virtual void retract();

/* -------------------------------------------------------------------------- */
/* Callbacks */
/* -------------------------------------------------------------------------- */
public:
virtual void onInit() {}
virtual void onReset() {}
virtual void onPopOut() {}
virtual void onRetract() {}
virtual void onUpdate() {}
virtual void onRender() {}
virtual void onPostRender() {}
Expand Down

0 comments on commit 0e22c25

Please sign in to comment.