Browse Source

Change Visibility to IsVisible.

pull/4/head
Steven Kirk 12 years ago
parent
commit
0b81fc2ca0
  1. 16
      Perspex.Direct2D1/Renderer.cs
  2. 25
      Perspex/Controls/Border.cs
  3. 13
      Perspex/Controls/ContentPresenter.cs
  4. 27
      Perspex/Controls/Control.cs
  5. 77
      Perspex/Controls/StackPanel.cs
  6. 13
      Perspex/Controls/TemplatedControl.cs
  7. 22
      Perspex/Controls/TextBlock.cs
  8. 2
      Perspex/IVisual.cs
  9. 29
      Perspex/Layout/LayoutHelper.cs
  10. 2
      Perspex/Shapes/Shape.cs
  11. 4
      Perspex/Themes/Default/CheckBoxStyle.cs
  12. 19
      Perspex/Visual.cs

16
Perspex.Direct2D1/Renderer.cs

@ -7,6 +7,7 @@
namespace Perspex.Direct2D1
{
using System;
using System.Linq;
using Perspex.Direct2D1.Media;
using Perspex.Platform;
using SharpDX;
@ -119,15 +120,18 @@ namespace Perspex.Direct2D1
/// <param name="context">The drawing context.</param>
private void Render(IVisual visual, DrawingContext context)
{
visual.Render(context);
foreach (IVisual child in visual.VisualChildren)
if (visual.IsVisible)
{
Matrix translate = Matrix.Translation(child.Bounds.X, child.Bounds.Y);
visual.Render(context);
using (context.PushTransform(translate))
foreach (IVisual child in visual.VisualChildren)
{
this.Render(child, context);
Matrix translate = Matrix.Translation(child.Bounds.X, child.Bounds.Y);
using (context.PushTransform(translate))
{
this.Render(child, context);
}
}
}
}

25
Perspex/Controls/Border.cs

@ -23,22 +23,19 @@ namespace Perspex.Controls
public override void Render(IDrawingContext context)
{
if (this.Visibility == Visibility.Visible)
{
Brush background = this.Background;
Brush borderBrush = this.BorderBrush;
double borderThickness = this.BorderThickness;
Rect rect = new Rect(this.ActualSize).Deflate(BorderThickness / 2);
Brush background = this.Background;
Brush borderBrush = this.BorderBrush;
double borderThickness = this.BorderThickness;
Rect rect = new Rect(this.ActualSize).Deflate(BorderThickness / 2);
if (background != null)
{
context.FillRectange(background, rect);
}
if (background != null)
{
context.FillRectange(background, rect);
}
if (borderBrush != null && borderThickness > 0)
{
context.DrawRectange(new Pen(borderBrush, borderThickness), rect);
}
if (borderBrush != null && borderThickness > 0)
{
context.DrawRectange(new Pen(borderBrush, borderThickness), rect);
}
}

13
Perspex/Controls/ContentPresenter.cs

@ -145,15 +145,12 @@ namespace Perspex.Controls
protected override Size MeasureOverride(Size availableSize)
{
if (this.Visibility != Visibility.Collapsed)
{
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{
child.Measure(availableSize);
return child.DesiredSize.Value;
}
if (child != null)
{
child.Measure(availableSize);
return child.DesiredSize.Value;
}
return new Size();

27
Perspex/Controls/Control.cs

@ -128,6 +128,8 @@ namespace Perspex.Controls
this.PointerLeave += (s, e) => this.IsPointerOver = false;
this.AddPseudoClass(IsPointerOverProperty, ":pointerover");
this.AddPseudoClass(IsFocusedProperty, ":focus");
this.GetObservable(IsVisibleProperty).Subscribe(_ => this.InvalidateMeasure());
}
public event EventHandler<RoutedEventArgs> GotFocus
@ -401,7 +403,7 @@ namespace Perspex.Controls
{
ILayoutRoot root = this.GetLayoutRoot();
if (root != null)
if (root != null && root.LayoutManager != null)
{
root.LayoutManager.InvalidateMeasure(this);
}
@ -474,16 +476,23 @@ namespace Perspex.Controls
protected virtual Size MeasureCore(Size availableSize)
{
Size measuredSize = this.MeasureOverride(availableSize.Deflate(this.Margin));
double width = (this.Width > 0) ? this.Width : measuredSize.Width;
double height = (this.Height > 0) ? this.Height : measuredSize.Height;
if (this.IsVisible)
{
Size measuredSize = this.MeasureOverride(availableSize.Deflate(this.Margin));
double width = (this.Width > 0) ? this.Width : measuredSize.Width;
double height = (this.Height > 0) ? this.Height : measuredSize.Height;
width = Math.Min(width, this.MaxWidth);
width = Math.Max(width, this.MinWidth);
height = Math.Min(height, this.MaxHeight);
height = Math.Max(height, this.MinHeight);
width = Math.Min(width, this.MaxWidth);
width = Math.Max(width, this.MinWidth);
height = Math.Min(height, this.MaxHeight);
height = Math.Max(height, this.MinHeight);
return new Size(width, height);
return new Size(width, height);
}
else
{
return new Size();
}
}
protected virtual Size MeasureOverride(Size availableSize)

77
Perspex/Controls/StackPanel.cs

@ -40,61 +40,56 @@ namespace Perspex.Controls
protected override Size MeasureOverride(Size availableSize)
{
if (this.Visibility != Visibility.Collapsed)
double childAvailableWidth = double.PositiveInfinity;
double childAvailableHeight = double.PositiveInfinity;
if (this.Orientation == Orientation.Vertical)
{
double childAvailableWidth = double.PositiveInfinity;
double childAvailableHeight = double.PositiveInfinity;
childAvailableWidth = availableSize.Width;
if (this.Orientation == Orientation.Vertical)
if (!double.IsNaN(this.Width))
{
childAvailableWidth = availableSize.Width;
childAvailableWidth = this.Width;
}
if (!double.IsNaN(this.Width))
{
childAvailableWidth = this.Width;
}
childAvailableWidth = Math.Min(childAvailableWidth, this.MaxWidth);
childAvailableWidth = Math.Max(childAvailableWidth, this.MinWidth);
}
else
{
childAvailableHeight = availableSize.Height;
childAvailableWidth = Math.Min(childAvailableWidth, this.MaxWidth);
childAvailableWidth = Math.Max(childAvailableWidth, this.MinWidth);
}
else
if (!double.IsNaN(this.Height))
{
childAvailableHeight = availableSize.Height;
childAvailableHeight = this.Height;
}
if (!double.IsNaN(this.Height))
{
childAvailableHeight = this.Height;
}
childAvailableHeight = Math.Min(childAvailableHeight, this.MaxHeight);
childAvailableHeight = Math.Max(childAvailableHeight, this.MinHeight);
}
childAvailableHeight = Math.Min(childAvailableHeight, this.MaxHeight);
childAvailableHeight = Math.Max(childAvailableHeight, this.MinHeight);
}
double measuredWidth = 0;
double measuredHeight = 0;
double gap = this.Gap;
double measuredWidth = 0;
double measuredHeight = 0;
double gap = this.Gap;
foreach (Control child in this.Children)
{
child.Measure(new Size(childAvailableWidth, childAvailableHeight));
Size size = child.DesiredSize.Value;
foreach (Control child in this.Children)
if (Orientation == Orientation.Vertical)
{
child.Measure(new Size(childAvailableWidth, childAvailableHeight));
Size size = child.DesiredSize.Value;
if (Orientation == Orientation.Vertical)
{
measuredHeight += size.Height + gap;
measuredWidth = Math.Max(measuredWidth, size.Width);
}
else
{
measuredWidth += size.Width + gap;
measuredHeight = Math.Max(measuredHeight, size.Height);
}
measuredHeight += size.Height + gap;
measuredWidth = Math.Max(measuredWidth, size.Width);
}
else
{
measuredWidth += size.Width + gap;
measuredHeight = Math.Max(measuredHeight, size.Height);
}
return new Size(measuredWidth, measuredHeight);
}
return new Size();
return new Size(measuredWidth, measuredHeight);
}
protected override Size ArrangeOverride(Size finalSize)

13
Perspex/Controls/TemplatedControl.cs

@ -78,15 +78,12 @@ namespace Perspex.Controls
protected override Size MeasureOverride(Size availableSize)
{
if (this.Visibility != Visibility.Collapsed)
{
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{
child.Measure(availableSize);
return child.DesiredSize.Value;
}
if (child != null)
{
child.Measure(availableSize);
return child.DesiredSize.Value;
}
return new Size();

22
Perspex/Controls/TextBlock.cs

@ -42,27 +42,21 @@ namespace Perspex.Controls
public override void Render(IDrawingContext context)
{
if (this.Visibility == Visibility.Visible)
{
Brush background = this.Background;
if (background != null)
{
context.FillRectange(background, new Rect(this.ActualSize));
}
Brush background = this.Background;
context.DrawText(this.Foreground, new Rect(this.ActualSize), this.FormattedText);
if (background != null)
{
context.FillRectange(background, new Rect(this.ActualSize));
}
context.DrawText(this.Foreground, new Rect(this.ActualSize), this.FormattedText);
}
protected override Size MeasureOverride(Size availableSize)
{
if (this.Visibility != Visibility.Collapsed)
if (!string.IsNullOrEmpty(this.Text))
{
if (!string.IsNullOrEmpty(this.Text))
{
return this.FormattedText.Size;
}
return this.FormattedText.Size;
}
return new Size();

2
Perspex/IVisual.cs

@ -16,6 +16,8 @@ namespace Perspex
IEnumerable<IVisual> ExistingVisualChildren { get; }
bool IsVisible { get; }
IEnumerable<IVisual> VisualChildren { get; }
IVisual VisualParent { get; set; }

29
Perspex/Layout/LayoutHelper.cs

@ -24,25 +24,22 @@ namespace Perspex.Layout
double width = 0;
double height = 0;
if (decorator.Visibility != Visibility.Collapsed)
if (content != null)
{
if (content != null)
{
content.Measure(availableSize);
Size s = content.DesiredSize.Value.Inflate(padding);
width = s.Width;
height = s.Height;
}
content.Measure(availableSize);
Size s = content.DesiredSize.Value.Inflate(padding);
width = s.Width;
height = s.Height;
}
if (decorator.Width > 0)
{
width = decorator.Width;
}
if (decorator.Width > 0)
{
width = decorator.Width;
}
if (decorator.Height > 0)
{
height = decorator.Height;
}
if (decorator.Height > 0)
{
height = decorator.Height;
}
return new Size(width, height);

2
Perspex/Shapes/Shape.cs

@ -130,7 +130,7 @@ namespace Perspex.Shapes
public override void Render(IDrawingContext context)
{
if (this.RenderedGeometry != null && this.Visibility == Visibility.Visible)
if (this.RenderedGeometry != null)
{
context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry);
}

4
Perspex/Themes/Default/CheckBoxStyle.cs

@ -30,14 +30,14 @@ namespace Perspex.Themes.Default
{
Setters = new[]
{
new Setter(TextBlock.VisibilityProperty, Visibility.Hidden),
new Setter(Shape.IsVisibleProperty, false),
},
},
new Style(x => x.OfType<CheckBox>().Class(":checked").Template().Id("checkMark"))
{
Setters = new[]
{
new Setter(TextBlock.VisibilityProperty, Visibility.Visible),
new Setter(Shape.IsVisibleProperty, true),
},
},
});

19
Perspex/Visual.cs

@ -14,17 +14,10 @@ namespace Perspex
using Perspex.Rendering;
using Splat;
public enum Visibility
{
Visible,
Hidden,
Collapsed,
}
public abstract class Visual : PerspexObject, IVisual
{
public static readonly PerspexProperty<Visibility> VisibilityProperty =
PerspexProperty.Register<Visual, Visibility>("Visibility");
public static readonly PerspexProperty<bool> IsVisibleProperty =
PerspexProperty.Register<Visual, bool>("IsVisible", true);
private IVisual visualParent;
@ -32,13 +25,13 @@ namespace Perspex
public Visual()
{
this.GetObservable(VisibilityProperty).Subscribe(_ => this.InvalidateVisual());
this.GetObservable(IsVisibleProperty).Subscribe(_ => this.InvalidateVisual());
}
public Visibility Visibility
public bool IsVisible
{
get { return this.GetValue(VisibilityProperty); }
set { this.SetValue(VisibilityProperty, value); }
get { return this.GetValue(IsVisibleProperty); }
set { this.SetValue(IsVisibleProperty, value); }
}
Rect IVisual.Bounds

Loading…
Cancel
Save