private static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceContainer, ThemeConfig theme, Action selectionChanged) { GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom) { Margin = new BorderDouble(0, 3, 0, 0), }; var parentOfSubtractTargets = sourceContainer.SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf(); var sourceChildren = parentOfSubtractTargets.Children.ToList(); var objectChecks = new Dictionary <ICheckbox, IObject3D>(); var radioSiblings = new List <GuiWidget>(); for (int i = 0; i < sourceChildren.Count; i++) { var itemIndex = i; var child = sourceChildren[itemIndex]; var rowContainer = new FlowLayoutWidget() { Padding = new BorderDouble(15, 0, 0, 3) }; GuiWidget selectWidget; if (sourceChildren.Count == 2) { var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.ID), TextColor = theme.TextColor, Margin = 0, }; radioSiblings.Add(radioButton); radioButton.SiblingRadioButtonList = radioSiblings; selectWidget = radioButton; } else { selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.ID), TextColor = theme.TextColor, }; } objectChecks.Add((ICheckbox)selectWidget, child); rowContainer.AddChild(selectWidget); var checkBox = selectWidget as ICheckbox; checkBox.CheckedStateChanged += (s, e) => { if (s is ICheckbox checkbox) { if (checkBox.Checked) { if (!childSelector.Contains(objectChecks[checkbox].ID)) { childSelector.Add(objectChecks[checkbox].ID); } } else { if (childSelector.Contains(objectChecks[checkbox].ID)) { childSelector.Remove(objectChecks[checkbox].ID); } } selectionChanged?.Invoke(); } }; tabContainer.AddChild(rowContainer); } return(tabContainer); }
private static GuiWidget CreateSelector(SelectedChildren childSelector, IObject3D parent, ThemeConfig theme) { GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); void UpdateSelectColors(bool selectionChanged = false) { foreach (var child in parent.Children.ToList()) { using (child.RebuildLock()) { if (selectionChanged) { child.Visible = true; } } } } tabContainer.Closed += (s, e) => UpdateSelectColors(); var children = parent.Children.ToList(); var objectChecks = new Dictionary <ICheckbox, IObject3D>(); var radioSiblings = new List <GuiWidget>(); for (int i = 0; i < children.Count; i++) { var itemIndex = i; var child = children[itemIndex]; var rowContainer = new FlowLayoutWidget(); GuiWidget selectWidget; if (children.Count == 2) { var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.ID), TextColor = theme.TextColor }; radioSiblings.Add(radioButton); radioButton.SiblingRadioButtonList = radioSiblings; selectWidget = radioButton; } else { selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.ID), TextColor = theme.TextColor }; } objectChecks.Add((ICheckbox)selectWidget, child); rowContainer.AddChild(selectWidget); var checkBox = selectWidget as ICheckbox; checkBox.CheckedStateChanged += (s, e) => { if (s is ICheckbox checkbox) { if (checkBox.Checked) { if (!childSelector.Contains(objectChecks[checkbox].ID)) { childSelector.Add(objectChecks[checkbox].ID); } } else { if (childSelector.Contains(objectChecks[checkbox].ID)) { childSelector.Remove(objectChecks[checkbox].ID); } } if (parent is MeshWrapperObject3D meshWrapper) { using (meshWrapper.RebuildLock()) { meshWrapper.ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None); } } UpdateSelectColors(true); } }; tabContainer.AddChild(rowContainer); UpdateSelectColors(); } return(tabContainer); }
private static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceCantainer, ThemeConfig theme) { GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); var sourceChildren = sourceCantainer.SourceContainer.VisibleMeshes().ToList(); var objectChecks = new Dictionary <ICheckbox, IObject3D>(); var radioSiblings = new List <GuiWidget>(); for (int i = 0; i < sourceChildren.Count; i++) { var itemIndex = i; var child = sourceChildren[itemIndex]; var rowContainer = new FlowLayoutWidget(); GuiWidget selectWidget; if (sourceChildren.Count == 2) { var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.Name), TextColor = theme.TextColor }; radioSiblings.Add(radioButton); radioButton.SiblingRadioButtonList = radioSiblings; selectWidget = radioButton; } else { selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}") { Checked = childSelector.Contains(child.Name), TextColor = theme.TextColor }; } objectChecks.Add((ICheckbox)selectWidget, child); rowContainer.AddChild(selectWidget); var checkBox = selectWidget as ICheckbox; checkBox.CheckedStateChanged += (s, e) => { if (s is ICheckbox checkbox) { if (checkBox.Checked) { if (!childSelector.Contains(objectChecks[checkbox].Name)) { childSelector.Add(objectChecks[checkbox].Name); } } else { if (childSelector.Contains(objectChecks[checkbox].Name)) { childSelector.Remove(objectChecks[checkbox].Name); } } } }; tabContainer.AddChild(rowContainer); } return(tabContainer); }