diff --git a/libGUIDoc/README.md b/libGUIDoc/README.md new file mode 100644 index 0000000..1f74303 --- /dev/null +++ b/libGUIDoc/README.md @@ -0,0 +1,9 @@ +# libGUI +## Classes +- [Screen](Screen.md) +- [ImageFile](ImageFile.md) +- *[widget.Widget](widget/Widget.md)* +- [widget.Rectangle](widget/Rectangle.md) +- [widget.Text](widget/Text.md) +- [widget.Input](widget/Input.md) +- [widget.Image](widget/Image.md) \ No newline at end of file diff --git a/libGUIDoc/Screen.md b/libGUIDoc/Screen.md new file mode 100644 index 0000000..d3f0352 --- /dev/null +++ b/libGUIDoc/Screen.md @@ -0,0 +1,58 @@ +# Screen +Group widgets together do draw them, hide or show, enable or disable them. +You should always put any widget in at least one Screen as it manage a [frame buffer](https://ocdoc.cil.li/component:gpu#video_ram_buffers) to speed up drawing +## Constructor +Take no arguments + +## Public methods +### setVisible +Set the Screen's visibility. When hidden, no child widgets will be drawn. +#### Arguments +- visible : boolean + +--- +### enable +Enable or disable the Screen. When disabled, the trigger event won't be propagated to the children. +#### Arguments +- enable : boolean + +--- +### isVisible +Check if the Screen is visible. +#### Return +- boolean + +--- +### isEnabled +Check if the Screen is enable. +#### Return +- boolean + +--- +### addChild +Add a child to the Screen. +#### Arguments +- child : Widget|Screen + +--- +### trigger +Method to call to handle events. Most often a `touch` handler. +```lua +local gui = require "libGUI" +local event = require "event" + +local screen = gui.Screen() +event.listen("touch",function(...) screen:trigger(...) end) +``` +#### Arguments +- ... : any. The event infos + +--- +### draw +Draw the child widgets. +#### Arguments +- useBuffer : boolean. Should the Screen create a frame buffer to draw in. Default is true. +## Private methods +### clickHandler(eventName:string, uuid:string, x:int, y:int, button:int, playerName:string) +#### Parameter +`touch` event property. diff --git a/libGUIDoc/uml.txt b/libGUIDoc/uml.txt index c04e6a7..42871e4 100644 --- a/libGUIDoc/uml.txt +++ b/libGUIDoc/uml.txt @@ -13,7 +13,7 @@ class Screen { + bool isEnabled() + void addChild(Widget|Screen child) + void trigger(...) - + void draw() + + void draw(bool useBuffer) + childs[] Widget } class ImageFile { diff --git a/libGUIDoc/widget/Image.md b/libGUIDoc/widget/Image.md new file mode 100644 index 0000000..ac97f83 --- /dev/null +++ b/libGUIDoc/widget/Image.md @@ -0,0 +1,52 @@ +# Image([Widget](Widget.md)) +Display a image. Supported format are `.ppm` and `.pam` both in ASCII or RAW (binary) format. + +## Constructor +- x : int +- y : int +- img : string|[ImageFile](ImageFile.md). The image file path +- drawMethod : int + +## Inherited public methods +- [setX](Widget.md#setx) +- [setY](Widget.md#sety) +- [setPos](Widget.md#setpos) +- [getX](Widget.md#getx) +- [getY](Widget.md#gety) +- [getPos](Widget.md#getpos) +- [setCallback](Widget.md#setcallback) +- [draw](Widget.md#draw) +- [collide](Widget.md#collide) + +## Public methods +### getWidth +#### Return +- width : int +--- +### getHeight +#### Return +- height: int + +--- +### getSize +#### Return +- width : int +- height : int + +--- +### setDrawMethod +Define how a individual pixel is drawn : +- true : 2 pixels per character (square pixel) +- false : 1 pixel per character (rectangle pixel) +#### Argument +- drawMethod : boolean + +--- +### getDrawMethod +How a individual pixel is drawn : +- true : 2 pixels per character (square pixel) +- false : 1 pixel per character (rectangle pixel) +#### Return +- drawMethod : boolean + +--- \ No newline at end of file diff --git a/libGUIDoc/widget/Input.md b/libGUIDoc/widget/Input.md new file mode 100644 index 0000000..dae359f --- /dev/null +++ b/libGUIDoc/widget/Input.md @@ -0,0 +1,57 @@ +# Input([Text](Text.md)) +Get text input from the user. +The widget must be able to + +## Inherited public methods +- [setX](Widget.md#setx) +- [setY](Widget.md#sety) +- [setPos](Widget.md#setpos) +- [getX](Widget.md#getx) +- [getY](Widget.md#gety) +- [getPos](Widget.md#getpos) +- [draw](Widget.md#draw) +- [collide](Widget.md#collide) +- [setWidth](Rectangle.md#setwidth) +- [setHeight](Rectangle.mdsetHeight) +- [setSize](Rectangle.mdd#setsize) +- [setColor](Rectangle.md#setcolor) +- [getWidth](Rectangle.md#getwidth) +- [getHeight](Rectangle.md#getheight) +- [getSize](Rectangle.mdd#getsize) +- [getColor](Rectangle.md#getcolor) +- [getForeground](Text.md#getforeground) +- [getBackground](Text.md#getbackground) +- [setForeground](Text.md#setforeground) +- [setBackground](Text.md#setbackground) + +Do not use : +- [setCallback](Widget.md#setcallback) + +This methods are replaced by [getValue](#getvalue) and [setValue](#setvalue) +- [getText](Text.md#gettext) +- [setText](Text.md#settext) + +## Public methods +### setPlaceholder +If set, the widget will show the placeholder character instead of the normal text. Useful for password prompts +#### Arguments +- char : string|nil + +--- +### getPlaceholder +Get the placeholder character. +#### Return +- char : string + +--- +### getValue +Get the inputted value. Return a different value than `getText`. Prefer this method. +#### Return +- value : string +--- +### setValue +Get the inputted value. Should be used instead of `setText` +#### Arguments +#### Return + +--- \ No newline at end of file diff --git a/libGUIDoc/widget/Rectangle.md b/libGUIDoc/widget/Rectangle.md new file mode 100644 index 0000000..4568814 --- /dev/null +++ b/libGUIDoc/widget/Rectangle.md @@ -0,0 +1,61 @@ +# Rectangle([Widget](Widget.md)) +Basic rectangle shape. + +## Constructor +- x : int +- y : int +- width : int +- height : int +- color : int + +## Inherited public methods +- [setX](Widget.md#setx) +- [setY](Widget.md#sety) +- [setPos](Widget.md#setpos) +- [getX](Widget.md#getx) +- [getY](Widget.md#gety) +- [getPos](Widget.md#getpos) +- [setCallback](Widget.md#setcallback) +- [draw](Widget.md#draw) +- [collide](Widget.md#collide) + +## Public methods +### setWidth +#### Arguments +- width : int + +--- +### setHeight +#### Arguments +- height : int + +--- +### setSize +#### Arguments +- width : int +- height : int + +--- +### setColor +#### Arguments +- color : int. RGB color + +--- +### getWidth +#### Return +- width : int +--- +### getHeight +#### Return +- height: int + +--- +### getSize +#### Return +- width : int +- height : int + +--- +### getColor +#### Return +- color : int. RGB color diff --git a/libGUIDoc/widget/Text.md b/libGUIDoc/widget/Text.md new file mode 100644 index 0000000..dcf51ef --- /dev/null +++ b/libGUIDoc/widget/Text.md @@ -0,0 +1,59 @@ +# Text([Rectangle](Rectangle.md)) +Display text. +## Constructor +- x : int +- y : int +- width : int +- height : int +- backgroundColor : int +- text : string + +## Inherited public methods +- [setX](Widget.md#setx) +- [setY](Widget.md#sety) +- [setPos](Widget.md#setpos) +- [getX](Widget.md#getx) +- [getY](Widget.md#gety) +- [getPos](Widget.md#getpos) +- [setCallback](Widget.md#setcallback) +- [draw](Widget.md#draw) +- [collide](Widget.md#collide) +- [setWidth](Rectangle.md#setwidth) +- [setHeight](Rectangle.md#setheight) +- [setSize](Rectangle.mdd#setsize) +- [setColor](Rectangle.md#setcolor) +- [getWidth](Rectangle.md#getwidth) +- [getHeight](Rectangle.md#getheight) +- [getSize](Rectangle.mdd#getsize) +- [getColor](Rectangle.md#getcolor) + +## Public methods +### getText +#### Return +- text : string + +--- +### setText +#### Arguments +- text : string + +--- +### getForeground +#### Return +- color : int. RGB color + +--- +### getBackground +#### Return +- color : int. RGB color + +--- +### setForeground +#### Arguments +- color : int. RGB color + +--- +### setBackground +#### Arguments +- color : int. RGB color + diff --git a/libGUIDoc/widget/Widget.md b/libGUIDoc/widget/Widget.md new file mode 100644 index 0000000..1fc5e36 --- /dev/null +++ b/libGUIDoc/widget/Widget.md @@ -0,0 +1,64 @@ +# *Widget* +Abstract class. Define the basic information any widget need. +## Constructor +### Arguments +- x : int +- y : int + +## Abstract public methods + +### setPos +#### Arguments +- x : int +- y : int + +--- +### setX +#### Arguments + - x : int + +--- +### setY +#### Arguments + - y : int + +--- +### setCallback +Set the function called when `trigger` is called. This usually happen when the widget is clicked. +#### Arguments +- callback : function + +--- +### getX +#### Return +- x : int + +--- +### getY +#### Return +- y : int + +--- +### getPos +#### Return +- x : int +- y : int + +--- +### *collide* +Check if the position passed as arguments is on the widget +#### Arguments +- x : int +- y : int + +--- +### *draw* +Draw the widget. + +--- +## Public methods + +### trigger +Call the callback method if the widget is enabled. Pass the widget and all arguments passed to it to the callback method. +### Arguments +- ... : any \ No newline at end of file