From 9a5de048d88efcfc32066e5518f4f96360f14099 Mon Sep 17 00:00:00 2001
From: Robert Jelic <36573031+NoryiE@users.noreply.github.com>
Date: Sat, 2 Apr 2022 03:02:43 +0200
Subject: [PATCH] Updated Objects (markdown)
---
Objects.md | 279 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 243 insertions(+), 36 deletions(-)
diff --git a/Objects.md b/Objects.md
index 96ed1e8..fea81ec 100644
--- a/Objects.md
+++ b/Objects.md
@@ -1,48 +1,255 @@
-# Screens
+All the functions you can see here are available for all objects! It doesn't matter if its a frame or a button or a list (or something else).
-Screens are the most basic thing you need, to create a GUI. They are basically level 0 frames (yes they are frames!)
+Here is a list of possible functions:
+## show
+shows the object (only if the parent frame is already visible)
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local button = mainFrame:addButton("myFirstButton")
+button:show()
+````
+**args:** -
+**returns:** the object
-Example on how to create a screen:
+## hide
+hides the object
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(function() mainFrame:hide() end)
+button:show()
+````s
+**args:** -
+**returns:** the object
+
+# setPosition
+Changes the position relative to its parent frame
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setPosition(2,3)
+````
+**args:** int x, int y
+**returns:** the frame object
+
+
+
+## setBackground
+Changes the object background color
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setBackground(colors.lightGray)
+````
+**args:** int color
+**returns:** the object
+
+## setForeground
+Changes the object text color
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setForeground(colors.black)
+````
+**args:** int color
+**returns:** the object
+
+## setSize
+Changes the object size
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setSize(15,5)
+````
+**args:** width, length
+**returns:** the object
+
+## setFocus
+sets the object to be the focused object
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setFocus():show()
+````
+**args:** -
+**returns:** the object
+
+## setZIndex
+changes the z index (lower z index do have higher draw priority)
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):show()
+````
+**args:** index
+**returns:** the object
+
+## setParent
+changes the frame parent of that object
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aRandomFrame = CreateFrame("aRandomFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):onClick(function() aRandomFrame:setParent(mainFrame) end):show()
+````
+**args:** frame object
+**returns:** the object
+
+## isFocusedObject
+returns if the object is currently the focused object of the parent frame
````lua
-local firstScreen = screen.new("myFirstScreen")
-firstScreen:setTitle("First Screen")
-firstScreen:showBar()
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):show()
+NyoUI.debug(aButton:isFocusedObject()) -- shows true or false as a debug message
````
+**args:** -
+**returns:** true or false
-Only one screen can be active at the same time, this means, if you use firstScreen:show() and you already created another screen, it will automatically hide the old screen
+## getAnchorPosition
+converts the x,y coordinates into the anchor coordinates of that object
-Here you can see all the methods you can use: Frames
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setSize(15,15):show()
+local aButton = mainFrame:addButton("myFirstButton"):setAnchor("right","bottom"):setSize(8,1):setPosition(1,1):show()
+NyoUI.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1
+````
+**args:** x,y or nothing - if nothing it uses the object x,y
+**returns:** converted coordinates
-# Frames
+## setAnchor
+sets the anchor of that object
-Frames are like screens or screens are frames. Frames can be sub objects of screens, while screens cannot be sub objects of frames OR screens. This is the only difference between screens and frames. Everything else is the same.
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setAnchor("right"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setAnchor("bottom","right"):setSize(8,1):setPosition(1,1):show()
+````
+**args:** "left", "right", "top", "bottom" - doesn't matter which order
+**returns:** the object
-Here are all possible functions you can use with screens and frames:
+## relativeToAbsolutePosition
+converts the relative coordinates into absolute coordinates
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):setPosition(3,3):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(8,1):setPosition(4,2):show()
+NyoUI.debug(aButton:relativeToAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2
+````
+**args:** x,y or nothing - if nothing it uses the object x,y
+**returns:** the object
+## setTextAlign
+sets the align of the object (as example buttons)
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(12,3):setTextAlign("right", "center"):setText("Dont't..."):show()
+````
+**args:** horizontal,vertical you can use "left", "center", "right"
+**returns:** the object
-* screen.new(string) -- creates a new screen object
-* frame:addFrame(string) -- creates a new frame object
-* frame:setTitle(string) -- sets the title
-* frame:setTitleAlign(string) -- sets the title alignment ("left","right","center")
-* frame:setPosition(int, int) -- changes the position relative to its parent frame
-* frame:setBackground(int) -- changes the background color
-* frame:setForeground(int) -- changes the text color
-* frame:setSize(int, int) -- changes the size (width, height)
-* frame:showBar([bool]) -- shows/hides the bar on top where you will see the title if its active (no args = true)
-* frame:isModifierActive(int or string) -- returns true if user is currently holding a key (following strings are possible: "shift","ctrl","alt"), int can be everything computercraft supports
-* frame:show() -- shows the frame on the screen
-* frame:hide() -- hides the frame
-* frame:remove() -- removes the frame completly
-* frame:getObject(string) - gets an created object (arg = id)
-* frame:removeObject(string) - removes the object with the id
-* frame:addObject(object) -- you can add a object manually, normaly you shouldn't use this function, it gets called internally
-* frame:drawObject() -- this draws the frame, you dont need that function, it gets called internally
-* frame:mouseEvent(string,int,int,int) -- internal mouse event, better don't use it, i created mouse hooks for you
-* frame:keyEvent(string,int) -- internal keyevent, better don't use it, i created key hooks for you
-* frame:changeZIndexOfObj(object, int) -- changes the z index of an object
-* frame:setFocusedElement(object) -- changes the currently focused element
-* frame:removeFocusedElement(object) -- removes the focus of the currently focused element
-* frame:getFocusedElement() -- gets the currently focused element
-* frame:getFocusEvent() -- event which gets fired when the frame gets the focus -- its more for internal usage
-* frame:setMoveable(bool) -- sets if the frame should be moveable or not (to move the frame you need to drag it on the top bar
+## setCustomArgs
+WIP
+
+## setValue
+sets the value of that object (input, label, checkbox, textfield, scrollbar,...)
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
+````
+**args:** value (text,checked,number,...)
+**returns:** the object
+
+## getValue
+returns the currently saved value
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
+NyoUI.debug(aCheckbox:getValue()) -- returns true
+````
+**args:**-
+**returns:** the value
+
+## isLinked
+WIP done but buggy have to look
+
+## linkTo
+WIP done but buggy have to look
+
+## getHeight/getWidth
+returns the height or width of that object
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
+NyoUI.debug(aButton:getHeight()) -- returns 8
+````
+**args:**-
+**returns:** returns the height or the width
+
+## isVisible
+returns if the object is currently visible
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
+NyoUI.debug(aButton:isVisible()) -- returns true
+````
+**args:**-
+**returns:** returns the visible state of that object
+
+## getName
+returns the given name of that object
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+NyoUI.debug(mainFrame:getName()) -- returns myFirstFrame
+````
+**args:**-
+**returns:** returns the name
+
+# Object Events
+These object events are available for all objects, if a object got some unique events, you can see them in their own category
+
+## onClick
+creates a mouse_click event
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClick(function(self,event,button,x,y) NyoUI.debug("Hellooww UwU") end):show()
+````
+**args:** function
+**returns:** the object
+
+## onClickUp
+creates a click_up event
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClickUp(function(self,event,button,x,y) NyoUI.debug("Byeeeee UwU") end):show()
+````
+**args:** function
+**returns:** the object
+
+## onMouseDrag
+creates a mouse_drag event
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClickUp(function(self,event,button,x,y) NyoUI.debug("Byeeeee UwU") end):show()
+````
+**args:** function
+**returns:** the object
+
+## onChange
+creates a change event (fires as soon as the value gets changed)
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):show()
+local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):onChange(function(self) NyoUI.debug("i got changed into "..self:getValue()) end):show()
+````
+**args:** function
+**returns:** the object
+
+## onKey
+creates a key(board) - event can be key or char
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):onKey(function(self,event,key) NyoUI.debug("you clicked "..key) end):show()
+````
+**args:** function
+**returns:** the object
+
+## onLoseFocus
+creates a lose focus event
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):onLoseFocus(function(self) NyoUI.debug("please come back..") end):show()
+````
+**args:** function
+**returns:** the object
+
+## onGetFocus
+creates a get focus event
+````lua
+local mainFrame = CreateFrame("myFirstFrame"):onGetFocus(function(self) NyoUI.debug("thanks!") end):show()
+````
+**args:** function
+**returns:** the object
\ No newline at end of file