Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping for helpers, comments, and new helper features #453

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 109 additions & 82 deletions src/Renderer/Common/CommonTypes.fs

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions src/Renderer/Common/DrawHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ type PortLocation = {
R: float
}

type MouseOp =
type MouseOp =
/// button up
| Up
/// button down
| Down
/// Move with button up
| Move
| Move
/// Move with button Down
| Drag

Expand All @@ -46,7 +46,7 @@ type MouseT = {
/// Record to help draw SVG circles
type Circle = {
/// Radius of the circle
R: float
R: float
/// color of outline: default => black color
Stroke: string
/// width of outline: default => thin
Expand Down Expand Up @@ -108,7 +108,7 @@ let getTextWidthInPixels (font:Text) (txt:string) =
canvasWidthContext.font <- askedFont
//printf "Measururing '%s' -> '%s' with txt '%s' - fontSize=%s, sizeInpx = %.2f" askedFont canvasWidthContext.font txt font.FontSize sizeInPx
let textMetrics = canvasWidthContext.measureText(txt)
let ms = textMetrics.width
let ms = textMetrics.width
ms

/// Default line, change this one to create new lines
Expand Down Expand Up @@ -180,7 +180,7 @@ let uuid():string = System.Guid.NewGuid.ToString()

// ----------------------------- SVG Helpers ----------------------------- //

/// Makes a line ReactElement, wildcard inputs as position can be a number or a string
/// Makes a line ReactElement, wildcard inputs as position can be a number or a string
let makeLine (x1: 'a) (y1: 'b) (x2: 'c) (y2: 'd) (lineParameters: Line) =
line [
X1 x1
Expand Down Expand Up @@ -248,8 +248,8 @@ let makePath (startingPoint: XYPos) (startingControlPoint: XYPos) (endingControl
SVGAttr.StrokeLinecap pathParameters.StrokeLinecap
SVGAttr.Fill pathParameters.Fill
] []
/// Makes a polygon ReactElement, points are to be given as a correctly formatted SVGAttr.Points string

/// Makes a polygon ReactElement, points are to be given as a correctly formatted SVGAttr.Points string
let makePolygon (points: string) (polygonParameters: Polygon) =
polygon [
SVGAttr.Points points
Expand All @@ -258,12 +258,12 @@ let makePolygon (points: string) (polygonParameters: Polygon) =
SVGAttr.Fill polygonParameters.Fill
SVGAttr.FillOpacity polygonParameters.FillOpacity
] []


/// Makes a circle ReactElement
let makeCircle (centreX: float) (centreY: float) (circleParameters: Circle) =
circle
[
[
Cx centreX
Cy centreY
R circleParameters.R
Expand All @@ -272,36 +272,36 @@ let makeCircle (centreX: float) (centreY: float) (circleParameters: Circle) =
SVGAttr.Stroke circleParameters.Stroke
SVGAttr.StrokeWidth circleParameters.StrokeWidth
] []

/// Makes a text ReactElement
let makeText (posX: float) (posY: float) (displayedText: string) (textParameters: Text) =
text [
X posX;
Y posY;
X posX;
Y posY;
Style [
TextAnchor textParameters.TextAnchor
DominantBaseline textParameters.DominantBaseline
FontWeight textParameters.FontWeight
FontSize textParameters.FontSize
FontFamily textParameters.FontFamily
Fill textParameters.Fill
UserSelect textParameters.UserSelect
UserSelect textParameters.UserSelect
]
] [str <| sprintf "%s" (displayedText)]

/// makes a two-line text ReactElement
/// Dy parameter determines line spacing
let makeTwoLinesOfText (posX: float) (posY: float) (line1: string) (line2: string) (textParameters: Text) =
text [
X posX;
Y posY;
X posX;
Y posY;
Style [
TextAnchor textParameters.TextAnchor
DominantBaseline textParameters.DominantBaseline
FontWeight textParameters.FontWeight
FontSize textParameters.FontSize
Fill textParameters.Fill
UserSelect textParameters.UserSelect
UserSelect textParameters.UserSelect
]
] [tspan [] [str line1]; tspan [Dy "1.2em"] [str line2] ]

Expand All @@ -317,13 +317,13 @@ let getColorString (col: CommonTypes.HighLightColor) =
/// Calculates if two bounding boxes intersect by comparing corner coordinates of each box
let boxesIntersect (box1: BoundingBox) (box2: BoundingBox) =
// Requires min and max since H & W can be negative, i.e. we don't know which corner is which automatically
// Boxes intersect if there is overlap in both x and y coordinates
// Boxes intersect if there is overlap in both x and y coordinates
min box1.TopLeft.X (box1.TopLeft.X + box1.W) < max box2.TopLeft.X (box2.TopLeft.X + box2.W)
&& min box2.TopLeft.X (box2.TopLeft.X + box2.W) < max box1.TopLeft.X (box1.TopLeft.X + box1.W)
&& min box1.TopLeft.Y (box1.TopLeft.Y + box1.H) < max box2.TopLeft.Y (box2.TopLeft.Y + box2.H)
&& min box2.TopLeft.Y (box2.TopLeft.Y + box2.H) < max box1.TopLeft.Y (box1.TopLeft.Y + box1.H)





Loading