Skip to content

Commit

Permalink
adding smooth shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed May 20, 2024
1 parent e2c32f3 commit 2c0fded
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/smooth_ui_toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "widgets/base/base.h"
#include "widgets/selector/base/option.h"
#include "widgets/selector/base/selelctor.h"
#include "widgets/selector/smooth_selector/smooth_option.h"
#include "widgets/selector/smooth_selector/smooth_selector.h"
#include "widgets/smooth_widget/smooth_widget.h"

#include "misc/water_wave_generator/water_wave_generator.h"
3 changes: 0 additions & 3 deletions src/widgets/selector/base/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
*
*/
#pragma once
#include "../../../core/transition4d/transition4d.h"
#include "../../base/base.h"
#include <functional>

namespace SmoothUIToolKit
{
Expand Down
23 changes: 20 additions & 3 deletions src/widgets/selector/base/selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,41 @@

using namespace SmoothUIToolKit::Widgets::Selector;

SmoothUIToolKit::Widgets::WidgetBase* SelectorBase::getSelectedWidget()
{
if (_selector_base_data.current_widget == nullptr)
return nullptr;
if (_selector_base_data.selected_option_index < 0)
return nullptr;
return _selector_base_data.current_widget->getChildren()[_selector_base_data.selected_option_index];
}

void SelectorBase::enter(WidgetBase* widget)
{
if (widget == nullptr)
return;

// Set current widget
_selector_base_data.current_widget = widget;
onEnter();

// Select first widget
if (!_selector_base_data.current_widget->isLeaf())
goTo(0);
}

bool SelectorBase::back()
{
if (_selector_base_data.current_widget->isRoot())
return false;
_selector_base_data.current_widget = _selector_base_data.current_widget->getParent();
onBack();
return true;
}

void SelectorBase::goLast()
{
if (getOptionNum() <= 0)
if (getOptionNum() == 0)
return;

int new_index = _selector_base_data.selected_option_index - 1;
Expand All @@ -42,7 +59,7 @@ void SelectorBase::goLast()

void SelectorBase::goNext()
{
if (getOptionNum() <= 0)
if (getOptionNum() == 0)
return;

int new_index = _selector_base_data.selected_option_index + 1;
Expand All @@ -55,7 +72,7 @@ void SelectorBase::goNext()

void SelectorBase::goTo(int optionIndex)
{
if (getOptionNum() <= 0)
if (getOptionNum() == 0)
return;
if (optionIndex < 0 || optionIndex > (getOptionNum() - 1))
return;
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/selector/base/selelctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*
*/
#pragma once
#include "../../../core/transition4d/transition4d.h"
#include "../../base/base.h"
#include "option.h"
#include <cstddef>
Expand All @@ -32,14 +31,15 @@ namespace SmoothUIToolKit
{
WidgetBase* current_widget = nullptr;
bool move_in_loop = true;
int selected_option_index = 0;
int selected_option_index = -1;
};
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; }
WidgetBase* getSelectedWidget();

public:
/**
Expand All @@ -64,6 +64,8 @@ namespace SmoothUIToolKit
void goTo(int optionIndex);

public:
virtual void onEnter() {}
virtual void onBack() {}
virtual void onGoLast() {}
virtual void onGoNext() {}
virtual void onGoTo() {}
Expand Down
26 changes: 26 additions & 0 deletions src/widgets/selector/smooth_selector/smooth_option.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file smooth_option.h
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2024-05-20
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#include "../../smooth_widget/smooth_widget.h"
#include "../base/option.h"

namespace SmoothUIToolKit
{
namespace Widgets
{
namespace Selector
{
class SmoothOption : public SmoothWidgetBase, public OptionBase
{
};
} // namespace Selector
} // namespace Widgets
} // namespace SmoothUIToolKit
21 changes: 21 additions & 0 deletions src/widgets/selector/smooth_selector/smooth_selector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file smooth_selector.cpp
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2024-05-20
*
* @copyright Copyright (c) 2024
*
*/
#include "smooth_selector.h"
#include "smooth_option.h"

using namespace SmoothUIToolKit::Widgets::Selector;

void SmoothSelector::onGoTo()
{
// Get selected widget frame
auto target_frame = ((SmoothOption*)getSelectedWidget())->getTransition().getTargetPoint();
getTransition().moveTo(target_frame);
}
27 changes: 27 additions & 0 deletions src/widgets/selector/smooth_selector/smooth_selector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file smooth_selector.h
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2024-05-20
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#include "../../smooth_widget/smooth_widget.h"
#include "../base/selelctor.h"

namespace SmoothUIToolKit
{
namespace Widgets
{
namespace Selector
{
class SmoothSelector : public SmoothWidgetBase, public SelectorBase
{
void onGoTo() override;
};
} // namespace Selector
} // namespace Widgets
} // namespace SmoothUIToolKit

0 comments on commit 2c0fded

Please sign in to comment.