Skip to content

Commit

Permalink
Fixed review feedback
Browse files Browse the repository at this point in the history
Static check error fixed; Fixed rotating arrow heads
  • Loading branch information
pbrown12303 committed Sep 11, 2023
1 parent 58a0e64 commit 3be0276
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 70 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module fyne.io/x/fyne
go 1.14

require (
fyne.io/fyne/v2 v2.3.5
fyne.io/fyne/v2 v2.4.0
github.com/Andrew-M-C/go.jsonvalue v1.1.2-0.20211223013816-e873b56b4a84
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/gorilla/websocket v1.4.2
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780
github.com/stretchr/testify v1.8.1
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
github.com/stretchr/testify v1.8.4
github.com/twpayne/go-geom v1.0.0
github.com/wagslane/go-password-validator v0.3.0
golang.org/x/image v0.3.0
golang.org/x/image v0.11.0
)
111 changes: 78 additions & 33 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fyne.io/fyne/v2 v2.4.0 h1:LlyOyHmvkSo9IBm3aY+NVWSBIw+GMnssmyyIMK8F7zM=
fyne.io/fyne/v2 v2.4.0/go.mod h1:AWM1iPM2YfliduZ4u/kQzP9E6ARIWm0gg+57GpYzWro=
github.com/Andrew-M-C/go.jsonvalue v1.1.2-0.20211223013816-e873b56b4a84 h1:L2C3QKBQwuHuiKwaBj8HDs2r0bAUGqtBYe3ymG0S6Z4=
github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/wagslane/go-password-validator v0.3.0 h1:vfxOPzGHkz5S146HDpavl0cw1DSVP061Ry2PX0/ON6I=
2 changes: 2 additions & 0 deletions widget/diagramwidget/anchoredtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"image/color"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
Expand Down Expand Up @@ -40,6 +41,7 @@ func NewAnchoredText(text string) *AnchoredText {
at.textEntry = widget.NewEntryWithData(at.displayedTextBinding)
at.displayedTextBinding.AddListener(at)
at.textEntry.Wrapping = fyne.TextWrapOff
at.textEntry.Scroll = container.ScrollNone
at.textEntry.Validator = nil
at.ExtendBaseWidget(at)
return at
Expand Down
4 changes: 4 additions & 0 deletions widget/diagramwidget/arrowhead.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (ar *arrowheadRenderer) Refresh() {
ar.right.StrokeWidth = ar.arrowhead.StrokeWidth
ar.left.StrokeColor = ar.arrowhead.StrokeColor
ar.right.StrokeColor = ar.arrowhead.StrokeColor
ar.left.Position1 = fyne.Position{X: 0, Y: 0}
ar.left.Position2 = ar.arrowhead.LeftPoint()
ar.right.Position1 = fyne.Position{X: 0, Y: 0}
ar.right.Position2 = ar.arrowhead.RightPoint()
ar.left.Refresh()
ar.right.Refresh()
}
64 changes: 33 additions & 31 deletions widget/diagramwidget/diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Verify that interfaces are fully implemented
var _ fyne.Tappable = (*drawingArea)(nil)
var _ fyne.Tappable = (*DrawingArea)(nil)

type linkPadPair struct {
link *BaseDiagramLink
Expand All @@ -26,7 +26,7 @@ type linkPadPair struct {
type DiagramWidget struct {
widget.BaseWidget
scrollingContainer *container.Scroll
drawingArea *drawingArea
DrawingArea *DrawingArea

// ID is expected to be unique across all DiagramWidgets in the application.
ID string
Expand Down Expand Up @@ -89,9 +89,9 @@ func NewDiagramWidget(id string) *DiagramWidget {
selection: map[string]DiagramElement{},
diagramElementLinkDependencies: map[string][]linkPadPair{},
}
dw.drawingArea = newDrawingArea(dw)
dw.drawingArea.Resize(dw.DesiredSize)
dw.scrollingContainer = container.NewScroll(dw.drawingArea)
dw.DrawingArea = newDrawingArea(dw)
dw.DrawingArea.Resize(dw.DesiredSize)
dw.scrollingContainer = container.NewScroll(dw.DrawingArea)
appTheme := fyne.CurrentApp().Settings().Theme()
appVariant := fyne.CurrentApp().Settings().ThemeVariant()
dw.DefaultDiagramElementProperties.ForegroundColor = appTheme.Color(theme.ColorNameForeground, appVariant)
Expand Down Expand Up @@ -156,8 +156,8 @@ func (dw *DiagramWidget) addNode(node DiagramNode) {
// adjustBounds calculates the bounds of the diagram elements and adjusts the size of the drawing area accordingly
// If necessary, it also moves all the diagram elements so that their position coordinates are all positive
func (dw *DiagramWidget) adjustBounds() {
position := dw.drawingArea.Position()
size := dw.drawingArea.Size()
position := dw.DrawingArea.Position()
size := dw.DrawingArea.Size()
left := position.X
right := position.X + size.Width
top := position.Y
Expand All @@ -172,20 +172,20 @@ func (dw *DiagramWidget) adjustBounds() {
}
moveDelta := fyne.NewPos(0, 0)
moveDeltaChanged := false
if left < dw.drawingArea.Position().X {
if left < dw.DrawingArea.Position().X {
moveDelta.X = -left
moveDeltaChanged = true
}
if top < dw.drawingArea.Position().Y {
if top < dw.DrawingArea.Position().Y {
moveDelta.Y = -top
moveDeltaChanged = true
}
if moveDeltaChanged {
dw.moveDiagramElements(moveDelta)
// moving the elements might have pushed an element beyond the newly computed bounds.
// we have to recompute
position = dw.drawingArea.Position()
size = dw.drawingArea.Size()
position = dw.DrawingArea.Position()
size = dw.DrawingArea.Size()
left = position.X
right = position.X + size.Width
top = position.Y
Expand All @@ -200,7 +200,7 @@ func (dw *DiagramWidget) adjustBounds() {
}
}
dw.DesiredSize = fyne.NewSize(right-left, bottom-top)
dw.drawingArea.Resize(dw.DesiredSize)
dw.DrawingArea.Resize(dw.DesiredSize)
dw.scrollingContainer.Refresh()
}

Expand All @@ -211,7 +211,7 @@ func (dw *DiagramWidget) BringToFront(elementID string) {
diagramElement := value.(DiagramElement)
if diagramElement.GetDiagramElementID() == elementID {
dw.DiagramElements.MoveToBack(listElement)
dw.drawingArea.Refresh()
dw.DrawingArea.Refresh()
}
}
}
Expand All @@ -223,7 +223,7 @@ func (dw *DiagramWidget) BringForward(elementID string) {
diagramElement := value.(DiagramElement)
if diagramElement.GetDiagramElementID() == elementID {
dw.DiagramElements.MoveAfter(listElement, listElement.Next())
dw.drawingArea.Refresh()
dw.DrawingArea.Refresh()
}
}
}
Expand Down Expand Up @@ -467,7 +467,7 @@ func (dw *DiagramWidget) RemoveElement(elementID string) {
if element.IsLink() {
dw.removeDependenciesInvolvingLink(elementID)
}
dw.drawingArea.Refresh()
dw.DrawingArea.Refresh()
}

// SelectDiagramElement clears the selection, makes the indicated element the primary selection, and invokes
Expand Down Expand Up @@ -496,7 +496,7 @@ func (dw *DiagramWidget) SendToBack(elementID string) {
diagramElement := value.(DiagramElement)
if diagramElement.GetDiagramElementID() == elementID {
dw.DiagramElements.MoveToFront(listElement)
dw.drawingArea.Refresh()
dw.DrawingArea.Refresh()
}
}
}
Expand All @@ -508,7 +508,7 @@ func (dw *DiagramWidget) SendBackward(elementID string) {
diagramElement := value.(DiagramElement)
if diagramElement.GetDiagramElementID() == elementID {
dw.DiagramElements.MoveBefore(listElement, listElement.Prev())
dw.drawingArea.Refresh()
dw.DrawingArea.Refresh()
}
}
}
Expand Down Expand Up @@ -554,78 +554,80 @@ func (r *diagramWidgetRenderer) Objects() []fyne.CanvasObject {
}

func (r *diagramWidgetRenderer) Refresh() {
r.diagramWidget.drawingArea.Refresh()
r.diagramWidget.DrawingArea.Refresh()
}

type drawingArea struct {
// DrawingArea is the widget representing the page upon which the diagram appears.
type DrawingArea struct {
widget.BaseWidget
diagram *DiagramWidget
}

func newDrawingArea(diagram *DiagramWidget) *drawingArea {
drawingArea := &drawingArea{
func newDrawingArea(diagram *DiagramWidget) *DrawingArea {
drawingArea := &DrawingArea{
diagram: diagram,
}
drawingArea.ExtendBaseWidget(drawingArea)
return drawingArea
}

func (da *drawingArea) CreateRenderer() fyne.WidgetRenderer {
// CreateRenderer is the required function for widgets
func (da *DrawingArea) CreateRenderer() fyne.WidgetRenderer {
dar := &drawingAreaRenderer{}
dar.da = da
return dar
}

// DragEnd is called when the drag comes to an end. It refreshes the widget
func (da *drawingArea) DragEnd() {
func (da *DrawingArea) DragEnd() {
da.Refresh()
}

// Dragged responds to a drag movement in the background of the diagram. It moves the widget itself.
func (da *drawingArea) Dragged(event *fyne.DragEvent) {
func (da *DrawingArea) Dragged(event *fyne.DragEvent) {
delta := fyne.NewPos(event.Dragged.DX, event.Dragged.DY)
da.diagram.moveDiagramElements(delta)
da.diagram.adjustBounds()
}

// MouseDown responds to MouseDown events. It invokes the callback, if present
func (da *drawingArea) MouseDown(event *desktop.MouseEvent) {
func (da *DrawingArea) MouseDown(event *desktop.MouseEvent) {
if da.diagram.MouseDownCallback != nil {
da.diagram.MouseDownCallback(event)
}
}

// MouseIn responds to the mouse moving into the diagram. It presently is a noop
func (da *drawingArea) MouseIn(event *desktop.MouseEvent) {
func (da *DrawingArea) MouseIn(event *desktop.MouseEvent) {
if da.diagram.MouseInCallback != nil {
da.diagram.MouseInCallback(event)
}
}

// MouseMoved responds to mouse movements in the diagram. It presently is a noop
func (da *drawingArea) MouseMoved(event *desktop.MouseEvent) {
func (da *DrawingArea) MouseMoved(event *desktop.MouseEvent) {
if da.diagram.MouseMovedCallback != nil {
da.diagram.MouseMovedCallback(event)
}
}

// MouseOut responds to the mouse leaving the diagram. It presently is a noop
func (da *drawingArea) MouseOut() {
func (da *DrawingArea) MouseOut() {
if da.diagram.MouseOutCallback != nil {
da.diagram.MouseOutCallback()
}
}

// MouseUp responds to MouseUp events. It invokes the callback, if present
func (da *drawingArea) MouseUp(event *desktop.MouseEvent) {
func (da *DrawingArea) MouseUp(event *desktop.MouseEvent) {
if da.diagram.MouseUpCallback != nil {
da.diagram.MouseUpCallback(event)
}
}

// Tapped respondss to taps in the diagram background. It removes all diagram elements
// from the selection
func (da *drawingArea) Tapped(event *fyne.PointEvent) {
func (da *DrawingArea) Tapped(event *fyne.PointEvent) {
if da.diagram.OnTappedCallback != nil {
da.diagram.OnTappedCallback(da.diagram, event)
} else {
Expand All @@ -634,7 +636,7 @@ func (da *drawingArea) Tapped(event *fyne.PointEvent) {
}

type drawingAreaRenderer struct {
da *drawingArea
da *DrawingArea
}

func (dar *drawingAreaRenderer) Destroy() {
Expand Down
3 changes: 1 addition & 2 deletions widget/diagramwidget/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ type BaseDiagramNode struct {
// to retrieve the DiagramNode from the DiagramWidget. It is permissible for the canvas object to
// be nil when this function is called and then add the canvas object later.
func NewDiagramNode(diagram *DiagramWidget, obj fyne.CanvasObject, nodeID string) DiagramNode {
var diagramNode DiagramNode
diagramNode = &BaseDiagramNode{}
var diagramNode DiagramNode = &BaseDiagramNode{}
InitializeBaseDiagramNode(diagramNode, diagram, obj, nodeID)
return diagramNode
}
Expand Down

0 comments on commit 3be0276

Please sign in to comment.