Skip to content

Commit

Permalink
Remove unreliable test. Don't depend on local time zones.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Aug 19, 2024
1 parent c76822e commit 502d112
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
10 changes: 5 additions & 5 deletions packages/rendering/include/rendering/ui/UIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ namespace l::ui {
return ImVec2(mPosition.x + mSize.x, mPosition.y + mSize.y);
}

ImVec2 Transform(const ImVec2& rootPos, const ImVec2& p, ImVec2 pixelOffset = ImVec2()) const {
ImVec2 Transform(const ImVec2& p, ImVec2 rootPos = ImVec2()) const {
ImVec2 transformed;
transformed.x = rootPos.x + mPosition.x + p.x * mScale + pixelOffset.x;
transformed.y = rootPos.y + mPosition.y + p.y * mScale + pixelOffset.y;
transformed.x = rootPos.x + mPosition.x + p.x * mScale;
transformed.y = rootPos.y + mPosition.y + p.y * mScale;
return transformed;
}
};

ImVec2 DragMovement(const ImVec2& prevPos, const ImVec2& curPos, float curScale);
bool Overlap(const ImVec2& p, const ImVec2& pMin, const ImVec2& pMax);
bool Overlap(const ImVec2 rootPos, const ImVec2& p, const ImVec2& pMin, const ImVec2& pMax, const ContainerArea& parent);
bool OverlapPixelArea(const ImVec2 rootPos, const ImVec2& p, const ImVec2& pCenter, const ImVec2& offset, const ContainerArea& parent);
bool Overlap(const ImVec2& p, const ImVec2& pMin, const ImVec2& pMax, const ContainerArea& parent);
bool OverlapScreenRect(const ImVec2& p, const ImVec2& pCenter, const ImVec2& offset, const ContainerArea& parent);

class UIContainer;

Expand Down
34 changes: 20 additions & 14 deletions packages/rendering/source/common/ui/UIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ namespace l::ui {
return pMin.x < p.x && pMin.y < p.y && pMax.x > p.x && pMax.y > p.y;
}

bool Overlap(const ImVec2 rootPos, const ImVec2& p, const ImVec2& pMin, const ImVec2& pMax, const ContainerArea& parent) {
ImVec2 pMinT = parent.Transform(rootPos, pMin);
ImVec2 pMaxT = parent.Transform(rootPos, pMax);
bool Overlap(const ImVec2& p, const ImVec2& pMin, const ImVec2& pMax, const ContainerArea& parent) {
ImVec2 pMinT = parent.Transform(pMin);
ImVec2 pMaxT = parent.Transform(pMax);
return pMinT.x < p.x && pMinT.y < p.y && pMaxT.x > p.x && pMaxT.y > p.y;
}

bool OverlapPixelArea(const ImVec2 rootPos, const ImVec2& p, const ImVec2& pCenter, const ImVec2& offset, const ContainerArea& parent) {
ImVec2 pMinT = parent.Transform(rootPos, pCenter, ImVec2(-offset.x, -offset.y));
ImVec2 pMaxT = parent.Transform(rootPos, pCenter, ImVec2(offset.x, offset.y));
bool OverlapScreenRect(const ImVec2& p, const ImVec2& pCenter, const ImVec2& offset, const ContainerArea& parent) {
ImVec2 pMinT = parent.Transform(pCenter, ImVec2(-offset.x, -offset.y));
ImVec2 pMaxT = parent.Transform(pCenter, ImVec2(offset.x, offset.y));
return pMinT.x < p.x && pMinT.y < p.y && pMaxT.x > p.x && pMaxT.y > p.y;
}

bool OverlapScreenCircle(const ImVec2& p, const ImVec2& pCenter, float radii, const ContainerArea& parent) {
ImVec2 pT = parent.Transform(pCenter);
ImVec2 d = ImVec2(pT.x - p.x, pT.y - p.y);
return d.x*d.x + d.y*d.y < radii * radii;
}

bool UIContainer::Accept(UIVisitor& visitor, const InputState& input, uint32_t flags) {
ContainerArea current;
return Accept(visitor, input, current, flags);
Expand Down Expand Up @@ -196,7 +202,7 @@ namespace l::ui {

bool UIMove::Visit(UIContainer& container, const InputState& input, const ContainerArea& parent) {
if (input.mStarted && !mMoving) {
if (Overlap(ImVec2(), input.GetLocalPos(), container.GetPosition(), container.GetPositionAtSize(), parent)) {
if (Overlap(input.GetLocalPos(), container.GetPosition(), container.GetPositionAtSize(), parent)) {
mMoving = true;
mCurrentContainer = &container;
}
Expand All @@ -219,7 +225,7 @@ namespace l::ui {
if (!mResizing) {
const float radii = mResizeAreaSize * 0.5f;
ImVec2 p = container.GetPositionAtSize();
if (OverlapPixelArea(ImVec2(), input.GetLocalPos(), p, ImVec2(radii, radii), parent)) {
if (OverlapScreenRect(input.GetLocalPos(), p, ImVec2(radii, radii), parent)) {
mCurrentContainer = &container;
container.Notification(UIContainer_ResizeFlag);

Expand Down Expand Up @@ -261,19 +267,19 @@ namespace l::ui {
ImVec2 pTopLeft = container.GetPosition();
ImVec2 pLowRight = container.GetPositionAtSize();

ImVec2 p1 = parent.Transform(input.mRootPos, pTopLeft);
ImVec2 p2 = parent.Transform(input.mRootPos, pLowRight);
ImVec2 p1 = parent.Transform(pTopLeft, input.mRootPos);
ImVec2 p2 = parent.Transform(pLowRight, input.mRootPos);

ImVec4 colf = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
const ImU32 col = ImColor(colf);

mDrawList->AddRect(p1, p2, col, 2.0f, ImDrawFlags_RoundCornersAll, 2.0f);

ImVec2 p3 = parent.Transform(input.mRootPos, pLowRight, ImVec2(-3.0f, -3.0f));
ImVec2 p4 = parent.Transform(input.mRootPos, pLowRight, ImVec2(3.0f, 3.0f));
ImVec2 p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 3.0f, input.mRootPos.y - 3.0f));
ImVec2 p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 3.0f, input.mRootPos.y + 3.0f));
if (container.HasNotification(ui::UIContainer_ResizeFlag)) {
p3 = parent.Transform(input.mRootPos, pLowRight, ImVec2(-5.0f, -5.0f));
p4 = parent.Transform(input.mRootPos, pLowRight, ImVec2(5.0f, 5.0f));
p3 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x - 5.0f, input.mRootPos.y - 5.0f));
p4 = parent.Transform(pLowRight, ImVec2(input.mRootPos.x + 5.0f, input.mRootPos.y + 5.0f));
}
mDrawList->AddRectFilled(p3, p4, col);
return false;
Expand Down
5 changes: 0 additions & 5 deletions packages/testing/tests/common/LoggingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ TEST(Logging, TimeConversions) {
auto unixtime2 = l::string::to_unix_time_from_local(fullDate);
TEST_EQ(unixtime, unixtime2, "");
}
{
auto unixtime = 1724097382;
auto timeString = l::string::get_local_time_string(unixtime);
TEST_TRUE(l::string::cstring_equal(timeString.c_str(), "2024-08-19 21:56:22"), "");
}

return 0;
}
Expand Down

0 comments on commit 502d112

Please sign in to comment.