Skip to content

Commit

Permalink
Merge branch 'develop/fix_dropdown_invalid_size'
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqunaga committed Oct 10, 2024
2 parents fffd847 + ec18f6f commit 2f553ea
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"references": [
"GUID:2b1b0416520827b409049c7e4d90bcc1",
"GUID:e707c3091e2a19c4aa687e0b6273f7c1",
"GUID:4d1159afe4006d44595a6424bec07c77",
"GUID:2d4534a5f6b965d4d836067a71671abf"
"GUID:4d1159afe4006d44595a6424bec07c77"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rootNamespace": "",
"references": [
"GUID:2b1b0416520827b409049c7e4d90bcc1",
"GUID:2d4534a5f6b965d4d836067a71671abf"
"GUID:10043d6ab0c030d489fbc2555e20e9b5"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
m_Name: RosettaUI_DefaultPanelSettings
m_EditorClassIdentifier:
themeUss: {fileID: -4733365628477956816, guid: 6f5bb9440d7de664c85a078c1537f946,
type: 3}
themeUss: {fileID: -4733365628477956816, guid: 6f5bb9440d7de664c85a078c1537f946, type: 3}
m_DisableNoThemeWarning: 0
m_TargetTexture: {fileID: 0}
m_RenderMode: 0
m_WorldSpaceLayer: 0
m_ScaleMode: 1
m_ReferenceSpritePixelsPerUnit: 100
m_PixelsPerUnit: 100
m_Scale: 1
m_ReferenceDpi: 96
m_FallbackDpi: 96
Expand All @@ -25,9 +28,11 @@ MonoBehaviour:
m_Match: 0
m_SortingOrder: 0
m_TargetDisplay: 0
m_BindingLogLevel: 0
m_ClearDepthStencil: 1
m_ClearColor: 0
m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0}
m_VertexBudget: 0
m_DynamicAtlasSettings:
m_MinAtlasSize: 64
m_MaxAtlasSize: 4096
Expand All @@ -36,4 +41,6 @@ MonoBehaviour:
m_AtlasBlitShader: {fileID: 9101, guid: 0000000000000000f000000000000000, type: 0}
m_RuntimeShader: {fileID: 9100, guid: 0000000000000000f000000000000000, type: 0}
m_RuntimeWorldShader: {fileID: 9102, guid: 0000000000000000f000000000000000, type: 0}
m_ICUDataAsset: {fileID: 0}
forceGammaRendering: 0
textSettings: {fileID: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ Unity2022.2.0b6
margin: 2px;
width: 16px;
height: 16px;
min-width: 16px;
min-height: 16px;
align-self: center;
-unity-background-image-tint-color: initial;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UnityEngine;
using UnityEngine.UIElements;

namespace RosettaUI.UIToolkit
{
// Dropdown()の第3引数を無視するGenericDropdownMenu
// BasePopupFieldがDropdownMenuでanchor == trueで呼び出しているが、
// falseにしたいために作成
// IGenericMenuがinternalなのが辛い
public class GenericDropdownMenuIgnoreAnchored : GenericDropdownMenu, IGenericMenu
{
void IGenericMenu.DropDown(Rect position, VisualElement targetElement, bool anchored)
=> base.DropDown(position, targetElement, false);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Unity.UIElements",
"name": "Unity.InternalAPIEngineBridge.001",
"rootNamespace": "",
"references": [
"GUID:2b1b0416520827b409049c7e4d90bcc1"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.UIElements;

#if !UNITY_2022_1_OR_NEWER
using RosettaUI.UIToolkit.UnityInternalAccess;
#endif

namespace RosettaUI.UIToolkit
{
/// <summary>
/// choicesの全要素が収まるようにwidthを広げるPopupField
///
/// PopupFieldの拡張
///
/// 1. choicesの全要素が収まるようにwidthを広げるPopupField
/// BasePopupField.PopupTextElementを継承してDoMeasure()をoverrideするのがよさそうだが、
/// 継承したクラスをBasePopupField.m_TextElementにセットする方法がなさそうなので
/// styleでminWidthを指定する
///
/// 2. ドロップダウンメニューをanchoredをfalse(指定矩形の幅を使用しない)で呼ぶ
/// BasePopupFieldが行っているanchored==trueで呼ぶとvisualInputの幅でメニューが表示されるが、
/// これが十分な幅ではないためメニューないにスクロールバーが出てしまう
/// 外側Windowが小さいサイズにされた場合はさらにvisualInputが小さくなってしまう
/// </summary>
public class PopupFieldCustom<T> : PopupField<T>
{
#region choicesの全要素が収まるようにwidthを広げる

public override List<T> choices
{
get => base.choices;
Expand Down Expand Up @@ -65,5 +74,22 @@ private string GetValueToDisplay(T str)
return formatListItemCallback?.Invoke(str) ??
(choices.Contains(str) ? str.ToString() : string.Empty);
}

#endregion


#region ドロップダウンメニューをanchorをfalse(指定矩形の幅を使用しない)で呼ぶ

private static readonly FieldInfo CreateMenuCallbackFieldInfo = typeof(BasePopupField<T, T>).GetField("createMenuCallback", BindingFlags.NonPublic | BindingFlags.Instance);

public PopupFieldCustom()
{
CreateMenuCallbackFieldInfo.SetValue(this, (Func<GenericDropdownMenu>)CreateMenu);
return;

GenericDropdownMenu CreateMenu() => new GenericDropdownMenuIgnoreAnchored();
}

#endregion
}
}
7 changes: 4 additions & 3 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"dependencies": {
"com.unity.ide.rider": "3.0.28",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.inputsystem": "1.8.2",
"com.unity.test-framework": "1.4.4",
"com.unity.inputsystem": "1.11.0",
"com.unity.multiplayer.center": "1.0.0",
"com.unity.test-framework": "1.4.5",
"com.unity.ugui": "2.0.0",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.ai": "1.0.0",
Expand Down
14 changes: 11 additions & 3 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.28",
"version": "3.0.31",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -26,16 +26,24 @@
"url": "https://packages.unity.com"
},
"com.unity.inputsystem": {
"version": "1.8.2",
"version": "1.11.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.multiplayer.center": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.uielements": "1.0.0"
}
},
"com.unity.test-framework": {
"version": "1.4.4",
"version": "1.4.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 6000.0.2f1
m_EditorVersionWithRevision: 6000.0.2f1 (c36be92430b9)
m_EditorVersion: 6000.0.22f1
m_EditorVersionWithRevision: 6000.0.22f1 (001fa5a8e29a)

0 comments on commit 2f553ea

Please sign in to comment.