Show radio button images in the server list

This commit is contained in:
Henrik Rydgård
2026-03-10 09:21:19 +01:00
parent e0f1b6b7d9
commit 33c8bdc05b
5 changed files with 27 additions and 7 deletions
+8 -3
View File
@@ -1024,19 +1024,24 @@ void RadioButton::Draw(UIContext &dc) {
ImageView::ImageView(ImageID atlasImage, const std::string &text, LayoutParams *layoutParams)
: InertView(layoutParams), text_(text), atlasImage_(atlasImage) {}
ImageView::ImageView(std::function<ImageID()> func, LayoutParams *layoutParams)
: InertView(layoutParams), func_(func) {}
void ImageView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
dc.Draw()->GetAtlas()->measureImage(atlasImage_, &w, &h);
ImageID id = func_ ? func_() : atlasImage_;
dc.Draw()->GetAtlas()->measureImage(id, &w, &h);
w *= scale_;
h *= scale_;
// TODO: involve sizemode
}
void ImageView::Draw(UIContext &dc) {
const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(atlasImage_);
ImageID id = func_ ? func_() : atlasImage_;
const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(id);
if (img) {
// TODO: involve sizemode
float scale = bounds_.w / img->w;
dc.Draw()->DrawImage(atlasImage_, bounds_.x, bounds_.y, scale, 0xFFFFFFFF, ALIGN_TOPLEFT);
dc.Draw()->DrawImage(id, bounds_.x, bounds_.y, scale, 0xFFFFFFFF, ALIGN_TOPLEFT);
}
}
+3
View File
@@ -1139,15 +1139,18 @@ private:
class ImageView : public InertView {
public:
ImageView(ImageID atlasImage, const std::string &text, LayoutParams *layoutParams = nullptr);
ImageView(std::function<ImageID()> func, LayoutParams *layoutParams = nullptr);
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;
std::string DescribeText() const override { return text_; }
void SetScale(float s) { scale_ = s; } // Only used for measuring.
void SetFunc(std::function<ImageID()> func) { func_ = func; }
private:
std::string text_;
ImageID atlasImage_;
float scale_ = 1.0f;
std::function<ImageID()> func_;
};
class ProgressBar : public InertView {
+4
View File
@@ -193,7 +193,11 @@ AdhocServerRow::AdhocServerRow(std::string *editValue, const AdhocServerListEntr
: UI::LinearLayout(ORIENT_HORIZONTAL, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::WRAP_CONTENT, UI::Margins(5.0f, 0.0f))), value_(editValue), entry_(entry) {
using namespace UI;
SetSpacing(5.0f);
// Show as radio button to make it really clear that selection actually is the choice.
int number = 0;
Add(new ImageView([editValue, host = entry.host]() { return host == *editValue ? ImageID("I_RADIO_SELECTED") : ImageID("I_RADIO_EMPTY"); },
new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity::G_VCENTER, Margins(5, 0, 0, 0))));
LinearLayout *lines = Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(Margins(5, 5))));
lines->SetSpacing(0.0f);
+2
View File
@@ -185,6 +185,8 @@ static const ImageMeta imageIDs[] = {
{"I_KEYBOARD", false},
{"I_MOUSE", false},
{"I_FILE_SAVE", false},
{"I_RADIO_EMPTY", false},
{"I_RADIO_SELECTED", false},
};
static std::string PNGNameFromID(std::string_view id) {
+10 -4
View File
@@ -24,9 +24,9 @@
inkscape:pagecheckerboard="true"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
inkscape:zoom="5.6568542"
inkscape:cx="302.55332"
inkscape:cy="546.85871"
inkscape:zoom="2.8284271"
inkscape:cx="280.36784"
inkscape:cy="558.43759"
inkscape:window-width="3840"
inkscape:window-height="2071"
inkscape:window-x="-9"
@@ -4666,7 +4666,13 @@
d="M 16.533,8.562 V 6.915 c 0,-0.487 1.029,-1.131 1.855,-1.649 1.184,-0.741 2.41,-1.509 2.41,-2.627 V 0.006 h -1.066 v 2.633 c 0,0.527 -1.058,1.19 -1.909,1.723 -1.158,0.725 -2.356,1.475 -2.356,2.552 V 8.561 C 11.3,8.829 8.003,12.187 8.003,16.3 v 7.927 c 0,4.288 3.58,7.765 7.997,7.765 4.417,0 7.997,-3.477 7.997,-7.765 V 16.3 c 0,-4.114 -3.297,-7.472 -7.464,-7.739 z m 6.398,7.739 v 0.765 H 16.533 V 9.628 c 3.572,0.265 6.398,3.153 6.398,6.673 z m -13.862,0 c 0,-3.52 2.825,-6.408 6.398,-6.673 v 7.438 H 9.069 Z M 16,30.927 c -3.821,0 -6.931,-3.005 -6.931,-6.699 V 18.132 H 22.93 v 6.096 c 0,3.694 -3.109,6.699 -6.931,6.699 z"
fill="#000000"
id="path1-15"
style="fill:#ffffff;fill-opacity:1;stroke:none" /></g></g><style
style="fill:#ffffff;fill-opacity:1;stroke:none" /></g><path
id="I_RADIO_EMPTY"
style="baseline-shift:baseline;display:inline;overflow:visible;vector-effect:none;fill:#ffffff;enable-background:accumulate;stop-color:#000000;stop-opacity:1;opacity:1"
d="M 64.677698 159.5489 C 61.797142 159.5489 59.453211 161.89077 59.453211 164.77132 C 59.453211 167.65188 61.797142 169.99425 64.677698 169.99425 C 67.558255 169.99425 69.900634 167.65188 69.900634 164.77132 C 69.900634 161.89077 67.558255 159.5489 64.677698 159.5489 z M 64.677698 160.20519 C 67.203779 160.20519 69.244343 162.24524 69.244343 164.77132 C 69.244343 167.2974 67.203779 169.33796 64.677698 169.33796 C 62.151618 169.33796 60.109502 167.2974 60.109502 164.77132 C 60.109502 162.24524 62.151618 160.20519 64.677698 160.20519 z " /><path
id="I_RADIO_SELECTED"
style="baseline-shift:baseline;display:inline;overflow:visible;vector-effect:none;fill:#ffffff;enable-background:accumulate;stop-color:#000000;stop-opacity:1;opacity:1"
d="M 76.583946 159.28328 C 73.70339 159.28328 71.35946 161.62514 71.35946 164.5057 C 71.35946 167.38626 73.70339 169.72864 76.583946 169.72864 C 79.464503 169.72864 81.806883 167.38626 81.806883 164.5057 C 81.806883 161.62514 79.464503 159.28328 76.583946 159.28328 z M 76.583946 159.93957 C 79.110027 159.93957 81.150592 161.97962 81.150592 164.5057 C 81.150592 167.03178 79.110027 169.07441 76.583946 169.07441 C 74.057866 169.07441 72.01575 167.03178 72.01575 164.5057 C 72.01575 161.97962 74.057866 159.93957 76.583946 159.93957 z M 76.582913 161.3891 A 3.117686 3.117686 0 0 0 73.465274 164.50673 A 3.117686 3.117686 0 0 0 76.582913 167.62437 A 3.117686 3.117686 0 0 0 79.700551 164.50673 A 3.117686 3.117686 0 0 0 76.582913 161.3891 z " /></g><style
type="text/css"
id="style1">
.st0{fill:#000000;}

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 258 KiB