[wpigui] Add GetDistSquared and MaxFit functions

These utility functions were moved from halsim_gui.
This commit is contained in:
Peter Johnson
2020-08-29 10:32:49 -07:00
parent c699d55175
commit b83709b269
5 changed files with 47 additions and 55 deletions

View File

@@ -413,4 +413,19 @@ bool gui::CreateTextureFromImage(const unsigned char* data, int len,
return true;
}
void gui::MaxFit(ImVec2* min, ImVec2* max, float width, float height) {
float destWidth = max->x - min->x;
float destHeight = max->y - min->y;
if (width == 0 || height == 0) return;
if (destWidth * height > destHeight * width) {
float outputWidth = width * destHeight / height;
min->x += (destWidth - outputWidth) / 2;
max->x -= (destWidth - outputWidth) / 2;
} else {
float outputHeight = height * destWidth / width;
min->y += (destHeight - outputHeight) / 2;
max->y -= (destHeight - outputHeight) / 2;
}
}
} // namespace wpi