Skip to content

Commit

Permalink
feat: objectcontroller层级展示优化
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYunPlayer committed Nov 27, 2024
1 parent 5c6fa00 commit eda36e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
3 changes: 2 additions & 1 deletion TuneLab/GUI/Components/CollapsiblePanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -29,6 +30,6 @@ public CollapsiblePanel()
mTitlePanel.PointerPressed += (s, e) => { mContentPanel.IsVisible = !mContentPanel.IsVisible; };
}

LayerPanel mTitlePanel = new();
LayerPanel mTitlePanel = new() { Background = Brushes.Transparent } ;
LayerPanel mContentPanel = new();
}
51 changes: 44 additions & 7 deletions TuneLab/GUI/Controllers/ObjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Buffers;
using TuneLab.Base.Properties;
using TuneLab.Base.Structures;
using TuneLab.Base.Event;
using TuneLab.Base.Data;
using Microsoft.Extensions.ObjectPool;
using TuneLab.Utils;
using TuneLab.Base.Utils;
using TuneLab.GUI.Components;

namespace TuneLab.GUI.Controllers;

Expand Down Expand Up @@ -157,27 +156,62 @@ public ObjectCreator(ObjectController controller, string key, ObjectConfig confi
{
mController = controller;
mKey = key;
mLabelCreator = new LabelCreator(controller, key);

var label = ObjectPoolManager.Get<Label>();
label = ObjectPoolManager.Get<Label>();
label.Height = 26;
label.FontSize = 12;
label.VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Bottom;
label.Foreground = Style.LIGHT_WHITE.ToBrush();
label.Content = key;
label.Padding = new(24, 0);
mLabel = label;

mBorder = ObjectPoolManager.Get<Border>();
mBorder.Margin = new(23, 12, 0, 0);
mBorder.Width = 1;
mBorder.Background = Style.BACK.ToBrush();

objectController = ObjectPoolManager.Get<ObjectController>();
objectController.SetConfig(config);
objectController.ValueWillChange.Subscribe(mController.mValueWillChange);
objectController.ValueChanged.Subscribe(OnValueChanged);
objectController.ValueCommited.Subscribe(OnValueCommited);
mController.Children.Add(objectController);

mDockPanel = ObjectPoolManager.Get<DockPanel>();
mDockPanel.Margin = new(0, 0, 0, 0);
mDockPanel.AddDock(mBorder, Dock.Left);
mDockPanel.AddDock(objectController);

mCollapsiblePanel = ObjectPoolManager.Get<CollapsiblePanel>();
mCollapsiblePanel.Margin = new(0, 0, 0, 12);
mCollapsiblePanel.Title = label;
mCollapsiblePanel.Content = mDockPanel;

mController.Children.Add(mCollapsiblePanel);
mController.mControllers.Add(mKey, this);
}

public void Dispose()
{
mLabelCreator.Dispose();
mController.mControllers.Remove(mKey);
mController.Children.Remove(objectController);
mController.Children.Remove(mCollapsiblePanel);

mCollapsiblePanel.Title = null;
mCollapsiblePanel.Content = null;
ObjectPoolManager.Return(mCollapsiblePanel);

mDockPanel.Children.Clear();
ObjectPoolManager.Return(mDockPanel);
ObjectPoolManager.Return(mBorder);

objectController.ValueWillChange.Unsubscribe(mController.mValueWillChange);
objectController.ValueChanged.Unsubscribe(OnValueChanged);
objectController.ValueCommited.Unsubscribe(OnValueCommited);
objectController.ResetConfig();
ObjectPoolManager.Return(objectController);

ObjectPoolManager.Return(mLabel);
}

public void Display(PropertyPath.Key key, PropertyValue value)
Expand All @@ -201,7 +235,10 @@ void OnValueCommited(PropertyPath path, PropertyValue value)
}

readonly string mKey;
readonly LabelCreator mLabelCreator;
readonly Border mBorder;
readonly DockPanel mDockPanel;
readonly CollapsiblePanel mCollapsiblePanel;
readonly Label mLabel;
readonly ObjectController mController;
readonly ObjectController objectController;
}
Expand Down

0 comments on commit eda36e5

Please sign in to comment.