Skip to content

Commit

Permalink
add more state shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed May 10, 2024
1 parent 90fb06e commit a6a00e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
32 changes: 23 additions & 9 deletions src/widgets/smooth_widget/smooth_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ void SmoothWidgetBase::popOut()
{
onPopOut();
iterateChildren([&](WidgetBase* child) { ((SmoothWidgetBase*)child)->popOut(); });
_smooth_base_data.is_widget_retracting = false;
_smooth_base_data.is_hiding = false;
}

void SmoothWidgetBase::retract()
void SmoothWidgetBase::hide()
{
onRetract();
iterateChildren([&](WidgetBase* child) { ((SmoothWidgetBase*)child)->retract(); });
_smooth_base_data.is_widget_retracting = true;
onHide();
iterateChildren([&](WidgetBase* child) { ((SmoothWidgetBase*)child)->hide(); });
_smooth_base_data.is_hiding = true;
}

bool SmoothWidgetBase::isRetracting()
bool SmoothWidgetBase::isHidden()
{
// Self check
if (!isTransitionFinish())
return false;
if (!_smooth_base_data.is_widget_retracting)
if (!_smooth_base_data.is_hiding)
return false;

// Children check
for (const auto& i : _base_data.children)
{
if (!((SmoothWidgetBase*)i)->isRetracting())
if (!((SmoothWidgetBase*)i)->isHidden())
return false;
}
return true;
Expand All @@ -48,7 +48,7 @@ bool SmoothWidgetBase::isPoppedOut()
// Self check
if (!isTransitionFinish())
return false;
if (_smooth_base_data.is_widget_retracting)
if (_smooth_base_data.is_hiding)
return false;

// Children check
Expand All @@ -60,6 +60,20 @@ bool SmoothWidgetBase::isPoppedOut()
return true;
}

bool SmoothWidgetBase::isHidding()
{
if (_smooth_base_data.is_hiding && !isHidden())
return true;
return false;
}

bool SmoothWidgetBase::isPoppingOut()
{
if (!_smooth_base_data.is_hiding && !isPoppedOut())
return true;
return false;
}

void SmoothWidgetBase::updateTransition(const TimeSize_t& currentTime)
{
// Update transition
Expand Down
30 changes: 23 additions & 7 deletions src/widgets/smooth_widget/smooth_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace SmoothUIToolKit
Transition4D transition;

// Transition direction
bool is_widget_retracting = true;
bool is_hiding = true;
};
SmoothBaseData_t _smooth_base_data;

Expand All @@ -49,10 +49,10 @@ namespace SmoothUIToolKit
virtual void popOut();

/**
* @brief Retract widget
* @brief Hide widget
*
*/
virtual void retract();
virtual void hide();

/**
* @brief Is transition finished
Expand All @@ -63,12 +63,12 @@ namespace SmoothUIToolKit
virtual bool isTransitionFinish() { return _smooth_base_data.transition.isFinish(); }

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

/**
* @brief Is widget completely popped out
Expand All @@ -78,6 +78,22 @@ namespace SmoothUIToolKit
*/
virtual bool isPoppedOut();

/**
* @brief Is widget hidding currently
*
* @return true
* @return false
*/
virtual bool isHidding();

/**
* @brief Is widget popping out currently
*
* @return true
* @return false
*/
virtual bool isPoppingOut();

/**
* @brief Update transition
*
Expand All @@ -103,10 +119,10 @@ namespace SmoothUIToolKit
virtual void onPopOut() {}

/**
* @brief Setup your retract transition
* @brief Setup your hiding transition
*
*/
virtual void onRetract() {}
virtual void onHide() {}
};
} // namespace Widgets
} // namespace SmoothUIToolKit

0 comments on commit a6a00e4

Please sign in to comment.