图形化设计工具 v1.0.0.1

This commit is contained in:
杨红岩 2023-02-12 13:55:39 +08:00
parent ecd8b5fb1a
commit c467ce6009
4 changed files with 258 additions and 232 deletions

View File

@ -0,0 +1,229 @@
package ide
import (
"github.com/energye/energy/cef"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"github.com/energye/golcl/lcl/types/colors"
)
type anchor struct {
component *IDEComponent
top *lcl.TPanel
bottom *lcl.TPanel
left *lcl.TPanel
right *lcl.TPanel
topLeft *lcl.TPanel
topRight *lcl.TPanel
bottomLeft *lcl.TPanel
bottomRight *lcl.TPanel
isShow bool
dx, dy int32
}
func (m *anchor) hide() {
if m == nil || !m.isShow {
return
}
m.top.Hide()
m.bottom.Hide()
m.left.Hide()
m.right.Hide()
m.topLeft.Hide()
m.topRight.Hide()
m.bottomLeft.Hide()
m.bottomRight.Hide()
m.isShow = false
}
func (m *anchor) show() {
if m == nil || m.isShow {
return
}
m.top.Show()
m.bottom.Show()
m.left.Show()
m.right.Show()
m.topLeft.Show()
m.topRight.Show()
m.bottomLeft.Show()
m.bottomRight.Show()
m.isShow = true
}
func (m *anchor) remove() {
if m == nil {
return
}
m.top.Free()
m.bottom.Free()
m.left.Free()
m.right.Free()
m.topLeft.Free()
m.topRight.Free()
m.bottomLeft.Free()
m.bottomRight.Free()
}
func (m *anchor) refreshAnchorsPoint() {
if m == nil {
return
}
if m.isShow {
rect := m.component.parentToControl().BoundsRect()
m.left.SetBounds(rect.Left-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
m.top.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Top-pointWC, pointW, pointW)
m.bottom.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Bottom-pointWC, pointW, pointW)
m.right.SetBounds(rect.Right-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
m.topLeft.SetBounds(rect.Left-pointWC, rect.Top-pointWC, pointW, pointW)
m.topRight.SetBounds(rect.Right-pointWC, rect.Top-pointWC, pointW, pointW)
m.bottomLeft.SetBounds(rect.Left-pointWC, rect.Bottom-pointWC, pointW, pointW)
m.bottomRight.SetBounds(rect.Right-pointWC, rect.Bottom-pointWC, pointW, pointW)
}
}
func (m *anchor) newAnchorPoint(owner lcl.IWinControl, ht int32) *lcl.TPanel {
point := lcl.NewPanel(owner)
point.SetParent(owner)
point.SetBevelInner(types.BvSpace)
point.SetBevelOuter(types.BvNone)
cef.SetPanelBevelColor(point, colors.ClBlack)
point.SetColor(colors.ClTeal)
point.SetOnMouseMove(func(sender lcl.IObject, shift types.TShiftState, x, y int32) {
m.component.borderHT = ht
switch ht {
case HTTOP, HTBOTTOM:
point.SetCursor(types.CrSizeN)
case HTLEFT, HTRIGHT:
point.SetCursor(types.CrSizeW)
case HTTOPRIGHT, HTBOTTOMLEFT:
point.SetCursor(types.CrSizeSW)
case HTTOPLEFT, HTBOTTOMRIGHT:
point.SetCursor(types.CrSizeSE)
default:
point.SetCursor(types.CrDefault)
}
//m.mouseMove(sender, shift, x, y)
if m.component.isDown && m.component.isResize {
var (
x, y = x - m.component.anchor.dx, y - m.component.anchor.dy
rect = m.component.parentToControl().BoundsRect()
)
switch ht {
case HTRIGHT:
tmpWidth := rect.Width() + x
if tmpWidth <= minW {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetWidth(tmpWidth + border)
}
m.component.parentToControl().SetWidth(tmpWidth)
case HTLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
if tmpWidth <= minW {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetLeft(tmpX - border/2)
m.component.borderPanel.SetWidth(tmpWidth + border)
}
m.component.parentToControl().SetLeft(tmpX)
m.component.parentToControl().SetWidth(tmpWidth)
case HTTOP:
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
if tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetTop(tmpY - border/2)
m.component.borderPanel.SetHeight(tmpHeight + border)
}
m.component.parentToControl().SetTop(tmpY)
m.component.parentToControl().SetHeight(tmpHeight)
case HTBOTTOM:
tmpHeight := rect.Height() + y
if tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetHeight(tmpHeight + border)
}
m.component.parentToControl().SetHeight(tmpHeight)
case HTTOPRIGHT:
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
tmpWidth := rect.Width() + x
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetTop(tmpY - border/2)
m.component.borderPanel.SetHeight(tmpHeight + border)
m.component.borderPanel.SetWidth(tmpWidth + border)
}
m.component.parentToControl().SetTop(tmpY)
m.component.parentToControl().SetHeight(tmpHeight)
m.component.parentToControl().SetWidth(tmpWidth)
case HTTOPLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetLeft(tmpX - border/2)
m.component.borderPanel.SetWidth(tmpWidth + border)
m.component.borderPanel.SetTop(tmpY - border/2)
m.component.borderPanel.SetHeight(tmpHeight + border)
}
m.component.parentToControl().SetLeft(tmpX)
m.component.parentToControl().SetWidth(tmpWidth)
m.component.parentToControl().SetTop(tmpY)
m.component.parentToControl().SetHeight(tmpHeight)
case HTBOTTOMRIGHT:
tmpWidth := rect.Width() + x
tmpHeight := rect.Height() + y
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetWidth(tmpWidth + border)
m.component.borderPanel.SetHeight(tmpHeight + border)
}
m.component.parentToControl().SetWidth(tmpWidth)
m.component.parentToControl().SetHeight(tmpHeight)
case HTBOTTOMLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
tmpHeight := rect.Height() + y
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.component.borderPanel != nil {
m.component.borderPanel.SetLeft(tmpX - border/2)
m.component.borderPanel.SetWidth(tmpWidth + border)
m.component.borderPanel.SetHeight(tmpHeight + border)
}
m.component.parentToControl().SetLeft(tmpX)
m.component.parentToControl().SetWidth(tmpWidth)
m.component.parentToControl().SetHeight(tmpHeight)
default:
return
}
m.component.anchor.refreshAnchorsPoint()
}
})
point.SetOnMouseDown(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
m.component.isDown = true
m.component.anchor.dx, m.component.anchor.dy = x, y
})
point.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
m.component.isDown = false
})
return point
}

View File

@ -204,7 +204,7 @@ func (m *IDEComponent) mouseUp(sender lcl.IObject, button types.TMouseButton, sh
fmt.Println("双击自定义组件", m.Id, m.name)
return
}
m.refreshAnchorsPoint()
m.anchor.refreshAnchorsPoint()
m.parentToControl().SetCursor(types.CrDefault)
if m.component != nil {
switch m.component.(type) {

View File

@ -1,7 +1,6 @@
package ide
import (
"github.com/energye/energy/cef"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"github.com/energye/golcl/lcl/types/colors"
@ -9,6 +8,7 @@ import (
)
type dClick func(button types.TMouseButton, shift types.TShiftState, x, y int32)
type IDEComponent struct {
form *IDEForm
Id int
@ -29,63 +29,6 @@ type IDEComponent struct {
dClick dClick
}
type anchor struct {
top *lcl.TPanel
bottom *lcl.TPanel
left *lcl.TPanel
right *lcl.TPanel
topLeft *lcl.TPanel
topRight *lcl.TPanel
bottomLeft *lcl.TPanel
bottomRight *lcl.TPanel
isShow bool
dx, dy int32
}
func (m *anchor) hide() {
if m == nil || !m.isShow {
return
}
m.top.Hide()
m.bottom.Hide()
m.left.Hide()
m.right.Hide()
m.topLeft.Hide()
m.topRight.Hide()
m.bottomLeft.Hide()
m.bottomRight.Hide()
m.isShow = false
}
func (m *anchor) show() {
if m == nil || m.isShow {
return
}
m.top.Show()
m.bottom.Show()
m.left.Show()
m.right.Show()
m.topLeft.Show()
m.topRight.Show()
m.bottomLeft.Show()
m.bottomRight.Show()
m.isShow = true
}
func (m *anchor) remove() {
if m == nil {
return
}
m.top.Free()
m.bottom.Free()
m.left.Free()
m.right.Free()
m.topLeft.Free()
m.topRight.Free()
m.bottomLeft.Free()
m.bottomRight.Free()
}
func (m *IDEComponent) parentToPanel() *lcl.TPanel {
return m.componentParentPanel.(*lcl.TPanel)
}
@ -94,184 +37,38 @@ func (m *IDEComponent) parentToControl() lcl.IControl {
return m.componentParentPanel.(lcl.IControl)
}
func (m *IDEComponent) newAnchorPoint(owner lcl.IWinControl, ht int32) *lcl.TPanel {
point := lcl.NewPanel(owner)
point.SetParent(owner)
point.SetBevelInner(types.BvSpace)
point.SetBevelOuter(types.BvNone)
cef.SetPanelBevelColor(point, colors.ClBlack)
point.SetColor(colors.ClTeal)
point.SetOnMouseMove(func(sender lcl.IObject, shift types.TShiftState, x, y int32) {
m.borderHT = ht
switch ht {
case HTTOP, HTBOTTOM:
point.SetCursor(types.CrSizeN)
case HTLEFT, HTRIGHT:
point.SetCursor(types.CrSizeW)
case HTTOPRIGHT, HTBOTTOMLEFT:
point.SetCursor(types.CrSizeSW)
case HTTOPLEFT, HTBOTTOMRIGHT:
point.SetCursor(types.CrSizeSE)
default:
point.SetCursor(types.CrDefault)
}
//m.mouseMove(sender, shift, x, y)
if m.isDown && m.isResize {
var (
x, y = x - m.anchor.dx, y - m.anchor.dy
rect = m.parentToControl().BoundsRect()
)
switch ht {
case HTRIGHT:
tmpWidth := rect.Width() + x
if tmpWidth <= minW {
return
}
if m.borderPanel != nil {
m.borderPanel.SetWidth(tmpWidth + border)
}
m.parentToControl().SetWidth(tmpWidth)
case HTLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
if tmpWidth <= minW {
return
}
if m.borderPanel != nil {
m.borderPanel.SetLeft(tmpX - border/2)
m.borderPanel.SetWidth(tmpWidth + border)
}
m.parentToControl().SetLeft(tmpX)
m.parentToControl().SetWidth(tmpWidth)
case HTTOP:
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
if tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetTop(tmpY - border/2)
m.borderPanel.SetHeight(tmpHeight + border)
}
m.parentToControl().SetTop(tmpY)
m.parentToControl().SetHeight(tmpHeight)
case HTBOTTOM:
tmpHeight := rect.Height() + y
if tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetHeight(tmpHeight + border)
}
m.parentToControl().SetHeight(tmpHeight)
case HTTOPRIGHT:
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
tmpWidth := rect.Width() + x
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetTop(tmpY - border/2)
m.borderPanel.SetHeight(tmpHeight + border)
m.borderPanel.SetWidth(tmpWidth + border)
}
m.parentToControl().SetTop(tmpY)
m.parentToControl().SetHeight(tmpHeight)
m.parentToControl().SetWidth(tmpWidth)
case HTTOPLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
tmpY := rect.Top + y
tmpHeight := rect.Height() + (rect.Top - tmpY)
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetLeft(tmpX - border/2)
m.borderPanel.SetWidth(tmpWidth + border)
m.borderPanel.SetTop(tmpY - border/2)
m.borderPanel.SetHeight(tmpHeight + border)
}
m.parentToControl().SetLeft(tmpX)
m.parentToControl().SetWidth(tmpWidth)
m.parentToControl().SetTop(tmpY)
m.parentToControl().SetHeight(tmpHeight)
case HTBOTTOMRIGHT:
tmpWidth := rect.Width() + x
tmpHeight := rect.Height() + y
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetWidth(tmpWidth + border)
m.borderPanel.SetHeight(tmpHeight + border)
}
m.parentToControl().SetWidth(tmpWidth)
m.parentToControl().SetHeight(tmpHeight)
case HTBOTTOMLEFT:
tmpX := rect.Left + x
tmpWidth := rect.Width() + (rect.Left - tmpX)
tmpHeight := rect.Height() + y
if tmpWidth <= minW || tmpHeight <= minH {
return
}
if m.borderPanel != nil {
m.borderPanel.SetLeft(tmpX - border/2)
m.borderPanel.SetWidth(tmpWidth + border)
m.borderPanel.SetHeight(tmpHeight + border)
}
m.parentToControl().SetLeft(tmpX)
m.parentToControl().SetWidth(tmpWidth)
m.parentToControl().SetHeight(tmpHeight)
default:
return
}
m.refreshAnchorsPoint()
}
})
point.SetOnMouseDown(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
m.isDown = true
m.anchor.dx, m.anchor.dy = x, y
})
point.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
m.isDown = false
})
return point
}
func (m *IDEComponent) createAnchor() {
owner := m.parentToControl().Parent()
acr := &anchor{}
acr := &anchor{component: m}
acr.isShow = true
acr.top = m.newAnchorPoint(owner, HTTOP)
acr.bottom = m.newAnchorPoint(owner, HTBOTTOM)
acr.left = m.newAnchorPoint(owner, HTLEFT)
acr.right = m.newAnchorPoint(owner, HTRIGHT)
acr.topLeft = m.newAnchorPoint(owner, HTTOPLEFT)
acr.topRight = m.newAnchorPoint(owner, HTTOPRIGHT)
acr.bottomLeft = m.newAnchorPoint(owner, HTBOTTOMLEFT)
acr.bottomRight = m.newAnchorPoint(owner, HTBOTTOMRIGHT)
acr.top = acr.newAnchorPoint(owner, HTTOP)
acr.bottom = acr.newAnchorPoint(owner, HTBOTTOM)
acr.left = acr.newAnchorPoint(owner, HTLEFT)
acr.right = acr.newAnchorPoint(owner, HTRIGHT)
acr.topLeft = acr.newAnchorPoint(owner, HTTOPLEFT)
acr.topRight = acr.newAnchorPoint(owner, HTTOPRIGHT)
acr.bottomLeft = acr.newAnchorPoint(owner, HTBOTTOMLEFT)
acr.bottomRight = acr.newAnchorPoint(owner, HTBOTTOMRIGHT)
m.anchor = acr
m.refreshAnchorsPoint()
m.anchor.refreshAnchorsPoint()
}
func (m *IDEComponent) refreshAnchorsPoint() {
if m.anchor == nil {
return
}
if m.anchor.isShow {
rect := m.parentToControl().BoundsRect()
m.anchor.left.SetBounds(rect.Left-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
m.anchor.top.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Top-pointWC, pointW, pointW)
m.anchor.bottom.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Bottom-pointWC, pointW, pointW)
m.anchor.right.SetBounds(rect.Right-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
m.anchor.topLeft.SetBounds(rect.Left-pointWC, rect.Top-pointWC, pointW, pointW)
m.anchor.topRight.SetBounds(rect.Right-pointWC, rect.Top-pointWC, pointW, pointW)
m.anchor.bottomLeft.SetBounds(rect.Left-pointWC, rect.Bottom-pointWC, pointW, pointW)
m.anchor.bottomRight.SetBounds(rect.Right-pointWC, rect.Bottom-pointWC, pointW, pointW)
}
}
//func (m *IDEComponent) refreshAnchorsPoint() {
// if m.anchor == nil {
// return
// }
// if m.anchor.isShow {
// rect := m.parentToControl().BoundsRect()
// m.anchor.left.SetBounds(rect.Left-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
// m.anchor.top.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Top-pointWC, pointW, pointW)
// m.anchor.bottom.SetBounds(rect.Left+rect.Width()/2-pointWC, rect.Bottom-pointWC, pointW, pointW)
// m.anchor.right.SetBounds(rect.Right-pointWC, rect.Top+rect.Height()/2-pointWC, pointW, pointW)
// m.anchor.topLeft.SetBounds(rect.Left-pointWC, rect.Top-pointWC, pointW, pointW)
// m.anchor.topRight.SetBounds(rect.Right-pointWC, rect.Top-pointWC, pointW, pointW)
// m.anchor.bottomLeft.SetBounds(rect.Left-pointWC, rect.Bottom-pointWC, pointW, pointW)
// m.anchor.bottomRight.SetBounds(rect.Right-pointWC, rect.Bottom-pointWC, pointW, pointW)
// }
//}
func (m *IDEComponent) setBorderColor(color types.TColor) {
if m == nil || m.borderPanel == nil {

View File

@ -63,7 +63,7 @@ func (m *IDEForm) newIDEComponentContainer(useBorder bool, left, top, width, hei
ideComponent.parentToPanel().SetBevelInner(types.BvNone)
ideComponent.parentToPanel().SetBevelOuter(types.BvNone)
ideComponent.parentToPanel().SetBorderStyle(types.BsNone)
ideComponent.parentToPanel().SetColor(colors.ClSysDefault)
//ideComponent.parentToPanel().SetColor(colors.ClSysDefault)
if useBorder {
ideComponent.parentToPanel().SetBounds(left-border/2, top-border/2, width, height)
} else {