From 2377f92589b8dcb85f7fd856f5cb63de91a3b082 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Fri, 23 Jan 2026 00:55:31 +0800 Subject: [PATCH] ui fix --- UXAssist/UI/MyComboBox.cs | 21 --------------------- UXAssist/UI/MyConfigWindow.cs | 3 ++- UXAssist/UI/MyWindow.cs | 20 +++++++++++++++++--- UXAssist/UIConfigWindow.cs | 3 ++- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/UXAssist/UI/MyComboBox.cs b/UXAssist/UI/MyComboBox.cs index 19766a5..600115e 100644 --- a/UXAssist/UI/MyComboBox.cs +++ b/UXAssist/UI/MyComboBox.cs @@ -10,7 +10,6 @@ public class MyComboBox : MonoBehaviour { private RectTransform _rectTrans; private UIComboBox _comboBox; - private Text _text; public Action OnSelChanged; private static GameObject _baseObject; @@ -34,7 +33,6 @@ public class MyComboBox : MonoBehaviour if (fontSource) { var txtComp = cbctrl.m_ListItemRes.GetComponentInChildren(); - UXAssist.Logger.LogDebug($"txtComp: [{txtComp}]"); if (txtComp) { txtComp.font = fontSource.font; @@ -42,7 +40,6 @@ public class MyComboBox : MonoBehaviour txtComp.fontStyle = fontSource.fontStyle; } txtComp = rect.Find("Main Button/Text")?.GetComponent(); - UXAssist.Logger.LogDebug($"txtComp: [{txtComp}]"); if (txtComp) { txtComp.font = fontSource.font; @@ -63,8 +60,6 @@ public class MyComboBox : MonoBehaviour var cb = gameObject.AddComponent(); var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent); cb._rectTrans = rtrans; - cb._text = gameObject.transform.Find("Main Button/Text")?.GetComponent(); - UXAssist.Logger.LogDebug($"cb._text: [{cb._text}]"); var box = rtrans.GetComponent(); cb._comboBox = box; box.onItemIndexChange.AddListener(() => { cb.OnSelChanged?.Invoke(box.itemIndex); }); @@ -81,21 +76,11 @@ public class MyComboBox : MonoBehaviour private void UpdateComboBoxPosition() { var rtrans = (RectTransform)_comboBox.transform; - var oldPosition = rtrans.localPosition; - var pwidth = _text.preferredWidth; - rtrans.localPosition = new Vector3(pwidth + 5f, oldPosition.y, oldPosition.z); _rectTrans.sizeDelta = new Vector2(rtrans.localPosition.x + 5f + rtrans.sizeDelta.x, _rectTrans.sizeDelta.y); } - public void SetPrompt(string prompt) - { - _text.text = prompt.Translate(); - UpdateComboBoxPosition(); - } - public void SetFontSize(int size) { - _text.fontSize = size; _comboBox.ItemButtons.ForEach(b => b.GetComponentInChildren().fontSize = size); _comboBox.m_ListItemRes.GetComponentInChildren().fontSize = size; var txtComp = _comboBox.transform.Find("Main Button")?.GetComponentInChildren(); @@ -137,12 +122,6 @@ public class MyComboBox : MonoBehaviour config.SettingChanged += _configChanged; } - public MyComboBox WithPrompt(string prompt) - { - SetPrompt(prompt); - return this; - } - public MyComboBox WithFontSize(int size) { SetFontSize(size); diff --git a/UXAssist/UI/MyConfigWindow.cs b/UXAssist/UI/MyConfigWindow.cs index ad09b05..0c6efc8 100644 --- a/UXAssist/UI/MyConfigWindow.cs +++ b/UXAssist/UI/MyConfigWindow.cs @@ -25,9 +25,10 @@ public class MyConfigWindow : MyWindowWithTabs base._OnCreate(); _windowTrans = GetComponent(); OnUICreated?.Invoke(this, _windowTrans); - AutoFitWindowSize(); SetCurrentTab(0); OnUpdateUI?.Invoke(); + // Delay 500ms to run AutoFitWindowSize() after the window is created + // Invoke(nameof(AutoFitWindowSize), 0f); } public override void _OnDestroy() diff --git a/UXAssist/UI/MyWindow.cs b/UXAssist/UI/MyWindow.cs index ee068f6..7975613 100644 --- a/UXAssist/UI/MyWindow.cs +++ b/UXAssist/UI/MyWindow.cs @@ -30,7 +30,7 @@ public class MyWindow : ManualBehaviour var go = Instantiate(UIRoot.instance.uiGame.inserterWindow.gameObject); go.SetActive(false); go.name = "my-window"; - Destroy(go.GetComponent()); + Destroy(go.GetComponent()); for (var i = go.transform.childCount - 1; i >= 0; i--) { var child = go.transform.GetChild(i).gameObject; @@ -63,6 +63,11 @@ public class MyWindow : ManualBehaviour return (T)win; } + public override void _OnOpen() + { + AutoFitWindowSize(); + } + public override void _OnFree() { OnFree?.Invoke(); @@ -99,6 +104,15 @@ public class MyWindow : ManualBehaviour { var trans = GetComponent(); trans.sizeDelta = new Vector2(_maxX + Margin + TabWidth + Spacing + Margin, MaxY + TitleHeight + Margin); + // var panelBgTrans = trans.Find("panel-bg")?.GetComponent(); + // if (panelBgTrans != null) + // { + // panelBgTrans.anchorMax = new Vector2(0f, 1f); + // panelBgTrans.anchorMin = new Vector2(0f, 1f); + // panelBgTrans.pivot = new Vector2(0f, 1f); + // panelBgTrans.localPosition = new Vector3(0f, 0f, 0f); + // panelBgTrans.sizeDelta = new Vector2(_maxX + Margin + TabWidth + Spacing + Margin, MaxY + TitleHeight + Margin); + // } } private static void AddElement(float x, float y, RectTransform rect, RectTransform parent = null) @@ -212,9 +226,9 @@ public class MyWindow : ManualBehaviour return cb; } - public MyComboBox AddComboBox(float x, float y, RectTransform parent, string label = "", int fontSize = 15) + public MyComboBox AddComboBox(float x, float y, RectTransform parent, int fontSize = 15) { - var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithPrompt(label).WithFontSize(fontSize); + var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithFontSize(fontSize); _maxX = Math.Max(_maxX, x + comboBox.Width); MaxY = Math.Max(MaxY, y + comboBox.Height); return comboBox; diff --git a/UXAssist/UIConfigWindow.cs b/UXAssist/UIConfigWindow.cs index ee70ff5..e731b82 100644 --- a/UXAssist/UIConfigWindow.cs +++ b/UXAssist/UIConfigWindow.cs @@ -333,7 +333,8 @@ public static class UIConfigWindow x = 0f; } y += 36f; - wnd.AddComboBox(x + 2f, y, tab1, "Process priority").WithItems("High", "Above Normal", "Normal", "Below Normal", "Idle").WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority); + txt = wnd.AddText2(x + 2f, y, tab1, "Process priority", 15, "process-priority"); + wnd.AddComboBox(x + 7f + txt.preferredWidth, y, tab1).WithItems("High", "Above Normal", "Normal", "Below Normal", "Idle").WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority); var tab2 = wnd.AddTab(trans, "Factory"); x = 0f;