Show text on the Browse button
This commit is contained in:
parent
d390127cc6
commit
08b7d646e8
2 changed files with 16 additions and 8 deletions
|
@ -431,10 +431,15 @@ void Choice::Click() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const {
|
void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const {
|
||||||
|
float totalW = 0.0f;
|
||||||
|
float totalH = 0.0f;
|
||||||
if (image_.isValid()) {
|
if (image_.isValid()) {
|
||||||
dc.Draw()->GetAtlas()->measureImage(image_, &w, &h);
|
dc.Draw()->GetAtlas()->measureImage(image_, &w, &h);
|
||||||
} else {
|
totalW = w;
|
||||||
const int paddingX = 12;
|
totalH = h;
|
||||||
|
}
|
||||||
|
if (!text_.empty()) {
|
||||||
|
const int paddingX = 12 + (image_.isValid() ? 6 : 0);
|
||||||
float availWidth = horiz.size - paddingX * 2 - textPadding_.horiz();
|
float availWidth = horiz.size - paddingX * 2 - textPadding_.horiz();
|
||||||
if (availWidth < 0.0f) {
|
if (availWidth < 0.0f) {
|
||||||
// Let it have as much space as it needs.
|
// Let it have as much space as it needs.
|
||||||
|
@ -444,10 +449,13 @@ void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz,
|
||||||
availWidth = layoutParams_->width;
|
availWidth = layoutParams_->width;
|
||||||
float scale = CalculateTextScale(dc, availWidth);
|
float scale = CalculateTextScale(dc, availWidth);
|
||||||
Bounds availBounds(0, 0, availWidth, vert.size);
|
Bounds availBounds(0, 0, availWidth, vert.size);
|
||||||
dc.MeasureTextRect(dc.theme->uiFont, scale, scale, text_.c_str(), (int)text_.size(), availBounds, &w, &h, FLAG_WRAP_TEXT);
|
float textW = 0.0f, textH = 0.0f;
|
||||||
|
dc.MeasureTextRect(dc.theme->uiFont, scale, scale, text_.c_str(), (int)text_.size(), availBounds, &textW, &textH, FLAG_WRAP_TEXT);
|
||||||
|
totalH = std::max(totalH, textH);
|
||||||
|
totalW += textW;
|
||||||
}
|
}
|
||||||
w += 24;
|
w = totalW + 24;
|
||||||
h += 16;
|
h = totalH + 16;
|
||||||
h = std::max(h, ITEM_HEIGHT);
|
h = std::max(h, ITEM_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,8 +506,8 @@ void Choice::Draw(UIContext &dc) {
|
||||||
|
|
||||||
if (image_.isValid()) {
|
if (image_.isValid()) {
|
||||||
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(image_);
|
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(image_);
|
||||||
paddingX += image->w + 12;
|
paddingX += image->w + 6;
|
||||||
availWidth -= image->w + 12;
|
availWidth -= image->w + 6;
|
||||||
// TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now)
|
// TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now)
|
||||||
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);
|
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -680,7 +680,7 @@ void GameBrowser::Refresh() {
|
||||||
topBar->Add(new Choice(ImageID("I_SDCARD"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::StorageClick);
|
topBar->Add(new Choice(ImageID("I_SDCARD"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::StorageClick);
|
||||||
}
|
}
|
||||||
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
|
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
|
||||||
topBar->Add(new Choice(ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick);
|
topBar->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
topBar->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
|
topBar->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue