diff --git a/src/frameworks/customtk/widgets/base.js b/src/frameworks/customtk/widgets/base.js index 3fa63f3..40839c8 100644 --- a/src/frameworks/customtk/widgets/base.js +++ b/src/frameworks/customtk/widgets/base.js @@ -88,8 +88,8 @@ export class CustomTkBase extends Widget { 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) + // config["width"] = Math.trunc(this.state.size.width) + // config["height"] = Math.trunc(this.state.size.height) // if (!this.state.fitContent.width){ // config["width"] = this.state.size.width @@ -1017,6 +1017,7 @@ export class CustomTkWidgetBase extends CustomTkBase{ ...this.state, attrs: { ...newAttrs, + fitContent: {width: false, height: false}, styling: { ...newAttrs.styling, foregroundColor: { @@ -1167,7 +1168,7 @@ export class CustomTkWidgetBase extends CustomTkBase{ label: "font size", tool: Tools.NUMBER_INPUT, toolProps: {min: 3, max: 140}, - value: null, + value: undefined, onChange: (value) => { this.setWidgetInnerStyle("fontSize", `${value}px`) this.setAttrValue("font.fontSize", value) @@ -1197,6 +1198,12 @@ export class CustomTkWidgetBase extends CustomTkBase{ fg_color: `"${this.getAttrValue("styling.backgroundColor")}"`, } + if (!this.state.fitContent.width) + config["width"] = Math.trunc(this.state.size.width) + + if (!this.state.fitContent.height) + config["height"] = Math.trunc(this.state.size.height) + if (this.getAttrValue("styling.foregroundColor")){ config["text_color"] = `"${this.getAttrValue("styling.foregroundColor")}"` } diff --git a/src/frameworks/customtk/widgets/checkButton.js b/src/frameworks/customtk/widgets/checkButton.js index 8faeff0..d68cefd 100644 --- a/src/frameworks/customtk/widgets/checkButton.js +++ b/src/frameworks/customtk/widgets/checkButton.js @@ -3,6 +3,8 @@ import Tools from "../../../canvas/constants/tools" import { convertObjectToKeyValueString, removeKeyFromObject } from "../../../utils/common" import { CheckSquareFilled } from "@ant-design/icons" import { CustomTkWidgetBase } from "./base" +import { Layouts } from "../../../canvas/constants/layouts" +import React from "react" export class CheckBox extends CustomTkWidgetBase{ @@ -132,6 +134,8 @@ export class RadioButton extends CustomTkWidgetBase{ this.minSize = {width: 50, height: 30} + this.firstDivRef = React.createRef() + this.state = { ...this.state, size: { width: 80, height: 30 }, @@ -180,7 +184,7 @@ export class RadioButton extends CustomTkWidgetBase{ code.push(`\n`) code.push(`${radioBtnVariable} = ctk.CTkRadioButton(master=${parent}, variable=${variableName}_var, text="${radio_text}", value=${idx})`) code.push(`${radioBtnVariable}.configure(${convertObjectToKeyValueString(config)})`) - code.push(`${radioBtnVariable}.${this.getLayoutCode()}`) + code.push(`${radioBtnVariable}.${this.getLayoutCode({index: idx})}`) }) const defaultSelected = radios.selectedRadio @@ -193,6 +197,39 @@ export class RadioButton extends CustomTkWidgetBase{ return code } + /** + * + * The index is required for pack as in pack every widget would be packed on top of each other in radio button + */ + getLayoutCode({index=0}){ + let layoutManager = super.getLayoutCode() + + const {layout: parentLayout, direction, gap, align="start"} = this.getParentLayout() + const absolutePositioning = this.getAttrValue("positioning") + + + if (parentLayout === Layouts.PLACE || absolutePositioning){ + const config = {} + + const elementRect = this.firstDivRef.current?.getBoundingClientRect() + + config['x'] = Math.trunc(this.state.pos.x) + config['y'] = Math.trunc(this.state.pos.y) + + if (elementRect?.height){ + config['y'] = Math.trunc(config['y'] + (index * elementRect.height)) // the index is the radiobutton index + } + + const configStr = convertObjectToKeyValueString(config) + + layoutManager = `place(${configStr})` + + } + + return layoutManager + + } + getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() @@ -219,8 +256,12 @@ export class RadioButton extends CustomTkWidgetBase{