本文整理汇总了C#中Cell.Map方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.Map方法的具体用法?C# Cell.Map怎么用?C# Cell.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cell
的用法示例。
在下文中一共展示了Cell.Map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FrButton
private FrButton(Cell<string> label, StreamLoop<Unit> sClicked)
: base((size, sMouse, sKey, focus, idSupply) =>
{
Stream<Unit> sPressed = sMouse.Snapshot(size,
(e, mSize) => mSize.Match(
s =>
{
MouseButtonEventArgs b = e.Args as MouseButtonEventArgs;
Point p = e.GetPosition();
return b != null && b.ChangedButton == MouseButton.Left && b.ButtonState == MouseButtonState.Pressed
&& p.X >= 2 && p.X < s.Width - 2 && p.Y >= 2 && p.Y < s.Height - 2
? Maybe.Just(Unit.Value)
: Maybe.Nothing<Unit>();
},
Maybe.Nothing<Unit>)).FilterMaybe();
Stream<Unit> sReleased = sMouse.Snapshot(size,
(e, mSize) => mSize.Match(
s =>
{
MouseButtonEventArgs b = e.Args as MouseButtonEventArgs;
return b != null && b.ChangedButton == MouseButton.Left && b.ButtonState == MouseButtonState.Released
? Maybe.Just(Unit.Value)
: Maybe.Nothing<Unit>();
},
Maybe.Nothing<Unit>)).FilterMaybe();
Cell<bool> pressed = sPressed.Map(_ => true).OrElse(sReleased.Map(_ => false)).Hold(false);
sClicked.Loop(sReleased.Gate(pressed));
Typeface typeface = new Typeface(new FontFamily("Helvetica"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
Cell<Size> desiredSize = label.Map(l =>
{
Size labelSize = FontUtilities.MeasureString(l, typeface, 13);
return new Size(labelSize.Width + 14, labelSize.Height + 10);
});
return new Output(
label.Lift(
size, pressed,
(l, mSize, p) => new DrawableDelegate(d =>
{
mSize.Match(sz =>
{
d.DrawRectangle(p ? Brushes.DarkGray : Brushes.LightGray, new Pen(Brushes.Black, 1), new Rect(new Point(2, 2), new Size(sz.Width - 5, sz.Height - 5)));
FormattedText t = FontUtilities.GetStandardFormattedText(l, typeface, 13, Brushes.Black);
d.DrawText(t, new Point((sz.Width - t.Width) / 2, (sz.Height - t.Height) / 2));
}, () => { });
})),
desiredSize,
Stream.Never<long>());
})
{
this.SClicked = sClicked;
}
示例2: BounceAt
private static Stream<Signal> BounceAt(TimerSystem<double> sys,
Cell<Signal> vel, Cell<Signal> pos, double target)
{
return sys.At(pos.Map(p => p.When(target))).Snapshot(vel, (t, v) =>
new Signal(t, v.A, v.B, -v.ValueAt(t) * Restitution));
}