Updated Objects (markdown)

Robert Jelic
2022-04-02 03:02:43 +02:00
parent 648578d851
commit 9a5de048d8

@@ -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:** -<br>
**returns:** the object<br>
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:** -<br>
**returns:** the object<br>
# setPosition
Changes the position relative to its parent frame
````lua
local mainFrame = CreateFrame("myFirstFrame"):setPosition(2,3)
````
**args:** int x, int y<br>
**returns:** the frame object<br>
## setBackground
Changes the object background color
````lua
local mainFrame = CreateFrame("myFirstFrame"):setBackground(colors.lightGray)
````
**args:** int color<br>
**returns:** the object<br>
## setForeground
Changes the object text color
````lua
local mainFrame = CreateFrame("myFirstFrame"):setForeground(colors.black)
````
**args:** int color<br>
**returns:** the object<br>
## setSize
Changes the object size
````lua
local mainFrame = CreateFrame("myFirstFrame"):setSize(15,5)
````
**args:** width, length<br>
**returns:** the object<br>
## setFocus
sets the object to be the focused object
````lua
local mainFrame = CreateFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setFocus():show()
````
**args:** -<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## 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:** -<br>
**returns:** true or false<br>
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<br>
**returns:** converted coordinates<br>
# 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<br>
**returns:** the object<br>
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<br>
**returns:** the object<br>
## 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"<br>
**returns:** the object<br>
* 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,...)<br>
**returns:** the object<br>
## 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:**-<br>
**returns:** the value<br>
## 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:**-<br>
**returns:** returns the height or the width<br>
## 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:**-<br>
**returns:** returns the visible state of that object<br>
## getName
returns the given name of that object
````lua
local mainFrame = CreateFrame("myFirstFrame"):show()
NyoUI.debug(mainFrame:getName()) -- returns myFirstFrame
````
**args:**-<br>
**returns:** returns the name<br>
# 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<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## 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<br>
**returns:** the object<br>
## onLoseFocus
creates a lose focus event
````lua
local mainFrame = CreateFrame("myFirstFrame"):onLoseFocus(function(self) NyoUI.debug("please come back..") end):show()
````
**args:** function<br>
**returns:** the object<br>
## onGetFocus
creates a get focus event
````lua
local mainFrame = CreateFrame("myFirstFrame"):onGetFocus(function(self) NyoUI.debug("thanks!") end):show()
````
**args:** function<br>
**returns:** the object<br>