This commit is contained in:
elushaX 2024-03-20 00:47:46 -07:00 committed by Ilya Shurupov
parent 6d02137dca
commit a46a2167ba
13 changed files with 182 additions and 90 deletions

View file

@ -29,6 +29,9 @@ namespace tp {
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
mIsHover = false;
if (!areaParent.isOverlap(aArea)) {
@ -37,13 +40,13 @@ namespace tp {
return;
}
mIsHover = aArea.isInside(events.getPos());
mIsHover = aArea.isInside(events.getPointer());
if (events.isPressed() && mIsHover) {
if (events.isPressed(InputID::MOUSE1) && mIsHover) {
mIsPressed = true;
}
if (mIsPressed && mIsHover && events.isReleased()) {
if (mIsPressed && mIsHover && events.isReleased(InputID::MOUSE1)) {
mIsReleased = true;
mIsPressed = false;
}
@ -54,6 +57,8 @@ namespace tp {
}
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
if (mIsPressed) {
canvas.rect(this->mArea, this->getColor("Pressed"), this->getValue("Rounding"));
} else if (mIsHover) {

View file

@ -15,9 +15,13 @@ namespace tp {
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
}
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
canvas.text(
mLabel.read(),
this->mArea,

View file

@ -22,9 +22,11 @@ namespace tp {
// takes whole area
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
auto area = getHandle();
mHovered = getHandleHandle().isInside(events.getPos());
mHovered = getHandleHandle().isInside(events.getPointer());
if (mSizeFraction > 1.f) {
mPositionFraction = 0;
@ -36,7 +38,7 @@ namespace tp {
return;
}
if (events.getScrollY() != 0 && areaParent.isInside(events.getPos())) {
if (events.getScrollY() != 0 && areaParent.isInside(events.getPointer())) {
auto offset = events.getScrollY() < 0 ? 1.0f : -1.0f;
if (scrollInertia * offset > 0) {
scrollInertia += offset;
@ -53,14 +55,14 @@ namespace tp {
return;
}
if (events.isPressed() && area.isInside(events.getPos())) {
if (events.isPressed(InputID::MOUSE1) && area.isInside(events.getPointer())) {
mIsScrolling = true;
} else if (!events.isDown()) {
} else if (events.isReleased(InputID::MOUSE1)) {
mIsScrolling = false;
}
if (mIsScrolling) {
tp::halnf pos = events.getPos().y;
tp::halnf pos = events.getPointer().y;
pos = (pos - area.y - mSizeFraction * area.w / 2.f) / area.w;
mPositionFraction = tp::clamp(pos, 0.f, 1.f - mSizeFraction);
}
@ -69,6 +71,8 @@ namespace tp {
}
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
auto area = getHandle();
if (mSizeFraction > 1.f) return;
@ -142,7 +146,6 @@ namespace tp {
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
updateContents();
@ -170,6 +173,7 @@ namespace tp {
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
mScroller.draw(canvas);
canvas.pushClamp(this->mArea);

View file

@ -17,8 +17,9 @@ namespace tp {
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!areaParent.isOverlap(aArea)) {
if (!this->mVisible) {
mResizeInProcess = false;
return;
}
@ -27,12 +28,12 @@ namespace tp {
if (events.isPressed(InputID::MOUSE1) && mIsHover) {
mResizeInProcess = true;
} else if (!events.isDown()) {
} else if (events.isReleased(InputID::MOUSE1)) {
mResizeInProcess = false;
}
if (mResizeInProcess) {
halnf pos = events.getPos().x;
halnf pos = events.getPointer().x;
auto diff = pos - (this->mArea.x + mFactor * this->mArea.z);
mFactor += diff / this->mArea.z;
}
@ -46,6 +47,8 @@ namespace tp {
// takes whole area
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"));

View file

@ -20,6 +20,13 @@ namespace tp {
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
}
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
nChanged = false;
const auto col = this->getColor("Accent");
@ -58,10 +65,6 @@ namespace tp {
ImGui::PopStyleVar(3);
}
void draw(Canvas& canvas) override {
// canvas.rect(this->mArea, this->getColor("Base"));
}
enum { mMaxBufferSize = 512 };
char mBuff[mMaxBufferSize] = "";
bool nChanged = false;