#337 UnitSize scale and location disparity 4.x-dev

Sat, 23 Oct 2021 08:10:10 +0300

author
cemkalyoncu
date
Sat, 23 Oct 2021 08:10:10 +0300
branch
4.x-dev
changeset 1740
fe1c233c3a96
parent 1739
e2466f630836
child 1741
29e95844622d

#337 UnitSize scale and location disparity
* resize and move functions are non public

Source/Gorgon/UI/ComponentStack.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/UI/ComponentStackWidget.h file | annotate | diff | comparison | revisions
Source/Gorgon/UI/Dimension.h file | annotate | diff | comparison | revisions
Source/Gorgon/UI/Widget.h file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Composer.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Composer.h 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
--- a/Source/Gorgon/UI/ComponentStack.cpp	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/UI/ComponentStack.cpp	Sat Oct 23 08:10:10 2021 +0300
@@ -2767,42 +2767,42 @@
             
             //this will convert width to pixels
             if(widthch == -1) { //value channel is not in effect
-                comp.size.Width = size.Width(maxsize.Width - tagsize.Width, unitsize, spacing, emsize) + tagsize.Width;
-                curtw = size.Width(curtw - tagsize.Width, unitsize, spacing, emsize) + tagsize.Width;
+                comp.size.Width = size.Width(maxsize.Width - tagsize.Width, unitsize, spacing, emsize, true) + tagsize.Width;
+                curtw = size.Width(curtw - tagsize.Width, unitsize, spacing, emsize, true) + tagsize.Width;
             }
             else {//calculate and use value channel
                 //original width will be used as minimum size
-                auto min = size.Width(maxsize.Width, unitsize, spacing, emsize) + tagsize.Width;
+                auto min = size.Width(maxsize.Width, unitsize, spacing, emsize, true) + tagsize.Width;
                 
                 //calculate value and use it as basis point as relative size, then covert to pixels
                 comp.size.Width = 
                     Dimension{
                         int(calculatevalue(val, widthch, comp)*10000), Dimension::BasisPoint
-                    } (maxsize.Width - min, unitsize, spacing, emsize)
+                    } (maxsize.Width - min, unitsize, spacing, emsize, true)
                     + min;
                 
-                min = size.Width(curtw, unitsize, spacing, emsize) + tagsize.Width;
+                min = size.Width(curtw, unitsize, spacing, emsize, true) + tagsize.Width;
                 curtw = 
                     Dimension{
                         int(calculatevalue(val, widthch, comp)*10000), Dimension::BasisPoint
-                    } (curtw - min, unitsize, spacing, emsize)
+                    } (curtw - min, unitsize, spacing, emsize, true)
                     + min;
                     
             }
             
             //this will convert height to pixels
             if(heightch == -1) { //value channel is not in effect
-                comp.size.Height = size.Height(maxsize.Height - tagsize.Height, unitsize, spacing, emsize) + tagsize.Height;
+                comp.size.Height = size.Height(maxsize.Height - tagsize.Height, unitsize, spacing, emsize, true) + tagsize.Height;
             }
             else {//calculate and use value channel
                 //original height will be used as minimum size
-                auto min = size.Height(maxsize.Height, unitsize, spacing, emsize) + tagsize.Height;
+                auto min = size.Height(maxsize.Height, unitsize, spacing, emsize, true) + tagsize.Height;
                 
                 //calculate value and use it as basis point as relative size, then covert to pixels
                 comp.size.Height = 
                     Dimension{
                         int(calculatevalue(val, heightch, comp)*10000), Dimension::BasisPoint
-                    } (maxsize.Height - min, unitsize, spacing, emsize)
+                    } (maxsize.Height - min, unitsize, spacing, emsize, true)
                     + min;                
                     
                     comp.range.Width = maxsize.Height - min;
@@ -3151,13 +3151,13 @@
             if(temp.GetPositioning() == temp.PolarAbsolute) {
                 //center of parent
                 auto pcenter = Geometry::Pointf(
-                    cont.GetCenter().X.CalculateFloat((float)maxsize.Width, (float)emsize), 
-                    cont.GetCenter().Y.CalculateFloat((float)maxsize.Height, (float)emsize));
+                    cont.GetCenter().X.CalculateFloat((float)maxsize.Width, unitsize, spacing, (float)emsize), 
+                    cont.GetCenter().Y.CalculateFloat((float)maxsize.Height, unitsize, spacing, (float)emsize));
 
                 //center of object
                 auto center  = Geometry::Pointf(
-                    temp.GetCenter().X.CalculateFloat((float)comp.size.Width, (float)emsize), 
-                    temp.GetCenter().Y.CalculateFloat((float)comp.size.Height, (float)emsize)
+                    temp.GetCenter().X.CalculateFloat((float)comp.size.Width, unitsize, spacing, (float)emsize), 
+                    temp.GetCenter().Y.CalculateFloat((float)comp.size.Height, unitsize, spacing, (float)emsize)
                 );
 
                 pcenter += parentmargin.TopLeft();
@@ -3240,9 +3240,9 @@
 
                 //TODO use value channels
                 //calculate radius
-                auto r = pos.X.CalculateFloat(std::min(xrad, yrad), (float)emsize);
+                auto r = pos.X.CalculateFloat(std::min(xrad, yrad), unitsize, spacing, (float)emsize);
                 
-                auto a = pos.Y.CalculateFloat(float(maxang), 45) + stang; //em size for angle is 45
+                auto a = pos.Y.CalculateFloat(float(maxang), unitsize, spacing, 45) + stang; //em size for angle is 45
                 
                 //convert to radians
                 a *= -PI / 180.0f;
--- a/Source/Gorgon/UI/ComponentStackWidget.h	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/UI/ComponentStackWidget.h	Sat Oct 23 08:10:10 2021 +0300
@@ -36,24 +36,6 @@
         virtual ~ComponentStackWidget() {
             delete &stack;
         }
-        
-        using Widget::Move;
-        
-        virtual void Move(const Geometry::Point &location) override {
-            stack.Move(location);
-
-            if(IsVisible() && HasParent())
-                boundschanged();
-        }
-        
-        using Widget::Resize;
-        
-        virtual void Resize(const Geometry::Size &size) override {
-            stack.Resize(size);
-
-            if(IsVisible() && HasParent())
-                boundschanged();
-        }
 
         virtual Geometry::Point GetLocation() const override {
             return stack.GetLocation();
@@ -208,6 +190,21 @@
         
         
 
+    protected:        
+        virtual void move(const Geometry::Point &location) override {
+            stack.Move(location);
+
+            if(IsVisible() && HasParent())
+                boundschanged();
+        }
+        
+        virtual void resize(const Geometry::Size &size) override {
+            stack.Resize(size);
+
+            if(IsVisible() && HasParent())
+                boundschanged();
+        }
+
     private:
         virtual void show() override {
             stack.Show();
--- a/Source/Gorgon/UI/Dimension.h	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/UI/Dimension.h	Sat Oct 23 08:10:10 2021 +0300
@@ -78,12 +78,12 @@
         }
 
         /// Returns the calculated dimension in pixels
-        int operator ()(int parentwidth, int unitsize, int spacing, int emwidth = 10) const {
-            return Calculate(parentwidth, unitsize, spacing, emwidth);
+        int operator ()(int parentwidth, int unitsize, int spacing, int emwidth = 10, bool issize = false) const {
+            return Calculate(parentwidth, unitsize, spacing, emwidth, issize);
         }
 
         /// Returns the calculated dimension in pixels
-        int Calculate(int parentwidth, int unitsize, int spacing, int emwidth = 10) const {
+        int Calculate(int parentwidth, int unitsize, int spacing, int emwidth = 10, bool issize = false) const {
             switch(unit) {
                 case Percent:
                     return int(std::round((double)value * parentwidth / 100));
@@ -94,11 +94,15 @@
                 case EM:
                     return int(std::round(value * emwidth / 100));
                 case UnitSize:
-                    if(value >= -1 && value <= 1)
+                    if(!issize)
+                        return value * (unitsize + spacing);
+                    else if(value >= -1 && value <= 1)
                         return value * unitsize;
                     return value * unitsize + (value - 1) * spacing;
                 case MilliUnitSize:
-                    if(value >= -1000 && value <= 1000)
+                    if(!issize)
+                        return value * (unitsize + spacing);
+                    else if(value >= -1000 && value <= 1000)
                         return int(std::round((double)value * unitsize / 1000));
                     return int(std::round(((double)value * unitsize + (double)(value - 1000) * spacing) / 1000));
                 case Pixel:
@@ -108,7 +112,7 @@
         }
 
         /// Returns the calculated dimension in pixels
-        float CalculateFloat(float parentwidth, float emwidth = 10) const {
+        float CalculateFloat(float parentwidth, int unitsize, int spacing, float emwidth = 10, bool issize = false) const {
             switch(unit) {
                 case Percent:
                     return (float)value * parentwidth / 100.f;
@@ -118,6 +122,14 @@
                     return (float)value / 1000;
                 case EM:
                     return (float)value * emwidth / 100.f;
+                case UnitSize:
+                    if(!issize || (value >= -1 && value <= 1))
+                        return value * unitsize;
+                    return value * unitsize + (value - 1) * spacing;
+                case MilliUnitSize:
+                    if(!issize || (value >= -1000 && value <= 1000))
+                        return (float)value * unitsize / 1000;
+                    return ((float)value * unitsize + (float)(value - 1000) * spacing) / 1000;
                 case Pixel:
                 default:
                     return (float)value;
@@ -188,7 +200,7 @@
     
     /// Converts a dimension based size to pixel based size
     inline Geometry::Size Convert(const Size &s, const Geometry::Size &parent, int unitsize, int spacing, int emwidth = 10) {
-        return {s.Width(parent.Width, unitsize, spacing, emwidth), s.Height(parent.Height, unitsize, spacing, emwidth)};
+        return {s.Width(parent.Width, unitsize, spacing, emwidth, true), s.Height(parent.Height, unitsize, spacing, emwidth, true)};
     }
     
     /// Converts a dimension based margin to pixel based margin
--- a/Source/Gorgon/UI/Widget.h	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/UI/Widget.h	Sat Oct 23 08:10:10 2021 +0300
@@ -18,21 +18,18 @@
     friend class WidgetContainer;
         //Non-virtual functions for visual studio
 
-        void resize(const Geometry::Size &size) {
-            Resize(size);
-        }
+        virtual void resize(const Geometry::Size &size) = 0;
 
         Geometry::Size getsize() const {
             return GetSize();
         }
 
-        void move(const Geometry::Point &value) {
-            Move(value);
-        }
+        virtual void move(const Geometry::Point &value) = 0;
 
         Geometry::Point getlocation() const {
             return GetLocation();
         }
+        
     public:
         
         Widget() : Location(this), Size(this), Tooltip(this) {
@@ -46,7 +43,9 @@
         void Move(int x, int y) { Move({x, y}); }
         
         /// Moves this widget to the given position.
-        virtual void Move(const Geometry::Point &location) = 0;
+        void Move(const Geometry::Point &location) {
+            move(location);
+        }
 
         /// Returns the location of the widget
         virtual Geometry::Point GetLocation() const = 0;
@@ -55,7 +54,9 @@
         virtual void Resize(int w, int h) { Resize({w, h}); };
 
         /// Changes the size of the widget.
-        virtual void Resize(const Geometry::Size &size) = 0;
+        virtual void Resize(const Geometry::Size &size) {
+            resize(size);
+        }
 
         /// Returns the size of the widget
         virtual Geometry::Size GetSize() const = 0;
@@ -220,8 +221,8 @@
         /// invalidated in the event handlers registered to this function.
         Event<Widget> DestroyedEvent        = Event<Widget>{*this};
         
-        Geometry::PointProperty<Widget, &Widget::getlocation, &Widget::move> Location;
-        Geometry::SizeProperty<Widget, &Widget::getsize, &Widget::resize> Size;
+        Geometry::PointProperty<Widget, &Widget::getlocation, &Widget::Move> Location;
+        Geometry::SizeProperty<Widget, &Widget::getsize, &Widget::Resize> Size;
         TextualProperty<Widget, std::string, &Widget::GetTooltip, &Widget::SetTooltip> Tooltip;
         
         /// This is a debug feature
--- a/Source/Gorgon/Widgets/Composer.cpp	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/Widgets/Composer.cpp	Sat Oct 23 08:10:10 2021 +0300
@@ -68,13 +68,13 @@
             boundschanged();
     }
 
-    void Composer::Resize(const Geometry::Size &size) {
+    void Composer::resize(const Geometry::Size &size) {
         base.Resize(size);
         if (IsVisible() && HasParent())
             boundschanged();
 
     }
-    void Composer::Move(const Geometry::Point &location) {
+    void Composer::move(const Geometry::Point &location) {
         base.Move(location);
         if (IsVisible() && HasParent())
             boundschanged();
@@ -173,8 +173,8 @@
             RemoveFocus();
     }
 
-    void ComponentStackComposer::Resize(const Geometry::Size &size) {
-        ComponentStackWidget::Resize(size);
+    void ComponentStackComposer::resize(const Geometry::Size &size) {
+        ComponentStackWidget::resize(size);
         
         if(HasOrganizer())
             GetOrganizer().Reorganize();
@@ -183,8 +183,8 @@
         distributeparentboundschanged();
     }
     
-    void ComponentStackComposer::Move(const Geometry::Point &location) {
-        ComponentStackWidget::Move(location);
+    void ComponentStackComposer::move(const Geometry::Point &location) {
+        ComponentStackWidget::move(location);
         
         distributeparentboundschanged();
     }
--- a/Source/Gorgon/Widgets/Composer.h	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/Widgets/Composer.h	Sat Oct 23 08:10:10 2021 +0300
@@ -49,14 +49,11 @@
             
             return true;
         }
-        
-        virtual void Resize(const Geometry::Size &size) override;
 
         virtual Geometry::Point GetLocation() const override {
             return base.GetLocation();
         }
         
-        virtual void Move(const Geometry::Point &location) override;
         
         virtual void SetVisible(bool value) override {
             Widget::SetVisible(value);
@@ -175,6 +172,11 @@
         
         
     private:
+        
+        virtual void resize(const Geometry::Size &size) override;
+
+        virtual void move(const Geometry::Point &location) override;
+
         bool enabled = true;
         
         virtual void hide() override;
@@ -230,10 +232,6 @@
             return GetInteriorSize() == size;
         }
         
-        virtual void Resize(const Geometry::Size &size) override;
-
-        virtual void Move(const Geometry::Point &location) override;
-        
         virtual void SetVisible(bool value) override {
             ComponentStackWidget::SetVisible(value);
             distributeparentboundschanged();
@@ -272,7 +270,11 @@
         ComponentStackComposer(const UI::Template &temp, std::map<UI::ComponentTemplate::Tag, std::function<Widget *(const UI::Template &)>> generators = {}) :
             ComponentStackWidget(temp, generators)
         { }
-        
+
+        virtual void resize(const Geometry::Size &size) override;
+
+        virtual void move(const Geometry::Point &location) override;
+                
         virtual bool allowfocus() const override;
         
         virtual void focused() override;
--- a/Source/Gorgon/Widgets/Panel.cpp	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/Widgets/Panel.cpp	Sat Oct 23 08:10:10 2021 +0300
@@ -119,8 +119,8 @@
         return stack.TagBounds(UI::ComponentTemplate::ContentsTag).GetSize() == size;
     }
     
-    void Panel::Resize(const Geometry::Size &size) { 
-        ComponentStackWidget::Resize(size);
+    void Panel::resize(const Geometry::Size &size) { 
+        ComponentStackWidget::resize(size);
         
         if(HasOrganizer())
             GetOrganizer().Reorganize();
@@ -129,8 +129,8 @@
         distributeparentboundschanged();
     }
     
-    void Panel::Move(const Geometry::Point &location) { 
-        ComponentStackWidget::Move(location);
+    void Panel::move(const Geometry::Point &location) { 
+        ComponentStackWidget::move(location);
         
         distributeparentboundschanged();
     }
--- a/Source/Gorgon/Widgets/Panel.h	Fri Oct 22 06:46:12 2021 +0300
+++ b/Source/Gorgon/Widgets/Panel.h	Sat Oct 23 08:10:10 2021 +0300
@@ -18,18 +18,11 @@
         
         explicit Panel(Registry::TemplateType type = Registry::Panel_Regular) : Panel(Registry::Active()[type]) { }
 
-        using Widget::Resize;
         
         using Widget::Remove;
         
         using WidgetContainer::Remove;
         
-        virtual void Resize(const Geometry::Size &size) override;
-        
-        using Widget::Move;
-        
-        virtual void Move(const Geometry::Point &location) override;
-        
 
         virtual bool Activate() override;
 
@@ -265,6 +258,13 @@
         int spacing   = 0;
         int unitwidth = 0;
         bool issizesset = false;
+        
+    private:
+                
+        virtual void resize(const Geometry::Size &size) override;
+        
+        virtual void move(const Geometry::Point &location) override;
+
     };
     
 } }

mercurial