Sat, 09 Oct 2021 09:27:52 +0300
* Textwrap support for Label, Button and Checkbox
#331: Textwrap control support, replaced TopPanel
--- a/Source/Gorgon/UI/ComponentStack.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/UI/ComponentStack.h Sat Oct 09 09:27:52 2021 +0300 @@ -465,6 +465,7 @@ /// Disables text wrapping on a specific tag, default is enabled. void DisableTagWrap(ComponentTemplate::Tag tag) { tagnowrap.insert(tag); + Update(); } /// Sets whether the ComponentStack should be autosized. Autosize
--- a/Source/Gorgon/UI/ComponentStackWidget.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/UI/ComponentStackWidget.h Sat Oct 09 09:27:52 2021 +0300 @@ -161,7 +161,7 @@ stack.Refresh(); boundschanged(); } - + /// Adjusts autosizing of the widget. In autosize mode, set width is used to limit /// text width so that it will flow to next line. void SetHorizonalAutosize(UI::Autosize value) { @@ -169,7 +169,7 @@ stack.Refresh(); boundschanged(); } - + /// Adjusts autosizing of the widget. In autosize mode, set width is used to limit /// text width so that it will flow to next line. void SetVerticalAutosize(UI::Autosize value) { @@ -177,7 +177,25 @@ stack.Refresh(); boundschanged(); } - + + /// Adjusts autosizing of the widget. Setting autosize to true sets the autosize to + /// automatic to nearest unit size + void SetAutosize(bool hor, bool ver) { + SetAutosize(hor ? Autosize::Unit : Autosize::None, ver ? Autosize::Unit : Autosize::None); + } + + /// Adjusts autosizing of the widget. Setting autosize to true sets the autosize to + /// automatic to nearest unit size + void SetHorizonalAutosize(bool value) { + SetHorizonalAutosize(value ? Autosize::Unit : Autosize::None); + } + + /// Adjusts autosizing of the widget. Setting autosize to true sets the autosize to + /// automatic to nearest unit size + void SetVerticalAutosize(bool value) { + SetVerticalAutosize(value ? Autosize::Unit : Autosize::None); + } + /// Returns the horizontal autosize mode of the widget UI::Autosize GetHorizontalAutosize() const { return stack.GetAutosize().first; @@ -213,4 +231,23 @@ using ComponentStackWidget::GetHorizontalAutosize; \ using ComponentStackWidget::GetVerticalAutosize +#define GORGON_UI_CSW_WRAP_WIDGET(cls, tag, def) \ + /** Text wrap controls if the text will be wrapped if it is too long. It also controls autosize behaviour. Default value is true. */ \ + void SetTextWrap(const bool &value) { \ + if(textwrap == value) \ + return; \ + textwrap = value; \ + if(textwrap) stack.EnableTagWrap(UI::ComponentTemplate::tag); \ + else stack.DisableTagWrap(UI::ComponentTemplate::tag);\ + } \ + /** Text wrap controls if the text will be wrapped if it is too long. It also controls autosize behaviour. */ \ + bool GetTextWrap() const { \ + return textwrap; \ + } \ + private: \ + bool textwrap = def;\ + public:\ + PROPERTY_GETSET(cls, Boolean, bool, TextWrap); + + } }
--- a/Source/Gorgon/UI/Template.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/UI/Template.h Sat Oct 09 09:27:52 2021 +0300 @@ -953,6 +953,7 @@ ExpandTag, ToggleTag, ContentsTag, + TextTag, ViewPortTag, SelectionTag, CaretTag,
--- a/Source/Gorgon/Widgets/Button.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/Button.h Sat Oct 09 09:27:52 2021 +0300 @@ -122,6 +122,7 @@ /// Deactivates click repeat. void DeactivateClickRepeat(); + GORGON_UI_CSW_WRAP_WIDGET(Button, TextTag, true); GORGON_UI_CSW_AUTOSIZABLE_WIDGET; virtual bool Activate() override;
--- a/Source/Gorgon/Widgets/Checkbox.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/Checkbox.h Sat Oct 09 09:27:52 2021 +0300 @@ -165,6 +165,7 @@ virtual bool Activate() override; + GORGON_UI_CSW_WRAP_WIDGET(Checkbox, TextTag, true); GORGON_UI_CSW_AUTOSIZABLE_WIDGET; bool KeyPressed(Input::Key key, float state) override;
--- a/Source/Gorgon/Widgets/Generator.cpp Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/Generator.cpp Sat Oct 09 09:27:52 2021 +0300 @@ -1073,6 +1073,7 @@ txt.SetAnchor(UI::Anchor::MiddleRight, UI::Anchor::MiddleLeft, UI::Anchor::MiddleLeft); txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::TextTag); }; setuptext(FgC(Regular), UI::ComponentCondition::Always); @@ -1162,6 +1163,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::TextTag); }; setuptext(FgC(Regular), UI::ComponentCondition::Always); @@ -1259,6 +1261,7 @@ txt.SetAnchor(UI::Anchor::MiddleRight, UI::Anchor::MiddleLeft, UI::Anchor::MiddleLeft); txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::TextTag); }; setuptext(FgC(Regular), UI::ComponentCondition::Always); @@ -1320,6 +1323,7 @@ tt.SetDataEffect(UI::ComponentTemplate::Text); tt.SetSize(100, 100, UI::Dimension::Percent); tt.SetSizing(UI::ComponentTemplate::ShrinkOnly, UI::ComponentTemplate::ShrinkOnly); + tt.SetTag(UI::ComponentTemplate::TextTag); }; makestate(Graphics::Color::Regular, UI::ComponentCondition::Always); @@ -1418,6 +1422,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::TextTag); }; setuptext(FgC(Regular), UI::ComponentCondition::Always); @@ -1480,6 +1485,7 @@ tt.SetDataEffect(UI::ComponentTemplate::Text); tt.SetSize(100, 100, UI::Dimension::Percent); tt.SetSizing(UI::ComponentTemplate::ShrinkOnly, UI::ComponentTemplate::ShrinkOnly); + tt.SetTag(UI::ComponentTemplate::TextTag); }; makestate(Graphics::Color::Regular, UI::ComponentCondition::Always); @@ -1492,6 +1498,7 @@ return temp; } + //TODO: join labels into two or three functions UI::Template SimpleGenerator::Label() { Geometry::Size defsize = {GetUnitSize(6), borderlessheight}; @@ -1521,6 +1528,7 @@ txt.SetAnchor(UI::Anchor::MiddleRight, UI::Anchor::MiddleLeft, UI::Anchor::MiddleLeft); txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); + txt.SetTag(UI::ComponentTemplate::ContentsTag); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); return temp; @@ -1556,6 +1564,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); //TODO: background? @@ -1592,6 +1601,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); return temp; } @@ -1627,6 +1637,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); auto &ln = temp.AddGraphics(3, UI::ComponentCondition::Always); ln.Content.SetAnimation(Graphics::BlankImage::Get()); @@ -1669,6 +1680,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); auto &ln = temp.AddGraphics(3, UI::ComponentCondition::Always); ln.Content.SetAnimation(Graphics::BlankImage::Get()); @@ -1712,6 +1724,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); auto &ln = temp.AddGraphics(3, UI::ComponentCondition::Always); ln.Content.SetAnimation(Graphics::BlankImage::Get()); @@ -1767,6 +1780,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); return temp; @@ -1801,6 +1815,7 @@ txt.SetDataEffect(UI::ComponentTemplate::Text); txt.SetSize(100, 100, UI::Dimension::Percent); txt.SetSizing(UI::ComponentTemplate::ShrinkOnly); + txt.SetTag(UI::ComponentTemplate::ContentsTag); auto &icon = temp.AddGraphics(1, UI::ComponentCondition::Icon1IsSet); icon.SetDataEffect(UI::ComponentTemplate::Icon); @@ -2725,7 +2740,7 @@ UI::Template SimpleGenerator::TabPanel() { Geometry::Size defsize = { - GetUnitSize(6) + Border.Width * 2 + spacing * 2, + GetUnitSize(6) + Border.Width * 2 + spacing * 3 + (*this)[Scrollbar_Vertical].GetSize().Width, GetUnitSize(10) + Border.Width * 2 + spacing * 2 }; @@ -2764,7 +2779,8 @@ auto &container = temp.AddPlaceholder(2, UI::ComponentCondition::Always); container.SetTag(UI::ComponentTemplate::PanelTag); - container.SetTemplate((*this)[Panel_Top]); // TODO: replace + auto &pnltmp = *new UI::Template(makepanel(AssetID::AllExceptTop, true)); + container.OwnTemplate(pnltmp);// TODO: replace? container.SetSize(100, 100, UI::Dimension::Percent); container.SetSizing(UI::ComponentTemplate::Fixed); container.SetAnchor(UI::Anchor::BottomLeft, UI::Anchor::TopLeft, UI::Anchor::TopLeft);
--- a/Source/Gorgon/Widgets/Label.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/Label.h Sat Oct 09 09:27:52 2021 +0300 @@ -98,7 +98,8 @@ void OwnIcon(Graphics::Bitmap &&value); virtual bool Activate() override; - + + GORGON_UI_CSW_WRAP_WIDGET(Label, ContentsTag, true); GORGON_UI_CSW_AUTOSIZABLE_WIDGET; TextualProperty<Label, std::string, &Label::gettext, &Label::settext> Text;
--- a/Source/Gorgon/Widgets/Panel.cpp Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/Panel.cpp Sat Oct 09 09:27:52 2021 +0300 @@ -47,7 +47,7 @@ SetSmoothScrollSpeed(scrollspeed); - scrolldist = {temp.GetWidth()/4, temp.GetHeight()/4}; + scrolldist = {temp.GetUnitWidth()*4, temp.GetUnitWidth()*2}; } bool Panel::Activate() {
--- a/Source/Gorgon/Widgets/TabPanel.h Sun Oct 03 15:49:47 2021 +0300 +++ b/Source/Gorgon/Widgets/TabPanel.h Sat Oct 09 09:27:52 2021 +0300 @@ -267,7 +267,13 @@ /// Sets if the button text would be wrapped. If true, current tab size /// will be used to determine wrap width. Default value is false. - void SetButtonTextWrap(bool value); + void SetButtonTextWrap(bool value) { + if(value == buttontextwrap) + return; + + buttontextwrap = value; + Refresh(); + } /// Returns if the button text would wrapped. bool GetButtonTextWrap() const { @@ -312,7 +318,9 @@ for(int i=0; i<tabs.GetCount(); i++) { buttons[i].SetText(tabs[i].GetTitle()); buttons[i].Location.X = x; + buttons[i].SetTextWrap(buttontextwrap); x = buttons[i].GetBounds().Right; + tabs[i].Resize(stack.BoundsOf(stack.IndexOfTag(UI::ComponentTemplate::PanelTag)).GetSize()); } if(buttonspnl) {
--- a/Testing/Source/Manual/UI_WidgetTest.cpp Sun Oct 03 15:49:47 2021 +0300 +++ b/Testing/Source/Manual/UI_WidgetTest.cpp Sat Oct 09 09:27:52 2021 +0300 @@ -6,6 +6,7 @@ #include <Gorgon/Widgets/Window.h> #include <Gorgon/Widgets/TabPanel.h> #include <Gorgon/Widgets/Button.h> +#include <Gorgon/Widgets/Label.h> std::string helptext = "Key list:\n" @@ -21,17 +22,25 @@ Widgets::TabPanel wgt1; - org - << wgt1 ; + org + << wgt1; - wgt1.New("Tab 1"); + wgt1.New("Tab 1", "Tab 1 long text"); wgt1.New("Tab 2"); Widgets::Button btn1("Hey tab 1"); + Widgets::Label lbl1("Hey tab 2"); + Widgets::Label lbl2("Tab control is now working, scroll down for the button"); + lbl2.SetAutosize(true, true); Widgets::Button btn2("Hey tab 2"); wgt1["Tab 1"].Add(btn1); + wgt1["Tab 2"].Add(lbl1); + wgt1["Tab 2"].Add(lbl2); wgt1["Tab 2"].Add(btn2); + lbl2.Location.Y = lbl1.GetBounds().Bottom + Widgets::Registry::Active().GetSpacing(); + btn2.Location.Y = 400; + btn2.Location.X = Widgets::Registry::Active().GetUnitSize(3) + Widgets::Registry::Active().GetSpacing();