#122: CheckboxButton 4.x-dev

Wed, 04 Mar 2020 22:28:07 +0200

author
cemkalyoncu
date
Wed, 04 Mar 2020 22:28:07 +0200
branch
4.x-dev
changeset 1367
b125e0e6452d
parent 1366
7eea05431e78
child 1368
9135822b5605

#122: CheckboxButton

Source/Gorgon/Widgets/Generator.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Generator.h file | annotate | diff | comparison | revisions
Testing/Source/Manual/UI_Generate.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Widgets/Generator.cpp	Wed Mar 04 19:58:27 2020 +0200
+++ b/Source/Gorgon/Widgets/Generator.cpp	Wed Mar 04 22:28:07 2020 +0200
@@ -101,6 +101,10 @@
         delete normaleditborder;
         delete hovereditborder;
         delete focusborder;
+        delete normalemptyborder;
+        delete normalbg;
+        delete hoverbg;
+        delete downbg;
     }
     
     void SimpleGenerator::UpdateDimensions() {
@@ -116,6 +120,26 @@
         return *normalborder;
     }
     
+    Graphics::BitmapRectangleProvider &SimpleGenerator::HoverBorder() {
+        if(!hoverborder) {
+            auto c = Background.Regular;
+            c.Blend(Background.Hover);
+            hoverborder = makeborder(Border.Color, c);
+        }
+        
+        return *hoverborder;
+    }
+    
+    Graphics::BitmapRectangleProvider &SimpleGenerator::DownBorder() {
+        if(!downborder) {
+            auto c = Background.Regular;
+            c.Blend(Background.Down);
+            downborder = makeborder(Border.Color, c);
+        }
+        
+        return *downborder;
+    }
+    
     Graphics::BitmapRectangleProvider &SimpleGenerator::PanelBorder() {
         if(!panelborder)
             panelborder = makeborder(Border.Color, Background.Panel);
@@ -168,27 +192,34 @@
         
         return *hovereditborder;
     }
-    
-    Graphics::BitmapRectangleProvider &SimpleGenerator::HoverBorder() {
-        if(!hoverborder) {
-            auto c = Background.Regular;
-            c.Blend(Background.Hover);
-            hoverborder = makeborder(Border.Color, c);
-        }
+
+    Graphics::BitmapRectangleProvider &SimpleGenerator::NormalBG() {
+        if(!normalbg)
+            normalbg = makeborder(0x0, Background.Regular);
         
-        return *hoverborder;
+        return *normalbg;
     }
     
-    Graphics::BitmapRectangleProvider &SimpleGenerator::DownBorder() {
-        if(!downborder) {
+    Graphics::BitmapRectangleProvider &SimpleGenerator::HoverBG() {
+        if(!hoverbg) {
+            auto c = Background.Regular;
+            c.Blend(Background.Hover);
+            hoverbg = makeborder(0x0, c);
+        }
+        
+        return *hoverbg;
+    }
+    
+    Graphics::BitmapRectangleProvider &SimpleGenerator::DownBG() {
+        if(!downbg) {
             auto c = Background.Regular;
             c.Blend(Background.Down);
-            downborder = makeborder(Border.Color, c);
+            downbg = makeborder(0x0, c);
         }
         
-        return *downborder;
+        return *downbg;
     }
-    
+        
     Graphics::RectangleProvider &SimpleGenerator::FocusBorder() {
         if(!focusborder)
             focusborder = makefocusborder();
@@ -196,6 +227,13 @@
         return *focusborder;
     }
     
+    Graphics::BitmapRectangleProvider &SimpleGenerator::NormalEmptyBorder() {
+        if(!normalemptyborder)
+            normalemptyborder = makeborder(Border.Color, 0x0);
+        
+        return *normalemptyborder;
+    }
+    
     Graphics::BitmapRectangleProvider *SimpleGenerator::makeborder(Graphics::RGBA border, Graphics::RGBA bg, int missingside) {
         int bsize = (Border.Width + Border.Radius + 1) * 2 + 16;
         float off = (int)(Border.Width + 1) / 2; //round up
@@ -261,7 +299,7 @@
                 list[7].X = bsize - off;
             }
             
-            CGI::DrawLines(bi.GetData(), list, (float)Border.Width, CGI::SolidFill<>(Border.Color));
+            CGI::DrawLines(bi.GetData(), list, (float)Border.Width, CGI::SolidFill<>(border));
         }
         
         if(missingside == 2) {
@@ -682,6 +720,81 @@
         return temp;
     }
     
+    UI::Template SimpleGenerator::CheckboxButton() {
+        
+        UI::Template temp;
+        temp.SetSize((WidgetWidth-Spacing*3)/4, BordedWidgetHeight);
+        
+        auto bgsize = temp.GetSize();
+        
+        {
+            auto &bg = temp.AddContainer(0, UI::ComponentCondition::Always);
+            
+            bg.Background.SetAnimation(NormalBG());
+            bg.AddIndex(1);
+            bg.AddIndex(2);
+            bg.AddIndex(3);
+        }
+        
+        {
+            auto &bg = temp.AddContainer(0, UI::ComponentCondition::Hover);
+            
+            bg.Background.SetAnimation(HoverBG());
+            bg.AddIndex(1);
+            bg.AddIndex(2);
+            bg.AddIndex(3);
+        }
+        
+        {
+            auto &bg = temp.AddContainer(0, UI::ComponentCondition::Down);
+            
+            bg.Background.SetAnimation(DownBG());
+            bg.AddIndex(1);
+            bg.AddIndex(2);
+            bg.AddIndex(3);
+        }
+        
+        auto &icon = temp.AddPlaceholder(1, UI::ComponentCondition::Always);
+        icon.SetDataEffect(icon.Icon);
+        icon.SetAnchor(UI::Anchor::MiddleCenter, UI::Anchor::MiddleCenter, UI::Anchor::MiddleCenter);
+        icon.SetSize(100, 100, UI::Dimension::Percent);
+        icon.SetPositioning(icon.Absolute);
+        icon.SetSizing(icon.Fixed);
+        icon.SetClip(true);
+
+        {
+            auto &txt_n = temp.AddTextholder(3, UI::ComponentCondition::Always);
+            txt_n.SetRenderer(RegularFont);
+            txt_n.SetColor(Forecolor.Regular);
+            txt_n.SetAnchor(UI::Anchor::None, UI::Anchor::MiddleCenter, UI::Anchor::MiddleCenter);
+            txt_n.SetDataEffect(UI::ComponentTemplate::Text);
+            txt_n.SetClip(true);
+            txt_n.SetSize(100, 100, UI::Dimension::Percent);
+            txt_n.SetSizing(UI::ComponentTemplate::ShrinkOnly);
+            txt_n.SetPositioning(txt_n.Absolute);
+        }
+
+        
+        {
+            auto &foc = temp.AddContainer(2, UI::ComponentCondition::Focused);
+            foc.Background.SetAnimation(FocusBorder());
+            foc.SetMargin(1);
+            foc.SetSize(100, 100, UI::Dimension::Percent);
+            foc.SetPositioning(foc.Absolute);
+            foc.SetAnchor(UI::Anchor::None, UI::Anchor::MiddleCenter, UI::Anchor::MiddleCenter);
+        }
+        
+        {
+            auto &sel = temp.AddContainer(2, UI::ComponentCondition::State2);
+            sel.Background.SetAnimation(NormalEmptyBorder());
+            sel.SetSize(100, 100, UI::Dimension::Percent);
+            sel.SetPositioning(sel.Absolute);
+            sel.SetAnchor(UI::Anchor::None, UI::Anchor::MiddleCenter, UI::Anchor::MiddleCenter);
+        }
+        
+        return temp;
+    }
+    
     UI::Template SimpleGenerator::RadioButton() {
         Geometry::Size defsize = {WidgetWidth * 2 + Spacing, WidgetHeight};
         
--- a/Source/Gorgon/Widgets/Generator.h	Wed Mar 04 19:58:27 2020 +0200
+++ b/Source/Gorgon/Widgets/Generator.h	Wed Mar 04 22:28:07 2020 +0200
@@ -24,6 +24,8 @@
         
         virtual UI::Template Checkbox() = 0;
         
+        virtual UI::Template CheckboxButton() = 0;
+        
         virtual UI::Template RadioButton() = 0;
         
         
@@ -71,6 +73,8 @@
         
         virtual UI::Template Checkbox() override;
         
+        virtual UI::Template CheckboxButton() override;
+        
         virtual UI::Template RadioButton() override;
         
         
@@ -106,6 +110,12 @@
         Graphics::BitmapRectangleProvider &NormalEditBorder();
         Graphics::BitmapRectangleProvider &HoverEditBorder();
         
+        Graphics::BitmapRectangleProvider &NormalEmptyBorder();
+        
+        Graphics::BitmapRectangleProvider &NormalBG();
+        Graphics::BitmapRectangleProvider &HoverBG();
+        Graphics::BitmapRectangleProvider &DownBG();
+        
         Graphics::RectangleProvider &FocusBorder();
         
         int Spacing      = 4;
@@ -177,6 +187,12 @@
         Graphics::BitmapRectangleProvider *normaleditborder = nullptr;
         Graphics::BitmapRectangleProvider *hovereditborder = nullptr;
         
+        Graphics::BitmapRectangleProvider *normalemptyborder = nullptr;
+        
+        Graphics::BitmapRectangleProvider *normalbg = nullptr;
+        Graphics::BitmapRectangleProvider *hoverbg = nullptr;
+        Graphics::BitmapRectangleProvider *downbg = nullptr;
+        
         Graphics::RectangleProvider *focusborder = nullptr;
     };
 
--- a/Testing/Source/Manual/UI_Generate.cpp	Wed Mar 04 19:58:27 2020 +0200
+++ b/Testing/Source/Manual/UI_Generate.cpp	Wed Mar 04 22:28:07 2020 +0200
@@ -42,6 +42,7 @@
     auto btntemp = gen.Button();
     auto radtemp = gen.RadioButton();
     auto chktemp = gen.Checkbox();
+    auto chktemp2 = gen.CheckboxButton();
     auto icobtntemp = gen.IconButton();
     auto lbltemp = gen.Label();
     auto pnltemp = gen.BlankPanel();
@@ -138,7 +139,7 @@
     });
     decrease.ActivateClickRepeat();
     
-    Widgets::Checkbox chk1(chktemp, "Sugar?");
+    Widgets::Checkbox chk1(chktemp2, "Su?");
     
     //app.wind.Add(chk1);
     chk1.Move(300, 0);

mercurial