fixed padx/y and ipadx/y

This commit is contained in:
paul
2025-04-01 20:42:14 +05:30
parent 0243b3b9e8
commit d10928bb5a
2 changed files with 81 additions and 86 deletions

View File

@@ -58,13 +58,35 @@ export class CustomTkBase extends Widget {
const absolutePositioning = this.getAttrValue("positioning")
let layoutManager = `pack()`
const marginX = this.getAttrValue("margin.marginX")
const marginY = this.getAttrValue("margin.marginY")
const paddingX = this.getAttrValue("padding.padX")
const paddingY = this.getAttrValue("padding.padY")
let config = {}
if (marginX){
config["padx"] = marginX
}
if (marginY){
config["pady"] = marginY
}
if (paddingX){
config["ipadx"] = paddingX
}
if (paddingY){
config["ipady"] = paddingY
}
if (parentLayout === Layouts.PLACE || absolutePositioning){
const config = {
x: Math.trunc(this.state.pos.x),
y: Math.trunc(this.state.pos.y),
}
config['x'] = Math.trunc(this.state.pos.x)
config['y'] = Math.trunc(this.state.pos.y)
config["width"] = Math.trunc(this.state.size.width)
config["height"] = Math.trunc(this.state.size.height)
@@ -84,12 +106,6 @@ export class CustomTkBase extends Widget {
const packSide = this.getAttrValue("flexManager.side")
const marginX = this.getAttrValue("margin.marginX")
const marginY = this.getAttrValue("margin.marginY")
const paddingX = this.getAttrValue("padding.padX")
const paddingY = this.getAttrValue("padding.padY")
const config = {}
if (packSide === "" || packSide === "top"){
@@ -113,21 +129,6 @@ export class CustomTkBase extends Widget {
// config["pady"] = gap
// }
if (marginX){
config["padx"] = marginX
}
if (marginY){
config["pady"] = marginY
}
if (paddingX){
config["ipadx"] = paddingX
}
if (paddingY){
config["ipady"] = paddingY
}
// if (align === "start"){
// config["anchor"] = "'nw'"
@@ -167,10 +168,8 @@ export class CustomTkBase extends Widget {
const sticky = this.getAttrValue("gridManager.sticky")
const config = {
row: row-1, // unlike css grid tkinter grid starts from 0
column: column-1, // unlike css grid tkinter grid starts from 0
}
config['row'] = row - 1
config['column'] = column - 1
if (rowSpan > 1){
config['rowspan'] = rowSpan
@@ -1221,23 +1220,23 @@ export class CustomTkWidgetBase extends CustomTkBase{
if (this.getAttrValue("cursor"))
config["cursor"] = `"${this.getAttrValue("cursor")}"`
if (this.getAttrValue("padding.padX")){
// inner padding
config["ipadx"] = this.getAttrValue("padding.padX")
}
// if (this.getAttrValue("padding.padX")){
// // inner padding
// config["ipadx"] = this.getAttrValue("padding.padX")
// }
if (this.getAttrValue("padding.padY")){
config["ipady"] = this.getAttrValue("padding.padY")
}
// if (this.getAttrValue("padding.padY")){
// config["ipady"] = this.getAttrValue("padding.padY")
// }
if (this.getAttrValue("margin.marginX")){
config["padx"] = this.getAttrValue("margin.marginX")
}
// if (this.getAttrValue("margin.marginX")){
// config["padx"] = this.getAttrValue("margin.marginX")
// }
if (this.getAttrValue("margin.marginY")){
config["pady"] = this.getAttrValue("margin.marginY")
}
// if (this.getAttrValue("margin.marginY")){
// config["pady"] = this.getAttrValue("margin.marginY")
// }
// FIXME: add width and height, the scales may not be correct as the width and height are based on characters in pack and grid not pixels

View File

@@ -59,13 +59,34 @@ export class TkinterBase extends Widget {
const absolutePositioning = this.getAttrValue("positioning")
let layoutManager = `pack()`
const marginX = this.getAttrValue("margin.marginX")
const marginY = this.getAttrValue("margin.marginY")
const paddingX = this.getAttrValue("padding.padX")
const paddingY = this.getAttrValue("padding.padY")
let config = {}
if (marginX){
config["padx"] = marginX
}
if (marginY){
config["pady"] = marginY
}
if (paddingX){
config["ipadx"] = paddingX
}
if (paddingY){
config["ipady"] = paddingY
}
if (parentLayout === Layouts.PLACE || absolutePositioning){
const config = {
x: Math.trunc(this.state.pos.x),
y: Math.trunc(this.state.pos.y),
}
config['x'] = Math.trunc(this.state.pos.x)
config['y'] = Math.trunc(this.state.pos.y)
config["width"] = Math.trunc(this.state.size.width)
config["height"] = Math.trunc(this.state.size.height)
@@ -85,14 +106,6 @@ export class TkinterBase extends Widget {
const packSide = this.getAttrValue("flexManager.side")
const marginX = this.getAttrValue("margin.marginX")
const marginY = this.getAttrValue("margin.marginY")
const paddingX = this.getAttrValue("padding.padX")
const paddingY = this.getAttrValue("padding.padY")
const config = {}
if (packSide === "" || packSide === "top"){
config['side'] = `tk.TOP`
@@ -114,21 +127,6 @@ export class TkinterBase extends Widget {
// config["pady"] = gap
// }
if (marginX){
config["padx"] = marginX
}
if (marginY){
config["pady"] = marginY
}
if (paddingX){
config["ipadx"] = paddingX
}
if (paddingY){
config["ipady"] = paddingY
}
// if (align === "start"){
// config["anchor"] = "'nw'"
@@ -168,10 +166,8 @@ export class TkinterBase extends Widget {
const sticky = this.getAttrValue("gridManager.sticky")
const config = {
row: row-1, // unlike css grid tkinter grid starts from 0
column: column-1, // unlike css grid tkinter grid starts from 0
}
config['row'] = row - 1 // unlike css grid tkinter grid starts from 0
config['column'] = column - 1 // unlike css grid tkinter grid starts from 0
if (rowSpan > 1){
config['rowspan'] = rowSpan
@@ -1229,23 +1225,23 @@ export class TkinterWidgetBase extends TkinterBase{
if (this.getAttrValue("cursor"))
config["cursor"] = `"${this.getAttrValue("cursor")}"`
if (this.getAttrValue("padding.padX")){
// inner padding
config["ipadx"] = this.getAttrValue("padding.padX")
}
// if (this.getAttrValue("padding.padX")){
// // inner padding
// config["ipadx"] = this.getAttrValue("padding.padX")
// }
if (this.getAttrValue("padding.padY")){
config["ipady"] = this.getAttrValue("padding.padY")
}
// if (this.getAttrValue("padding.padY")){
// config["ipady"] = this.getAttrValue("padding.padY")
// }
if (this.getAttrValue("margin.marginX")){
config["padx"] = this.getAttrValue("margin.marginX")
}
// if (this.getAttrValue("margin.marginX")){
// config["padx"] = this.getAttrValue("margin.marginX")
// }
if (this.getAttrValue("margin.marginY")){
config["pady"] = this.getAttrValue("margin.marginY")
}
// if (this.getAttrValue("margin.marginY")){
// config["pady"] = this.getAttrValue("margin.marginY")
// }
// FIXME: add width and height, the scales may not be correct as the width and height are based on characters in label and grid not pixels
// if (!this.state.fitContent.width){