Replace Old Widgets
This commit is contained in:
parent
03da5e41d6
commit
c41dc20132
81 changed files with 388 additions and 278 deletions
20
Widgets/public/widgets/AnimationTestWidget.hpp
Normal file
20
Widgets/public/widgets/AnimationTestWidget.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.hpp"
|
||||
|
||||
namespace tp {
|
||||
class AnimationTestWidget : public Widget {
|
||||
|
||||
public:
|
||||
AnimationTestWidget() = default;
|
||||
~AnimationTestWidget() override = default;
|
||||
|
||||
void draw(Canvas& canvas) override;
|
||||
void process(const EventHandler& events) override;
|
||||
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
|
||||
private:
|
||||
mutable SpringRect mTestSpring;
|
||||
};
|
||||
}
|
||||
42
Widgets/public/widgets/DockWidget.hpp
Normal file
42
Widgets/public/widgets/DockWidget.hpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "DockLayout.hpp"
|
||||
|
||||
namespace tp {
|
||||
class DockWidget : public Widget {
|
||||
public:
|
||||
DockWidget();
|
||||
|
||||
public:
|
||||
void process(const EventHandler& events) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
void drawOverlay(Canvas& canvas) override;
|
||||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
[[nodiscard]]bool processesEvents() const override { return true; }
|
||||
|
||||
void drawSide(DockLayout::Side side, Canvas& canvas);
|
||||
|
||||
public:
|
||||
void setCenterWidget(Widget* widget);
|
||||
|
||||
void dockWidget(Widget* widget, DockLayout::Side side);
|
||||
void undockWidget(DockLayout::Side side, bool restoreArea = true);
|
||||
void toggleWidgetVisibility(DockLayout::Side side);
|
||||
|
||||
private:
|
||||
DockLayout* layout() { return dynamic_cast<DockLayout*>(mLayout); }
|
||||
const DockLayout* layout() const { return dynamic_cast<const DockLayout*>(mLayout); }
|
||||
|
||||
private:
|
||||
Widget* mPreviewWidget = nullptr;
|
||||
|
||||
private:
|
||||
halnf mRounding = 10;
|
||||
halnf mPadding = 4;
|
||||
|
||||
RGBA mResizeHandleColorHovered = RGBA(0.3, 0.3, 0.3, 1);
|
||||
RGBA mResizeHandleColorActive = RGBA(0.6, 0.6, 0.6, 1);
|
||||
RGBA mBackgroundColor = RGBA(0, 0, 0, 1);
|
||||
RGBA mPreviewColor = RGBA(0.6, 0.6, 0.6, 0.2);
|
||||
};
|
||||
}
|
||||
62
Widgets/public/widgets/FloatingWidget.hpp
Normal file
62
Widgets/public/widgets/FloatingWidget.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include "SimpleWidgets.hpp"
|
||||
#include "FloatingLayout.hpp"
|
||||
#include "ScrollableWidget.hpp"
|
||||
|
||||
namespace tp {
|
||||
class FloatingWidget : public Widget {
|
||||
public:
|
||||
FloatingWidget() : Widget() {
|
||||
setDebug("float", { 0.0, 0.9, 0.1, 1 });
|
||||
setLayout(new FloatingLayout(this));
|
||||
}
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
[[nodiscard]] bool processesEvents() const override;
|
||||
|
||||
[[nodiscard]] bool isFloating() const;
|
||||
|
||||
private:
|
||||
FloatingLayout* layout();
|
||||
[[nodiscard]] const FloatingLayout* layout() const;
|
||||
};
|
||||
|
||||
class FloatingMenu : public FloatingWidget {
|
||||
public:
|
||||
FloatingMenu();
|
||||
|
||||
public:
|
||||
void addToMenu(Widget* widget) {
|
||||
widget->setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mContentWidget.addChild(widget);
|
||||
}
|
||||
|
||||
const List<Widget*>& getContent() {
|
||||
return mContentWidget.getChildren();
|
||||
}
|
||||
|
||||
void clearChildren() {
|
||||
mContentWidget.clear();
|
||||
}
|
||||
|
||||
void setText(const std::string& text);
|
||||
|
||||
private:
|
||||
// VerticalLayout mMenuLayout;
|
||||
Widget mBodyLayout;
|
||||
Widget mContentWidget;
|
||||
ScrollableBarWidget mScrollBar;
|
||||
|
||||
LabelWidget mHeader;
|
||||
|
||||
// ButtonWidget mTestButton;
|
||||
};
|
||||
}
|
||||
57
Widgets/public/widgets/ScrollableWidget.hpp
Normal file
57
Widgets/public/widgets/ScrollableWidget.hpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.hpp"
|
||||
|
||||
namespace tp {
|
||||
// just the scrolling bar
|
||||
class ScrollableBarWidget : public Widget {
|
||||
public:
|
||||
ScrollableBarWidget() = default;
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return true; }
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override { return false; }
|
||||
[[nodiscard]] bool needsNextFrame() const override { return mScrolling; }
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
void updateSizeFactor(halnf factor); // holder-size divided by content-size
|
||||
|
||||
[[nodiscard]] bool getDirection() const { return mVertical; }
|
||||
[[nodiscard]] halnf getPosFactor() const { return mPosFactor - mSizeFactor / 2; }
|
||||
|
||||
private:
|
||||
[[nodiscard]] const RectF& getHandleRect() const;
|
||||
void updateHandleRect();
|
||||
void jumpTo(halnf);
|
||||
void moveBy(halnf);
|
||||
void clamp();
|
||||
|
||||
private: // state
|
||||
bool mVertical = true;
|
||||
bool mScrolling = false;
|
||||
bool mHandleHovered = false;
|
||||
|
||||
Vec2F mStartPos = {};
|
||||
|
||||
halnf mPosFactor = 0.2f; // (center-of-holder - content-start) / content-size
|
||||
halnf mSizeFactor = 0.3f;
|
||||
|
||||
private: // TODO : make params static
|
||||
halnf mRounding = 5;
|
||||
halnf mHandlePadding = 0;
|
||||
|
||||
RGBA mBGColor = { 0.1, 0.1, 0.1, 0.0 };
|
||||
RGBA mHandleColor = { 0.2, 0.2, 0.2, 1 };
|
||||
RGBA mHandleHoverColor = { 0.3, 0.3, 0.3, 1 };
|
||||
RGBA mHandleSlideColor = { 0.5, 0.5, 0.5, 1 };
|
||||
|
||||
private: // cache
|
||||
RectF mHandleRect;
|
||||
};
|
||||
|
||||
class ScrollableWidget : public Widget {
|
||||
public:
|
||||
ScrollableWidget();
|
||||
};
|
||||
}
|
||||
94
Widgets/public/widgets/SimpleWidgets.hpp
Normal file
94
Widgets/public/widgets/SimpleWidgets.hpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace tp {
|
||||
class LabelWidget : public Widget {
|
||||
public:
|
||||
LabelWidget() : Widget() {
|
||||
setDebug("label", { 0.1, 0.1, 0.1, 0.1 });
|
||||
}
|
||||
|
||||
void setText(const std::string& text);
|
||||
|
||||
[[nodiscard]] const std::string& getText() const;
|
||||
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return false; }
|
||||
|
||||
private:
|
||||
std::string mText = "Text";
|
||||
|
||||
halnf mPadding = 5;
|
||||
RGBA mColor = 1.f;
|
||||
halnf mSize = 17.f;
|
||||
};
|
||||
|
||||
class ButtonWidget : public LabelWidget {
|
||||
public:
|
||||
ButtonWidget();
|
||||
|
||||
void setAction(const std::function<void()>& action);
|
||||
|
||||
void process(const EventHandler& eventHandler) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
void mouseEnter() override;
|
||||
void mouseLeave() override;
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return true; }
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
|
||||
void endAnimations() override;
|
||||
void updateAnimations() override;
|
||||
|
||||
void setColor(const RGBA& in);
|
||||
|
||||
private:
|
||||
std::function<void()> mAction;
|
||||
|
||||
SpringRect mColorAnimated;
|
||||
|
||||
halnf mRounding = 5;
|
||||
RGBA mColorHovered = { 0.0f, 0.4f, 0.4f, 1.f };
|
||||
RGBA mColor = { 0.13f, 0.13f, 0.13f, 1.f };
|
||||
};
|
||||
|
||||
class SliderWidget : public Widget {
|
||||
enum State {
|
||||
IDLE,
|
||||
HOVER,
|
||||
SLIDING,
|
||||
};
|
||||
|
||||
public:
|
||||
SliderWidget() = default;
|
||||
|
||||
void process(const EventHandler& eventHandler) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return true; }
|
||||
[[nodiscard]] bool needsNextFrame() const override { return mState != SLIDING; }
|
||||
|
||||
[[nodiscard]] halnf val() const { return mFactor; }
|
||||
|
||||
private:
|
||||
[[nodiscard]] RectF getHandleArea() const;
|
||||
|
||||
private:
|
||||
halnf mFactor = 0;
|
||||
State mState = IDLE;
|
||||
|
||||
private:
|
||||
halnf mHandleSize = 20;
|
||||
halnf mRounding = 5;
|
||||
|
||||
RGBA mColorActive = { 0.5f, 0.5f, 0.5f, 1.f };
|
||||
RGBA mColorHovered = { 0.3f, 0.3f, 0.3f, 1.f };
|
||||
RGBA mColorIdle = { 0.2f, 0.2f, 0.2f, 1.f };
|
||||
RGBA mColorBG = { 0.08f, 0.08f, 0.08f, 1.0f };
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue