finish zh document and vertical layout design

This commit is contained in:
2021-09-21 20:17:03 +08:00
parent 352c133620
commit 0534b22501
6 changed files with 422 additions and 156 deletions

View File

@ -16,29 +16,94 @@ using System.Windows.Shapes;
namespace BallanceTASEditor.UI {
public class TASSlider {
public TASSlider(Slider slider) {
mSlider = slider;
mSlider.Minimum = 0;
public TASSlider(TASSliderComponents _components) {
components = _components;
components.mSlider.Minimum = 0;
mIsHorizontalLayout = true;
mSlider.ValueChanged += func_SliderValueChanged;
components.mSlider.ValueChanged += func_SliderValueChanged;
}
public event Action<long> ValueChanged;
Slider mSlider;
TASSliderComponents components;
bool mIsHorizontalLayout;
public void MoveSliderManually(bool isPrev, bool isFast, int fastCount) {
var step = isFast ? fastCount : 1;
mSlider.Value = Util.Clamp(mSlider.Value.ToInt32() + (isPrev ? -1 : 1) * step, mSlider.Minimum.ToInt32(), mSlider.Maximum.ToInt32());
components.mSlider.Value = Core.Util.Clamp(components.mSlider.Value.ToInt32() + (isPrev ? -1 : 1) * step, components.mSlider.Minimum.ToInt32(), components.mSlider.Maximum.ToInt32());
}
public void UpdateRange(TASFile mFile) {
mSlider.Maximum = mFile.mFrameCount - 1;
mSlider.Value = mFile.GetPointerIndex();
components.mSlider.Maximum = mFile.mFrameCount - 1;
components.mSlider.Value = mFile.GetPointerIndex();
}
private void func_SliderValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
ValueChanged?.Invoke(e.NewValue.ToInt64());
}
public void ChangeLayout(bool isHorizontal) {
if (isHorizontal == mIsHorizontalLayout) return;
// the layout changed, re-construct elements
mIsHorizontalLayout = isHorizontal;
// change container
components.container.RowDefinitions.Clear();
components.container.ColumnDefinitions.Clear();
if (mIsHorizontalLayout) {
for(int i = 0; i < 4; i++) {
UI.Util.GridColumnAdder(components.container, GridLength.Auto);
}
UI.Util.GridColumnAdder(components.container, new GridLength(1, GridUnitType.Star));
} else {
for (int i = 0; i < 4; i++) {
UI.Util.GridRowAdder(components.container, GridLength.Auto);
}
UI.Util.GridRowAdder(components.container, new GridLength(1, GridUnitType.Star));
}
// flip elements
UI.Util.SwapGridItemRC(components.btnFastPrev);
UI.Util.SwapGridItemRC(components.btnPrev);
UI.Util.SwapGridItemRC(components.btnNext);
UI.Util.SwapGridItemRC(components.btnFastNext);
UI.Util.SwapGridItemRC(components.mSlider);
// change transform
if (mIsHorizontalLayout) {
// clear all btn's transform and set slider as horizontal style
components.btnFastPrev.RenderTransform = Transform.Identity;
components.btnPrev.RenderTransform = Transform.Identity;
components.btnNext.RenderTransform = Transform.Identity;
components.btnFastNext.RenderTransform = Transform.Identity;
components.mSlider.RenderTransform = Transform.Identity;
components.mSlider.Orientation = Orientation.Horizontal;
components.mSlider.VerticalAlignment = VerticalAlignment.Center;
components.mSlider.HorizontalAlignment = HorizontalAlignment.Stretch;
} else {
components.btnFastPrev.RenderTransform = new RotateTransform(90);
components.btnPrev.RenderTransform = new RotateTransform(90);
components.btnNext.RenderTransform = new RotateTransform(90);
components.btnFastNext.RenderTransform = new RotateTransform(90);
components.mSlider.RenderTransform = new RotateTransform(180);
components.mSlider.Orientation = Orientation.Vertical;
components.mSlider.VerticalAlignment = VerticalAlignment.Stretch;
components.mSlider.HorizontalAlignment = HorizontalAlignment.Center;
}
}
}
public class TASSliderComponents {
public Grid container;
public Button btnFastPrev;
public Button btnPrev;
public Button btnNext;
public Button btnFastNext;
public Slider mSlider;
}
}