diff --git a/src/frameworks/tkinter/widgets/input.js b/src/frameworks/tkinter/widgets/input.js
index 82d475f..9b306b9 100644
--- a/src/frameworks/tkinter/widgets/input.js
+++ b/src/frameworks/tkinter/widgets/input.js
@@ -1,26 +1,26 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
+import { removeKeyFromObject } from "../../../utils/common"
-class Input extends Widget{
+export class Input extends Widget{
- static widgetType = "input"
- // TODO: override the widgetName value
+ static widgetType = "entry"
+ // TODO: remove layouts
constructor(props) {
super(props)
- this.droppableTags = {
- // TODO: exclude all
- exclude: ["image", "video", "media", "main_window", "toplevel"]
- }
+ this.droppableTags = null // disables drops
+
+ const newAttrs = removeKeyFromObject("layout", this.state.attrs)
this.state = {
...this.state,
size: { width: 120, height: 40 },
attrs: {
- ...this.state.attrs,
+ ...newAttrs,
styling: {
- ...this.state.attrs.styling,
+ ...newAttrs.styling,
foregroundColor: {
label: "Foreground Color",
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
@@ -46,37 +46,93 @@ class Input extends Widget{
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#fff")
+ this.setWidgetName("Entry")
}
getToolbarAttrs(){
+
+ const toolBarAttrs = super.getToolbarAttrs()
+
return ({
id: this.__id,
- widgetName: {
- label: "Widget Name",
- tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "Widget name", maxLength: 40 },
- value: this.state.widgetName,
- onChange: (value) => this.setWidgetName(value)
- },
+ widgetName: toolBarAttrs.widgetName,
placeHolder: this.state.attrs.placeHolder,
- size: {
- label: "Size",
- display: "horizontal",
- width: {
- label: "Width",
- tool: Tools.NUMBER_INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "width", max: this.maxSize.width, min: this.minSize.width },
- value: this.state.size.width || 100,
- onChange: (value) => this.setWidgetSize(value, null)
+ size: toolBarAttrs.widgetName,
+
+ ...this.state.attrs,
+
+ })
+ }
+
+ renderContent(){
+ return (
+
+
+
+ {this.getAttrValue("placeHolder")}
+
+
+
+ )
+ }
+
+}
+
+
+export class Text extends Widget{
+
+ static widgetType = "Text"
+
+ constructor(props) {
+ super(props)
+
+ this.droppableTags = null
+
+ const newAttrs = removeKeyFromObject("layout", this.state.attrs)
+
+ this.state = {
+ ...this.state,
+ size: { width: 120, height: 80 },
+ attrs: {
+ ...newAttrs,
+ styling: {
+ ...newAttrs.styling,
+ foregroundColor: {
+ label: "Foreground Color",
+ tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
+ value: "#000",
+ onChange: (value) => {
+ this.setWidgetStyling("color", value)
+ this.setAttrValue("styling.foregroundColor", value)
+ }
+ }
},
- height: {
- label: "Height",
- tool: Tools.NUMBER_INPUT,
- toolProps: { placeholder: "height", max: this.maxSize.height, min: this.minSize.height },
- value: this.state.size.height || 100,
- onChange: (value) => this.setWidgetSize(null, value)
- },
- },
+ placeHolder: {
+ label: "PlaceHolder",
+ tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
+ toolProps: {placeholder: "text", maxLength: 100},
+ value: "placeholder text",
+ onChange: (value) => this.setAttrValue("placeHolder", value)
+ }
+
+ }
+ }
+ }
+
+ componentDidMount(){
+ super.componentDidMount()
+ this.setAttrValue("styling.backgroundColor", "#fff")
+ this.setWidgetName("text")
+ }
+
+ getToolbarAttrs(){
+ const toolBarAttrs = super.getToolbarAttrs()
+
+ return ({
+ id: this.__id,
+ widgetName: toolBarAttrs.widgetName,
+ placeHolder: this.state.attrs.placeHolder,
+ size: toolBarAttrs.size,
...this.state.attrs,
@@ -96,6 +152,3 @@ class Input extends Widget{
}
}
-
-
-export default Input
\ No newline at end of file
diff --git a/src/frameworks/tkinter/widgets/label.js b/src/frameworks/tkinter/widgets/label.js
index 78f12b7..3239fc4 100644
--- a/src/frameworks/tkinter/widgets/label.js
+++ b/src/frameworks/tkinter/widgets/label.js
@@ -1,5 +1,6 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
+import { removeKeyFromObject } from "../../../utils/common"
class Label extends Widget{
@@ -14,13 +15,16 @@ class Label extends Widget{
exclude: ["image", "video", "media", "main_window", "toplevel"]
}
+ const newAttrs = removeKeyFromObject("layout", this.state.attrs)
+
+
this.state = {
...this.state,
size: { width: 80, height: 40 },
attrs: {
- ...this.state.attrs,
+ ...newAttrs,
styling: {
- ...this.state.attrs.styling,
+ ...newAttrs.styling,
foregroundColor: {
label: "Foreground Color",
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
@@ -45,38 +49,18 @@ class Label extends Widget{
componentDidMount(){
super.componentDidMount()
- this.setAttrValue("styling.backgroundColor", "#E4E2E2")
+ this.setAttrValue("styling.backgroundColor", "#fff")
+ this.setWidgetStyling("backgroundColor", "#fff0")
}
getToolbarAttrs(){
+ const toolBarAttrs = super.getToolbarAttrs()
+
return ({
id: this.__id,
- widgetName: {
- label: "Widget Name",
- tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "Widget name", maxLength: 40 },
- value: this.state.widgetName,
- onChange: (value) => this.setWidgetName(value)
- },
+ widgetName: toolBarAttrs.widgetName,
labelWidget: this.state.attrs.labelWidget,
- size: {
- label: "Size",
- display: "horizontal",
- width: {
- label: "Width",
- tool: Tools.NUMBER_INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "width", max: this.maxSize.width, min: this.minSize.width },
- value: this.state.size.width || 100,
- onChange: (value) => this.setWidgetSize(value, null)
- },
- height: {
- label: "Height",
- tool: Tools.NUMBER_INPUT,
- toolProps: { placeholder: "height", max: this.maxSize.height, min: this.minSize.height },
- value: this.state.size.height || 100,
- onChange: (value) => this.setWidgetSize(null, value)
- },
- },
+ size: toolBarAttrs.size,
...this.state.attrs,
diff --git a/src/frameworks/tkinter/widgets/mainWindow.js b/src/frameworks/tkinter/widgets/mainWindow.js
index 3d91972..fc0ccbc 100644
--- a/src/frameworks/tkinter/widgets/mainWindow.js
+++ b/src/frameworks/tkinter/widgets/mainWindow.js
@@ -33,37 +33,17 @@ class MainWindow extends Widget{
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#E4E2E2")
+ this.setWidgetName("main")
}
getToolbarAttrs(){
+ const toolBarAttrs = super.getToolbarAttrs()
+
return ({
id: this.__id,
- widgetName: {
- label: "Widget Name",
- tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "Widget name", maxLength: 40 },
- value: this.state.widgetName,
- onChange: (value) => this.setWidgetName(value)
- },
+ widgetName: toolBarAttrs.widgetName,
title: this.state.attrs.title,
- size: {
- label: "Size",
- display: "horizontal",
- width: {
- label: "Width",
- tool: Tools.NUMBER_INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "width", max: this.maxSize.width, min: this.minSize.width },
- value: this.state.size.width || 100,
- onChange: (value) => this.setWidgetSize(value, null)
- },
- height: {
- label: "Height",
- tool: Tools.NUMBER_INPUT,
- toolProps: { placeholder: "height", max: this.maxSize.height, min: this.minSize.height },
- value: this.state.size.height || 100,
- onChange: (value) => this.setWidgetSize(null, value)
- },
- },
+ size: toolBarAttrs.size,
...this.state.attrs,
diff --git a/src/frameworks/tkinter/widgets/toplevel.js b/src/frameworks/tkinter/widgets/toplevel.js
index ba71a6f..731096d 100644
--- a/src/frameworks/tkinter/widgets/toplevel.js
+++ b/src/frameworks/tkinter/widgets/toplevel.js
@@ -34,37 +34,16 @@ class TopLevel extends Widget{
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#E4E2E2")
+ this.setWidgetName("toplevel")
}
getToolbarAttrs(){
+ const toolBarAttrs = super.getToolbarAttrs()
+
return ({
- id: this.__id,
- widgetName: {
- label: "Widget Name",
- tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "Widget name", maxLength: 40 },
- value: this.state.widgetName,
- onChange: (value) => this.setWidgetName(value)
- },
+ widgetName: toolBarAttrs.widgetName,
title: this.state.attrs.title,
- size: {
- label: "Size",
- display: "horizontal",
- width: {
- label: "Width",
- tool: Tools.NUMBER_INPUT, // the tool to display, can be either HTML ELement or a constant string
- toolProps: { placeholder: "width", max: this.maxSize.width, min: this.minSize.width },
- value: this.state.size.width || 100,
- onChange: (value) => this.setWidgetSize(value, null)
- },
- height: {
- label: "Height",
- tool: Tools.NUMBER_INPUT,
- toolProps: { placeholder: "height", max: this.maxSize.height, min: this.minSize.height },
- value: this.state.size.height || 100,
- onChange: (value) => this.setWidgetSize(null, value)
- },
- },
+ size: toolBarAttrs.size,
...this.state.attrs,
diff --git a/src/utils/common.js b/src/utils/common.js
index 2b658d7..85001ad 100644
--- a/src/utils/common.js
+++ b/src/utils/common.js
@@ -2,15 +2,15 @@
export function removeDuplicateObjects(array, key) {
- const seen = new Set()
-
- return array.filter(item => {
- if (!seen.has(item[key])) {
- seen.add(item[key])
- return true
- }
- return false
- })
+ const seen = new Set()
+
+ return array.filter(item => {
+ if (!seen.has(item[key])) {
+ seen.add(item[key])
+ return true
+ }
+ return false
+ })
}
@@ -20,5 +20,34 @@ export function removeDuplicateObjects(array, key) {
* @returns
*/
export function capitalize(str) {
- return str.charAt(0).toUpperCase() + str.slice(1)
-}
\ No newline at end of file
+ return str.charAt(0).toUpperCase() + str.slice(1)
+}
+
+
+/**
+* Given the key as a path, removes the widget attribute at the given path
+* @param {string} path - path to the key, eg: styling.backgroundColor
+* @param {{}} _object - object with key and value
+*/
+export function removeKeyFromObject(path, _object) {
+ const keys = path.split('.')
+ const lastKey = keys.pop()
+
+ // Traverse the state and find the nested object up to the second last key
+ let newAttrs = { ..._object }
+ let nestedObject = newAttrs
+
+ for (const key of keys) {
+ if (nestedObject[key] !== undefined) {
+ nestedObject[key] = { ...nestedObject[key] } // Ensure immutability
+ nestedObject = nestedObject[key]
+ } else {
+ return // Key doesn't exist, so nothing to remove
+ }
+ }
+
+ // Remove the attribute
+ delete nestedObject[lastKey]
+
+ return newAttrs
+}
\ No newline at end of file