Refactor done
This commit is contained in:
parent
3e37f0cd3d
commit
1508a51cde
25 changed files with 797 additions and 610 deletions
|
|
@ -1,32 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include "SpringAnimations.hpp"
|
||||
#include "LayoutPolicies.hpp"
|
||||
#include "LayoutManager.hpp"
|
||||
|
||||
#include "EventHandler.hpp"
|
||||
#include "Graphics.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace tp {
|
||||
class WidgetManagerInterface;
|
||||
class WidgetLayout;
|
||||
class LayoutManager;
|
||||
class RootWidget;
|
||||
|
||||
class Widget {
|
||||
friend class RootWidget;
|
||||
friend RootWidget;
|
||||
friend LayoutManager;
|
||||
|
||||
public:
|
||||
Widget();
|
||||
virtual ~Widget();
|
||||
|
||||
void addChild(Widget* child);
|
||||
void addChild(Widget* child, bool front = false);
|
||||
void removeChild(Widget* child);
|
||||
|
||||
void bringToFront();
|
||||
void bringToBack();
|
||||
|
||||
void setLayout(WidgetLayout* layout);
|
||||
void setSizePolicy(SizePolicy x, SizePolicy y) { getLayout()->setSizePolicy(x, y); }
|
||||
|
||||
WidgetLayout* getLayout();
|
||||
const WidgetLayout* getLayout() const;
|
||||
|
||||
void triggerWidgetUpdate(const char* reason = nullptr);
|
||||
|
||||
protected:
|
||||
virtual void process(const EventHandler& events) {}
|
||||
|
|
@ -45,20 +54,34 @@ namespace tp {
|
|||
protected:
|
||||
void setDebug(const char* name, RGBA col);
|
||||
WidgetManagerInterface* getRoot();
|
||||
void triggerWidgetUpdate(const char* reason = nullptr);
|
||||
|
||||
public:
|
||||
[[nodiscard]] RectF getArea() const;
|
||||
[[nodiscard]] RectF getAreaT() const;
|
||||
[[nodiscard]] const RectF& getAreaCache() const;
|
||||
// [[nodiscard]] const RectF& getAreaCache() const;
|
||||
|
||||
[[nodiscard]] RectF getRelativeArea() const;
|
||||
[[nodiscard]] RectF getRelativeAreaT() const;
|
||||
[[nodiscard]] RectF getRelativeAreaCache() const;
|
||||
// [[nodiscard]] RectF getRelativeAreaCache() const;
|
||||
|
||||
void setArea(const RectF& area);
|
||||
void setAreaCache(const RectF& area);
|
||||
|
||||
private:
|
||||
using DFSAction = std::function<void(Widget*)>;
|
||||
|
||||
static void dfs(Widget* iter, const DFSAction& before, const DFSAction& after = [](auto){}) {
|
||||
if (!iter->mNeedsProcessing) return;
|
||||
|
||||
before(iter);
|
||||
|
||||
for (auto child : iter->mDepthOrder) {
|
||||
dfs(child.data(), before, after);
|
||||
}
|
||||
|
||||
after(iter);
|
||||
}
|
||||
|
||||
protected:
|
||||
friend WidgetLayout;
|
||||
|
||||
|
|
@ -73,7 +96,10 @@ namespace tp {
|
|||
|
||||
WidgetLayout* mLayout = nullptr;
|
||||
|
||||
// TODO : make bitfield processing flags
|
||||
bool mInFocus = false;
|
||||
bool mNeedsProcessing = false;
|
||||
bool mTriggered = false;
|
||||
|
||||
// debug
|
||||
struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue