public GameObject Build() { var comp = GetUIComponent(); OnRealize?.Invoke(comp); return(comp); }
public GameObject Build() { var textField = PUIElements.CreateUI(null, Name); // Background var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; textField.AddComponent <Image>().color = style.textColor; // Text box with rectangular clipping area; put pivot in upper left var textArea = PUIElements.CreateUI(textField, "Text Area", false); textArea.rectTransform().pivot = Vector2.up; textArea.AddComponent <Image>().color = BackColor; var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI(textArea, "Text", true, PUIAnchoring.Beginning, PUIAnchoring.End); // Text to display var textDisplay = textBox.AddComponent <TextMeshProUGUI>(); textDisplay.alignment = TextAlignment; textDisplay.autoSizeTextContainer = false; textDisplay.enabled = true; textDisplay.color = style.textColor; textDisplay.font = style.sdfFont; textDisplay.fontSize = style.fontSize; textDisplay.fontStyle = style.style; // Text field itself textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textField.SetActive(true); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; // Events! ConfigureTextEntry(textEntry); var events = textField.AddComponent <PTextFieldEvents>(); events.OnTextChanged = OnTextChanged; events.OnValidate = OnValidate; // Add tooltip if (!string.IsNullOrEmpty(ToolTip)) { textField.AddComponent <ToolTip>().toolTip = ToolTip; } mask.enabled = true; // Lay out, even better than before var layout = textField.AddComponent <RelativeLayoutGroup>(); layout.SetTopEdge(textArea, fraction: 1.0f).SetBottomEdge(textArea, fraction: 0.0f). SetMargin(textArea, new RectOffset(1, 1, 1, 1)).OverrideSize(textArea, new Vector2(MinWidth, Math.Max(LineCount, 1) * PUIUtils.GetLineHeight(style))). LockLayout(); layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; OnRealize?.Invoke(textField); return(textField); }
public GameObject Build() { var textField = PUIElements.CreateUI(null, Name); // Background var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; textField.AddComponent <Image>().color = style.textColor; // Text box with rectangular clipping area var textArea = PUIElements.CreateUI(textField, "Text Area", false); textArea.AddComponent <Image>().color = BackColor; var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI(textArea, "Text"); // Text to display var textDisplay = textBox.AddComponent <TextMeshProUGUI>(); textDisplay.alignment = TextAlignment; textDisplay.autoSizeTextContainer = false; textDisplay.enabled = true; textDisplay.color = style.textColor; textDisplay.font = style.sdfFont; textDisplay.fontSize = style.fontSize; textDisplay.fontStyle = style.style; textDisplay.maxVisibleLines = 1; // Text field itself textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textField.SetActive(true); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; // Events! ConfigureTextEntry(textEntry); var events = textField.AddComponent <PTextFieldEvents>(); events.OnTextChanged = OnTextChanged; events.OnValidate = OnValidate; // Add tooltip if (!string.IsNullOrEmpty(ToolTip)) { textField.AddComponent <ToolTip>().toolTip = ToolTip; } mask.enabled = true; // Lay out, even better than before var tbTransform = textBox.rectTransform(); LayoutRebuilder.ForceRebuildLayoutImmediate(tbTransform); new RelativeLayout(textField).SetTopEdge(textArea, fraction: 1.0f).SetBottomEdge( textArea, fraction: 0.0f).SetMargin(textArea, new RectOffset(1, 1, 1, 1)). OverrideSize(textArea, new Vector2(MinWidth, LayoutUtility.GetPreferredHeight( tbTransform))).Execute(true); textField.SetFlexUISize(FlexSize); OnRealize?.Invoke(textField); return(textField); }
public GameObject Build() { var toggle = PUIElements.CreateUI(null, Name); // Set on click event var kToggle = toggle.AddComponent <KToggle>(); var evt = OnStateChanged; if (evt != null) { kToggle.onValueChanged += (on) => { evt?.Invoke(toggle, on); } } ; kToggle.artExtension = new KToggleArtExtensions(); kToggle.soundPlayer = PUITuning.ToggleSounds; // Background image var fgImage = toggle.AddComponent <KImage>(); fgImage.color = Color.activeColor; fgImage.sprite = InactiveSprite; toggle.SetActive(false); // Toggled images var toggleImage = toggle.AddComponent <ImageToggleState>(); toggleImage.TargetImage = fgImage; toggleImage.useSprites = true; toggleImage.InactiveSprite = InactiveSprite; toggleImage.ActiveSprite = ActiveSprite; toggleImage.startingState = InitialState ? ImageToggleState.State.Active : ImageToggleState.State.Inactive; toggleImage.useStartingState = true; toggleImage.ActiveColour = Color.activeColor; toggleImage.DisabledActiveColour = Color.disabledActiveColor; toggleImage.InactiveColour = Color.inactiveColor; toggleImage.DisabledColour = Color.disabledColor; toggleImage.HoverColour = Color.hoverColor; toggleImage.DisabledHoverColor = Color.disabledhoverColor; kToggle.isOn = InitialState; toggle.SetActive(true); // Set size if (Size.x > 0.0f && Size.y > 0.0f) { toggle.SetUISize(Size, true); } else { PUIElements.AddSizeFitter(toggle, DynamicSize); } // Add tooltip if (!string.IsNullOrEmpty(ToolTip)) { toggle.AddComponent <ToolTip>().toolTip = ToolTip; } toggle.SetFlexUISize(FlexSize).SetActive(true); OnRealize?.Invoke(toggle); return(toggle); }
public GameObject Build() { var textField = PUIElements.CreateUI(null, Name); // Background var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; textField.AddComponent <Image>().color = style.textColor; // Text box with rectangular clipping area var textArea = PUIElements.CreateUI(textField, "Text Area", false); textArea.AddComponent <Image>().color = BackColor; var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI(textArea, "Text"); // Text to display var textDisplay = textBox.AddComponent <TextMeshProUGUI>(); textDisplay.alignment = TextAlignment; textDisplay.autoSizeTextContainer = false; textDisplay.enabled = true; textDisplay.color = style.textColor; textDisplay.font = style.sdfFont; textDisplay.fontSize = style.fontSize; textDisplay.fontStyle = style.style; textDisplay.maxVisibleLines = 1; // Text field itself textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textField.SetActive(true); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; // Events! ConfigureTextEntry(textEntry); var events = textField.AddComponent <PTextFieldEvents>(); events.OnTextChanged = OnTextChanged; events.OnValidate = OnValidate; // Add tooltip if (!string.IsNullOrEmpty(ToolTip)) { textField.AddComponent <ToolTip>().toolTip = ToolTip; } mask.enabled = true; // Lay out - TMP_InputField does not support auto layout so we have to do a hack var rt = textBox.rectTransform(); float height = LayoutUtility.GetPreferredHeight(rt); textField.SetUISize(new Vector2(MinWidth + 2.0f, height + 2.0f), true). SetFlexUISize(FlexSize); textArea.SetUISize(new Vector2(MinWidth, height)); OnRealize?.Invoke(textField); return(textField); }
public GameObject Build() { if (Child == null) { throw new InvalidOperationException("No child component"); } var pane = BuildScrollPane(null, Child.Build()); OnRealize?.Invoke(pane); return(pane); }
public GameObject Build() { var toggle = PUIElements.CreateUI(null, Name); // Set on click event var kToggle = toggle.AddComponent <KToggle>(); var evt = OnStateChanged; if (evt != null) { kToggle.onValueChanged += (on) => { evt?.Invoke(toggle, on); } } ; UIDetours.ART_EXTENSION.Set(kToggle, new KToggleArtExtensions()); UIDetours.SOUND_PLAYER_TOGGLE.Set(kToggle, PUITuning.ToggleSounds); // Background image var fgImage = toggle.AddComponent <Image>(); fgImage.color = Color.activeColor; fgImage.sprite = InactiveSprite; toggle.SetActive(false); // Toggled images var toggleImage = toggle.AddComponent <ImageToggleState>(); toggleImage.TargetImage = fgImage; toggleImage.useSprites = true; toggleImage.InactiveSprite = InactiveSprite; toggleImage.ActiveSprite = ActiveSprite; toggleImage.startingState = InitialState ? ImageToggleState.State.Active : ImageToggleState.State.Inactive; toggleImage.useStartingState = true; toggleImage.ActiveColour = Color.activeColor; toggleImage.DisabledActiveColour = Color.disabledActiveColor; toggleImage.InactiveColour = Color.inactiveColor; toggleImage.DisabledColour = Color.disabledColor; toggleImage.HoverColour = Color.hoverColor; toggleImage.DisabledHoverColor = Color.disabledhoverColor; UIDetours.IS_ON.Set(kToggle, InitialState); toggle.SetActive(true); // Set size if (Size.x > 0.0f && Size.y > 0.0f) { toggle.SetUISize(Size, true); } else { PUIElements.AddSizeFitter(toggle, DynamicSize); } // Add tooltip PUIElements.SetToolTip(toggle, ToolTip).SetFlexUISize(FlexSize).SetActive(true); OnRealize?.Invoke(toggle); return(toggle); }
public GameObject Build() { var textField = PUIElements.CreateUI(null, Name); var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; // Background var border = textField.AddComponent <Image>(); border.sprite = PUITuning.Images.BoxBorderWhite; border.type = Image.Type.Sliced; border.color = style.textColor; // Text box with rectangular clipping area; put pivot in upper left var textArea = PUIElements.CreateUI(textField, "Text Area", false); textArea.AddComponent <Image>().color = BackColor; var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI(textArea, "Text"); // Text to display var textDisplay = PTextField.ConfigureField(textBox.AddComponent <TextMeshProUGUI>(), style, TextAlignment); textDisplay.enableWordWrapping = true; textDisplay.raycastTarget = true; // Text field itself textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; // Events! ConfigureTextEntry(textEntry); var events = textField.AddComponent <PTextFieldEvents>(); events.OnTextChanged = OnTextChanged; events.OnValidate = OnValidate; events.TextObject = textBox; // Add tooltip PUIElements.SetToolTip(textField, ToolTip); mask.enabled = true; PUIElements.SetAnchorOffsets(textBox, new RectOffset()); textField.SetActive(true); // Lay out var layout = PUIUtils.InsetChild(textField, textArea, Vector2.one, new Vector2( MinWidth, Math.Max(LineCount, 1) * PUIUtils.GetLineHeight(style))). AddOrGet <LayoutElement>(); layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; OnRealize?.Invoke(textField); return(textField); }
public GameObject Build() { if (Child == null) { throw new InvalidOperationException("No child component"); } var pane = PUIElements.CreateUI(null, Name); if (BackColor.a > 0.0f) { pane.AddComponent <Image>().color = BackColor; } // Scroll pane itself var scroll = pane.AddComponent <KScrollRect>(); scroll.horizontal = ScrollHorizontal; scroll.vertical = ScrollVertical; // Viewport var viewport = PUIElements.CreateUI(pane, "Viewport", true, PUIAnchoring.Stretch, PUIAnchoring.Stretch); viewport.AddComponent <RectMask2D>().enabled = true; // BoxLayoutGroup resizes the viewport which is undesired, we only want to pass // an auto-layout request on to the children viewport.AddComponent <VerticalLayoutGroup>().childAlignment = TextAnchor.UpperLeft; scroll.viewport = viewport.rectTransform(); // Make the child; give it a separate Canvas to reduce layout rebuilds var child = Child.Build(); child.AddOrGet <Canvas>().pixelPerfect = false; child.AddOrGet <GraphicRaycaster>(); PUIElements.SetAnchors(PUIElements.SetParent(child, viewport), PUIAnchoring. Beginning, PUIAnchoring.End); scroll.content = child.rectTransform(); pane.SetActive(true); // Vertical scrollbar if (ScrollVertical) { scroll.verticalScrollbar = CreateScrollVert(pane); scroll.verticalScrollbarVisibility = AlwaysShowVertical ? ScrollRect. ScrollbarVisibility.Permanent : ScrollRect.ScrollbarVisibility.AutoHide; } if (ScrollHorizontal) { scroll.horizontalScrollbar = CreateScrollHoriz(pane); scroll.horizontalScrollbarVisibility = AlwaysShowHorizontal ? ScrollRect. ScrollbarVisibility.Permanent : ScrollRect.ScrollbarVisibility.AutoHide; } pane.SetFlexUISize(FlexSize); OnRealize?.Invoke(pane); return(pane); }
public GameObject Build() { var spacer = new GameObject(Name); var le = spacer.AddComponent <LayoutElement>(); le.flexibleHeight = FlexSize.y; le.flexibleWidth = FlexSize.x; le.minHeight = 0.0f; le.minWidth = 0.0f; le.preferredHeight = PreferredSize.y; le.preferredWidth = PreferredSize.x; OnRealize?.Invoke(spacer); return(spacer); }
public GameObject Build() { if (Parent == null) { throw new InvalidOperationException("Parent for dialog may not be null"); } var dialog = PUIElements.CreateUI(Parent, Name); var dComponent = dialog.AddComponent <PDialogComp>(); // Background dialog.AddComponent <Canvas>(); dialog.AddComponent <GraphicRaycaster>(); var bg = dialog.AddComponent <Image>(); bg.color = DialogBackColor; bg.sprite = PUITuning.Images.BoxBorder; bg.type = Image.Type.Sliced; // Add each component var layout = dialog.AddComponent <PGridLayoutGroup>(); layout.AddRow(new GridRowSpec()); layout.AddRow(new GridRowSpec(flex: 1.0f)); layout.AddRow(new GridRowSpec()); layout.AddColumn(new GridColumnSpec(flex: 1.0f)); layout.AddColumn(new GridColumnSpec()); LayoutTitle(layout, dComponent.DoButton); layout.AddComponent(Body.Build(), new GridComponentSpec(1, 0) { ColumnSpan = 2, Margin = new RectOffset(10, 10, 10, 10) }); CreateUserButtons(layout, dComponent.DoButton); // Configure body position SetDialogSize(dialog); // Dialog is realized dComponent.dialog = this; dComponent.sortKey = SortKey; OnRealize?.Invoke(dialog); return(dialog); }
public GameObject Build() { var panel = PUIElements.CreateUI(Name); if (BackColor.a > 0.0f) { panel.AddComponent <Image>().color = BackColor; } panel.layer = LayerMask.NameToLayer("UI"); // Add children foreach (var child in children) { PUIElements.SetParent(child.Build(), panel); } // Add layout component var args = new BoxLayoutParams() { Direction = Direction, Alignment = Alignment, Spacing = Spacing, Margin = Margin }; // Gotta love freezable layouts if (DynamicSize) { var lg = panel.AddComponent <BoxLayoutGroup>(); lg.Params = args; lg.flexibleWidth = FlexSize.x; lg.flexibleHeight = FlexSize.y; } else { BoxLayoutGroup.LayoutNow(panel, args).SetFlexUISize(FlexSize); } OnRealize?.Invoke(panel); return(panel); }
public GameObject Build() { var combo = PUIElements.CreateUI(null, Name); var style = TextStyle ?? PUITuning.Fonts.UILightStyle; var entryColor = EntryColor ?? PUITuning.Colors.ButtonBlueStyle; RectOffset margin = Margin, im = ItemMargin; // Background color var bgImage = combo.AddComponent <KImage>(); var backColorStyle = BackColor ?? PUITuning.Colors.ButtonBlueStyle; UIDetours.COLOR_STYLE_SETTING.Set(bgImage, backColorStyle); PButton.SetupButtonBackground(bgImage); // Need a LocText (selected item) var selection = PUIElements.CreateUI(combo, "SelectedItem"); if (MinWidth > 0) { selection.SetMinUISize(new Vector2(MinWidth, 0.0f)); } var selectedLabel = PUIElements.AddLocText(selection, style); // Vertical flow panel with the choices var contentContainer = PUIElements.CreateUI(null, "Content"); contentContainer.AddComponent <VerticalLayoutGroup>().childForceExpandWidth = true; // Scroll pane with items is laid out below everything else var pullDown = new PScrollPane("PullDown") { ScrollHorizontal = false, ScrollVertical = true, AlwaysShowVertical = true, FlexSize = Vector2.right, TrackSize = 8.0f, BackColor = entryColor. inactiveColor }.BuildScrollPane(combo, contentContainer); // Add a black border (Does not work, covered by the combo box buttons...) #if false var pdImage = pullDown.GetComponent <Image>(); pdImage.sprite = PUITuning.Images.BoxBorder; pdImage.type = Image.Type.Sliced; #endif pullDown.rectTransform().pivot = new Vector2(0.5f, 1.0f); // Initialize the drop down var comboBox = combo.AddComponent <PComboBoxComponent>(); comboBox.CheckColor = style.textColor; comboBox.ContentContainer = contentContainer.rectTransform(); comboBox.EntryPrefab = BuildRowPrefab(style, entryColor); comboBox.MaxRowsShown = MaxRowsShown; comboBox.Pulldown = pullDown; comboBox.SelectedLabel = selectedLabel; comboBox.SetItems(Content); comboBox.SetSelectedItem(InitialItem); comboBox.OnSelectionChanged = (obj, item) => OnOptionSelected?.Invoke(obj. gameObject, item as T); // Inner component with the pulldown image var image = PUIElements.CreateUI(combo, "OpenImage"); var icon = image.AddComponent <Image>(); icon.sprite = PUITuning.Images.Contract; icon.color = style.textColor; // Button component var dropButton = combo.AddComponent <KButton>(); PButton.SetupButton(dropButton, bgImage); UIDetours.FG_IMAGE.Set(dropButton, icon); dropButton.onClick += comboBox.OnClick; // Add tooltip PUIElements.SetToolTip(selection, ToolTip); combo.SetActive(true); // Button gets laid out on the right, rest of space goes to the label // Scroll pane is laid out on the bottom var layout = combo.AddComponent <RelativeLayoutGroup>(); layout.AnchorYAxis(selection).SetLeftEdge(selection, fraction: 0.0f).SetRightEdge(selection, toLeft: image).AnchorYAxis(image).SetRightEdge( image, fraction: 1.0f).SetMargin(selection, new RectOffset(margin.left, im.right, margin.top, margin.bottom)).SetMargin(image, new RectOffset(0, margin.right, margin.top, margin.bottom)).OverrideSize(image, ArrowSize). AnchorYAxis(pullDown, 0.0f).OverrideSize(pullDown, Vector2.up); layout.LockLayout(); if (DynamicSize) { layout.UnlockLayout(); } // Disable sizing on the pulldown pullDown.AddOrGet <LayoutElement>().ignoreLayout = true; // Scroll pane is hidden right away pullDown.SetActive(false); layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; OnRealize?.Invoke(combo); return(combo); }
public GameObject Build() { var textField = PUIElements.CreateUI(Name); // Background var style = TextStyle ?? PUITuning.Fonts.TextLightStyle; textField.AddComponent <Image>().color = style.textColor; // Text box with rectangular clipping area var textArea = PUIElements.CreateUI("Text Area", true, false); textArea.AddComponent <Image>().color = BackColor; PUIElements.SetParent(textArea, textField); var mask = textArea.AddComponent <RectMask2D>(); // Scrollable text var textBox = PUIElements.CreateUI("Text"); PUIElements.SetParent(textBox, textArea); // Text to display var textDisplay = textBox.AddComponent <TextMeshProUGUI>(); textDisplay.alignment = TextAlignment; textDisplay.autoSizeTextContainer = false; textDisplay.enabled = true; textDisplay.color = style.textColor; textDisplay.font = style.sdfFont; textDisplay.fontSize = style.fontSize; textDisplay.fontStyle = style.style; textDisplay.maxVisibleLines = 1; // Text field itself var onChange = OnTextChanged; textField.SetActive(false); var textEntry = textField.AddComponent <TMP_InputField>(); textEntry.textComponent = textDisplay; textEntry.textViewport = textArea.rectTransform(); textField.SetActive(true); textEntry.text = Text ?? ""; textDisplay.text = Text ?? ""; ConfigureTextEntry(textEntry).onDeselect.AddListener((text) => { onChange?.Invoke(textField, (text ?? "").TrimEnd()); }); // Add tooltip if (!string.IsNullOrEmpty(ToolTip)) { textField.AddComponent <ToolTip>().toolTip = ToolTip; } mask.enabled = true; // Lay out - TMP_InputField does not support auto layout so we have to do a hack var minSize = new Vector2(MinWidth, LayoutUtility.GetPreferredHeight(textBox. rectTransform())); textArea.SetMinUISize(minSize).SetFlexUISize(Vector2.one); var lp = new BoxLayoutParams() { Direction = PanelDirection.Horizontal, Alignment = TextAnchor.MiddleLeft, Margin = new RectOffset(1, 1, 1, 1) }; if (DynamicSize) { var layout = textField.AddComponent <BoxLayoutGroup>(); layout.Params = lp; layout.flexibleWidth = FlexSize.x; layout.flexibleHeight = FlexSize.y; textField.SetMinUISize(minSize); } else { BoxLayoutGroup.LayoutNow(textField, lp, new Vector2(MinWidth, 0.0f)). SetFlexUISize(FlexSize); } OnRealize?.Invoke(textField); return(textField); }
public GameObject Build() { float iv; // Bounds must be valid if (MaxValue.IsNaNOrInfinity()) { throw new ArgumentException("MaxValue"); } if (MinValue.IsNaNOrInfinity()) { throw new ArgumentException("MinValue"); } // max > min if (MaxValue <= MinValue) { throw new ArgumentOutOfRangeException("MaxValue"); } // Initial value must be in range if (InitialValue.IsNaNOrInfinity()) { iv = MinValue; } else { iv = InitialValue.InRange(MinValue, MaxValue); } var slider = PUIElements.CreateUI(null, Name); bool isVertical = Direction == Slider.Direction.BottomToTop || Direction == Slider.Direction.TopToBottom; var trueColor = HandleColor ?? PUITuning.Colors.ButtonBlueStyle; slider.SetActive(false); // Track (visual) var trackImg = slider.AddComponent <Image>(); trackImg.sprite = isVertical ? PUITuning.Images.ScrollBorderVertical : PUITuning. Images.ScrollBorderHorizontal; trackImg.type = Image.Type.Sliced; // Fill var fill = PUIElements.CreateUI(slider, "Fill", true); var fillImg = fill.AddComponent <Image>(); fillImg.sprite = isVertical ? PUITuning.Images.ScrollHandleVertical : PUITuning. Images.ScrollHandleHorizontal; fillImg.color = trueColor.inactiveColor; fillImg.type = Image.Type.Sliced; PUIElements.SetAnchorOffsets(fill, 1.0f, 1.0f, 1.0f, 1.0f); // Slider component itself var ks = slider.AddComponent <KSlider>(); ks.maxValue = MaxValue; ks.minValue = MinValue; ks.value = InitialValue; ks.wholeNumbers = IntegersOnly; ks.handleRect = CreateHandle(slider).rectTransform(); ks.fillRect = fill.rectTransform(); ks.SetDirection(Direction, true); if (OnValueChanged != null) { ks.onValueChanged.AddListener((value) => OnValueChanged(slider, value)); } if (OnDrag != null) { ks.onDrag += () => OnDrag(slider, ks.value); } // Manually add tooltip with slider link string tt = ToolTip; if (!string.IsNullOrEmpty(tt)) { var toolTip = slider.AddComponent <ToolTip>(); toolTip.OnToolTip = () => string.Format(tt, ks.value); // Tooltip can be dynamically updated toolTip.refreshWhileHovering = true; } slider.SetActive(true); // Static layout! slider.SetMinUISize(isVertical ? new Vector2(TrackSize, PreferredLength) : new Vector2(PreferredLength, TrackSize)); slider.SetFlexUISize(FlexSize); OnRealize?.Invoke(slider); return(slider); }
/// <summary> /// Invokes the OnRealize event. /// </summary> /// <param name="obj">The realized text component.</param> protected void InvokeRealize(GameObject obj) { OnRealize?.Invoke(obj); }
public GameObject Build() { var flexW = new Vector2(1.0f, 0.0f); if (Parent == null) { throw new InvalidOperationException("Parent for dialog may not be null"); } var dialog = PUIElements.CreateUI(null, Name); var dComponent = dialog.AddComponent <PDialogComp>(); int i = 0; PUIElements.SetParent(dialog, Parent); // Background dialog.AddComponent <Image>().color = PUITuning.Colors.DialogBackground; dialog.AddComponent <Canvas>(); new PPanel("Header") { // Horizontal title bar Spacing = 3, Direction = PanelDirection.Horizontal, FlexSize = flexW }.SetKleiPinkColor().AddChild(new PLabel("Title") { // Title text, expand to width Text = Title, FlexSize = flexW, DynamicSize = true }).AddChild(new PButton(DIALOG_KEY_CLOSE) { // Close button Sprite = PUITuning.Images.Close, Margin = new RectOffset(3, 3, 3, 3), SpriteSize = new Vector2f(16.0f, 16.0f), OnClick = dComponent.DoButton }.SetKleiBlueStyle()).AddTo(dialog); // Buttons var buttonPanel = new PPanel("Buttons") { Alignment = TextAnchor.LowerCenter, Spacing = 5, Direction = PanelDirection. Horizontal, Margin = new RectOffset(5, 5, 5, 5) }; // Add each user button foreach (var button in buttons) { string key = button.key; var db = new PButton(key) { Text = button.text, ToolTip = button.tooltip, Margin = BUTTON_MARGIN, OnClick = dComponent.DoButton }; // Last button is special and gets a pink color if (++i >= buttons.Count) { db.SetKleiPinkStyle(); } else { db.SetKleiBlueStyle(); } buttonPanel.AddChild(db); } // Body, make it fill the flexible space new PPanel("BodyAndButtons") { Alignment = TextAnchor.MiddleCenter, Spacing = 5, Direction = PanelDirection. Vertical, Margin = new RectOffset(10, 10, 10, 5), FlexSize = Vector2.one, BackColor = DialogBackColor }.AddChild(Body).AddChild(buttonPanel).AddTo(dialog); // Lay out components vertically BoxLayoutGroup.LayoutNow(dialog, new BoxLayoutParams() { Alignment = TextAnchor.UpperCenter, Margin = new RectOffset(1, 1, 1, 1), Spacing = 1.0f, Direction = PanelDirection.Vertical }, Size); dialog.AddComponent <GraphicRaycaster>(); dComponent.dialog = this; dComponent.sortKey = SortKey; OnRealize?.Invoke(dialog); return(dialog); }