2017-10-14 00:20:41 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2017, 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 System;
|
2018-05-17 13:27:52 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-10-14 00:20:41 -07:00
|
|
|
|
using MatterHackers.Agg.Image;
|
|
|
|
|
|
using MatterHackers.Agg.Platform;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2018-03-08 17:23:03 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2017-10-14 00:20:41 -07:00
|
|
|
|
|
2018-01-08 21:29:41 -08:00
|
|
|
|
namespace MatterHackers.MatterControl.CustomWidgets
|
2017-10-14 00:20:41 -07:00
|
|
|
|
{
|
2018-01-10 23:59:36 -08:00
|
|
|
|
public class ExpandCheckboxButton : FlowLayoutWidget, ICheckbox
|
2017-10-14 00:20:41 -07:00
|
|
|
|
{
|
|
|
|
|
|
public event EventHandler CheckedStateChanged;
|
|
|
|
|
|
|
2022-07-16 07:46:44 -07:00
|
|
|
|
private ThemedIconButton imageButton;
|
2017-10-14 00:20:41 -07:00
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
private ImageBuffer arrowRight;
|
2018-02-09 22:51:18 -08:00
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
private ImageBuffer arrowDown;
|
2017-10-14 00:20:41 -07:00
|
|
|
|
|
2017-10-22 18:12:03 -07:00
|
|
|
|
private TextWidget textWidget;
|
|
|
|
|
|
|
2019-04-26 13:03:35 -07:00
|
|
|
|
private bool _expandable = true;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _checked;
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
public ExpandCheckboxButton(string text, ThemeConfig theme, int pointSize = 11, bool expandable = true)
|
2017-10-14 00:20:41 -07:00
|
|
|
|
{
|
2021-05-21 15:23:25 -07:00
|
|
|
|
arrowRight = StaticData.Instance.LoadIcon("fa-angle-right_12.png", 12, 12).SetToColor(theme.TextColor);
|
|
|
|
|
|
arrowDown = StaticData.Instance.LoadIcon("fa-angle-down_12.png", 12, 12).SetToColor(theme.TextColor);
|
2017-10-14 00:20:41 -07:00
|
|
|
|
|
2022-07-16 07:46:44 -07:00
|
|
|
|
imageButton = new ThemedIconButton(arrowRight, theme)
|
2017-10-14 00:20:41 -07:00
|
|
|
|
{
|
2018-09-11 08:53:04 -07:00
|
|
|
|
MinimumSize = new Vector2(theme.ButtonHeight, theme.ButtonHeight),
|
2018-02-09 22:51:18 -08:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2018-09-11 08:53:04 -07:00
|
|
|
|
Selectable = false,
|
|
|
|
|
|
Enabled = expandable
|
2017-10-14 00:20:41 -07:00
|
|
|
|
};
|
2018-02-09 22:51:18 -08:00
|
|
|
|
this.AddChild(imageButton);
|
|
|
|
|
|
|
|
|
|
|
|
_expandable = expandable;
|
|
|
|
|
|
|
2018-11-03 09:13:07 -07:00
|
|
|
|
this.AddChild(textWidget = new TextWidget(text, pointSize: pointSize, textColor: theme.TextColor)
|
2017-10-22 18:12:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
AutoExpandBoundsToText = true
|
2017-10-14 00:20:41 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
foreach(var child in this.Children)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Selectable = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 13:27:52 -07:00
|
|
|
|
internal void SetIconMargin(BorderDouble margin)
|
|
|
|
|
|
{
|
|
|
|
|
|
imageButton.Margin = margin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-26 22:10:49 -07:00
|
|
|
|
public bool AlwaysShowArrow { get; set; }
|
|
|
|
|
|
|
2018-02-09 22:51:18 -08:00
|
|
|
|
public bool Expandable
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _expandable;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_expandable != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
_expandable = value;
|
2018-05-17 13:27:52 -07:00
|
|
|
|
|
2018-10-26 22:10:49 -07:00
|
|
|
|
imageButton.SetIcon(_expandable || this.AlwaysShowArrow ? arrowRight : new ImageBuffer());
|
|
|
|
|
|
imageButton.Enabled = _expandable;
|
|
|
|
|
|
|
2018-09-11 08:53:04 -07:00
|
|
|
|
this.MinimumSize = new Vector2((_expandable) ? this.MinimumSize.X : 10, this.MinimumSize.Y);
|
2018-02-09 22:51:18 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-26 13:03:35 -07:00
|
|
|
|
public bool ShowIcon
|
|
|
|
|
|
{
|
|
|
|
|
|
get => imageButton.Visible;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!value)
|
|
|
|
|
|
{
|
|
|
|
|
|
imageButton.Parent.MinimumSize = new Vector2(0, imageButton.Height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
imageButton.Visible = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-22 18:12:03 -07:00
|
|
|
|
public override string Text
|
|
|
|
|
|
{
|
|
|
|
|
|
get => textWidget.Text;
|
|
|
|
|
|
set => textWidget.Text = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 00:20:41 -07:00
|
|
|
|
public void OnCheckChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
CheckedStateChanged?.Invoke(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-04 11:02:50 -07:00
|
|
|
|
protected override void OnClick(MouseEventArgs mouseEvent)
|
2017-10-14 00:20:41 -07:00
|
|
|
|
{
|
2018-09-11 08:53:46 -07:00
|
|
|
|
if (this.Expandable)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() => this.Checked = !this.Checked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 00:20:41 -07:00
|
|
|
|
base.OnClick(mouseEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Checked
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _checked;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_checked != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
_checked = value;
|
|
|
|
|
|
|
2018-09-07 15:16:40 -07:00
|
|
|
|
if (this.Expandable)
|
|
|
|
|
|
{
|
|
|
|
|
|
imageButton.SetIcon(value ? arrowDown : arrowRight);
|
|
|
|
|
|
}
|
2017-10-14 00:20:41 -07:00
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
|
|
|
|
OnCheckChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|