From 33c8bdc05b97c60d778db7adfd6ddc4cf0f054e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 10 Mar 2026 09:21:19 +0100 Subject: [PATCH] Show radio button images in the server list --- Common/UI/View.cpp | 11 ++++++++--- Common/UI/View.h | 3 +++ UI/AdhocServerScreen.cpp | 4 ++++ UI/UIAtlas.cpp | 2 ++ assets/ui_images/images.svg | 14 ++++++++++---- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 52824ec6b6..2bbf8bcbd6 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -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 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); } } diff --git a/Common/UI/View.h b/Common/UI/View.h index adc3febb26..05beee41ec 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -1139,15 +1139,18 @@ private: class ImageView : public InertView { public: ImageView(ImageID atlasImage, const std::string &text, LayoutParams *layoutParams = nullptr); + ImageView(std::function 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 func) { func_ = func; } private: std::string text_; ImageID atlasImage_; float scale_ = 1.0f; + std::function func_; }; class ProgressBar : public InertView { diff --git a/UI/AdhocServerScreen.cpp b/UI/AdhocServerScreen.cpp index 284b677f72..d173f7a8e2 100644 --- a/UI/AdhocServerScreen.cpp +++ b/UI/AdhocServerScreen.cpp @@ -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); diff --git a/UI/UIAtlas.cpp b/UI/UIAtlas.cpp index d1ac589e94..00843ae837 100644 --- a/UI/UIAtlas.cpp +++ b/UI/UIAtlas.cpp @@ -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) { diff --git a/assets/ui_images/images.svg b/assets/ui_images/images.svg index af42711bf1..ee44e418eb 100644 --- a/assets/ui_images/images.svg +++ b/assets/ui_images/images.svg @@ -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" />