From 6811035b75159b1bdd35956d0f2bab4907e14377 Mon Sep 17 00:00:00 2001 From: Oznogon Date: Thu, 23 Oct 2025 08:40:03 -0700 Subject: [PATCH 1/2] Refactor GuiProgressbar for improved accuracy GuiProgressbar can fail to show pixels near the min and max values, such as for 98-100% power or coolant on the Power Management screen or the final jump drive charge points in the jump drive controls. This appears to be caused by the GuiProgressbar being filled by a PNG with a transparent border of pixels, which become the only pixels rendered at these extremes, particularly on high-resolution displays. - Remove transparent pixels from edges of the default progress bar fill PNG that caused inaccuracies for values near min and max. Screens that implement GuiProgressbar should manage its width or height using size or margin attributes if necessary. - Conditionally reduce the default width of the fill rect when using a background. This is set to an arbitrary value that approximates the proportions used in existing behavior, but results in a tighter and more accurate fit on high-resolution displays. - Simplify min/max logic using clamps. --- resources/gui/widget/ProgressbarFill.png | Bin 100 -> 217 bytes src/gui/gui2_progressbar.cpp | 12 +++++++++++- src/gui/gui2_progressslider.cpp | 18 ++++++------------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/resources/gui/widget/ProgressbarFill.png b/resources/gui/widget/ProgressbarFill.png index aa695d0b28a943529da2a3fcd111755cc07c6362..699446ecb5bcc5189392b2b6e58eca348e4bac24 100644 GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC&H|6fVg?3oArNM~bhqvgP_Wz6 z#W5tq`R%2HyayBnjyO2|w{@N(_DpbY%D=eAv&Hu|v(2~t@$UZB>I3&#wF4MUE{Hod z_JlWxK5}3UP^0*5GC+V%8BMnpl e20wT`ZmnYEzj#~ry70$*kdUXVpUXO@geCy1ei#b? diff --git a/src/gui/gui2_progressbar.cpp b/src/gui/gui2_progressbar.cpp index 301f828391..33c566db75 100644 --- a/src/gui/gui2_progressbar.cpp +++ b/src/gui/gui2_progressbar.cpp @@ -15,13 +15,18 @@ void GuiProgressbar::onDraw(sp::RenderTarget& renderer) const auto& front = front_style->get(getState()); float f = (value - min_value) / (max_value - min_value); + sp::Rect fill_rect = rect; if (drawBackground) renderer.drawStretched(rect, back.texture, back.color); - sp::Rect fill_rect = rect; if (rect.size.x >= rect.size.y) { + if (drawBackground) + { + fill_rect.position.y += fill_rect.size.y * 0.125f; + fill_rect.size.y *= 0.75f; + } fill_rect.size.x *= f; if (max_value < min_value) fill_rect.position.x = rect.position.x + rect.size.x - fill_rect.size.x; @@ -29,6 +34,11 @@ void GuiProgressbar::onDraw(sp::RenderTarget& renderer) } else { + if (drawBackground) + { + fill_rect.position.x += fill_rect.size.x * 0.125f; + fill_rect.size.x *= 0.75f; + } fill_rect.size.y *= f; fill_rect.position.y = rect.position.y + rect.size.y - fill_rect.size.y; renderer.drawStretchedHVClipped(rect, fill_rect, front.size, front.texture, color); diff --git a/src/gui/gui2_progressslider.cpp b/src/gui/gui2_progressslider.cpp index fc85155b14..a5b09ee649 100644 --- a/src/gui/gui2_progressslider.cpp +++ b/src/gui/gui2_progressslider.cpp @@ -1,7 +1,6 @@ #include "gui2_progressslider.h" #include "theme.h" - GuiProgressSlider::GuiProgressSlider(GuiContainer* owner, string id, float min_value, float max_value, float start_value, func_t func) : GuiProgressbar(owner, id, min_value, max_value, start_value), callback(func) { @@ -20,19 +19,14 @@ void GuiProgressSlider::onMouseDrag(glm::vec2 position, sp::io::Pointer::ID id) new_value = (position.x - rect.position.x) / (rect.size.x); else new_value = (position.y - rect.position.y) / (rect.size.y); + new_value = min_value + (max_value - min_value) * new_value; + if (min_value < max_value) - { - if (new_value < min_value) - new_value = min_value; - if (new_value > max_value) - new_value = max_value; - }else{ - if (new_value > min_value) - new_value = min_value; - if (new_value < max_value) - new_value = max_value; - } + new_value = std::clamp(new_value, min_value, max_value); + else + new_value = std::clamp(new_value, max_value, min_value); + if (value != new_value) { value = new_value; From 141ae520cecab7fa9e5c424f5589719b7bab9ab4 Mon Sep 17 00:00:00 2001 From: Oznogon Date: Thu, 23 Oct 2025 08:47:26 -0700 Subject: [PATCH 2/2] Align GuiSlider min/max logic to revised GuiProgressbarslider logic --- src/gui/gui2_slider.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/gui/gui2_slider.cpp b/src/gui/gui2_slider.cpp index 2f41247bec..7926eee3b1 100644 --- a/src/gui/gui2_slider.cpp +++ b/src/gui/gui2_slider.cpp @@ -77,17 +77,10 @@ void GuiBasicSlider::onMouseUp(glm::vec2 position, sp::io::Pointer::ID id) GuiBasicSlider* GuiBasicSlider::setValue(float value) { if (min_value < max_value) - { - if (value < min_value) - value = min_value; - if (value > max_value) - value = max_value; - }else{ - if (value > min_value) - value = min_value; - if (value < max_value) - value = max_value; - } + this->value = std::clamp(value, min_value, max_value); + else + this->value = std::clamp(value, max_value, min_value); + this->value = value; return this; }