using Jovian.PopupSystem.UI;
using UnityEngine;
namespace Jovian.PopupSystem {
///
/// Fluent API struct for building popup content. Operates directly on cached elements
/// inside a — no intermediate allocations. Received in
/// the build callback passed to .
///
public struct PopupContentBuilder {
readonly PopupReference view;
///
/// Creates a builder targeting the given popup reference.
///
public PopupContentBuilder(PopupReference view) {
this.view = view;
}
///
/// Adds a header text element (bold, larger font).
///
public PopupContentBuilder AddHeader(string text) {
var header = view.GetHeader();
header.text = text;
return this;
}
///
/// Adds a body text element.
///
public PopupContentBuilder AddText(string text) {
var label = view.GetText();
label.text = text;
return this;
}
///
/// Adds a colored body text element. Hex color can be with or without the # prefix.
///
public PopupContentBuilder AddText(string text, string hexColor) {
var label = view.GetText();
var prefix = hexColor.Length > 0 && hexColor[0] == '#' ? "" : "#";
label.text = $"{text}";
return this;
}
///
/// Adds a stat row with a label and integer value.
///
public PopupContentBuilder AddStat(string label, int value) {
var (labelText, valueText) = view.GetStat();
labelText.text = label;
valueText.text = value.ToString();
return this;
}
///
/// Adds a stat row with a label and string value.
///
public PopupContentBuilder AddStat(string label, string value) {
var (labelText, valueText) = view.GetStat();
labelText.text = label;
valueText.text = value;
return this;
}
///
/// Adds an image element with the given sprite and optional height.
///
public PopupContentBuilder AddImage(Sprite sprite, float height = 64f) {
var image = view.GetImage();
image.sprite = sprite;
var rt = (RectTransform)image.transform;
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
return this;
}
///
/// Adds a horizontal separator line.
///
public PopupContentBuilder AddSeparator() {
view.GetSeparator();
return this;
}
}
}