Skip to content

Commit

Permalink
correct naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ababilinski committed Dec 20, 2023
1 parent 64077de commit adcabae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UnityEngine.UI;
using MagicLeap.XRKeyboard.Extensions;
using MagicLeap.XRKeyboard.Model;
using UnityEngine.Serialization;

namespace MagicLeap.XRKeyboard
{
Expand All @@ -17,13 +18,16 @@ public class KeyboardBuilder : MonoBehaviour
{


[FormerlySerializedAs("keyPrefab")]
[Header("Prefabs")]
public KeyboardKey keyPrefab;
public KeyboardKey KeyPrefab;

public KeyboardRow keyboardRowPrefab;
[FormerlySerializedAs("keyboardRowPrefab")]
public KeyboardRow KeyboardRowPrefab;

[FormerlySerializedAs("keyboardContainer")]
[Header("Grouped Layout Settings")]
public RectTransform keyboardContainer;
public RectTransform KeyboardContainer;

[Header("Data")]
public KeyboardLayoutData keyboardLayoutData;
Expand Down Expand Up @@ -89,9 +93,9 @@ public RectTransform AddHorizontalGap(Transform parent, Vector2 sizeDelta, Vecto
public void RegenerateKeyboard()
{

while (keyboardContainer.childCount > 0)
while (KeyboardContainer.childCount > 0)
{
DestroyImmediate(keyboardContainer.transform.GetChild(0).gameObject);
DestroyImmediate(KeyboardContainer.transform.GetChild(0).gameObject);
}

Keys.Clear();
Expand All @@ -101,19 +105,19 @@ public void RegenerateKeyboard()

var rows = keyboardLayoutData.GetKeyboardRows();

var rect = keyboardContainer.rect;
var rect = KeyboardContainer.rect;
Vector2 rowSize = new Vector2(rect.size.x, rect.size.y / rows.Count);
float rowCenterX = keyboardContainer.anchoredPosition.x / 2;
float rowTopY = keyboardContainer.rect.size.y/2;
float rowCenterX = KeyboardContainer.anchoredPosition.x / 2;
float rowTopY = KeyboardContainer.rect.size.y/2;

for (var i = 0; i < rows.Count; i++)
{
var row = rows[i];
var anchoredPosition = new Vector2(rowCenterX, rowTopY - (rowSize.y * i));


var keyRow = Instantiate(keyboardRowPrefab, keyboardContainer.transform);
keyRow.Initialize($"Row {i}", keyboardContainer, rowSize, anchoredPosition, row.Size, row.Spacing,row.VerticalGap);
var keyRow = Instantiate(KeyboardRowPrefab, KeyboardContainer.transform);
keyRow.Initialize($"Row {i}", KeyboardContainer, rowSize, anchoredPosition, row.Size, row.Spacing,row.VerticalGap);
Vector2 keySize = new Vector2(rowSize.x / row.Keys.Count, rowSize.y);


Expand All @@ -128,7 +132,7 @@ public void RegenerateKeyboard()
{
var sizeDelta = new Vector2(keySize.x * key.WidthScale, keySize.y);
var anchorPosition = new Vector2(keySize.x * j, 0);
var newKey = Instantiate(keyPrefab, keyRow.transform);
var newKey = Instantiate(KeyPrefab, keyRow.transform);
newKey.Initialize(key, sizeDelta, anchorPosition, new Vector2(row.PreferredKeySize.x * key.WidthScale, row.PreferredKeySize.y) , row.ShowAccentHint);
Keys.Add(newKey);
keyRow.Keys.Add(newKey);
Expand All @@ -143,8 +147,8 @@ public void RegenerateKeyboard()
Canvas.ForceUpdateCanvases();
}

keyboardContainer.MarkAsDirty($"Created Keyboard: {keyboardContainer.name}");
LayoutRebuilder.ForceRebuildLayoutImmediate(keyboardContainer);
KeyboardContainer.MarkAsDirty($"Created Keyboard: {KeyboardContainer.name}");
LayoutRebuilder.ForceRebuildLayoutImmediate(KeyboardContainer);
Canvas.ForceUpdateCanvases();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ private void LongPressStart(PointerEventData eventData)

private IEnumerator LongPressDetection(PointerEventData eventData)
{
float longpressThreshold = Time.time + _longPressedThreshold;
float longPressedThreshold = Time.time + _longPressedThreshold;
while (_isPressed && !_longPressed)
{
if (Time.time > longpressThreshold)
if (Time.time > longPressedThreshold)
{
_longPressed = true;
InvokeLongPress(eventData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
using MagicLeap.XRKeyboard.Component;
using UnityEngine;
using MagicLeap.XRKeyboard.Extensions;
using UnityEngine.Serialization;

namespace MagicLeap.XRKeyboard
{

/// <summary>
/// Groups the <see cref="KeyboardKey"/>s and <see cref="KeyboardRow"/>s and communicates to the <see cref="keyboardBuilder"/> to generate a new layout if needed.
/// Groups the <see cref="KeyboardKey"/>s and <see cref="KeyboardRow"/>s and communicates to the <see cref="KeyboardBuilder"/> to generate a new layout if needed.
/// </summary>
[RequireComponent(typeof(KeyboardBuilder))]
public class KeyboardLayout : MonoBehaviour
{

public KeyboardBuilder keyboardBuilder;
[FormerlySerializedAs("keyboardBuilder")]
public KeyboardBuilder KeyboardBuilder;
public string LayoutId;
[FormerlySerializedAs("regenKeyboardOnStart")]
[Tooltip("When enabled, the keyboard will regenerate from the key map on start")]
public bool regenKeyboardOnStart;
public bool RegenKeyboardOnStart;

private RectTransform _rectTransform;

Expand All @@ -27,27 +30,27 @@ public class KeyboardLayout : MonoBehaviour
void Start()
{
_rectTransform = gameObject.GetCachedComponent(ref _rectTransform);
keyboardBuilder = GetComponent<KeyboardBuilder>();
KeyboardBuilder = GetComponent<KeyboardBuilder>();

if (regenKeyboardOnStart) keyboardBuilder.RegenerateKeyboard();
if (RegenKeyboardOnStart) KeyboardBuilder.RegenerateKeyboard();
}

private void Reset()
{
keyboardBuilder = GetComponent<KeyboardBuilder>();
KeyboardBuilder = GetComponent<KeyboardBuilder>();

}

public Transform KeyboardContainer()
{
return keyboardBuilder.keyboardContainer;
return KeyboardBuilder.KeyboardContainer;
}
private void OnDrawGizmosSelected()
{
keyboardBuilder = gameObject.GetCachedComponent(ref keyboardBuilder);
if (keyboardBuilder)
KeyboardBuilder = gameObject.GetCachedComponent(ref KeyboardBuilder);
if (KeyboardBuilder)
{
LayoutId = keyboardBuilder.LayoutId;
LayoutId = KeyboardBuilder.LayoutId;
}
}

Expand All @@ -59,7 +62,7 @@ public IReadOnlyCollection<KeyboardKey> GetKeys()

public IReadOnlyCollection<KeyboardRow> GetRows()
{
return keyboardBuilder.KeyRows;
return KeyboardBuilder.KeyRows;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MagicLeap.XRKeyboard.Component;
using UnityEngine.Events;
using MagicLeap.XRKeyboard.Extensions;
using UnityEngine.Serialization;

namespace MagicLeap.XRKeyboard
{
Expand All @@ -17,8 +18,9 @@ public class PopupPanel : MonoBehaviour
{
public UnityEvent<KeyboardKey[]> OnKeysCreated;

[FormerlySerializedAs("keyPrefab")]
[Header("Prefabs")]
[SerializeField] private KeyboardKey keyPrefab;
[SerializeField] private KeyboardKey _keyPrefab;

[Header("Components")]
[SerializeField] private LayoutGroup _container;
Expand Down Expand Up @@ -127,7 +129,7 @@ public void GeneratePanel(Keyboard.Modifier modifier)
for (var i = 0; i < _keyCodes.Count; i++)
{
var special = _keyCodes[i];
var newKey = Instantiate(keyPrefab, _container.transform);
var newKey = Instantiate(_keyPrefab, _container.transform);


newKey.Initialize(_keySize, new Vector2(_keySize.x * i, 0), special, special, KeyboardKey.KeyGroup.Accent, modifier);
Expand Down

0 comments on commit adcabae

Please sign in to comment.