mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 06:41:42 -05:00
ZoomWindowTool and MeasureAreaTool port the WinForms Zoom Window and Select Area actions onto the shared plate tool framework; PartHoverTip is the plate view's delayed drawing-name tooltip; PlateZoom gives the Zoom To areas. ViewTransform now scales with the viewport on resize as DrawControl does and zooms about its center by the menu's 1.5 step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using OpenNest.Desktop.Interaction;
|
|
using OpenNest.Desktop.Rendering;
|
|
|
|
namespace OpenNest.Desktop.Tests.Interaction;
|
|
|
|
public class PartHoverTipTests
|
|
{
|
|
private readonly Part part = new(new Drawing("bracket", InteractionFixtures.Rect(10, 10)), Geometry.Vector.Zero);
|
|
|
|
[Fact]
|
|
public void The_tip_shows_the_drawing_name_only_after_the_delay_at_the_rest_point()
|
|
{
|
|
var tip = new PartHoverTip();
|
|
ScreenPoint? asked = null;
|
|
|
|
Assert.False(tip.Elapse(_ => part));
|
|
Assert.False(tip.Move(new ScreenPoint(5, 6)));
|
|
Assert.True(tip.IsPending);
|
|
Assert.Null(tip.Text);
|
|
|
|
Assert.True(tip.Elapse(at =>
|
|
{
|
|
asked = at;
|
|
return part;
|
|
}));
|
|
|
|
Assert.Equal(new ScreenPoint(5, 6), asked);
|
|
Assert.Equal("bracket", tip.Text);
|
|
Assert.Same(part, tip.Part);
|
|
Assert.False(tip.IsPending);
|
|
// The timer elapsing again changes nothing.
|
|
Assert.False(tip.Elapse(_ => null));
|
|
Assert.Same(part, tip.Part);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_move_or_clear_hides_the_tip_and_reports_a_redraw()
|
|
{
|
|
var tip = new PartHoverTip();
|
|
tip.Move(new ScreenPoint(1, 1));
|
|
tip.Elapse(_ => part);
|
|
|
|
Assert.True(tip.Move(new ScreenPoint(2, 2)));
|
|
Assert.Null(tip.Text);
|
|
Assert.False(tip.Move(new ScreenPoint(3, 3)));
|
|
|
|
tip.Elapse(_ => part);
|
|
Assert.True(tip.Clear());
|
|
Assert.False(tip.IsPending);
|
|
Assert.False(tip.Elapse(_ => part));
|
|
Assert.False(tip.Clear());
|
|
}
|
|
|
|
[Fact]
|
|
public void Over_bare_plate_no_tip_shows()
|
|
{
|
|
var tip = new PartHoverTip();
|
|
tip.Move(new ScreenPoint(1, 1));
|
|
|
|
Assert.False(tip.Elapse(_ => null));
|
|
Assert.Null(tip.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void The_tip_sits_above_right_and_flips_at_the_right_and_top_edges()
|
|
{
|
|
Assert.Equal((116.0, 74.0, 46.0, 24.0), PartHoverTip.Place(new ScreenPoint(100, 100), 40, 20, 1000));
|
|
// Past the right edge: to the left of the pointer.
|
|
Assert.Equal((52.0, 74.0, 46.0, 24.0), PartHoverTip.Place(new ScreenPoint(100, 100), 40, 20, 150));
|
|
// Past the top: below the pointer.
|
|
Assert.Equal((116.0, 30.0, 46.0, 24.0), PartHoverTip.Place(new ScreenPoint(100, 10), 40, 20, 1000));
|
|
}
|
|
}
|