UI: Add text description for all views.

This commit is contained in:
Unknown W. Brackets committed 2021-02-21 16:38:02 -08:00
1 parent 7c72fe7110
commit 3c778f567c
23 files changed
+252 -103

No files matched your search

+58 -2
View File
@@ -6,6 +6,7 @@
#include "Common/Render/DrawBuffer.h"
#include "Common/Render/TextureAtlas.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Data/Text/I18n.h"
#include "Common/UI/UI.h"
#include "Common/UI/View.h"
#include "Common/UI/Context.h"
@@ -513,6 +514,11 @@ void Choice::Draw(UIContext &dc) {
}
}
std::string Choice::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(u->T("%1 choice"), "%1", text_);
}
InfoItem::InfoItem(const std::string &text, const std::string &rightText, LayoutParams *layoutParams)
: Item(layoutParams), text_(text), rightText_(rightText) {
// We set the colors later once we have a UIContext.
@@ -547,6 +553,11 @@ void InfoItem::Draw(UIContext &dc) {
// dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor);
}
std::string InfoItem::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(ReplaceAll(u->T("%1: %2"), "%1", text_), "%2", rightText_);
}
ItemHeader::ItemHeader(const std::string &text, LayoutParams *layoutParams)
: Item(layoutParams), text_(text) {
layoutParams_->width = FILL_PARENT;
@@ -572,6 +583,11 @@ void ItemHeader::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec hor
dc.MeasureTextRect(dc.theme->uiFontSmall, 1.0f, 1.0f, text_.c_str(), (int)text_.length(), bounds, &w, &h, ALIGN_LEFT | ALIGN_VCENTER);
}
std::string ItemHeader::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(u->T("%1 heading"), "%1", text_);
}
void PopupHeader::Draw(UIContext &dc) {
const float paddingHorizontal = 12;
const float availableWidth = bounds_.w - paddingHorizontal * 2;
@@ -600,6 +616,11 @@ void PopupHeader::Draw(UIContext &dc) {
}
}
std::string PopupHeader::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(u->T("%1 heading"), "%1", text_);
}
void CheckBox::Toggle() {
if (toggle_) {
*toggle_ = !(*toggle_);
@@ -642,6 +663,15 @@ void CheckBox::Draw(UIContext &dc) {
dc.SetFontScale(1.0f, 1.0f);
}
std::string CheckBox::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
std::string text = ReplaceAll(u->T("%1 checkbox"), "%1", text_);
if (!smallText_.empty()) {
text += "\n" + smallText_;
}
return text;
}
float CheckBox::CalculateTextScale(const UIContext &dc, float availWidth) const {
float actualWidth, actualHeight;
Bounds availBounds(0, 0, availWidth, bounds_.h);
@@ -705,6 +735,11 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
h *= scale_;
}
std::string Button::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(u->T("%1 button"), "%1", GetText());
}
void Button::Click() {
Clickable::Click();
UI::PlayUISound(UI::UISound::CONFIRM);
@@ -812,8 +847,8 @@ void TextView::Draw(UIContext &dc) {
}
}
TextEdit::TextEdit(const std::string &text, const std::string &placeholderText, LayoutParams *layoutParams)
: View(layoutParams), text_(text), undo_(text), placeholderText_(placeholderText),
TextEdit::TextEdit(const std::string &text, const std::string &title, const std::string &placeholderText, LayoutParams *layoutParams)
: View(layoutParams), text_(text), title_(title), undo_(text), placeholderText_(placeholderText),
textColor_(0xFFFFFFFF), maxLen_(255) {
caret_ = (int)text_.size();
}
@@ -861,6 +896,11 @@ void TextEdit::GetContentDimensions(const UIContext &dc, float &w, float &h) con
h += 2;
}
std::string TextEdit::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
return ReplaceAll(u->T("%1 text field"), "%1", GetText());
}
// Handles both windows and unix line endings.
static std::string FirstLine(const std::string &text) {
size_t pos = text.find("\r\n");
@@ -1037,6 +1077,12 @@ void ProgressBar::Draw(UIContext &dc) {
dc.DrawTextRect(temp, bounds_, 0xFFFFFFFF, ALIGN_CENTER);
}
std::string ProgressBar::DescribeText() const {
auto u = GetI18NCategory("UI Elements");
float percent = progress_ * 100.0f;
return ReplaceAll(u->T("Progress: %1%"), "%1", StringFromInt((int)percent));
}
void Spinner::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = 48;
h = 48;
@@ -1181,6 +1227,12 @@ void Slider::Draw(UIContext &dc) {
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER | FLAG_DYNAMIC_ASCII);
}
std::string Slider::DescribeText() const {
if (showPercent_)
return StringFromFormat("%i%% / %i%%", *value_, maxValue_);
return StringFromFormat("%i / %i", *value_, maxValue_);
}
void Slider::Update() {
View::Update();
if (repeat_ >= 0) {
@@ -1291,6 +1343,10 @@ void SliderFloat::Draw(UIContext &dc) {
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER);
}
std::string SliderFloat::DescribeText() const {
return StringFromFormat("%0.2f / %0.2f", *value_, maxValue_);
}
void SliderFloat::Update() {
View::Update();
if (repeat_ >= 0) {