This commit is contained in:
IlyaShurupov 2024-05-03 15:09:26 +03:00
parent 86a41c1876
commit e2072d257f
14 changed files with 594 additions and 341 deletions

View file

@ -6,14 +6,7 @@ namespace tp {
template <typename Events, typename Canvas>
class SplitView : public Widget<Events, Canvas> {
public:
SplitView() {
this->createConfig("SplitView");
this->addColor("Handle", "Accent");
this->addColor("Hovered", "Interaction");
this->addColor("Resizing", "Action");
this->addValue("Min", 200.f);
this->addValue("HandleSize", 7.f);
}
SplitView() { this->mId = "SplitView"; }
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
@ -38,9 +31,9 @@ namespace tp {
mFactor += diff / this->mArea.z;
}
mFactor = tp::clamp(mFactor, this->getValue("Min") / this->mArea.z, 1 - this->getValue("Min") / this->mArea.z);
mFactor = tp::clamp(mFactor, mMinSize / this->mArea.z, 1 - mMinSize / this->mArea.z);
if (this->getValue("Min") * 2.f > this->mArea.z) {
if (mMinSize * 2.f > this->mArea.z) {
mFactor = 0.5f;
}
}
@ -49,34 +42,52 @@ namespace tp {
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
if (mResizeInProcess) canvas.rect(getHandle(), this->getColor("Resizing"));
else if (mIsHover) canvas.rect(getHandle(), this->getColor("Hovered"));
else canvas.rect(getHandle(), this->getColor("Handle"));
if (mResizeInProcess) canvas.rect(getHandle(), mResizingColor);
else if (mIsHover) canvas.rect(getHandle(), mHoveredColor);
else canvas.rect(getHandle(), mHandleColor);
}
RectF getFirst() const {
return {
this->mArea.x, this->mArea.y, mFactor * this->mArea.z - this->getValue("HandleSize") / 2.f, this->mArea.w
};
return { this->mArea.x, this->mArea.y, mFactor * this->mArea.z - mHandleSize / 2.f, this->mArea.w };
}
RectF getSecond() const {
return { this->mArea.x + mFactor * this->mArea.z + this->getValue("HandleSize") / 2.f,
return { this->mArea.x + mFactor * this->mArea.z + mHandleSize / 2.f,
this->mArea.y,
(1.f - mFactor) * this->mArea.z - this->getValue("HandleSize") / 2.f,
(1.f - mFactor) * this->mArea.z - mHandleSize / 2.f,
this->mArea.w };
}
RectF getHandle() const {
return { this->mArea.x + mFactor * this->mArea.z - this->getValue("HandleSize") / 2.f,
this->mArea.y,
this->getValue("HandleSize"),
this->mArea.w };
return { this->mArea.x + mFactor * this->mArea.z - mHandleSize / 2.f, this->mArea.y, mHandleSize, this->mArea.w };
}
void setupConfig(WidgetManager& wm) {
if (!wm.createWidgetConfig(this->mId)) return;
wm.addReference(this->mId, "Handle", "Accent");
wm.addReference(this->mId, "Hovered", "Interaction");
wm.addReference(this->mId, "Resizing", "Action");
wm.addNumber(this->mId, "Min", 200.f);
wm.addNumber(this->mId, "HandleSize", 7.f);
}
void updateConfigCache(const WidgetManager& wm) override {
mHandleColor = wm.getColor(this->mId, "Handle");
mHoveredColor = wm.getColor(this->mId, "Hovered");
mResizingColor = wm.getColor(this->mId, "Resizing");
mMinSize = wm.getNumber(this->mId, "Min");
mHandleSize = wm.getNumber(this->mId, "HandleSize");
}
public:
halnf mFactor = 0.7f;
bool mResizeInProcess = false;
bool mIsHover = false;
RGBA mHandleColor;
RGBA mHoveredColor;
RGBA mResizingColor;
halnf mMinSize = 0;
halnf mHandleSize = 0;
};
}