Skip to content

Commit

Permalink
constraints: a label is automatically anchored to its input box
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Sep 22, 2023
1 parent 76e033a commit bfa139a
Show file tree
Hide file tree
Showing 7 changed files with 4,989 additions and 4,710 deletions.
11 changes: 10 additions & 1 deletion Project/Sources/Classes/_DEMO_constraints_Controller.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Function init()
This:C1470.header2:=This:C1470.form.static.new("label1")

// Mark: Define the constraints
// 📌 Constraint rules can be loaded from a json file.

// The vertical center line must always be centered
This:C1470.form.constraints.add({\
target: "middleLine"; \
Expand Down Expand Up @@ -120,7 +122,7 @@ Function init()
reference: This:C1470.header2\
})

// The colored rectangle is centered on column 2
// The colored rectangle is centered on column 1
This:C1470.form.constraints.add({\
target: "rectangle"; \
type: "horizontal-alignment"; \
Expand All @@ -136,6 +138,13 @@ Function init()
reference: "rectangle"\
})

// The "input" box & the associated comment are centered in the dialog box.
// 📌 The "input.label" is automatically attached to the input box.
This:C1470.form.constraints.add({\
target: "input,Text11"; \
type: "horizontal-alignment"; \
alignment: "center"\
})

// === === === === === === === === === === === === === === === === === === === === ===
Function handleEvents($e : cs:C1710.evt)
Expand Down
26 changes: 17 additions & 9 deletions Project/Sources/Classes/constraintsDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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.labelMargin:=Is macOS:C1572 ? 10 : 10
This:C1470.offset:=2

This:C1470._matrix:=Not:C34(Is compiled mode:C492) // True if Dev mode
Expand Down Expand Up @@ -65,6 +65,13 @@ Function apply()
var $targets : Collection
var $cur; $ref; $viewport : cs:C1710.coord

If (This:C1470.rules.length=0)

// <NOTHING MORE TO DO>
return

End if

// Get the viewport
OBJECT GET SUBFORM CONTAINER SIZE:C1148($width; $height)
$viewport:=cs:C1710.coord.new(0; 0; $width; $height)
Expand Down Expand Up @@ -515,17 +522,18 @@ Function _adjustLabel($name : Text; $rule : Object; $cur : cs:C1710.coord)

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

//______________________________________________________
Else

return

//______________________________________________________
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
$width:=$label.width
$label.right:=$cur.left-This:C1470.labelMargin
$label.left:=$label.right-$width
$label.apply()

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _getName($target) : Text
Expand Down
2 changes: 1 addition & 1 deletion Project/Sources/Classes/evt.4dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class constructor($e : cs:C1710.evt)

// MARK:Common
// MARK:Common properties
This:C1470.objectName:=Null:C1517
This:C1470.code:=Null:C1517
This:C1470.description:=Null:C1517
Expand Down
19 changes: 13 additions & 6 deletions Project/Sources/Classes/formDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ Function init()
This:C1470._standardSuite(Current method name:C684)

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function handleEvents()
Function handleEvents($e : cs:C1710.evt)

This:C1470._standardSuite(Current method name:C684)
This:C1470._standardSuite(Current method name:C684; $e)

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function onLoad()
Expand Down Expand Up @@ -246,7 +246,7 @@ Function onLoad()
// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function update($stopTimer : Boolean)

If (Count parameters:C259=0 ? True:C214 : $stopTimer)
If (Count parameters:C259>=1 ? $stopTimer : True:C214)

SET TIMER:C645(0)

Expand Down Expand Up @@ -281,15 +281,22 @@ Function onOutsideCall()
This:C1470._standardSuite(Current method name:C684)

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _standardSuite($name : Text)
Function _standardSuite($name : Text; $e : cs:C1710.evt)

$name:=Split string:C1554($name; ".").last()

If (Asserted:C1132(This:C1470.__SUPER__#Null:C1517; "👀 "+$name+"() must be overriden by the subclass!"))\
& (Asserted:C1132(OB Instance of:C1731(This:C1470.__SUPER__[$name]; 4D:C1709.Function); "The function "+$name+"() is not define into the class "+This:C1470.__SUPER__.__CLASS__.name))

This:C1470.__SUPER__[$name]()

If ($name="handleEvents")

This:C1470.__SUPER__[$name]($e)

Else

This:C1470.__SUPER__[$name]()

End if
End if

// MARK:-[Focus]
Expand Down
2 changes: 1 addition & 1 deletion Project/Sources/Classes/listboxDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Function cellPosition($e : cs:C1710.evt) : Object

var $button; $column; $row; $x; $y : Integer

$e:=$e || FORM Event:C1606
$e:=$e || cs:C1710.evt.new()

If ($e.code=On Clicked:K2:4)\
| ($e.code=On Double Clicked:K2:5)\
Expand Down
33 changes: 31 additions & 2 deletions Project/Sources/Forms/DEMO_constraints/form.4DForm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
},
"Text8": {
"type": "text",
"text": "anchor-center on rect",
"text": "center on column 1",
"top": 308,
"left": 21,
"width": 80,
Expand Down Expand Up @@ -354,11 +354,40 @@
"left": 213,
"width": 91,
"height": 16
},
"Input": {
"type": "input",
"left": 145,
"top": 456,
"width": 50,
"height": 17
},
"Input.label": {
"type": "text",
"text": "Label",
"top": 456,
"left": 32,
"width": 96,
"height": 16,
"textAlign": "right"
},
"Text11": {
"type": "text",
"text": "the label is automatically anchored to the input",
"top": 424,
"left": 99,
"width": 137,
"height": 24,
"borderStyle": "none",
"fontStyle": "italic",
"stroke": "#0000cd",
"textAlign": "center",
"fontSize": 10
}
}
}
],
"geometryStamp": 862,
"geometryStamp": 899,
"editor": {
"activeView": "View 1",
"defaultView": "View 1",
Expand Down
Loading

0 comments on commit bfa139a

Please sign in to comment.