diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2023-06-05 20:25:15 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2023-06-05 20:25:15 +0200 |
| commit | e9bcc710ff40cd257de242a2ff3b68feb7b68cac (patch) | |
| tree | c209c55191ccedc1f8cedc7326ef89bdf5704242 /src | |
| parent | 2a4a20beefa533730d85a75bbc2dc6676fa247b5 (diff) | |
Debug bugs during canvas resize
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Scrollbar.cpp | 14 | ||||
| -rw-r--r-- | src/components/Scrollbar.hpp | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/components/Scrollbar.cpp b/src/components/Scrollbar.cpp index ac713e9..730d2ec 100644 --- a/src/components/Scrollbar.cpp +++ b/src/components/Scrollbar.cpp @@ -16,6 +16,8 @@ Scrollbar::Scrollbar(Status *s, bool IsHorizontal) : Component(s) { DragX = 0; DragY = 0; + CanvasWidth = 0; + CanvasHeight = 0; Trigger = false; } @@ -35,6 +37,15 @@ void Scrollbar::Refresh() { bar.width = bg.width; bar.height = bg.height; + // Check if resize, in this case, reset everything (avoid bugs). + // Not that this will be executed during first draw also but it is fine: + if((CanvasWidth != status->CanvasWidth) || (CanvasWidth != status->CanvasWidth)){ + status->ScrollX=0; + status->ScrollY=0; + bar.x=bg.x; + bar.y=bg.y; + } + // Compute move table canvas double MTCanvasHeight = status->CanvasHeight - status->ScrollbarWidth; double MTCanvasWidth = status->CanvasWidth - status->ScrollbarWidth; @@ -107,6 +118,9 @@ void Scrollbar::Refresh() { elements.clear(); elements.push_back(bg); elements.push_back(bar); + // Update cache: + CanvasWidth = status->CanvasWidth; + CanvasHeight = status->CanvasHeight; } void Scrollbar::Focus(double XorY){ diff --git a/src/components/Scrollbar.hpp b/src/components/Scrollbar.hpp index fa49eca..c313c69 100644 --- a/src/components/Scrollbar.hpp +++ b/src/components/Scrollbar.hpp @@ -9,6 +9,8 @@ class Scrollbar : public Component { Element bg,bar; double DragY,DragX; bool Trigger; + /// @brief Canvas size cache used to reset on resize + double CanvasWidth, CanvasHeight; public: Scrollbar(Status* s,bool IsHorizontal); void Refresh(); |
