* Component stack testing completed ComponentStackRework

Wed, 02 Sep 2020 14:41:27 +0300

author
cemkalyoncu
date
Wed, 02 Sep 2020 14:41:27 +0300
branch
ComponentStackRework
changeset 1425
96dfce008a48
parent 1424
3e441a112caf
child 1426
30303e4ede59

* Component stack testing completed

Source/Gorgon/UI/ComponentStack.h file | annotate | diff | comparison | revisions
Testing/Source/Manual/UI_Component.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/UI/ComponentStack.h	Wed Sep 02 11:45:14 2020 +0300
+++ b/Source/Gorgon/UI/ComponentStack.h	Wed Sep 02 14:41:27 2020 +0300
@@ -341,6 +341,15 @@
             taglocations[tag] = location;
             Update();
         }
+        
+        Geometry::Point GetTagLocation(ComponentTemplate::Tag tag) const {
+            auto f = taglocations.find(tag);
+            
+            if(f == taglocations.end())
+                return {0, 0};
+            else
+                return f->second;
+        }
 
         /// Removes the fixed location for a set tagged component
         void RemoveTagLocation(ComponentTemplate::Tag tag) {
@@ -353,20 +362,30 @@
             Update();
         }
 
+        Geometry::Size GetTagSize(ComponentTemplate::Tag tag) const {
+            auto f = tagsizes.find(tag);
+            
+            if(f == tagsizes.end())
+                return {0, 0};
+            else
+                return f->second;
+        }
+
         /// Removes the fixed size for a set tagged component
         void RemoveTagSize(ComponentTemplate::Tag tag) {
             tagsizes.erase(tag);
         }
         
+        /// Enables text wrapping on a specific tag, default is enabled.
+        void EnableTagWrap(ComponentTemplate::Tag tag) {
+            tagnowrap.erase(tag);
+        }
+        
         /// Disables text wrapping on a specific tag, default is enabled.
         void DisableTagWrap(ComponentTemplate::Tag tag) {
             tagnowrap.insert(tag);
         }
 
-        /// Enables text wrapping on a specific tag, default is enabled.
-        void EnableTagWrap(ComponentTemplate::Tag tag) {
-            tagnowrap.erase(tag);
-        }
 
         /// Sets a function to be called before update check
         void SetFrameEvent(std::function<void()> handler) {
--- a/Testing/Source/Manual/UI_Component.cpp	Wed Sep 02 11:45:14 2020 +0300
+++ b/Testing/Source/Manual/UI_Component.cpp	Wed Sep 02 14:41:27 2020 +0300
@@ -2364,7 +2364,7 @@
     stack.SetTagLocation(Gorgon::UI::ComponentTemplate::LeftTag, {10, 10});
     auto b = stack.TagBounds(Gorgon::UI::ComponentTemplate::LeftTag);
 
-    return {"Set tag position", String::Concat((b.operator ==({10,10,20,20}) ? "Passed" : "Failed"), ". Returned bounds = ", b, " should be [(10, 10) - (20, 20)]. Green rectangle should be 10, 10 from top left."), stack};
+    return {"Set tag position", String::Concat((b.operator ==({10,10,20,20}) && stack.GetTagLocation(Gorgon::UI::ComponentTemplate::LeftTag) == b.TopLeft() ? "Passed" : "Failed"), ". Returned bounds = ", b, " should be [(10, 10) - (20, 20)]. Green rectangle should be 10, 10 from top left."), stack};
 }
 
 TestData test_settagposabs(Layer &layer) {
@@ -2439,6 +2439,84 @@
     return {"Set tag position and remove", String::Concat((b.operator ==({0,0,10,10}) ? "Passed" : "Failed"), ". Returned bounds = ", b, " should be [(0, 0) - (10, 10)]. Green rectangle should be at top left."), stack};
 }
 
+TestData test_settagsize(Layer &layer) {
+    auto &temp = *new Template;
+    temp.SetSize(50, 50);
+
+    auto &cont1 = temp.AddContainer(0, Gorgon::UI::ComponentCondition::Always);
+    cont1.AddIndex(1);
+    cont1.Background.SetAnimation(whiteimg());
+
+    auto &cont2 = temp.AddGraphics(1, Gorgon::UI::ComponentCondition::Always);
+    cont2.Content.SetAnimation(greenimg());
+    cont2.SetTag(Gorgon::UI::ComponentTemplate::LeftTag);
+    cont2.SetSizing(Gorgon::UI::ComponentTemplate::Fixed);
+
+    auto &stack = *new ComponentStack(temp);
+
+    layer.Add(stack);
+
+    stack.SetTagSize(Gorgon::UI::ComponentTemplate::LeftTag, {30, 30});
+    auto b = stack.TagBounds(Gorgon::UI::ComponentTemplate::LeftTag);
+
+    return {"Set tag size", String::Concat((b.operator ==({0,0,30,30}) && stack.GetTagSize(Gorgon::UI::ComponentTemplate::LeftTag) == b.GetSize() ? "Passed" : "Failed"), ". Returned bounds = ", b, " should be [(0, 0) - (30, 30)]."), stack};
+}
+
+TestData test_tagtextwrap(Layer &layer) {
+    auto &app = getapp();
+
+    auto &temp = *new Template;
+    temp.SetSize(70, 50);
+    
+    auto &cont1 = temp.AddContainer(0, Gorgon::UI::ComponentCondition::Always);
+    cont1.AddIndex(1);
+    cont1.Background.SetAnimation(whiteimg());
+    
+    auto &cont2 = temp.AddTextholder(1, Gorgon::UI::ComponentCondition::Always);
+    cont2.SetDataEffect(Gorgon::UI::ComponentTemplate::Text);
+    cont2.SetColor(Color::Brown);
+    cont2.SetRenderer(app.fntlarge);
+    cont2.SetTag(Gorgon::UI::ComponentTemplate::LeftTag);
+    cont2.SetSize(100, 100, Gorgon::UI::Dimension::Percent);
+    cont2.SetText("Hello there");
+    
+    auto &stack = *new ComponentStack(temp);
+    
+    stack.DisableTagWrap(Gorgon::UI::ComponentTemplate::LeftTag);
+    
+    layer.Add(stack);
+    
+    return {"Tag text wrap", "Brown text 'Hello there' without wrapping.", stack};
+}
+
+TestData test_tagtextwrap2(Layer &layer) {
+    auto &app = getapp();
+
+    auto &temp = *new Template;
+    temp.SetSize(70, 50);
+    
+    auto &cont1 = temp.AddContainer(0, Gorgon::UI::ComponentCondition::Always);
+    cont1.AddIndex(1);
+    cont1.Background.SetAnimation(whiteimg());
+    
+    auto &cont2 = temp.AddTextholder(1, Gorgon::UI::ComponentCondition::Always);
+    cont2.SetDataEffect(Gorgon::UI::ComponentTemplate::Text);
+    cont2.SetColor(Color::Brown);
+    cont2.SetRenderer(app.fntlarge);
+    cont2.SetTag(Gorgon::UI::ComponentTemplate::LeftTag);
+    cont2.SetSize(100, 100, Gorgon::UI::Dimension::Percent);
+    cont2.SetText("Hello there");
+    
+    auto &stack = *new ComponentStack(temp);
+    
+    stack.DisableTagWrap(Gorgon::UI::ComponentTemplate::LeftTag);
+    stack.EnableTagWrap(Gorgon::UI::ComponentTemplate::LeftTag);
+    
+    layer.Add(stack);
+    
+    return {"Tag text wrap 2", "Brown text 'Hello there' with wrapping.", stack};
+}
+
 
 std::vector<std::function<TestData(Layer &)>> tests = {
     &test_graphic,
@@ -2542,6 +2620,9 @@
     &test_settagposabs,
     &test_settagposval,
     &test_settagposrem,
+    &test_settagsize,
+    &test_tagtextwrap,
+    &test_tagtextwrap2,
 };
 
 //END tests

mercurial