Refactor
This commit is contained in:
parent
49cfe70c0d
commit
72c4740f82
18 changed files with 592 additions and 203 deletions
56
WidgetsNew/public/LayoutWidget.hpp
Normal file
56
WidgetsNew/public/LayoutWidget.hpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.hpp"
|
||||
|
||||
namespace tp {
|
||||
class DesktopLayout : public Widget {
|
||||
public:
|
||||
DesktopLayout() { setDebug("desktop layout", { 0, 0, 0.9, 0.9 }); }
|
||||
|
||||
void draw(Canvas& canvas) override {
|
||||
// canvas.rect(getRelativeArea(), RGBA(0, 0, 0, 1));
|
||||
}
|
||||
|
||||
void adjustRect() override {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void adjustChildrenRect() override {
|
||||
// todo : adjust by viewport pos
|
||||
}
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return false; }
|
||||
};
|
||||
|
||||
|
||||
class VerticalLayout : public Widget {
|
||||
public:
|
||||
VerticalLayout() {
|
||||
setDebug("vertical", { 0.8, 0.1, 0.1, 0.9 });
|
||||
}
|
||||
|
||||
void draw(Canvas& canvas) override {
|
||||
// canvas.frame(getRelativeArea(), RGBA(1));
|
||||
}
|
||||
|
||||
void adjustChildrenRect() override {
|
||||
auto content = &mChildren;
|
||||
auto area = getRelativeArea();
|
||||
|
||||
auto iterRect = area.shrink(mPadding);
|
||||
iterRect.height = ((iterRect.height + mGap) / (float) content->size()) - mGap;
|
||||
|
||||
for (auto widget :(*content)) {
|
||||
widget->setArea(iterRect);
|
||||
iterRect.y += iterRect.height + mGap;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool processesEvents() const override { return false; }
|
||||
|
||||
private:
|
||||
halnf mGap = 10;
|
||||
halnf mPadding = 10;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue