Skip to content

Commit

Permalink
File selector- add scrollbars
Browse files Browse the repository at this point in the history
  • Loading branch information
tzachshabtay committed Feb 24, 2019
1 parent 5c9528b commit 9628495
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
21 changes: 11 additions & 10 deletions Source/Editor/AGS.Editor/Components/FileSelector/FileSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@ private void configureSplitter()
{
_splitter.IsHorizontal = true;

var leftPanel = _factory.UI.GetPanel("FolderTree", 300f, 600f, 100f, 100f);
leftPanel.AddComponent<ICropChildrenComponent>();
//var contentsPanel = _factory.UI.CreateScrollingPanel(leftPanel);
leftPanel.Tint = GameViewColors.Panel;
leftPanel.Border = _factory.Graphics.Borders.SolidColor(GameViewColors.Border, 3f);
leftPanel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1000);
var leftScrollingPanel = _factory.UI.GetPanel("FolderTree", 300f, 600f, 100f, 100f);
leftScrollingPanel.Tint = GameViewColors.Panel;
leftScrollingPanel.Border = _factory.Graphics.Borders.SolidColor(GameViewColors.Border, 3f);
leftScrollingPanel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1000);
var leftPanel = _factory.UI.CreateScrollingPanel(leftScrollingPanel);
var tree = leftPanel.AddComponent<ITreeViewComponent>();
tree.LeftPadding = 10f;
tree.TopPadding = 30f;
_folderTree = leftPanel.AddComponent<FolderTree>();
_folderTree.DefaultFolder = "../../../../../Demo";

_splitter.SplitLineOffset = (15f, 15f); //Offsetting for the scrollbar
_splitter.TopPanel = leftPanel;

var rightPanel = _factory.UI.GetPanel("FilesView", 800f, 600f, 400f, 100f);
rightPanel.Tint = GameViewColors.Panel;
rightPanel.Border = _factory.Graphics.Borders.SolidColor(GameViewColors.Border, 3f);
rightPanel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1000);
var rightScrollingPanel = _factory.UI.GetPanel("FilesView", 800f, 600f, 400f, 100f);
rightScrollingPanel.Tint = GameViewColors.Panel;
rightScrollingPanel.Border = _factory.Graphics.Borders.SolidColor(GameViewColors.Border, 3f);
rightScrollingPanel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1000);
var rightPanel = _factory.UI.CreateScrollingPanel(rightScrollingPanel);
var inv = rightPanel.AddComponent<IInventoryWindowComponent>();
inv.Inventory = new AGSInventory();
inv.ItemSize = (120f, 120f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class AGSSplitPanelComponent : AGSComponent, ISplitPanelComponent

private IPanel _topPanel, _bottomPanel;
private bool _isHorizontal;
private PointF _splitLineOffset;
private float _lineWidth = 5f;
private Vector2 _startPositionDragLine, _startPositionBottomPanel;
private SizeF _startSizeTopPanel, _startSizeBottomPanel;
private IComponentBinding _splitLineMoveBinding;
Expand Down Expand Up @@ -53,6 +55,9 @@ public IPanel BottomPanel
public bool IsHorizontal { get => _isHorizontal; set { _isHorizontal = value; createNewSplitLine(); } }
public IObject DragLine { get; private set; }

public PointF SplitLineOffset { get => _splitLineOffset; set { _splitLineOffset = value; positionSplitLine(DragLine, TopPanel); }}
public float SplitLineWidth { get => _lineWidth; set { _lineWidth = value; positionSplitLine(DragLine, TopPanel); } }

private void disposeExistingSplitLine()
{
var existing = DragLine;
Expand All @@ -77,7 +82,6 @@ private void createNewSplitLine()
var topPanel = TopPanel;
if (topPanel == null) return;

const float lineWidth = 5f;
string suffix = IsHorizontal ? "Horiz" : "Vert";
var splitLine = _factory.Object.GetObject($"{topPanel.ID}_SplitLine_{suffix}");
_state.FocusedUI.CannotLoseFocus.Add(splitLine.ID);
Expand All @@ -86,11 +90,11 @@ private void createNewSplitLine()
crop?.EntitiesToSkipCrop.Add(splitLine.ID);
HoverEffect.Add(splitLine, Colors.Transparent, Colors.Yellow.WithAlpha(100));
splitLine.Pivot = new PointF(0f, 0f);
positionSplitLine(splitLine, topPanel, lineWidth);
positionSplitLine(splitLine, topPanel);
splitLine.Z = -1f;
topPanel.OnBoundingBoxesChanged.Subscribe(() =>
{
positionSplitLine(splitLine, topPanel, lineWidth);
positionSplitLine(splitLine, topPanel);
});
topPanel.Bind<IVisibleComponent>(c => c.PropertyChanged += onTopPanelVisibleChanged, c => c.PropertyChanged -= onTopPanelVisibleChanged);
_startPositionDragLine = new Vector2(splitLine.X, splitLine.Y);
Expand Down Expand Up @@ -119,16 +123,17 @@ private void onTopPanelVisibleChanged(object _, PropertyChangedEventArgs args)
line.Visible = panel != null && panel.Visible;
}

private void positionSplitLine(IObject splitLine, IPanel topPanel, float lineWidth)
private void positionSplitLine(IObject splitLine, IPanel topPanel)
{
if (splitLine == null || topPanel == null) return;
var boundingBoxes = topPanel.GetBoundingBoxes(_state.Viewport);
var box = boundingBoxes.ViewportBox;
float width = IsHorizontal ? lineWidth : box.Width;
float height = IsHorizontal ? box.Height : lineWidth;
float width = IsHorizontal ? _lineWidth : box.Width + _splitLineOffset.X;
float height = IsHorizontal ? box.Height + _splitLineOffset.Y : _lineWidth;
splitLine.Image = new EmptyImage(width, height);
float pivotX = -box.Width * topPanel.Pivot.X;
splitLine.X = IsHorizontal ? pivotX + box.MinX + box.Width - lineWidth / 2f : pivotX;
splitLine.Y = box.MinY;
splitLine.X = IsHorizontal ? pivotX + box.MinX + box.Width - _lineWidth / 2f + _splitLineOffset.X : pivotX + _splitLineOffset.X;
splitLine.Y = box.MinY - _splitLineOffset.Y;
}

private void onSplitLineMoved(object sender, PropertyChangedEventArgs args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@ public interface ISplitPanelComponent : IComponent
/// </summary>
/// <value><c>true</c> if is horizonal; otherwise, <c>false</c>.</value>
bool IsHorizontal { get; set;}

/// <summary>
/// By default the split line is located at the bottom of the top panel (or at the right of the left panel).
/// You can add an offset that will move and/or adjust the size of the split line.
/// </summary>
/// <value>The split line offset.</value>
PointF SplitLineOffset { get; set; }

/// <summary>
/// Gets or sets the width of the visible split line.
/// </summary>
/// <value>The width of the line.</value>
float SplitLineWidth { get; set; }
}
}

0 comments on commit 9628495

Please sign in to comment.