Ver Fonte

UITabContainer and UILayout usability enhancements

JimMarlowe há 8 anos atrás
pai
commit
90da88081b

+ 9 - 0
Source/Atomic/UI/UILayout.cpp

@@ -115,4 +115,13 @@ bool UILayout::OnEvent(const tb::TBWidgetEvent &ev)
     return UIWidget::OnEvent(ev);
 }
 
+/// one step to configure the main 5 fields in a UILayout
+void UILayout::SetLayoutConfig ( const String &settings )
+{
+    if (!widget_)
+        return;
+
+    ((tb::TBLayout*)widget_)->SetLayoutConfig(settings.CString());
+}
+
 }

+ 11 - 0
Source/Atomic/UI/UILayout.h

@@ -130,6 +130,17 @@ public:
     void SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION distribution);
     void SetLayoutDistributionPosition(UI_LAYOUT_DISTRIBUTION_POSITION distribution_pos);
 
+    /// A different way of setting up a layout, using a series of characters to program the main 5 layout fields
+    /// character [0] = 'X' or 'Y'  for UI_AXIS = X(D), Y
+    /// character [1] = 'A'|'G'|'P' for UI_LAYOUT_SIZE = Available, Gravity(D), Perferred
+    /// character [2] = 'C'|'G'|'L'|'R'  for UI_LAYOUT_POSITION = Center(D), Gravity, LeftTop, RightBottom
+    /// character [3] = 'A'|'G'|'P'  for UI_LAYOUT_DISTRIBUTION = Available, Gravity, Perferred(D)
+    /// character [4] = 'C'|'L'|'R'  for UI_LAYOUT_DISTRIBUTION_POSITION, Center(D), LeftTop, RightBottom
+    /// A '-' character in any field will not program that entry.
+    /// Any character used that is not an allowed characters or a '-' will result in the default setting to be used.
+    /// Any text in the string above character 5 is ignored.
+    /// If the input string is less than 5 characters it will not program any of the fields.
+    void SetLayoutConfig ( const String &settings );
 
 protected:
 

+ 106 - 0
Source/Atomic/UI/UITabContainer.cpp

@@ -28,6 +28,8 @@
 #include "UI.h"
 #include "UIEvents.h"
 #include "UITabContainer.h"
+#include "UILayout.h"
+#include "UIButton.h"
 
 using namespace tb;
 
@@ -96,4 +98,108 @@ bool UITabContainer::OnEvent(const tb::TBWidgetEvent &ev)
     return UIWidget::OnEvent(ev);
 }
 
+
+/// returns the current page number
+int UITabContainer::GetCurrentPage()
+{
+    if (!widget_)
+        return 0;
+
+    return ((TBTabContainer*)widget_)->GetCurrentPage();
+
+}
+
+/// deletes a tab + page, returns true if successful
+bool UITabContainer::DeletePage( int page )
+{
+    if (!widget_ || page < 0 || page > GetNumPages() - 1)
+        return false;
+
+    UILayout *uil = GetTabLayout();
+    if (uil)
+    {
+        UIWidget* mytab = NULL;
+        int nn=0; 
+        for (UIWidget *child = uil->GetFirstChild(); child; child = child->GetNext())
+            if (nn++ == page)
+                mytab = child;
+        if (mytab)
+        {
+            mytab->UnsubscribeFromAllEvents();
+            uil->RemoveChild( mytab, true );
+        }
+    }
+
+    UIWidget *pages = GetContentRoot(); 
+    if (pages)
+    {
+        UIWidget* mypage = NULL;
+        int nn=0; 
+        for (UIWidget *child = pages->GetFirstChild(); child; child = child->GetNext())
+            if (nn++ == page)
+                mypage = child;
+        if (mypage)
+        {
+            mypage->UnsubscribeFromAllEvents();
+            pages->RemoveChild( mypage, true );
+        }
+    }
+    
+    Invalidate();
+
+    // tab container "feature", can not set it to the page number that was removed.
+    int num = 0;
+    if ( page - 1 > 0 ) num = page - 1;
+    SetCurrentPage(num);
+
+    return true;
+}
+
+/// adds a tab + page from layout file
+void UITabContainer::AddTabPageFile ( const String &tabname, const String &layoutFile )
+{
+    UIButton* button = new UIButton(context_);
+    button->SetText(tabname);
+    button->SetId(tabname);
+    UILayout *uil = GetTabLayout();
+    if (uil && button)
+        uil->AddChild(button);
+    UILayout* layout = new UILayout(context_);
+    layout->SetAxis(UI_AXIS_Y);
+    layout->SetLayoutSize(UI_LAYOUT_SIZE_AVAILABLE); 
+    layout->SetLayoutPosition(UI_LAYOUT_POSITION_GRAVITY); 
+    layout->SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION_AVAILABLE); 
+    layout->Load (layoutFile);
+    UIWidget *pages = GetContentRoot();
+    if (pages && layout)
+        pages->AddChild(layout);
+
+    Invalidate();
+
+}
+
+/// adds a tab + page widget(s)
+void UITabContainer::AddTabPageWidget ( const String &tabname, UIWidget *widget ) 
+{
+    UIButton* button = new UIButton(context_);
+    button->SetText(tabname);
+    button->SetId(tabname);
+    UILayout *uil = GetTabLayout();
+    if (uil && button)
+        uil->AddChild(button);
+    UILayout* layout = new UILayout(context_);
+    layout->SetAxis(UI_AXIS_Y);
+    layout->SetLayoutSize(UI_LAYOUT_SIZE_AVAILABLE);
+    layout->SetLayoutPosition(UI_LAYOUT_POSITION_GRAVITY);
+    layout->SetLayoutDistribution(UI_LAYOUT_DISTRIBUTION_AVAILABLE);
+    layout->AddChild(widget);
+    UIWidget *pages = GetContentRoot();
+    if (pages && layout)
+        pages->AddChild(layout);
+
+    Invalidate();
+
+}
+
+
 }

+ 5 - 0
Source/Atomic/UI/UITabContainer.h

@@ -44,6 +44,11 @@ public:
     UIWidget* GetCurrentPageWidget();
 
     UILayout* GetTabLayout();
+    
+    int GetCurrentPage(); /// returns the current page number
+    bool DeletePage( int page ); /// deletes a tab + page, returns true if successful
+    void AddTabPageFile ( const String &tabname, const String &layoutFile ); /// adds a tab + page from file
+    void AddTabPageWidget ( const String &tabname, UIWidget *widget ); /// adds a tab + page widget(s)
 
 protected:
 

+ 73 - 0
Source/ThirdParty/TurboBadger/tb_layout.cpp

@@ -524,4 +524,77 @@ TBWidget::ScrollInfo TBLayout::GetScrollInfo()
     return info;
 }
 
+// ATOMIC BEGIN
+
+// defines for character positions
+#define LCFG_AXIS 0
+#define LCFG_SZ 1
+#define LCFG_POS 2
+#define LCFG_DST 3
+#define LCFG_DSPOS 4
+
+/// A different way of setting up a layout, using a series of characters to program the main 5 layout fields
+/// character [0] = 'X' or 'Y'  for UI_AXIS = X(D), Y
+/// character [1] = 'A'|'G'|'P' for UI_LAYOUT_SIZE = Available, Gravity(D), Perferred
+/// character [2] = 'C'|'G'|'L'|'R'  for UI_LAYOUT_POSITION = Center(D), Gravity, LeftTop, RightBottom
+/// character [3] = 'A'|'G'|'P'  for UI_LAYOUT_DISTRIBUTION = Available, Gravity, Perferred(D)
+/// character [4] = 'C'|'L'|'R'  for UI_LAYOUT_DISTRIBUTION_POSITION, Center(D), LeftTop, RightBottom
+/// A '-' character in any field will not program that entry.
+/// Any character used that is not an allowed characters or a '-' will result in the default setting to be used.
+/// Any text in the string above character 5 is ignored.
+/// If the input string is less than 5 characters it will not program any of the fields.
+void TBLayout::SetLayoutConfig ( const char *settings )
+{
+    if ( settings && strlen(settings) >= 4 )
+    {
+        switch ( settings[LCFG_AXIS] ) // AXIS
+        {
+            case 'X': SetAxis(AXIS_X); break;
+            case 'Y': SetAxis(AXIS_Y); break;
+            default: if ( settings[LCFG_AXIS] != '-')
+                        SetAxis(AXIS_X);
+                break;
+        }
+        switch ( settings[LCFG_SZ] ) // SIZE
+        {
+            case 'A' : SetLayoutSize(LAYOUT_SIZE_AVAILABLE); break;
+            case 'G' : SetLayoutSize(LAYOUT_SIZE_GRAVITY); break;
+            case 'P' : SetLayoutSize(LAYOUT_SIZE_PREFERRED); break;
+            default: if (settings[LCFG_SZ] != '-')
+                        SetLayoutSize(LAYOUT_SIZE_GRAVITY);
+                break;
+        }
+        switch ( settings[LCFG_POS] ) // POSITION
+        {
+            case 'C' : SetLayoutPosition(LAYOUT_POSITION_CENTER); break;
+            case 'G' : SetLayoutPosition(LAYOUT_POSITION_GRAVITY); break;
+            case 'L' : SetLayoutPosition(LAYOUT_POSITION_LEFT_TOP); break;
+            case 'R' : SetLayoutPosition(LAYOUT_POSITION_RIGHT_BOTTOM); break;
+            default: if (settings[LCFG_POS] != '-' )
+                        SetLayoutPosition(LAYOUT_POSITION_CENTER);
+                 break;
+        }
+        switch ( settings[LCFG_DST] ) // DISTRIBUTION
+        {
+            case 'A' : SetLayoutDistribution(LAYOUT_DISTRIBUTION_AVAILABLE); break;
+            case 'G' : SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY); break;
+            case 'P' : SetLayoutDistribution(LAYOUT_DISTRIBUTION_PREFERRED); break;
+            default: if (settings[LCFG_DST] != '-')
+                        SetLayoutDistribution(LAYOUT_DISTRIBUTION_PREFERRED ); 
+                break;
+        }
+        switch ( settings[LCFG_DSPOS] ) // DISTRIBUTION_POSITION
+        {
+            case 'C' : SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_CENTER); break;
+            case 'L' : SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP); break;
+            case 'R' : SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM); break;
+            default: if (settings[LCFG_DSPOS] != '-' )
+                        SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_CENTER);
+                break;
+        }
+    }
+}
+
+// ATOMIC END
+
 }; // namespace tb

+ 15 - 0
Source/ThirdParty/TurboBadger/tb_layout.h

@@ -133,6 +133,21 @@ public:
     virtual void GetChildTranslation(int &x, int &y) const;
     virtual void ScrollTo(int x, int y);
     virtual TBWidget::ScrollInfo GetScrollInfo();
+    
+    // ATOMIC BEGIN
+    /// A different way of setting up a layout, using a series of characters to program the main 5 layout fields
+    /// character [0] = 'X' or 'Y'  for UI_AXIS = X(D), Y
+    /// character [1] = 'A'|'G'|'P' for UI_LAYOUT_SIZE = Available, Gravity(D), Perferred
+    /// character [2] = 'C'|'G'|'L'|'R'  for UI_LAYOUT_POSITION = Center(D), Gravity, LeftTop, RightBottom
+    /// character [3] = 'A'|'G'|'P'  for UI_LAYOUT_DISTRIBUTION = Available, Gravity, Perferred(D)
+    /// character [4] = 'C'|'L'|'R'  for UI_LAYOUT_DISTRIBUTION_POSITION, Center(D), LeftTop, RightBottom
+    /// A '-' character in any field will not program that entry.
+    /// Any character used that is not an allowed characters or a '-' will result in the default setting to be used.
+    /// Any text in the string above character 5 is ignored.
+    /// If the input string is less than 5 characters it will not program any of the fields.
+    void SetLayoutConfig ( const char *settings );
+    // ATOMIC END
+    
 protected:
     AXIS m_axis;
     int m_spacing;

+ 6 - 0
Source/ThirdParty/TurboBadger/tb_widgets_reader.cpp

@@ -263,6 +263,12 @@ void TBLayout::OnInflate(const INFLATE_INFO &info)
             ld = LAYOUT_DISTRIBUTION_POSITION_RIGHT_BOTTOM;
         SetLayoutDistributionPosition(ld);
     }
+
+// ATOMIC BEGIN
+    if (const char *layoutConfig = info.node->GetValueString("config", nullptr))
+        SetLayoutConfig(layoutConfig);
+// ATOMIC END
+
     TBWidget::OnInflate(info);
 }