Skip to content

Commit

Permalink
center alignment should take padding into account
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Mar 12, 2023
1 parent 80806da commit f8ef78f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions haxe/ui/layouts/DefaultLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class DefaultLayout extends Layout {
}

private override function repositionChildren() {
var usableSize = this.usableSize;

for (child in component.childComponents) {
if (child.includeInLayout == false) {
continue;
Expand All @@ -155,7 +157,7 @@ class DefaultLayout extends Layout {

switch (horizontalAlign(child)) {
case "center":
xpos = ((component.componentWidth - child.componentWidth) / 2) + marginLeft(child) - marginRight(child);
xpos = ((usableSize.width - child.componentWidth) / 2) + paddingLeft + marginLeft(child) - marginRight(child);
case "right":
xpos = component.componentWidth - (child.componentWidth + paddingRight + marginRight(child));
default: //left
Expand All @@ -164,7 +166,7 @@ class DefaultLayout extends Layout {

switch (verticalAlign(child)) {
case "center":
ypos = ((component.componentHeight - child.componentHeight) / 2) + marginTop(child) - marginBottom(child);
ypos = ((usableSize.height - child.componentHeight) / 2) + paddingTop + marginTop(child) - marginBottom(child);
case "bottom":
ypos = component.componentHeight - (child.componentHeight + paddingBottom + marginBottom(child));
default: //top
Expand Down
5 changes: 3 additions & 2 deletions haxe/ui/layouts/HorizontalLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class HorizontalLayout extends DefaultLayout {

private override function repositionChildren() {
var xpos = paddingLeft;

var usableSize = this.usableSize;

for (child in component.childComponents) {
if (child.includeInLayout == false) {
continue;
Expand All @@ -21,7 +22,7 @@ class HorizontalLayout extends DefaultLayout {

switch (verticalAlign(child)) {
case "center":
ypos = ((component.componentHeight - child.componentHeight) / 2) + marginTop(child) - marginBottom(child);
ypos = ((usableSize.height - child.componentHeight) / 2) + paddingTop + marginTop(child) - marginBottom(child);
case "bottom":
if (child.componentHeight < component.componentHeight) {
ypos = component.componentHeight - (child.componentHeight + paddingBottom + marginTop(child));
Expand Down
3 changes: 2 additions & 1 deletion haxe/ui/layouts/VerticalLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class VerticalLayout extends DefaultLayout {

private override function repositionChildren() {
var ypos = paddingTop;
var usableSize = this.usableSize;

for (child in component.childComponents) {
if (child.includeInLayout == false) {
Expand All @@ -20,7 +21,7 @@ class VerticalLayout extends DefaultLayout {

switch (horizontalAlign(child)) {
case "center":
xpos = ((component.componentWidth - child.componentWidth) / 2) + marginLeft(child) - marginRight(child);
xpos = ((usableSize.width - child.componentWidth) / 2) + paddingLeft + marginLeft(child) - marginRight(child);
case "right":
if (child.componentWidth < component.componentWidth) {
xpos = component.componentWidth - (child.componentWidth + paddingRight + marginLeft(child));
Expand Down

0 comments on commit f8ef78f

Please sign in to comment.