Skip to content

Commit

Permalink
enhance constraintsDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Sep 21, 2023
1 parent d615db9 commit 76e033a
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 38 deletions.
140 changes: 113 additions & 27 deletions Project/Sources/Classes/constraintsDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Class constructor($metrics : Object)
This:C1470.marginV:=$metrics.marginV || Is macOS:C1572 ? 2 : 2
This:C1470.marginH:=$metrics.marginH || Is macOS:C1572 ? 20 : 20

This:C1470.labelMargin:=5
This:C1470.offset:=2

This:C1470._matrix:=Not:C34(Is compiled mode:C492) // True if Dev mode
Expand All @@ -20,27 +21,15 @@ Function add($rule : Object) : cs:C1710.constraintsDelegate

If ($rule.set#Null:C1517)

If (Value type:C1509($rule.target)=Is object:K8:27)\
&& ($rule.target.name#Null:C1517)

$name:=$rule.target.name

Else

$name:=String:C10($rule.target)

End if
$name:=This:C1470._getName($rule.target)

For each ($o; $rule.set)

$o.target:=$name

If ($o.reference#Null:C1517)\
&& (Value type:C1509($o.reference)=Is object:K8:27)\
&& ($o.reference.name#Null:C1517)
If ($o.reference#Null:C1517)


$o.reference:=$o.reference.name
$o.reference:=This:C1470._getName($o.reference)

End if

Expand All @@ -50,22 +39,14 @@ Function add($rule : Object) : cs:C1710.constraintsDelegate

Else

If (Value type:C1509($rule.target)=Is object:K8:27)\
&& ($rule.target.name#Null:C1517)

$rule.target:=$rule.target.name

End if
$rule.target:=This:C1470._getName($rule.target)

If ($rule.reference#Null:C1517)\
&& (Value type:C1509($rule.reference)=Is object:K8:27)\
&& ($rule.reference.name#Null:C1517)
If ($rule.reference#Null:C1517)

$rule.reference:=$rule.reference.name
$rule.reference:=This:C1470._getName($rule.reference)

End if


This:C1470.rules.push($rule)

End if
Expand Down Expand Up @@ -100,6 +81,12 @@ Function apply()

Case of

//______________________________________________________
: (Value type:C1509($rule.target)=Is object:K8:27)\
&& ($rule.target.name#Null:C1517) // widget

$targets:=[$rule.target.name]

//______________________________________________________
: (Value type:C1509($rule.target)=Is collection:K8:32)

Expand Down Expand Up @@ -201,6 +188,54 @@ Function apply()

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
// Defines the left edge of an element as a percentage of the reference or the form width
: ($rule.type="left") // Set the left edge in percent of the reference

// MARK:left
$width:=$cur.width
$cur.left:=$ref.width*($rule.value<1 ? $rule.value : $rule.value/100)

Case of

//……………………………………………………………………………………………………………
: ($type=Object type text input:K79:4)

// The scrollbar is outside
OBJECT GET SCROLLBAR:C1076(*; $name; $horizontal; $vertical)

If ($vertical)

$cur.left-=This:C1470.scrollBarWidth

End if

//……………………………………………………………………………………………………………
: ($type=Object type picture input:K79:5)

$cur.left+=This:C1470.offset

//……………………………………………………………………………………………………………
: ($type=Object type rectangle:K79:32)

$cur.left+=(This:C1470.offset*2)

//……………………………………………………………………………………………………………
: ($type=Object type popup dropdown list:K79:13)

$cur.left+=5

//……………………………………………………………………………………………………………
End case

$cur.right:=$cur.left+$width

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
: ($rule.type="minimum-width") // Minimum object width

Expand Down Expand Up @@ -292,6 +327,8 @@ Function apply()

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
: ($rule.type="horizontal-alignment")

Expand Down Expand Up @@ -326,6 +363,8 @@ Function apply()

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
: ($rule.type="vertical-alignment")

Expand Down Expand Up @@ -365,6 +404,8 @@ Function apply()

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
: ($rule.type="inline")

Expand Down Expand Up @@ -434,6 +475,8 @@ Function apply()

$cur.apply()

This:C1470._adjustLabel($name; $rule; $cur)

//______________________________________________________
Else

Expand All @@ -453,4 +496,47 @@ Function apply()
End for each

// Delete one-shot rules
This:C1470.rules:=This:C1470.rules.filter(Formula:C1597($1.result:=Bool:C1537($1.value.toDelete)=False:C215))
This:C1470.rules:=This:C1470.rules.filter(Formula:C1597($1.result:=Bool:C1537($1.value.toDelete)=False:C215))

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _adjustLabel($name : Text; $rule : Object; $cur : cs:C1710.coord)

var $label : cs:C1710.coord
var $width : Integer

Case of
//______________________________________________________
: ($rule.label#Null:C1517)

$label:=cs:C1710.coord.new($rule.label)

//______________________________________________________
: (OBJECT Get type:C1300(*; $name+".label")#Object type unknown:K79:1)

$label:=cs:C1710.coord.new($name+".label")

//______________________________________________________
End case

If ($label#Null:C1517)

$width:=$label.width
$label.right:=$cur.left-This:C1470.labelMargin
$label.left:=$label.right-$width
$label.apply()

End if

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _getName($target) : Text

If (Value type:C1509($target)=Is object:K8:27)\
&& ($target.name#Null:C1517) // Widget

return $target.name

Else

return String:C10($target)

End if
25 changes: 14 additions & 11 deletions Project/Sources/Classes/coord.4dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
property name : Text
property left; top; right; bottom : Integer

Class constructor($left; $top : Integer; $right : Integer; $bottom : Integer)

This:C1470.name:=Null:C1517

Case of

//______________________________________________________
Expand All @@ -20,6 +25,7 @@ Class constructor($left; $top : Integer; $right : Integer; $bottom : Integer)
: (Value type:C1509($left)=Is text:K8:3) // Object name

This:C1470.name:=$left

OBJECT GET COORDINATES:C663(*; This:C1470.name; $left; $top; $right; $bottom)

//______________________________________________________
Expand All @@ -30,7 +36,7 @@ Class constructor($left; $top : Integer; $right : Integer; $bottom : Integer)
This:C1470.right:=$right
This:C1470.bottom:=$bottom

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get windowCoordinates() : Object

var $bottom; $left; $right; $top : Integer
Expand All @@ -50,7 +56,7 @@ Function get windowCoordinates() : Object
bottom: $bottom\
}

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get screenCoordinates() : Object

var $bottom; $left; $right; $top : Integer
Expand All @@ -70,31 +76,28 @@ Function get screenCoordinates() : Object
bottom: $bottom\
}

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get width() : Integer

return This:C1470.right-This:C1470.left

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get height() : Integer

return This:C1470.bottom-This:C1470.top

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get dimensions() : Object

return {\
width: This:C1470.width; \
height: This:C1470.height\
}

// === === === === === === === === === === === === === === === === === === === === === === === ===
// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function apply($name : Text)

$name:=$name || This:C1470.name
OBJECT SET COORDINATES:C1248(*; $name; This:C1470.left; This:C1470.top; This:C1470.right; This:C1470.bottom)

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function applyToWindow($winRef : Integer)
ASSERT:C1129($name#Null:C1517; "Missing target name!")

SET WINDOW RECT:C444(This:C1470.left; This:C1470.top; This:C1470.right; This:C1470.bottom; $winRef)
OBJECT SET COORDINATES:C1248(*; $name; This:C1470.left; This:C1470.top; This:C1470.right; This:C1470.bottom)

0 comments on commit 76e033a

Please sign in to comment.