improving sheet editor

fixed a bug with initializing property sliders
This commit is contained in:
Lars Brubaker 2021-09-03 16:58:15 -07:00
parent aca216f809
commit 736a41d40c
7 changed files with 166 additions and 26 deletions

View file

@ -601,7 +601,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
PresentationName = "Seam Placement".Localize(),
HelpText = "What to do when there is not a good place to hide the seam.".Localize(),
DataEditType = DataEditTypes.LIST,
ListValues = "Furthest Back,Centered In Back,Randomized,Closest",
ListValues = "Furthest Back,Centered In Back,Randomized,Fastest",
DefaultValue = "Furthest Back",
},
new SliceSettingData()

View file

@ -211,7 +211,9 @@ namespace MatterHackers.MatterControl.DesignTools
}
// set the initial value of the slider
changeDueToField = true;
slider.Value = GetSlider0To1FromField();
changeDueToField = false;
return content;
}

View file

@ -0,0 +1,142 @@
/*
Copyright (c) 2018, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using System;
using System.Linq;
namespace MatterHackers.MatterControl.DesignTools
{
public class GridWidget : FlowLayoutWidget
{
public int GridWidth => Children[0].Children.Count;
public int GridHeight => Children.Count;
public void SetColumnWidth(int index, double width)
{
for (int y = 0; y < GridHeight; y++)
{
Children[y].Children[index].Width = width * GuiWidget.DeviceScale;
}
}
public void SetRowHeight(int index, double height)
{
for (int x = 0; x < GridHeight; x++)
{
Children[index].Children[x].Height = height;
}
}
public double GetColumnWidth(int index)
{
return Children[0].Children[index].Width;
}
public double GetRowHeight(int index)
{
return Children[index].Children[0].Height;
}
public GridWidget(int gridWidth, int gridHeight, double columnWidth = 60, double rowHeight = 14, ThemeConfig theme = null)
: base(FlowDirection.TopToBottom)
{
for (int y = 0; y < gridHeight; y++)
{
var row = new FlowLayoutWidget();
this.AddChild(row);
for (int x = 0; x < gridWidth; x++)
{
row.AddChild(new GuiWidget()
{
Width = columnWidth * GuiWidget.DeviceScale,
Height = rowHeight * GuiWidget.DeviceScale,
Border = 1,
BorderColor = theme == null ? Color.LightGray : theme.BorderColor20,
});
}
}
}
public GuiWidget GetCell(int x, int y)
{
if (x < GridWidth && y < GridHeight)
{
return Children[y].Children[x];
}
return null;
}
public void ExpandRowToMaxHeight(int index)
{
var maxHeight = GetRowHeight(index);
for (int x = 0; x < GridWidth; x++)
{
var cell = GetCell(x, index).Children.FirstOrDefault();
if (cell != null)
{
maxHeight = Math.Max(maxHeight, cell.Height + cell.DeviceMarginAndBorder.Height);
}
}
SetRowHeight(index, maxHeight);
}
public void ExpandColumnToMaxWidth(int index)
{
var maxWidth = GetColumnWidth(index);
for (int y = 0; y < GridHeight; y++)
{
var cell = GetCell(index, y).Children.FirstOrDefault();
if (cell != null)
{
maxWidth = Math.Max(maxWidth, cell.Width + cell.DeviceMarginAndBorder.Width);
}
}
SetColumnWidth(index, maxWidth);
}
public void ExpandToFitContent()
{
for (int x = 0; x < GridWidth; x++)
{
ExpandColumnToMaxWidth(x);
}
for (int y = 0; y < GridHeight; y++)
{
ExpandRowToMaxHeight(y);
}
}
}
}

View file

@ -78,37 +78,29 @@ namespace MatterHackers.MatterControl.DesignTools
editSelectionGroup.AddChild(editSelectedExpression);
editSelectedExpression.ActualTextEditWidget.EditComplete += ActualTextEditWidget_EditComplete1;
// put in the header row
var topRow = this.AddChild(new FlowLayoutWidget()
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
});
var dataGrid = new GridWidget(sheetData.Width + 1, sheetData.Height + 1, theme: theme);
this.AddChild(dataGrid);
topRow.AddChild(new GuiWidget(cellWidth, 1));
for (int x = 0; x < sheetData.Width; x++)
{
topRow.AddChild(new TextWidget(((char)('A' + x)).ToString())
dataGrid.GetCell(x + 1, 0).AddChild(new TextWidget(((char)('A' + x)).ToString())
{
HAnchor = HAnchor.Stretch,
TextColor = theme.TextColor
HAnchor = HAnchor.Center,
VAnchor = VAnchor.Center,
TextColor = theme.TextColor,
});
}
dataGrid.SetColumnWidth(0, 20);
for (int y = 0; y < sheetData.Height; y++)
{
var row = new FlowLayoutWidget()
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
};
this.AddChild(row);
// add row count
row.AddChild(new TextWidget((y + 1).ToString())
dataGrid.GetCell(0, y + 1).AddChild(new TextWidget((y + 1).ToString())
{
TextColor = theme.TextColor,
VAnchor = VAnchor.Center
});
for (int x = 0; x < sheetData.Width; x++)
@ -122,11 +114,13 @@ namespace MatterHackers.MatterControl.DesignTools
SelectAllOnFocus = true,
};
edit.VAnchor |= VAnchor.Center;
CellWidgetsByLocation.Add((capturedX, capturedY), edit);
edit.MouseDown += (s, e) => SelectCell(capturedX, capturedY);
row.AddChild(edit);
dataGrid.GetCell(x + 1, y + 1).AddChild(edit);
edit.ActualTextEditWidget.EditComplete += (s, e) =>
{
editSelectedExpression.Text = edit.Text;
@ -134,6 +128,8 @@ namespace MatterHackers.MatterControl.DesignTools
sheetData.Recalculate();
};
}
dataGrid.ExpandToFitContent();
}
}

@ -1 +1 @@
Subproject commit e287a8facbfc409fdf281192eb84f338a7fb71f9
Subproject commit e4759abbec979a510d08aaea77c724000541bb51

@ -1 +1 @@
Subproject commit 657d27ede7f8b2e30a716dad426ae8b1d0657967
Subproject commit 41e9e098c5ca15eb6db6b123f0c1c38415ab92f9

View file

@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
var cube = testRunner.GetObjectByName(primitive, out _) as CubeObject3D;
Assert.AreEqual(20, cube.Width.Value(cube));
Assert.AreEqual(20, cube.Width.Value(cube), .001);
// Select scene object
testRunner.Select3DPart(primitive);
@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.Greater(cube.Width.Value(cube), 20.0);
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube));
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
// try scaling by text entry
testRunner.ClickByName("ScaleWidthLeft")
@ -97,7 +97,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.AreEqual(35, cube.Width.Value(cube));
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube));
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
// try scaling by text entry of an equation
testRunner.ClickByName("Width Field")
@ -119,7 +119,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.IsFalse(testRunner.NameExists("ScaleWidthRight", .2));
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube));
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
return Task.CompletedTask;
}, overrideWidth: 1300, maxTimeToRun: 60);