Functional improvements to Window widget resize.

This commit is contained in:
2024-08-01 19:37:45 -04:00
parent 31d5b09bfa
commit b8eadfbf03
2 changed files with 18 additions and 62 deletions

View File

@@ -110,6 +110,7 @@ namespace JUI
int titlebar_height = 16;
Vector2 max_size;
Vector2 min_size; //= {30, 30};
UDim2 size_when_restart_began;
};
}

View File

@@ -11,7 +11,6 @@ namespace JUI
min_size = {400, 200};
this->BGColor({0,0,0,0,});
//this->OnHoverEvent += [&] (Vector2 MousePos) {
//};
@@ -32,6 +31,7 @@ namespace JUI
};
*/
// TODO: Move out of Event callback
this->OnReleaseEvent += [&] (Vector2 dummy, MouseBtn btn, bool dummy3) {
if (dragging) {
SetDrag(false);
@@ -134,8 +134,9 @@ namespace JUI
this->SetDrag(true);
if (resizable && btn == MouseBtn::Right) {
this->SetResize(true);
this->StartResizing(last_known_mouse_pos);
this->SetResize(true);
size_when_restart_began = GetSize();
}
}
@@ -158,67 +159,28 @@ namespace JUI
}
if (resizing) {
UDim2 cursz = this->GetSize();
Vector2 newsz;
//x > y ? x - y : y - x
Vector2 mpos = this->last_known_mouse_pos;
Vector2 abspos = this->GetAbsolutePosition();
//newsz.x = mpos.x > 0 ? abspos.x - mpos.x : abspos.x + mpos.x;
//newsz.y = mpos.y > 0 ? abspos.y - mpos.y : abspos.y + mpos.y;
newsz.x = abspos.x < 0 ? abspos.x - mpos.x : mpos.x - abspos.x ;
newsz.y = abspos.y < 0 ? abspos.y - mpos.y : mpos.y - abspos.y ;
Vector2 resize_amt = mpos - initial_resize_offset;
//newsz.x = newsz.x / 100.f <= this->min_size.GetScale().x ? newsz.x : min_size.GetPixels().x;
//newsz.y = newsz.y / 100.f <= this->min_size.GetScale().y ? newsz.y : min_size.GetPixels().y;
//newsz.x = newsz.x <= this->min_size.GetPixels().x ? newsz.x : min_size.GetPixels().x;
//newsz.y = newsz.y <= this->min_size.GetPixels().y ? newsz.x : min_size.GetPixels().y;
SetSize(size_when_restart_began + UDim2(resize_amt.x, resize_amt.y, 0, 0));
//.if ((newsz.x / 100.f <= this->min_size.GetScale().x)) {// || (newsz.x <= this->min_size.GetPixels().x))
// newsz.x = this->min_size.GetScale().x / 100.f;
if (newsz.x <= this->min_size.x) {
newsz.x = this->min_size.x;
Vector2 abs_size = this->GetAbsoluteSize();
// Clamp X-axis.
if (abs_size.x < min_size.x)
{
float needed_amt_to_resize = min_size.x - abs_size.x;
SetSize(GetSize() + UDim2(needed_amt_to_resize, 0, 0, 0));
}
//if ((newsz.y / 100.f <= this->min_size.GetScale().y)) {// || (newsz.x <= this->min_size.GetPixels().x))
// newsz.y = this->min_size.GetScale().y / 100.f;
if (newsz.y <= this->min_size.y) {
newsz.y = this->min_size.y;
// Clamp Y-axis.
if (abs_size.y < min_size.y)
{
float needed_amt_to_resize = min_size.y - abs_size.y;
SetSize(GetSize() + UDim2(0, needed_amt_to_resize, 0, 0));
}
//newsz.x = std::abs(GetAbsolutePosition().x - last_known_mouse_pos.x);
//newsz.y = std::abs(GetAbsolutePosition().y - last_known_mouse_pos.y);
DEBUG(std::format("cursz {} {}", cursz.GetPixels().x, cursz.GetPixels().y))
DEBUG(std::format("newsz {} {}", newsz.x, newsz.y))
DEBUG(std::format("mpos {} {}", mpos.x, mpos.y))
//if (cursz.X.Scale < min_size.X.Scale)// || (cursz.X.Scale <= min_size.X.Scale))
// cursz.X.Pixels = std::abs(GetAbsolutePosition().x - last_known_mouse_pos.x);
//if (cursz.Y.Scale < min_size.Y.Scale)// || (cursz.Y.Scale <= min_size.Y.Scale))
// cursz.Y.Pixels = std::abs(GetAbsolutePosition().y - last_known_mouse_pos.y);
/*
bool stop;
if (newsz.x / 100.f <= this->min_size.GetScale().x)
stop = true;
if (newsz.y / 100.f <= this->min_size.GetScale().y)
stop = true;
if (newsz.x <= this->min_size.GetPixels().x)
stop = true;
if (newsz.y <= this->min_size.GetPixels().y)
stop = true;
*/
if ((this->last_known_mouse_pos != this->initial_resize_offset))// && !stop)
this->SetSize({{newsz}, {0,0}});//{newsz.x / 100.f, newsz.y / 100.f}});
//this->SetSize(UDim2{(int)last_known_mouse_pos.x, (int)last_known_mouse_pos.y, cursz.X.Scale, cursz.Y.Scale});
}
Widget::Update(delta);
@@ -238,13 +200,6 @@ namespace JUI
OnRelease(last_known_mouse_pos, mbtn, IsHovered());
}
//if (dragging) {
// DEBUG(std::format("mpos {} {}", last_known_mouse_pos.x, last_known_mouse_pos.y));
// Vector2 mpos = last_known_mouse_pos + initial_drag_offset;
// this->SetPosition(UDim2{(int)mpos.x, (int)mpos.y, 0,0});
//}
prev_mb_state = mb_state;
}