Vector2::ClampLength() and misc fixes

This commit is contained in:
zetaPRIME 2017-05-19 22:37:55 -04:00
parent ab5e6d42a6
commit 1a3948216f
5 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#include <algorithm>
#include <fastmath.h> #include <fastmath.h>
#include <limits> #include <limits>
@ -11,6 +12,11 @@ using starlight::Vector2;
float Vector2::Length() const { return sqrtf(x * x + y * y); } float Vector2::Length() const { return sqrtf(x * x + y * y); }
Vector2 Vector2::Normalized() const { float m = Length(); return m == 0.0f ? Vector2::zero : Vector2(x / m, y / m); } Vector2 Vector2::Normalized() const { float m = Length(); return m == 0.0f ? Vector2::zero : Vector2(x / m, y / m); }
Vector2 Vector2::ClampLength(float max) const {
float len = Length();
return *this * (std::min(len, max) / len);
}
Vector2 Vector2::Reciprocal() const { return Vector2(y, x); } Vector2 Vector2::Reciprocal() const { return Vector2(y, x); }
Vector2 Vector2::IntSnap() const { return Vector2(roundf(x), roundf(y)); } Vector2 Vector2::IntSnap() const { return Vector2(roundf(x), roundf(y)); }

View File

@ -19,6 +19,8 @@ namespace starlight {
Vector2 Normalized() const; Vector2 Normalized() const;
inline float Area() const { return x * y; } inline float Area() const { return x * y; }
Vector2 ClampLength(float max = 1) const;
Vector2 Reciprocal() const; Vector2 Reciprocal() const;
Vector2 IntSnap() const; Vector2 IntSnap() const;

View File

@ -34,6 +34,7 @@ void Label::SetText(const std::string& text) {
void Label::SetFont(const std::string& fontName) { void Label::SetFont(const std::string& fontName) {
textConfig->font = ThemeManager::GetFont(fontName); textConfig->font = ThemeManager::GetFont(fontName);
textConfig->Measure(""); // force load
AutoSize(); AutoSize();
} }

View File

@ -71,6 +71,7 @@ void UIContainer::RemoveAll() {
it->parent = std::weak_ptr<UIContainer>(); // clear parent it->parent = std::weak_ptr<UIContainer>(); // clear parent
} }
children.clear(); children.clear();
MarkForRedraw();
} }
void UIContainer::Update() { void UIContainer::Update() {

View File

@ -11,6 +11,13 @@ roadmap to v0.5.1 {
make button glyphs usable in conjunction with text (left edge, margin etc.) make button glyphs usable in conjunction with text (left edge, margin etc.)
give glyphs a color mode where they aren't set to text color give glyphs a color mode where they aren't set to text color
predrawoffscreen on hidden forms
paged field
figure out why first-draw in a given font sometimes derps up?
^ mitigate with a force-load-on-set for now
- libctru console as ui element - libctru console as ui element
- pngcrush the biggest assets (default and osk backdrops etc.) - pngcrush the biggest assets (default and osk backdrops etc.)