From 22e10462dc05bf14e2a711496286690407c7f2d7 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 7 Jun 2022 18:32:46 +0100 Subject: [PATCH] Debug: Redraw debug window content if line change moves scroll position --- src/newgrf_debug_gui.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 5d95b589ff..8b09ad455e 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -311,6 +311,8 @@ struct NewGRFInspectWindow : Window { Scrollbar *vscroll; int first_variable_line_index = 0; + bool redraw_panel = false; + bool redraw_scrollbar = false; bool auto_refresh = false; bool log_console = false; @@ -513,7 +515,12 @@ struct NewGRFInspectWindow : Window { /* Not nice and certainly a hack, but it beats duplicating * this whole function just to count the actual number of * elements. Especially because they need to be redrawn. */ + uint position = this->vscroll->GetPosition(); const_cast(this)->vscroll->SetCount(count); + const_cast(this)->redraw_scrollbar = true; + if (position != this->vscroll->GetPosition()) { + const_cast(this)->redraw_panel = true; + } } }); @@ -880,7 +887,14 @@ struct NewGRFInspectWindow : Window { void OnRealtimeTick(uint delta_ms) override { - if (this->auto_refresh) this->SetDirty(); + if (this->auto_refresh) { + this->SetDirty(); + } else { + if (this->redraw_panel) this->SetWidgetDirty(WID_NGRFI_MAINPANEL); + if (this->redraw_scrollbar) this->SetWidgetDirty(WID_NGRFI_SCROLLBAR); + } + this->redraw_panel = false; + this->redraw_scrollbar = false; } };