diff --git a/Import/GacUI.cpp b/Import/GacUI.cpp index fdf69843..55b9bcf5 100644 --- a/Import/GacUI.cpp +++ b/Import/GacUI.cpp @@ -33496,116 +33496,85 @@ GuiStackComposition void GuiStackComposition::UpdateStackItemBounds() { - if(stackItemBounds.Count()!=stackItems.Count()) + if (stackItemBounds.Count() != stackItems.Count()) { stackItemBounds.Resize(stackItems.Count()); } - stackItemTotalSize=Size(0, 0); - vint x=extraMargin.left?extraMargin.left:0; - vint y=extraMargin.top?extraMargin.top:0; - switch(direction) + stackItemTotalSize = Size(0, 0); + Point offset; + for (vint i = 0; i < stackItems.Count(); i++) { - case GuiStackComposition::Horizontal: - { - for(vint i=0;iGetMinSize(); - if(i>0) stackItemTotalSize.x+=padding; - if(stackItemTotalSize.yGetMinSize(); - if(i>0) stackItemTotalSize.y+=padding; - if(stackItemTotalSize.xGetMinSize(); + stackItemBounds[i] = Rect(offset, itemSize); - FixStackItemSizes(); +#define ACCUMULATE(U, V) \ + { \ + if (stackItemTotalSize.V < itemSize.V) \ + { \ + stackItemTotalSize.V = itemSize.V; \ + } \ + if (i > 0) \ + { \ + stackItemTotalSize.U += padding; \ + } \ + stackItemTotalSize.U += itemSize.U; \ + } \ + + switch (direction) + { + case GuiStackComposition::Horizontal: + case GuiStackComposition::ReversedHorizontal: + ACCUMULATE(x, y) + break; + case GuiStackComposition::Vertical: + case GuiStackComposition::ReversedVertical: + ACCUMULATE(y, x) + break; + } + +#undef ACCUMULATE + offset.x += itemSize.x + padding; + offset.y += itemSize.y + padding; + } + EnsureStackItemVisible(); } - void GuiStackComposition::FixStackItemSizes() + void GuiStackComposition::EnsureStackItemVisible() { - switch(direction) +#define ADJUSTMENT(U, V) \ + if (itemBounds.U() <= 0) \ + { \ + adjustment -= itemBounds.U(); \ + } \ + else \ + { \ + vint overflow = itemBounds.V() - previousBounds.V(); \ + if (overflow > 0) \ + { \ + adjustment -= overflow; \ + } \ + } \ + + if (ensuringVisibleStackItem) { - case Horizontal: - { - vint y=0; - if(extraMargin.top>0) y+=extraMargin.top; - if(extraMargin.bottom>0) y+=extraMargin.bottom; - - for(vint i=0;i0) x+=extraMargin.left; - if(extraMargin.right>0) x+=extraMargin.right; - - for(vint i=0;iGetBounds(); + switch (direction) { case Horizontal: - { - if(itemBounds.Left()<=0) - { - offset.x=-itemBounds.Left(); - } - else if(itemBounds.Right()>=size.x) - { - offset.x=size.x-itemBounds.Right(); - } - } + case ReversedHorizontal: + ADJUSTMENT(Left, Right) break; case Vertical: - { - if(itemBounds.Top()<=0) - { - offset.y=-itemBounds.Top(); - } - else if(itemBounds.Bottom()>=size.y) - { - offset.y=size.y-itemBounds.Bottom(); - } - } + case ReversedVertical: + ADJUSTMENT(Top, Bottom) break; } - for(vint i=0;i(child); - if(item && !stackItems.Contains(item)) + GuiStackItemComposition* item = dynamic_cast(child); + if (item && !stackItems.Contains(item)) { stackItems.Add(item); + UpdateStackItemBounds(); } } @@ -33630,18 +33600,15 @@ GuiStackComposition if(item) { stackItems.Remove(item); - if(item==ensuringVisibleStackItem) + if (item == ensuringVisibleStackItem) { - ensuringVisibleStackItem=0; - UpdateStackItemBounds(); + ensuringVisibleStackItem = 0; } + UpdateStackItemBounds(); } } GuiStackComposition::GuiStackComposition() - :direction(Horizontal) - ,padding(0) - ,ensuringVisibleStackItem(0) { BoundsChanged.AttachMethod(this, &GuiStackComposition::OnBoundsChanged); } @@ -33676,7 +33643,8 @@ GuiStackComposition void GuiStackComposition::SetDirection(Direction value) { - direction=value; + direction = value; + EnsureStackItemVisible(); } vint GuiStackComposition::GetPadding() @@ -33686,38 +33654,45 @@ GuiStackComposition void GuiStackComposition::SetPadding(vint value) { - padding=value; + padding = value; } Size GuiStackComposition::GetMinPreferredClientSize() { - Size minSize=GuiBoundsComposition::GetMinPreferredClientSize(); + Size minSize = GuiBoundsComposition::GetMinPreferredClientSize(); UpdateStackItemBounds(); - if(GetMinSizeLimitation()==GuiGraphicsComposition::LimitToElementAndChildren) + if (GetMinSizeLimitation() == GuiGraphicsComposition::LimitToElementAndChildren) { - if (!ensuringVisibleStackItem || direction == Vertical) + if (!ensuringVisibleStackItem || direction == Vertical || direction == ReversedVertical) { - if(minSize.x0) x+=extraMargin.left; - if(extraMargin.right>0) x+=extraMargin.right; - if(extraMargin.top>0) y+=extraMargin.top; - if(extraMargin.bottom>0) y+=extraMargin.bottom; - return minSize+Size(x, y); + + vint x = 0; + vint y = 0; + if (extraMargin.left > 0) x += extraMargin.left; + if (extraMargin.right > 0) x += extraMargin.right; + if (extraMargin.top > 0) y += extraMargin.top; + if (extraMargin.bottom > 0) y += extraMargin.bottom; + return minSize + Size(x, y); } Rect GuiStackComposition::GetBounds() { - Rect bounds=GuiBoundsComposition::GetBounds(); - previousBounds=bounds; - FixStackItemSizes(); + Rect bounds = GuiBoundsComposition::GetBounds(); + previousBounds = bounds; + EnsureStackItemVisible(); return bounds; } @@ -33733,36 +33708,36 @@ GuiStackComposition bool GuiStackComposition::IsStackItemClipped() { - Rect clientArea=GetClientArea(); - for(vint i=0;iGetBounds(); - switch(direction) + case Horizontal: + case ReversedHorizontal: { - case Horizontal: - { - if(stackItemBounds.Left()<0 || stackItemBounds.Right()>=clientArea.Width()) - { - return true; - } - } - break; - case Vertical: - { - if(stackItemBounds.Top()<0 || stackItemBounds.Bottom()>=clientArea.Height()) - { - return true; - } - } - break; + vint width = stackItemTotalSize.x + + (extraMargin.left > 0 ? extraMargin.left : 0) + + (extraMargin.right > 0 ? extraMargin.right : 0) + ; + return width > clientArea.Width(); } + break; + case Vertical: + case ReversedVertical: + { + vint height = stackItemTotalSize.y + + (extraMargin.top > 0 ? extraMargin.top : 0) + + (extraMargin.bottom > 0 ? extraMargin.bottom : 0) + ; + return height > clientArea.Height(); + } + break; } return false; } bool GuiStackComposition::EnsureVisible(vint index) { - if(0<=index && index(newParent); + stackParent = newParent == 0 ? 0 : dynamic_cast(newParent); } Size GuiStackItemComposition::GetMinSize() @@ -33806,30 +33781,65 @@ GuiStackItemComposition Rect GuiStackItemComposition::GetBounds() { - Rect result=bounds; + Rect result = bounds; if(stackParent) { - vint index=stackParent->stackItems.IndexOf(this); - if(index!=-1) + vint index = stackParent->stackItems.IndexOf(this); + if (index != -1) { - if(stackParent->stackItemBounds.Count()!=stackParent->stackItems.Count()) - { - stackParent->UpdateStackItemBounds(); - } - result=stackParent->stackItemBounds[index]; + result = stackParent->stackItemBounds[index]; } + + Rect parentBounds = stackParent->previousBounds; + Margin margin = stackParent->extraMargin; + if (margin.left <= 0) margin.left = 0; + if (margin.top <= 0) margin.top = 0; + if (margin.right <= 0) margin.right = 0; + if (margin.bottom <= 0) margin.bottom = 0; + + auto x = result.Left(); + auto y = result.Top(); + auto w = result.Width(); + auto h = result.Height(); + + switch (stackParent->direction) + { + case GuiStackComposition::Horizontal: + x += margin.left + stackParent->adjustment; + y = margin.top; + h = parentBounds.Height() - margin.top - margin.bottom; + break; + case GuiStackComposition::ReversedHorizontal: + x = parentBounds.Width() - margin.right - x - w + stackParent->adjustment; + y = margin.top; + h = parentBounds.Height() - margin.top - margin.bottom; + break; + case GuiStackComposition::Vertical: + x = margin.left; + y += margin.top + stackParent->adjustment; + w = parentBounds.Width() - margin.left - margin.right; + break; + case GuiStackComposition::ReversedVertical: + x = margin.left; + y = parentBounds.Height() - margin.bottom - y - h + stackParent->adjustment; + w = parentBounds.Width() - margin.left - margin.right; + break; + } + + result = Rect( + x - extraMargin.left, + y - extraMargin.top, + x + w + extraMargin.right, + y + h + extraMargin.bottom + ); } - result.x1-=extraMargin.left; - result.y1-=extraMargin.top; - result.x2+=extraMargin.right; - result.y2+=extraMargin.bottom; UpdatePreviousBounds(result); return result; } void GuiStackItemComposition::SetBounds(Rect value) { - bounds=value; + bounds = value; } Margin GuiStackItemComposition::GetExtraMargin() @@ -33839,7 +33849,7 @@ GuiStackItemComposition void GuiStackItemComposition::SetExtraMargin(Margin value) { - extraMargin=value; + extraMargin = value; } } } diff --git a/Import/GacUI.h b/Import/GacUI.h index 9119e333..007be29f 100644 --- a/Import/GacUI.h +++ b/Import/GacUI.h @@ -6693,23 +6693,30 @@ Stack Compositions /// Stack item layout direction. enum Direction { - /// Stack items is layouted horizontally. + /// Stack items is layouted from left to right. Horizontal, - /// Stack items is layouted vertically. + /// Stack items is layouted from top to bottom. Vertical, + /// Stack items is layouted from right to left. + ReversedHorizontal, + /// Stack items is layouted from bottom to top. + ReversedVertical, }; protected: - Direction direction; + Direction direction = Horizontal; ItemCompositionList stackItems; + GuiStackItemComposition* ensuringVisibleStackItem = nullptr; + + vint padding = 0; + vint adjustment = 0; + Margin extraMargin; + collections::Array stackItemBounds; Size stackItemTotalSize; - vint padding; Rect previousBounds; - Margin extraMargin; - GuiStackItemComposition* ensuringVisibleStackItem; void UpdateStackItemBounds(); - void FixStackItemSizes(); + void EnsureStackItemVisible(); void OnBoundsChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments); void OnChildInserted(GuiGraphicsComposition* child)override; void OnChildRemoved(GuiGraphicsComposition* child)override; diff --git a/Import/GacUIReflection.cpp b/Import/GacUIReflection.cpp index ac746e24..89ec0c6f 100644 --- a/Import/GacUIReflection.cpp +++ b/Import/GacUIReflection.cpp @@ -6065,7 +6065,7 @@ Module { auto fragment = MakePtr(); item->fragments.Add(fragment); - fragment->name.value = WString(wildcard, vint(end - wildcard - 1)); + fragment->name.value = WString(wildcard + 1, vint(end - wildcard - 1)); } } else if (begin < end) @@ -6963,6 +6963,8 @@ Workflow_GetSharedManager context->instance->Accept(&visitor); rootTypeDescriptor = visitor.rootTypeDescriptor; } + + if (errors.Count() == 0) { WorkflowCompileVisitor visitor(context, typeInfos, errors); context->instance->Accept(&visitor); @@ -10278,6 +10280,8 @@ Type Declaration ENUM_ITEM_NAMESPACE(GuiStackComposition) ENUM_NAMESPACE_ITEM(Horizontal) ENUM_NAMESPACE_ITEM(Vertical) + ENUM_NAMESPACE_ITEM(ReversedHorizontal) + ENUM_NAMESPACE_ITEM(ReversedVertical) END_ENUM_ITEM(GuiStackComposition::Direction) BEGIN_CLASS_MEMBER(GuiStackItemComposition) diff --git a/Tools/GacGen.exe b/Tools/GacGen.exe index 315c27c5..3588e51d 100644 Binary files a/Tools/GacGen.exe and b/Tools/GacGen.exe differ diff --git a/Tools/ParserGen.exe b/Tools/ParserGen.exe index bd972010..f2282d54 100644 Binary files a/Tools/ParserGen.exe and b/Tools/ParserGen.exe differ diff --git a/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin b/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin index 93a871f5..05b5ca35 100644 Binary files a/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin and b/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin differ diff --git a/Tutorial/GacUI_Layout/Alignment/UI/Resource.xml b/Tutorial/GacUI_Layout/Alignment/UI/Resource.xml index 9c47c43d..be2ec17e 100644 --- a/Tutorial/GacUI_Layout/Alignment/UI/Resource.xml +++ b/Tutorial/GacUI_Layout/Alignment/UI/Resource.xml @@ -17,6 +17,16 @@ + + + + diff --git a/Tutorial/GacUI_Layout/Stack/UI/Resource.xml b/Tutorial/GacUI_Layout/Stack/UI/Resource.xml index 87c2537d..2b0b0014 100644 --- a/Tutorial/GacUI_Layout/Stack/UI/Resource.xml +++ b/Tutorial/GacUI_Layout/Stack/UI/Resource.xml @@ -13,10 +13,94 @@ + + + + + + - + + + + + composeType:MinSize + composeType:MinSize + composeType:MinSize + composeType:MinSize + composeType:MinSize + composeType:Percentage percentage:1.0 + + + composeType:Percentage percentage:1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Tutorial/GacUI_Layout/Stack/UI/Source/DemoPartialClasses.h b/Tutorial/GacUI_Layout/Stack/UI/Source/DemoPartialClasses.h index 8088a85f..d0a9eab7 100644 --- a/Tutorial/GacUI_Layout/Stack/UI/Source/DemoPartialClasses.h +++ b/Tutorial/GacUI_Layout/Stack/UI/Source/DemoPartialClasses.h @@ -23,11 +23,15 @@ namespace demo friend struct vl::reflection::description::CustomTypeDescriptorSelector; private: protected: + vl::presentation::controls::GuiSelectableButton::MutexGroupController* groupStackDirection; + vl::presentation::compositions::GuiStackComposition* stackLayout; void InitializeComponents() { if (InitializeFromResource()) { + GUI_INSTANCE_REFERENCE(groupStackDirection); + GUI_INSTANCE_REFERENCE(stackLayout); } else { @@ -37,6 +41,8 @@ namespace demo MainWindow_() :vl::presentation::GuiInstancePartialClass(L"demo::MainWindow") ,vl::presentation::controls::GuiWindow(vl::presentation::theme::GetCurrentTheme()->CreateWindowStyle()) + ,groupStackDirection(0) + ,stackLayout(0) { } }; diff --git a/Tutorial/GacUI_Layout/Table/UI/Resource.xml b/Tutorial/GacUI_Layout/Table/UI/Resource.xml index 06536bbc..49ae52fe 100644 --- a/Tutorial/GacUI_Layout/Table/UI/Resource.xml +++ b/Tutorial/GacUI_Layout/Table/UI/Resource.xml @@ -17,6 +17,83 @@ + + + composeType:MinSize + composeType:Absolute absolute:20 + composeType:MinSize + composeType:MinSize + composeType:Percentage percentage:1.0 + composeType:MinSize + + + composeType:MinSize + composeType:Percentage percentage:1.0 + composeType:MinSize + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + composeType:MinSize + + + composeType:MinSize + composeType:MinSize + composeType:Percentage percentage:1.0 + composeType:MinSize + + + + + + + + + + + +
+ +
diff --git a/Tutorial/GacUI_Layout/UIRes/Alignment.bin b/Tutorial/GacUI_Layout/UIRes/Alignment.bin index 8ad771b2..c8949a4c 100644 Binary files a/Tutorial/GacUI_Layout/UIRes/Alignment.bin and b/Tutorial/GacUI_Layout/UIRes/Alignment.bin differ diff --git a/Tutorial/GacUI_Layout/UIRes/Stack.bin b/Tutorial/GacUI_Layout/UIRes/Stack.bin index 58ac5d80..6d7d20f6 100644 Binary files a/Tutorial/GacUI_Layout/UIRes/Stack.bin and b/Tutorial/GacUI_Layout/UIRes/Stack.bin differ diff --git a/Tutorial/GacUI_Layout/UIRes/Table.bin b/Tutorial/GacUI_Layout/UIRes/Table.bin index f0f877b0..b5fc8a35 100644 Binary files a/Tutorial/GacUI_Layout/UIRes/Table.bin and b/Tutorial/GacUI_Layout/UIRes/Table.bin differ