Widgets Additions and sketch3d new gui

This commit is contained in:
IlyaShurupov 2024-10-20 12:01:42 +03:00
parent aecc75828b
commit 762268387e
44 changed files with 1015 additions and 322 deletions

View file

@ -61,7 +61,7 @@ namespace tp {
protected:
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Fixed, SizePolicy::Fixed };
Vec2F mMinSize = { 50, 50 };
Vec2F mMinSize = { 30, 30 };
Vec2F mMaxSize = { FLT_MAX / 2, FLT_MAX / 2 };
private:

View file

@ -18,8 +18,6 @@ namespace tp {
void setRootWidget(Widget* widget);
static void setWidgetArea(Widget& widget, const RectF& rect);
[[nodiscard]] bool isDebug() const;
// Graphic Application Interface
public:
void processFrame(EventHandler* events, const RectF& screenArea);

View file

@ -59,6 +59,7 @@ namespace tp {
void setSizePolicy(SizePolicy x, SizePolicy y);
void setEnabled(bool val) { mFlags.set(ENABLED, val); }
[[nodiscard]] bool getEnabled() const { return mFlags.get(ENABLED); }
WidgetLayout* getLayout();
[[nodiscard]] const WidgetLayout* getLayout() const;

View file

@ -9,41 +9,24 @@ namespace tp {
public:
WidgetApplication() = default;
void setRoot(Widget* widget) {
mRootWidget.setRootWidget(widget);
}
void setRoot(Widget* widget);
private:
void processFrame(EventHandler* eventHandler, halnf deltaTime) override {
const auto rec = RectF({ 0, 0 }, mWindow->getSize());
void processFrame(EventHandler* eventHandler, halnf deltaTime) override;
Timer timer;
mRootWidget.processFrame(eventHandler, rec);
mProcTime = timer.timePassed();
}
void drawFrame(Canvas* canvas) override {
Timer timer;
mRootWidget.drawFrame(*canvas);
mDrawTime = timer.timePassed();
if (mRootWidget.isDebug()) {
drawDebug();
debugUI();
}
}
bool forceNewFrame() override {
return mRootWidget.needsUpdate();
}
void drawFrame(Canvas* canvas) override;
bool forceNewFrame() override ;
private:
void debugUI();
private:
time_ms mProcTime = 0;
time_ms mDrawTime = 0;
halnf mDebugSplitFactor = 0.7;
RootWidget mRootWidget;
private:
RectF mGuiArea;
RectF mDebugArea;
};
}

View file

@ -96,7 +96,7 @@ namespace tp {
bool mResizing = false;
Widget* mCenterWidget = nullptr;
RectF mCenterArea {};
RectF mCenterArea { 0, 0, 10, 10 };
// Parameters
const halnf mHandleSplitFactor = 0.3;

View file

@ -15,4 +15,19 @@ namespace tp {
void pickRect(bool vertical) override {}
void clampRect() override {}
};
class ToolBarLayout : public WidgetLayout {
friend class DebugManager;
public:
explicit ToolBarLayout(Widget* widget) : WidgetLayout(widget) {}
void updateLayout(bool vertical) override;
void pickRect(bool vertical) override {}
void clampRect() override {}
private:
halnf mToolBarHeight = 55;
};
}

View file

@ -5,12 +5,56 @@
#include <set>
namespace tp {
class DebugTimeline {
enum {
STEP = 10,
LEN = 200,
};
public:
DebugTimeline() = default;
void addSample(time_ms time) {
samples[end] = time;
start++;
end++;
shift();
}
[[nodiscard]] int size() const {
return LEN - STEP;
}
[[nodiscard]] const time_ms* get() const {
return samples + start;
}
private:
void shift() {
if (end >= LEN) {
for (ualni i = STEP; i < LEN; i++) {
samples[i - STEP] = samples[i];
}
start = 0;
end = LEN - STEP;
}
}
private:
ualni start = 0;
ualni end = LEN - STEP;
time_ms samples[LEN + 1] {};
};
class DebugManager {
public:
DebugManager() = default;
bool isRedrawAlways() const { return mDebugRedrawAlways; }
bool update(RootWidget* rootWidget, EventHandler& events);
[[nodiscard]] bool isFrozen() const { return mDebugStopProcessing; }
[[nodiscard]] bool isRedrawAlways() const { return mDebugRedrawAlways; }
void update(RootWidget* rootWidget, EventHandler& events);
void drawDebug(RootWidget* rootWidget, Canvas& canvas);
void checkProcBreakPoints(Widget* widget) {
@ -32,6 +76,7 @@ namespace tp {
private:
void recursiveDraw(Canvas& canvas, Widget* active, const Vec2F& pos, int depthOrder);
void drawPerformance();
static void widgetMenu(Widget*);
void drawLayoutOrder();
@ -42,10 +87,17 @@ namespace tp {
bool mDebug = false;
bool mDebugStopProcessing = false;
bool mDebugRedrawAlways = false;
bool mSlowMotion = false;
bool mDetailed = false;
std::set<Widget*> mProcBreakpoints;
std::set<Widget*> mLayBreakpoints;
public:
DebugTimeline mProcTime;
DebugTimeline mUpdManager;
DebugTimeline mLayManager;
DebugTimeline mDrawTime;
};
extern DebugManager gDebugWidget;

View file

@ -0,0 +1,18 @@
#pragma once
#include "Widget.hpp"
namespace tp {
class RGBPickerWidget : public Widget {
public:
RGBPickerWidget() = default;
void process(const EventHandler& events) override;
void draw(Canvas& canvas) override;
[[nodiscard]] bool processesEvents() const override { return true; }
public:
Canvas::ColorWheel mColorWheel;
};
}

View file

@ -17,6 +17,8 @@ namespace tp {
void drawSide(DockLayout::Side side, Canvas& canvas);
public:
DockLayout::Side getSide(Widget* widget) { return layout()->getSideFromWidget(widget); }
void setCenterWidget(Widget* widget);
void dockWidget(Widget* widget, DockLayout::Side side);

View file

@ -20,6 +20,8 @@ namespace tp {
[[nodiscard]] bool getDirection() const { return mVertical; }
[[nodiscard]] halnf getPosFactor() const { return mPosFactor - mSizeFactor / 2; }
void setDirection(bool direction) { mVertical = direction; }
private:
[[nodiscard]] const RectF& getHandleRect() const;
void updateHandleRect();
@ -53,5 +55,13 @@ namespace tp {
class ScrollableWidget : public Widget {
public:
ScrollableWidget();
void setDirection(bool direction);
Widget* getContainer() { return &mContent; }
private:
Widget mContent;
ScrollableBarWidget mScroller;
};
}

View file

@ -71,7 +71,7 @@ namespace tp {
void draw(Canvas& canvas) override;
[[nodiscard]] bool processesEvents() const override { return true; }
[[nodiscard]] bool needsNextFrame() const override { return mState != SLIDING; }
[[nodiscard]] bool needsNextFrame() const override { return mState != IDLE; }
[[nodiscard]] halnf val() const { return mFactor; }
@ -86,9 +86,55 @@ namespace tp {
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 };
RGBA mColorActive = { 0.99f, 0.99f, 0.99f, 1.f };
RGBA mColorHovered = { 0.9f, 0.9f, 0.9f, 1.f };
RGBA mColorIdle = { 0.8f, 0.8f, 0.8f, 1.f };
RGBA mColorBG = { 0.3f, 0.3f, 0.3f, 1.0f };
};
class PopupWidget : public Widget {
public:
PopupWidget() = default;
public:
void process(const EventHandler& events) override;
void draw(Canvas& canvas) override;
void open(Widget* parent, const RectF& at);
[[nodiscard]] bool processesEvents() const override { return true; }
private:
RectF mParentArea {};
RGBA col = RGBA(0.03f, 0.03f, 0.03f, 0.9f);
halnf rounding = 5;
halnf borders = 2;
};
class HoverPopupTriggerWidget : public LabelWidget {
public:
enum ExpandDirection {
Right,
Bottom,
};
public:
HoverPopupTriggerWidget() = default;
[[nodiscard]] bool processesEvents() const override { return true; }
void mouseEnter() override;
void draw(Canvas& canvas) override;
PopupWidget* getPopup();
void setDirection(ExpandDirection dir) { mDirection = dir; }
private:
PopupWidget mPopup;
private:
ExpandDirection mDirection = Bottom;
RGBA col = RGBA(0.03f, 0.03f, 0.03f, 0.07f);
halnf rounding = 5;
halnf gap = 7;
};
}