From 3c093ccf73af6d57ec6995cda56323082208515f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Jun 2015 18:47:52 -0700 Subject: [PATCH 1/2] Show popup headers as marquees if they are too long. They were just overflowing before. --- ui/view.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ui/view.cpp b/ui/view.cpp index 6014a67004..5e27c925b5 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -3,6 +3,7 @@ #include "base/mutex.h" #include "base/stringutil.h" +#include "base/timeutil.h" #include "input/input_state.h" #include "input/keycodes.h" #include "gfx_es2/draw_buffer.h" @@ -441,9 +442,31 @@ void ItemHeader::Draw(UIContext &dc) { } void PopupHeader::Draw(UIContext &dc) { + const float paddingHorizontal = 12; + const float availableWidth = bounds_.w - paddingHorizontal * 2; + + float tw, th; dc.SetFontStyle(dc.theme->uiFont); - dc.DrawText(text_.c_str(), bounds_.x + 12, bounds_.centerY(), dc.theme->popupTitle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); + dc.MeasureText(dc.GetFontStyle(), text_.c_str(), &tw, &th, 0); + + float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; + + float tx = paddingHorizontal; + if (availableWidth < tw) { + float overageRatio = 1.5f * availableWidth * 1.0f / tw; + tx -= (1.0f + sin(time_now_d() * overageRatio)) * sineWidth; + Bounds tb = bounds_; + tb.x = bounds_.x + paddingHorizontal; + tb.w = bounds_.w - paddingHorizontal * 2; + dc.PushScissor(tb); + } + + dc.DrawText(text_.c_str(), bounds_.x + tx, bounds_.centerY(), dc.theme->popupTitle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupTitle.fgColor); + + if (availableWidth < tw) { + dc.PopScissor(); + } } void CheckBox::Toggle(){ From 0f0115da8abbe6479e52c655dd9e8adbcab1c00e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Jun 2015 18:48:22 -0700 Subject: [PATCH 2/2] Show a highlight for focusable text views. --- ui/view.cpp | 6 ++++++ ui/view.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/view.cpp b/ui/view.cpp index 5e27c925b5..7a38d9acf1 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -622,6 +622,12 @@ void TextView::Draw(UIContext &dc) { dc.Flush(); dc.PushScissor(clipRect); } + // In case it's been made focusable. + if (HasFocus()) { + UI::Style style = dc.theme->itemFocusedStyle; + style.background.color &= 0x7fffffff; + dc.FillRect(style.background, bounds_); + } dc.SetFontStyle(small_ ? dc.theme->uiFontSmall : dc.theme->uiFont); if (shadow_) { uint32_t shadowColor = 0x80000000; diff --git a/ui/view.h b/ui/view.h index edc1418e74..7f82fdb61d 100644 --- a/ui/view.h +++ b/ui/view.h @@ -593,7 +593,7 @@ public: void Draw(UIContext &dc) override; - // These are focusable so that long lists of them can be keybaord scrolled. + // These are focusable so that long lists of them can be keyboard scrolled. bool CanBeFocused() const override { return true; } private: