Sat, 30 Oct 2021 08:17:43 +0300
#337 Flow organizer now works with units
* A few flow organizer issues are fixed
--- a/Source/Gorgon/UI/Dimension.h Fri Oct 29 16:10:51 2021 +0300 +++ b/Source/Gorgon/UI/Dimension.h Sat Oct 30 08:17:43 2021 +0300 @@ -180,11 +180,11 @@ this->unit = unit; } - constexpr bool operator ==(const Dimension &other) const { + bool operator ==(const Dimension &other) const { return other.unit == unit && other.value == value; } - constexpr bool operator !=(const Dimension &other) const { + bool operator !=(const Dimension &other) const { return !(*this == other); } @@ -207,6 +207,14 @@ } constexpr UnitDimension(const Dimension &d) : Dimension(d) { } + + bool operator ==(const UnitDimension &other) const { + return (const Unit&)(*this) == (const Unit&)(other); + } + + bool operator !=(const UnitDimension &other) const { + return !(*this == other); + } }; /// This class stores the location information for a box object @@ -394,6 +402,16 @@ inline Dimension operator""_u(long double val) { return Units(double(val)); } + + inline Dimension operator""_em(unsigned long long val) { + return {int(val)*100, Dimension::EM}; + } + + inline Dimension operator""_em(long double val) { + return {double(val), Dimension::EM}; + } + + } } }
--- a/Source/Gorgon/UI/Organizers/Flow.cpp Fri Oct 29 16:10:51 2021 +0300 +++ b/Source/Gorgon/UI/Organizers/Flow.cpp Sat Oct 30 08:17:43 2021 +0300 @@ -12,7 +12,10 @@ auto &att = GetAttached(); int x = 0; int width = att.GetInteriorSize().Width; + int height = att.GetInteriorSize().Height; + int usize = att.GetUnitSize(); int s = GetSpacing(); + int em = Widgets::Registry::Active().GetEmSize(); if(tight) { Utils::NotImplemented("Tight organization is not implemented yet."); @@ -25,6 +28,7 @@ int ind = 0; int indent = 0; int breaks = 0; + int breakspace = 0; int xoff; auto align = defaultalign; auto nextalign = defaultalign; @@ -39,7 +43,7 @@ y += maxy + s; if(breaks > 0) - y += (breaks-1) * (uw + s); + y += (breaks-1) * (uw + s) + breakspace; int w = 0; if(row.GetCount()) @@ -65,6 +69,7 @@ rowc = 0; maxy = 0; row.Clear(); + breakspace = 0; }; for(auto &widget : att) { @@ -76,24 +81,19 @@ switch(it->second.type) { case Flow::Modifier::Break: breaks++; + breakspace += it->second.size(width, usize, s, em); break; case Flow::Modifier::Align: nextalign = it->second.align; break; case Flow::Modifier::HSpace: - xoff = it->second.size * att.GetUnitSize() + GetSpacing(); + xoff = it->second.size(width, usize, s, em); break; case Flow::Modifier::VSpace: - y += it->second.size * GetSpacing(); + y += it->second.size(height, usize, s, em); break; case Flow::Modifier::Indent: - indent += it->second.size; - break; - case Flow::Modifier::IndentUnits: - indent += it->second.size * att.GetUnitSize() + GetSpacing(); - break; - case Flow::Modifier::IndentSpaces: - indent += it->second.size * GetSpacing(); + indent += it->second.size(width, usize, s, em); break; } } @@ -105,8 +105,10 @@ int w = widget.GetCurrentWidth(); - if((x + w > width && rowc > 0) && breaks == 0) + if(x + w + xoff > width && rowc > 0 && breaks == 0) { breaks = 1; + xoff = 0; + } if(breaks) { dorow(); @@ -181,9 +183,9 @@ } Flow &Flow::Add(Widget &widget) { - if(nextsize != -1) { - widget.SetWidth(Units(nextsize)); - nextsize = -1; + if(nextsize != Units(-1)) { + widget.SetWidth(nextsize); + nextsize = Units(-1); } Base::Add(widget); @@ -220,12 +222,8 @@ } void Flow::flow(BreakTag) { - InsertBreak(); - - if(nextsize != -1) { - flow(Modifier(Flow::Modifier::VSpace, nextsize)); - nextsize = -1; - } + flow(Modifier(Flow::Modifier::Break, nextsize != -1 ? nextsize : 0)); + nextsize = -1; } void Flow::flow(const std::string& title) {
--- a/Source/Gorgon/UI/Organizers/Flow.h Fri Oct 29 16:10:51 2021 +0300 +++ b/Source/Gorgon/UI/Organizers/Flow.h Sat Oct 30 08:17:43 2021 +0300 @@ -2,6 +2,7 @@ #include "Base.h" #include "../../Graphics.h" +#include "../Dimension.h" #include <iosfwd> #include <unordered_set> @@ -54,8 +55,6 @@ HSpace, VSpace, Indent, - IndentUnits, - IndentSpaces, }; Modifier(BreakTag) : type(Break) { @@ -64,13 +63,13 @@ Modifier(Graphics::TextAlignment align) : type(Align), align(align) { } - Modifier(Type type, int size) : type(type), size(size) { } + Modifier(Type type, const UnitDimension &size) : type(type), size(size) { } Type type; union { Graphics::TextAlignment align; - int size; + UnitDimension size; }; }; @@ -120,7 +119,7 @@ } /// Sets the size of the next widget in unit sizes - Flower &operator << (int size) { + Flower &operator << (const UnitDimension &size) { base->flow(size); return *this; @@ -234,28 +233,28 @@ } /// This will create a modifier object that should be inserted into ui stream - Modifier HSpace(int unitsize) { - return {Modifier::HSpace, unitsize}; + Modifier HSpace(const UnitDimension &size) { + return {Modifier::HSpace, size}; } - + /// This will create a modifier object that should be inserted into ui stream - Modifier VSpace(int spaces) { - return {Modifier::VSpace, spaces}; + Modifier VSpace(const UnitDimension &dist) { + return {Modifier::VSpace, dist}; } - + /// This will create a modifier object that should be inserted into ui stream - Modifier IndentPixels(int pixels) { - return {Modifier::Indent, pixels}; + Modifier VSpaceSpaces(int spaces) { + return {Modifier::VSpace, Pixels(spaces*spacing)}; } - + /// This will create a modifier object that should be inserted into ui stream - Modifier IndentUnits(int unitsize) { - return {Modifier::IndentUnits, unitsize}; + Modifier Indent(const UnitDimension &dist) { + return {Modifier::Indent, dist}; } /// This will create a modifier object that should be inserted into ui stream Modifier IndentSpaces(int spaces) { - return {Modifier::IndentSpaces, spaces}; + return {Modifier::Indent, Pixels(spaces*spacing)}; } virtual Flow &Add(const std::string &title) override { @@ -292,7 +291,7 @@ } /// Sets the size of the next widget in unit sizes - Flower operator << (unsigned size) { + Flower operator << (const UnitDimension &size) { return std::move(Flower(this) << size); } @@ -334,7 +333,7 @@ void flow(BreakTag); - void flow(unsigned size) { + void flow(const UnitDimension &size) { nextsize = size; } @@ -347,7 +346,7 @@ bool usedefaultspacing = true; int spacing = 0; bool tight = false; - int nextsize = -1; + UnitDimension nextsize = -1; std::unordered_multimap<int, Modifier> modifiers; Graphics::TextAlignment defaultalign = Graphics::TextAlignment::Left; };
--- a/Source/Gorgon/UI/WidgetContainer.cpp Fri Oct 29 16:10:51 2021 +0300 +++ b/Source/Gorgon/UI/WidgetContainer.cpp Sat Oct 30 08:17:43 2021 +0300 @@ -508,8 +508,17 @@ } void WidgetContainer::distributeparentboundschanged() { + //children might react to bounds changed events, instead of + //reorganizing everytime, only reorganize at the end. + if(organizer) + organizer->PauseReorganize(); + for(auto &w : widgets) w.parentboundschanged(); + + if(organizer) { + organizer->StartReorganize(); + } } void WidgetContainer::childboundschanged(Widget *) {
--- a/Testing/Source/Manual/UI_Generate.cpp Fri Oct 29 16:10:51 2021 +0300 +++ b/Testing/Source/Manual/UI_Generate.cpp Sat Oct 30 08:17:43 2021 +0300 @@ -301,9 +301,9 @@ Widgets::ColorPlane plane; - org << 9 << plane << org.Break + org << 100_perc << plane << org.Break << 2 << "Label" << 2 << "" << Coffee << l2 - << list << 2 << org.Break + << list << 5_perc << org.Break << icnbtn2 << icnbtn3 << dlist << radio << icnbtn << 5 << "Hello" << chk << chk2 << chkbutton