Skip to content

Commit

Permalink
feat: WindowElement.SetClosable()
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqunaga committed Jan 18, 2023
1 parent 3f0fd6b commit 82971ec
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Assets/Example/Runtime/RosettaUIExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private Element CreateElement()
{
return UI.Window(
ExampleTypes.Select(type => UI.WindowLauncher(null, false, false, false, type))
);
).SetClosable(false);
}

void Update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ private bool Bind_Window(Element element, VisualElement visualElement)
if (element is not WindowElement windowElement || visualElement is not Window window) return false;

var titleBarLeft = window.TitleBarContainerLeft.Children().FirstOrDefault();
var bound = titleBarLeft != null && Bind(windowElement.Header, titleBarLeft);
if (!bound)
var successBind = titleBarLeft != null && Bind(windowElement.Header, titleBarLeft);
if (!successBind)
{
window.TitleBarContainerLeft.Add(Build(windowElement.Header));
}

window.Closable = windowElement.Closable;

window.onShow += OnShow;
window.onHide += OnHide;
Expand Down
40 changes: 40 additions & 0 deletions Packages/RosettaUI/Runtime/Elements/ElementGroup/WindowElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using RosettaUI.Reactive;
using UnityEngine;
using UnityEngine.Assertions;

namespace RosettaUI
{
public class WindowElement : OpenCloseBaseElement
{
public readonly ReactiveProperty<Vector2?> positionRx = new();

private bool _closable = true;

public Vector2? Position
{
set => positionRx.Value = value;
}

public bool Closable
{
get => _closable;
set
{
if (_closable == value) return;
if (HasBuilt)
{
Debug.LogWarning($"{nameof(WindowElement)}.{nameof(Closable)} is not applied after {nameof(RosettaUIRoot)}.{nameof(RosettaUIRoot.Build)}().");
}

_closable = value;
}
}

public override ReactiveProperty<bool> IsOpenRx => enableRx;

public WindowElement(Element header, IEnumerable<Element> contents) : base(header, contents)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public static T Open<T>(this T element, bool recursive = false) where T : Elemen
public static T Close<T>(this T element, bool recursive = false) where T : Element
=> element.SetOpenFlag(false);

public static WindowElement SetClosable(this WindowElement windowElement, bool closable)
{
windowElement.Closable = closable;
return windowElement;
}

public static WindowElement SetPosition(this WindowElement windowElement, Vector2? position)
{
windowElement.Position = position;
Expand Down
21 changes: 0 additions & 21 deletions Packages/RosettaUI/Runtime/Elements/WindowElement.cs

This file was deleted.

0 comments on commit 82971ec

Please sign in to comment.