#337 Scroll amount and speed is not in dimensions 4.x-dev

Fri, 29 Oct 2021 16:10:51 +0300

author
cemkalyoncu
date
Fri, 29 Oct 2021 16:10:51 +0300
branch
4.x-dev
changeset 1749
f66c1dbd5e5e
parent 1748
f965ac36d227
child 1750
ed90f811fcba

#337 Scroll amount and speed is not in dimensions

Source/Gorgon/UI/Dialog.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/UI/Dialog.h file | annotate | diff | comparison | revisions
Source/Gorgon/UI/ScrollingWidget.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/UI/ScrollingWidget.h file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Generator.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Panel.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Panel.h file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/RadioButtons.h file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Textarea.h file | annotate | diff | comparison | revisions
Testing/Source/Manual/UI_Generate.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/UI/Dialog.cpp	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/UI/Dialog.cpp	Fri Oct 29 16:10:51 2021 +0300
@@ -227,7 +227,7 @@
         diag->Add(*text);
         diag->Own(*text);
         
-        diag->ResizeInterior(negotiatesize(diag, text));
+        diag->ResizeInterior(Pixels(negotiatesize(diag, text)));
         place(diag);
     }
 
@@ -300,9 +300,9 @@
         totw += diag->ButtonAreaOrganizer().GetSpacing() * (btnsarea.GetCount()-1);
 
         if(totw > diag->GetCurrentWidth())
-            diag->ResizeInterior({totw, diag->GetInteriorSize().Height});
+            diag->ResizeInterior(Pixels(totw, diag->GetInteriorSize().Height));
 
-        diag->ResizeInterior(negotiatesize(diag, text, false));
+        diag->ResizeInterior(Pixels(negotiatesize(diag, text, false)));
 
         diag->ButtonAreaOrganizer().Reorganize();
 
@@ -427,10 +427,10 @@
             diag->Own(*l);
         }
         
-        diag->ResizeInterior({
+        diag->ResizeInterior(Pixels(
             std::max(diag->GetInteriorSize().Width, inp->GetBounds().Right), 
             inp->GetBounds().Bottom
-        });
+        ));
         
         diag->KeyEvent.Register(
             [inp, message, label](Input::Key key, float state) {
@@ -464,7 +464,7 @@
             }
         );
         
-        diag->ResizeInterior(negotiatesize(diag, text, false));
+        diag->ResizeInterior(Pixels(negotiatesize(diag, text, false)));
         if(l) {
             l->Move(Pixels(text->GetCurrentLocation().X, text->GetBounds().Bottom + text->GetCurrentLocation().Y));
             l->SetHeight(inp->GetHeight());
@@ -476,8 +476,8 @@
             inp->SetWidth(Pixels(diag->GetInteriorSize().Width - text->GetCurrentLocation().X*2));
         }
         
-        diag->ResizeInterior({diag->GetInteriorSize().Width, inp->GetBounds().Bottom});
-        diag->ResizeInterior(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation()));
+        diag->ResizeInterior(Pixels(diag->GetInteriorSize().Width, inp->GetBounds().Bottom));
+        diag->ResizeInterior(Pixels(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation())));
         place(diag);
         diag->Center(); //input dialogs will be centered
     }
--- a/Source/Gorgon/UI/Dialog.h	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/UI/Dialog.h	Fri Oct 29 16:10:51 2021 +0300
@@ -344,10 +344,10 @@
             diag->Own(*l);
         }
         
-        diag->ResizeInterior({
+        diag->ResizeInterior(Pixels(
             std::max(diag->GetInteriorSize().Width, inp->GetBounds().Right), 
             inp->GetBounds().Bottom
-        });
+        ));
         
         diag->KeyEvent.Register(
             [inp, message, label](Input::Key key, float state) {
@@ -387,8 +387,8 @@
         }
 
         
-        diag->ResizeInterior({diag->GetInteriorSize().Width, inp->GetBounds().Bottom});
-        diag->ResizeInterior(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation()));
+        diag->ResizeInterior(Pixels(diag->GetInteriorSize().Width, inp->GetBounds().Bottom));
+        diag->ResizeInterior(Pixels(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation())));
 
         place(diag);
         diag->Center(); //input dialogs will be centered
@@ -593,10 +593,10 @@
             diag->Own(*l);
         }
         
-        diag->ResizeInterior({
+        diag->ResizeInterior(Pixels(
             std::max(diag->GetInteriorSize().Width, inp->GetBounds().Right), 
             inp->GetBounds().Bottom
-        });
+        ));
         
         diag->KeyEvent.Register(
             [inp, message, label](Input::Key key, float state) {
@@ -630,7 +630,7 @@
             }
         );
         
-        diag->ResizeInterior(negotiatesize(diag, text, false));
+        diag->ResizeInterior(Pixels(negotiatesize(diag, text, false)));
         if(l) {
             l->Move(Pixels(text->GetCurrentLocation().X, text->GetBounds().Bottom + text->GetCurrentLocation().Y));
             l->SetHeight(inp->GetHeight());
@@ -642,8 +642,8 @@
             inp->SetWidth(Pixels(diag->GetInteriorSize().Width - text->GetCurrentLocation().X*2));
         }
         
-        diag->ResizeInterior({diag->GetInteriorSize().Width, inp->GetBounds().Bottom});
-        diag->ResizeInterior(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation()));
+        diag->ResizeInterior(Pixels(diag->GetInteriorSize().Width, inp->GetBounds().Bottom));
+        diag->ResizeInterior(Pixels(Geometry::Size(inp->GetBounds().BottomRight() + text->GetCurrentLocation())));
         place(diag);
         diag->Center(); //input dialogs will be centered
     }
--- a/Source/Gorgon/UI/ScrollingWidget.cpp	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/UI/ScrollingWidget.cpp	Fri Oct 29 16:10:51 2021 +0300
@@ -17,7 +17,7 @@
         vscroller->Maximum = stack.TagBounds(UI::ComponentTemplate::ContentsTag).Height();
         vscroller->Range   = stack.TagBounds(UI::ComponentTemplate::ViewPortTag).Height();
         *vscroller         = target.Y;
-        vscroller->SetSmoothChangeSpeed(scrollspeed);
+        vscroller->SetSmoothChangeSpeed(Convert(scrollspeed, true));
         vscroller->ValueChanged.Register(*this, &ScrollingWidget::scrolltoy);
         
         return vscroller;
@@ -28,7 +28,7 @@
         hscroller->Maximum = stack.TagBounds(UI::ComponentTemplate::ContentsTag).Width();
         hscroller->Range   = stack.TagBounds(UI::ComponentTemplate::ViewPortTag).Width();
         *hscroller         = target.X;
-        hscroller->SetSmoothChangeSpeed(scrollspeed);
+        hscroller->SetSmoothChangeSpeed(Convert(scrollspeed, false));
         hscroller->ValueChanged.Register(*this, &ScrollingWidget::scrolltox);
         
         return hscroller;
@@ -81,9 +81,9 @@
         
         auto cur = -b.TopLeft();
         
-        auto curspeed = scrollspeed;
+        auto curspeed = scrollspeedpx;
         
-        if(1000*target.ManhattanDistance(cur)/scrollspeed > maxscrolltime) {
+        if(1000*target.ManhattanDistance(cur)/scrollspeedpx > maxscrolltime) {
             //due to integer division, this value would be scrollspeed at some points, which will reset smooth speed
             //if not, when scrolling is finished it will be reset
             curspeed = int(1000*target.ManhattanDistance(cur) / maxscrolltime);
@@ -139,11 +139,11 @@
                 
             auto vscroller = dynamic_cast<Widgets::VScroller<float>*>(stack.GetWidget(UI::ComponentTemplate::VScrollTag));
             if(vscroller)
-                vscroller->SetSmoothChangeSpeed(scrollspeed);
+                vscroller->SetSmoothChangeSpeed(scrollspeedpx);
             
             auto hscroller = dynamic_cast<Widgets::HScroller<float>*>(stack.GetWidget(UI::ComponentTemplate::HScrollTag));
             if(hscroller)
-                hscroller->SetSmoothChangeSpeed(scrollspeed);
+                hscroller->SetSmoothChangeSpeed(scrollspeedpx);
                     
             scrollleftover = 0;
         }
@@ -199,13 +199,14 @@
         return {xscroll, yscroll};
     }
 
-    void ScrollingWidget::SetSmoothScrollSpeed(int value){
+    void ScrollingWidget::SetSmoothScrollSpeed(const UnitDimension &value){
         auto b = stack.TagBounds(UI::ComponentTemplate::ContentsTag);
         auto s = b.GetSize();
         
         scrollspeed = value;
+        scrollspeedpx = Convert(scrollspeed, true);
         
-        if(value == 0 && isscrolling) {
+        if(scrollspeedpx == 0 && isscrolling) {
             stack.SetTagLocation(UI::ComponentTemplate::ContentsTag, target);
             
             isscrolling = false;
@@ -216,19 +217,19 @@
         auto vscroller = dynamic_cast<Widgets::VScrollbar*>(stack.GetWidget(UI::ComponentTemplate::VScrollTag));
         
         if(vscroller != nullptr) {
-            vscroller->SetSmoothChangeSpeed(scrollspeed);
+            vscroller->SetSmoothChangeSpeed(scrollspeedpx);
         }
         
         auto hscroller = dynamic_cast<Widgets::HScrollbar*>(stack.GetWidget(UI::ComponentTemplate::HScrollTag));
         
         if(hscroller != nullptr) {
-            hscroller->SetSmoothChangeSpeed(scrollspeed);
+            hscroller->SetSmoothChangeSpeed(scrollspeedpx);
         }
         
         if(s.Area() == 0) 
             stack.SetValueTransitionSpeed({0, 0, 0, 0});
         else
-            stack.SetValueTransitionSpeed({(float)value / s.Width, (float)value / s.Height, 0, 0});
+            stack.SetValueTransitionSpeed({(float)scrollspeedpx / s.Width, (float)scrollspeedpx / s.Height, 0, 0});
     }
     
     bool ScrollingWidget::MouseScroll(Input::Mouse::EventType type, Geometry::Point, float amount) {
@@ -247,7 +248,7 @@
             if(amount>0 && scrolloffset.Y <= 0)
                 return false;
             
-            scrollby(0, -(int)amount*scrolldist.Y);
+            scrollby(0, -(int)amount*scrolldistpx.Y);
             return true;
         }
         
@@ -258,7 +259,7 @@
             if(amount>0 && scrolloffset.X <= 0)
                 return false;
             
-            scrollby(-(int)amount*scrolldist.X, 0);
+            scrollby(-(int)amount*scrolldistpx.X, 0);
             return true;
         }
         
@@ -326,21 +327,27 @@
     }
 
 
-    void ScrollingWidget::SetScrollDistance(Geometry::Point dist) {
+    void ScrollingWidget::SetScrollDistance(const UnitPoint &dist) {
         scrolldist = dist;
+        scrolldistpx = Convert(scrolldist);
 
         auto vscroller = dynamic_cast<Widgets::VScrollbar*>(stack.GetWidget(UI::ComponentTemplate::VScrollTag));
 
         if(vscroller != nullptr) {
-            vscroller->SetSmallChange(dist.Y);
+            vscroller->SetSmallChange(scrolldistpx.Y);
         }
 
         auto hscroller = dynamic_cast<Widgets::HScrollbar*>(stack.GetWidget(UI::ComponentTemplate::HScrollTag));
 
         if(hscroller != nullptr) {
-            hscroller->SetSmallChange(dist.X);
+            hscroller->SetSmallChange(scrolldistpx.X);
         }
+    }
 
+    void ScrollingWidget::parentboundschanged() {
+        ComponentStackWidget::parentboundschanged();
+        scrolldistpx = Convert(scrolldist);
+        scrollspeedpx = Convert(scrollspeed, true);
     }
 
 } }
--- a/Source/Gorgon/UI/ScrollingWidget.h	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/UI/ScrollingWidget.h	Fri Oct 29 16:10:51 2021 +0300
@@ -35,11 +35,11 @@
         
         /// Adjusts the smooth scrolling speed of the panel. Given value is
         /// in pixels per second, default value is 500.
-        void SetSmoothScrollSpeed(int value);
+        void SetSmoothScrollSpeed(const UnitDimension &value);
         
         /// Returns the smooth scrolling speed of the panel. If smooth scroll
         /// is disabled, this value will be 0.
-        int GetSmoothScrollSpeed() const {
+        UnitDimension GetSmoothScrollSpeed() const {
             return scrollspeed;
         }
         
@@ -64,22 +64,22 @@
         
         /// Sets the horizontal scroll distance per click in pixels. Default depends
         /// on the default size of the panel.
-        void SetScrollDistance(int vert) {
+        void SetScrollDistance(const UnitDimension &vert) {
             SetScrollDistance({scrolldist.X, vert});
         }
 
         /// Sets the scroll distance per click in pixels. Default depends
         /// on the default size of the panel.
-        void SetScrollDistance(int hor, int vert) {
+        void SetScrollDistance(const UnitDimension &hor, const UnitDimension &vert) {
             SetScrollDistance({hor, vert});
         }
 
         /// Sets the scroll distance per click in pixels. Default depends
         /// on the default size of the panel.
-        void SetScrollDistance(Geometry::Point dist);
+        void SetScrollDistance(const UnitPoint &dist);
 
         /// Returns the scroll distance per click
-        Geometry::Point GetScrollDistance() const {
+        UnitPoint GetScrollDistance() const {
             return scrolldist;
         }
 
@@ -119,33 +119,25 @@
         /// Returns the current maximum scroll offset
         Geometry::Point maxscrolloffset() const;
         
-        /// Sets the scroll distance per click in pixels. Default depends
-        /// on the default size of the panel.
-        void setscrolldistance(Geometry::Point dist) {
-            scrolldist = dist;
-        }
-        
-        /// Returns the scroll distance per click
-        Geometry::Point getscrolldistance() const {
-            return scrolldist;
-        }
-        
         virtual UI::Widget *createvscroll(const UI::Template &temp);
         
         virtual UI::Widget *createhscroll(const UI::Template &temp);
         
-        
         virtual void updatescroll();
         
         virtual void updatebars();
         
         virtual void moved() { }
+
+        virtual void parentboundschanged() override;
         
         int overscroll = 0;
         bool scrollclipped = true;
-        Geometry::Point scrolldist = {80, 45};
+        Geometry::Point scrolldistpx = {108, 54};
+        UnitPoint scrolldist = Units(4, 2);
         Geometry::Point scrolloffset = {0, 0};
-        int scrollspeed = 500;
+        UnitDimension scrollspeed = Units(20);
+        int scrollspeedpx = 540;
         int maxscrolltime = 500;
         Geometry::Point target = {0, 0};
         bool isscrolling = false;
--- a/Source/Gorgon/Widgets/Generator.cpp	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/Widgets/Generator.cpp	Fri Oct 29 16:10:51 2021 +0300
@@ -1286,7 +1286,7 @@
     }
 
     UI::Template SimpleGenerator::Checkbox() {
-        UnitSize defsize = {Units(1), Pixels(borderlessheight)};
+        UnitSize defsize = {Units(6), Pixels(borderlessheight)};
         
         UI::Template temp = maketemplate();
         temp.SetSpacing(spacing);
--- a/Source/Gorgon/Widgets/Panel.cpp	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/Widgets/Panel.cpp	Fri Oct 29 16:10:51 2021 +0300
@@ -26,28 +26,24 @@
             
             switch(key) {
             case Keycodes::Down:
-                ScrollBy(scrolldist.Y);
+                ScrollBy(scrolldistpx.Y);
                 break;
                 
             case Keycodes::Up:
-                ScrollBy(-scrolldist.Y);
+                ScrollBy(-scrolldistpx.Y);
                 break;
                 
             case Keycodes::PageDown:
-                ScrollBy(std::max(scrolldist.Y, GetInteriorSize().Height - scrolldist.Y));
+                ScrollBy(std::max(scrolldistpx.Y, GetInteriorSize().Height - scrolldistpx.Y));
                 break;
                 
             case Keycodes::PageUp:
-                ScrollBy(-std::max(scrolldist.Y, GetInteriorSize().Height - scrolldist.Y));
+                ScrollBy(-std::max(scrolldistpx.Y, GetInteriorSize().Height - scrolldistpx.Y));
                 break;
             }
         });
         
         stack.AddCondition(UI::ComponentCondition::VScroll);
-
-        SetSmoothScrollSpeed(scrollspeed);
-        
-        SetScrollDistance(temp.GetUnitSize()*4, temp.GetUnitSize()*2);
     }
 
     bool Panel::Activate() {
--- a/Source/Gorgon/Widgets/Panel.h	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/Widgets/Panel.h	Fri Oct 29 16:10:51 2021 +0300
@@ -230,6 +230,7 @@
         virtual void childboundschanged(Widget *source) override;
         
         virtual void parentboundschanged () override {
+            ScrollingWidget::parentboundschanged();
             distributeparentboundschanged();
         }
         
--- a/Source/Gorgon/Widgets/RadioButtons.h	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/Widgets/RadioButtons.h	Fri Oct 29 16:10:51 2021 +0300
@@ -232,7 +232,7 @@
 
         /// Radio buttons height is automatically adjusted. Only width will be used.
         virtual void resize(const Geometry::Size &size) override {
-            Composer::Resize(size);
+            Composer::resize(size);
 
             for(auto p : this->elements) {
                 p.second.SetWidth(Pixels((GetCurrentWidth() - spacing * (GetColumns() - 1)) / GetColumns()));
--- a/Source/Gorgon/Widgets/Textarea.h	Fri Oct 29 14:08:50 2021 +0300
+++ b/Source/Gorgon/Widgets/Textarea.h	Fri Oct 29 16:10:51 2021 +0300
@@ -112,29 +112,6 @@
             return maxscrolloffset();
         }
         
-        /// Sets the horizontal scroll distance per click in pixels. Default depends
-        /// on the default size of the panel.
-        void SetScrollDistance(int vert) {
-            SetScrollDistance({scrolldist.X, vert});
-        }
-        
-        /// Sets the scroll distance per click in pixels. Default depends
-        /// on the default size of the panel.
-        void SetScrollDistance(int hor, int vert) {
-            SetScrollDistance({hor, vert});
-        }
-        
-        /// Sets the scroll distance per click in pixels. Default depends
-        /// on the default size of the panel.
-        void SetScrollDistance(Geometry::Point dist) {
-            setscrolldistance(dist);
-        }
-        
-        /// Returns the scroll distance per click
-        Geometry::Point GetScrollDistance() const {
-            return scrolldist;
-        }
-        
         /// Returns the length of the text in this inputbox. This value is in glyphs.
         int Length() const {
             return glyphcount;
--- a/Testing/Source/Manual/UI_Generate.cpp	Fri Oct 29 14:08:50 2021 +0300
+++ b/Testing/Source/Manual/UI_Generate.cpp	Fri Oct 29 16:10:51 2021 +0300
@@ -110,7 +110,7 @@
 
     Widgets::Panel blank/*(Widgets::Registry::Panel_Right)*/;
     blank.Move(Pixels(5, 50));
-    blank.SetWidth(6_u);
+    blank.SetInteriorWidth(6_u);
     std::cout << float(blank.GetInteriorSize().Width + blank.GetSpacing()) / (blank.GetUnitSize() + blank.GetSpacing()) << std::endl;
     blank.SetHeight(300_px);
     auto icon = Triangle(5, 10);

mercurial