using System; using Gwen.ControlInternal; namespace Gwen.Control { /// /// Single property row. /// public class PropertyRow : Base { private readonly Label m_Label; private readonly Property.Base m_Property; private bool m_LastEditing; private bool m_LastHover; /// /// Invoked when the property value has changed. /// public event GwenEventHandler ValueChanged; /// /// Indicates whether the property value is being edited. /// public bool IsEditing { get { return m_Property != null && m_Property.IsEditing; } } /// /// Property value. /// public String Value { get { return m_Property.Value; } set { m_Property.Value = value; } } /// /// Indicates whether the control is hovered by mouse pointer. /// public override bool IsHovered { get { return base.IsHovered || (m_Property != null && m_Property.IsHovered); } } /// /// Property name. /// public String Label { get { return m_Label.Text; } set { m_Label.Text = value; } } /// /// Initializes a new instance of the class. /// /// Parent control. /// Property control associated with this row. public PropertyRow(Base parent, Property.Base prop) : base(parent) { PropertyRowLabel label = new PropertyRowLabel(this); label.Dock = Pos.Left; label.Alignment = Pos.Left | Pos.Top; label.Margin = new Margin(2, 2, 0, 0); m_Label = label; m_Property = prop; m_Property.Parent = this; m_Property.Dock = Pos.Fill; m_Property.ValueChanged += OnValueChanged; } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { /* SORRY */ if (IsEditing != m_LastEditing) { OnEditingChanged(); m_LastEditing = IsEditing; } if (IsHovered != m_LastHover) { OnHoverChanged(); m_LastHover = IsHovered; } /* SORRY */ skin.DrawPropertyRow(this, m_Label.Right, IsEditing, IsHovered | m_Property.IsHovered); } /// /// Lays out the control's interior according to alignment, padding, dock etc. /// /// Skin to use. protected override void Layout(Skin.Base skin) { Properties parent = Parent as Properties; if (null == parent) return; m_Label.Width = parent.SplitWidth; if (m_Property != null) { Height = m_Property.Height; } } protected virtual void OnValueChanged(Base control) { if (ValueChanged != null) ValueChanged.Invoke(this); } private void OnEditingChanged() { m_Label.Redraw(); } private void OnHoverChanged() { m_Label.Redraw(); } } }