GalleryIconListViewVisualItem
This commit is contained in:
@@ -0,0 +1,106 @@
|
|||||||
|
using Telerik.WinControls;
|
||||||
|
using Telerik.WinControls.UI;
|
||||||
|
|
||||||
|
namespace Pilz.UI.WinForms.Telerik.Controls.RadListView;
|
||||||
|
|
||||||
|
public class GalleryIconListViewVisualItem : IconListViewVisualItem
|
||||||
|
{
|
||||||
|
public event EventHandler? ButtonClicked;
|
||||||
|
|
||||||
|
private readonly RadPanelElement panel = new();
|
||||||
|
private readonly StackLayoutElement stack = new();
|
||||||
|
private readonly LightVisualElement titleElem = new();
|
||||||
|
private readonly LightVisualElement imgElem = new();
|
||||||
|
private readonly LightVisualButtonElement buttonElem = new();
|
||||||
|
|
||||||
|
protected override Type ThemeEffectiveType => typeof(IconListViewVisualItem);
|
||||||
|
|
||||||
|
public RadSvgImage ButtonSvgImage
|
||||||
|
{
|
||||||
|
get => buttonElem.SvgImage;
|
||||||
|
set => buttonElem.SvgImage = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ButtonVisible
|
||||||
|
{
|
||||||
|
get => buttonElem.Visibility != ElementVisibility.Collapsed;
|
||||||
|
set => buttonElem.Visibility = value ? ElementVisibility.Hidden : ElementVisibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CreateChildElements()
|
||||||
|
{
|
||||||
|
base.CreateChildElements();
|
||||||
|
|
||||||
|
panel.StretchHorizontally = true;
|
||||||
|
panel.StretchVertically = true;
|
||||||
|
panel.ShouldHandleMouseInput = false;
|
||||||
|
panel.NotifyParentOnMouseInput = true;
|
||||||
|
panel.PanelBorder.Visibility = ElementVisibility.Collapsed;
|
||||||
|
|
||||||
|
stack.Orientation = Orientation.Vertical;
|
||||||
|
stack.StretchHorizontally = true;
|
||||||
|
stack.StretchVertically = true;
|
||||||
|
stack.ShouldHandleMouseInput = false;
|
||||||
|
stack.NotifyParentOnMouseInput = true;
|
||||||
|
|
||||||
|
imgElem.Margin = new Padding(0, 10, 0, 10);
|
||||||
|
imgElem.ShouldHandleMouseInput = false;
|
||||||
|
imgElem.NotifyParentOnMouseInput = true;
|
||||||
|
|
||||||
|
titleElem.Margin = new Padding(0, 10, 0, -10);
|
||||||
|
titleElem.AutoSize = true;
|
||||||
|
titleElem.ShouldHandleMouseInput = false;
|
||||||
|
titleElem.NotifyParentOnMouseInput = true;
|
||||||
|
|
||||||
|
buttonElem.Size = new Size(20, 20);
|
||||||
|
buttonElem.ImageDrawType = ImageDrawType.Svg;
|
||||||
|
buttonElem.ShouldHandleMouseInput = true;
|
||||||
|
buttonElem.NotifyParentOnMouseInput = true;
|
||||||
|
buttonElem.Click += ButtonElem_Click;
|
||||||
|
buttonElem.Visibility = ElementVisibility.Collapsed;
|
||||||
|
|
||||||
|
stack.Children.Add(imgElem);
|
||||||
|
stack.Children.Add(titleElem);
|
||||||
|
panel.Children.Add(stack);
|
||||||
|
panel.Children.Add(buttonElem);
|
||||||
|
Children.Add(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonElem_Click(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ButtonClicked?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DoMouseEnter(EventArgs e)
|
||||||
|
{
|
||||||
|
base.DoMouseEnter(e);
|
||||||
|
if (buttonElem.Visibility == ElementVisibility.Hidden)
|
||||||
|
buttonElem.Visibility = ElementVisibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DoMouseLeave(EventArgs e)
|
||||||
|
{
|
||||||
|
base.DoMouseLeave(e);
|
||||||
|
if (buttonElem.Visibility == ElementVisibility.Visible)
|
||||||
|
buttonElem.Visibility = ElementVisibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ArrangeContentCore(RectangleF clientRect)
|
||||||
|
{
|
||||||
|
base.ArrangeContentCore(clientRect);
|
||||||
|
buttonElem.Arrange(new RectangleF(
|
||||||
|
panel.Size.Width - buttonElem.DesiredSize.Width - buttonElem.Padding.Right,
|
||||||
|
buttonElem.Padding.Top,
|
||||||
|
buttonElem.DesiredSize.Width,
|
||||||
|
buttonElem.DesiredSize.Height));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SynchronizeProperties()
|
||||||
|
{
|
||||||
|
base.SynchronizeProperties();
|
||||||
|
DrawText = false;
|
||||||
|
DrawImage = false;
|
||||||
|
titleElem.Text = Data.Text;
|
||||||
|
imgElem.Image = Data.Image;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.14.2</Version>
|
<Version>2.14.3</Version>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user