Skip to content

Commit

Permalink
SplitPane fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Sep 19, 2024
1 parent a53b03e commit a0ea73a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/Myra/Graphics2D/UI/Containers/SplitPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,36 +163,40 @@ private void WidgetsOnCollectionChanged(object sender, NotifyCollectionChangedEv

private void GetProportions(int leftWidgetIndex,
out Proportion leftProportion,
out Proportion rightProportion)
out Proportion rightProportion,
out float total)
{
var allProps = Orientation == Orientation.Horizontal
? _layout.ColumnsProportions : _layout.RowsProportions;

total = 0;
for(var i = 0; i < allProps.Count; i += 2)
{
total += allProps[i].Value;
}

var baseIndex = leftWidgetIndex * 2;
leftProportion = Orientation == Orientation.Horizontal
? _layout.ColumnsProportions[baseIndex]
: _layout.RowsProportions[baseIndex];
rightProportion = Orientation == Orientation.Horizontal
? _layout.ColumnsProportions[baseIndex + 2]
: _layout.RowsProportions[baseIndex + 2];
leftProportion = allProps[baseIndex];
rightProportion = allProps[baseIndex + 2];
}

public float GetSplitterPosition(int leftWidgetIndex)
{
float total;
Proportion leftProportion, rightProportion;
GetProportions(leftWidgetIndex, out leftProportion, out rightProportion);

var total = leftProportion.Value + rightProportion.Value;
GetProportions(leftWidgetIndex, out leftProportion, out rightProportion, out total);

return leftProportion.Value / total;
}

public void SetSplitterPosition(int leftWidgetIndex, float proportion)
{
float total;
Proportion leftProportion, rightProportion;
GetProportions(leftWidgetIndex, out leftProportion, out rightProportion);

var total = leftProportion.Value + rightProportion.Value;
GetProportions(leftWidgetIndex, out leftProportion, out rightProportion, out total);

var fp = proportion * total;
var fp2 = total - fp;
var fp2 = leftProportion.Value + rightProportion.Value - fp;
leftProportion.Value = fp;
rightProportion.Value = fp2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MyraPad/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public MainForm(State state)
PropertyGrid.CustomSetter = RecordSetter;
PropertyGrid.Settings.AssetManager = MyraEnvironment.DefaultAssetManager;

_topSplitPane.SetSplitterPosition(0, state != null ? state.TopSplitterPosition1 : 0.75f);
_topSplitPane.SetSplitterPosition(0, state != null ? state.TopSplitterPosition1 : 0.25f);
_topSplitPane.SetSplitterPosition(1, state != null ? state.TopSplitterPosition2 : 0.75f);
_leftSplitPane.SetSplitterPosition(0, state != null ? state.CenterSplitterPosition : 0.5f);

Expand Down

0 comments on commit a0ea73a

Please sign in to comment.