Raygui done.

This commit is contained in:
jussi
2022-03-31 15:25:33 +03:00
parent 30d425aa26
commit 7928f9dbab
6 changed files with 352 additions and 13 deletions

96
API.md
View File

@@ -3472,25 +3472,59 @@ Get camera look-at matrix ( View matrix )
> RL_GuiEnable()
Enable gui controls ( Global state )
Enable gui controls ( global state )
---
> RL_GuiDisable()
Disable gui controls ( Global state )
Disable gui controls ( global state )
---
> RL_GuiLock()
Lock gui controls ( Global state )
Lock gui controls ( global state )
---
> RL_GuiUnlock()
Unlock gui controls ( Global state )
Unlock gui controls ( global state )
---
> locked = RL_GuiIsLocked()
Check if gui is locked ( global state )
- Success return bool
---
> success = RL_GuiFade( float alpha )
Set gui controls alpha ( global state ), alpha goes from 0.0f to 1.0f
- Failure return false
- Success return true
---
> success = RL_GuiSetState( int state )
Set gui state ( global state )
- Failure return false
- Success return true
---
> state = RL_GuiGetState()
Get gui state ( global state )
- Success return int
---
@@ -3615,6 +3649,15 @@ Button control, returns true when clicked
---
> clicked = RL_GuiLabelButton( Rectangle bounds, string text )
Label button control, show true when clicked
- Failure return nil
- Success return boolean
---
> active = RL_GuiToggle( Rectangle bounds, string text, bool active )
Toggle Button control, returns true when active
@@ -3642,6 +3685,15 @@ Check Box control, returns true when active
---
> active = RL_GuiComboBox( Rectangle bounds, string text, int active )
Combo Box control, returns selected item index
- Failure return nil
- Success return int
---
> pressed, text = RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )
Text Box control, updates input text
@@ -3723,6 +3775,33 @@ Dropdown Box control, returns selected item
---
> success = RL_GuiStatusBar( Rectangle bounds, string text )
Status Bar control, shows info text
- Failure return false
- Success return true
---
> success = RL_GuiDummyRec( Rectangle bounds, string text )
Dummy control for placeholders
- Failure return false
- Success return true
---
> cell = RL_GuiGrid( Rectangle bounds, string text, float spacing, int subdivs )
Grid control, returns mouse cell position
- Failure return false
- Success return Vector2
---
## Gui - Advanced
---
@@ -3736,6 +3815,15 @@ List View control, returns selected list item index and scroll index
---
> itemIndex, scrollIndex, focus = RL_GuiListViewEx( Rectangle bounds, string text, int focus, int scrollIndex, int active )
List View with extended parameters, returns selected list item index, scroll index and focus
- Failure return nil
- Success return int, int, int
---
> buttonIndex = RL_GuiMessageBox( Rectangle bounds, string title, string message, string buttons )
Message Box control, displays a message, returns button index ( 0 is x button )

View File

@@ -15,9 +15,9 @@ ReiLua is currently in arbitrary version 0.1 and some planned raylib functionali
List of some MISSING features that are planned to be included. For specific function, check API.
* Core
* Some screen-space-related functions
* Files drop
* camera2d and it's functions
* Camera2d and it's functions
* Screen-space-related functions
* VR stereo config functions for VR simulator
* Textures
* Image manipulation functions
@@ -32,7 +32,7 @@ List of some MISSING features that are planned to be included. For specific func
Submodules.
* Raygui
* Raygui ( Done )
* Raymath
* Quaternions
* Physac

View File

@@ -13,10 +13,12 @@ local dropdownValue = 0
local dropdownActive = false
local index = 0
local listView = { item = 0, scroll = 0 }
local listViewEx = { item = 0, scroll = 0, focus = 0 }
local messageBox = { buttonIndex = -1 }
local textInputBox = { buttonIndex = 0, text = "", secretViewActive = 1 }
local colorPicker = { color = { 255, 255, 255 } }
local colorPanel = { color = { 255, 255, 255 }, alpha = 1.0, hue = 1.0, oldHue = 1.0 }
local comboBoxActive = 0
function init()
local monitor = 0
@@ -35,8 +37,7 @@ end
function draw()
RL_ClearBackground( { 50, 20, 75 } )
if RL_GuiButton( { 112, 16, 96, 32 }, "Button" ) then
print( "Button pressed!" )
if RL_GuiButton( { 112, 16, 96, 32 }, "Exit" ) then
RL_CloseWindow()
end
@@ -77,6 +78,7 @@ function draw()
end
listView.item, listView.scroll = RL_GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item )
-- listViewEx.item, listViewEx.scroll, listViewEx.focus = RL_GuiListViewEx( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listViewEx.focus, listViewEx.scroll, listViewEx.item )
messageBox.buttonIndex = RL_GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes\nNo" )
if 0 <= messageBox.buttonIndex then
@@ -103,4 +105,6 @@ function draw()
end
RL_GuiDrawIcon( 121, { 6, 20 }, 2, WHITE )
comboBoxActive = RL_GuiComboBox( { 5, 50, 80, 20 }, "One\nTwo\nThree", comboBoxActive )
end

View File

@@ -5,6 +5,10 @@ int lguiGuiEnable( lua_State *L );
int lguiGuiDisable( lua_State *L );
int lguiGuiLock( lua_State *L );
int lguiGuiUnlock( lua_State *L );
int lguiGuiIsLocked( lua_State *L );
int lguiGuiFade( lua_State *L );
int lguiGuiSetState( lua_State *L );
int lguiGuiGetState( lua_State *L );
/* Font. */
int lguiGuiSetFont( lua_State *L );
/* Style */
@@ -21,9 +25,11 @@ int lguiGuiScrollPanel( lua_State *L );
/* Basic. */
int lguiGuiLabel( lua_State *L );
int lguiGuiButton( lua_State *L );
int lguiGuiLabelButton( lua_State *L );
int lguiGuiToggle( lua_State *L );
int lguiGuiToggleGroup( lua_State *L );
int lguiGuiCheckBox( lua_State *L );
int lguiGuiComboBox( lua_State *L );
int lguiGuiTextBox( lua_State *L );
int lguiGuiTextBoxMulti( lua_State *L );
int lguiGuiSpinner( lua_State *L );
@@ -33,8 +39,12 @@ int lguiGuiSliderBar( lua_State *L );
int lguiGuiProgressBar( lua_State *L );
int lguiGuiScrollBar( lua_State *L );
int lguiGuiDropdownBox( lua_State *L );
int lguiGuiStatusBar( lua_State *L );
int lguiGuiDummyRec( lua_State *L );
int lguiGuiGrid( lua_State *L );
/* Advanced. */
int lguiGuiListView( lua_State *L );
int lguiGuiListViewEx( lua_State *L );
int lguiGuiMessageBox( lua_State *L );
int lguiGuiTextInputBox( lua_State *L );
int lguiGuiColorPicker( lua_State *L );

View File

@@ -824,6 +824,10 @@ void luaRegister() {
lua_register( L, "RL_GuiDisable", lguiGuiDisable );
lua_register( L, "RL_GuiLock", lguiGuiLock );
lua_register( L, "RL_GuiUnlock", lguiGuiUnlock );
lua_register( L, "RL_GuiIsLocked", lguiGuiIsLocked );
lua_register( L, "RL_GuiFade", lguiGuiFade );
lua_register( L, "RL_GuiSetState", lguiGuiSetState );
lua_register( L, "RL_GuiGetState", lguiGuiGetState );
/* Font. */
lua_register( L, "RL_GuiSetFont", lguiGuiSetFont );
/* Style. */
@@ -840,9 +844,11 @@ void luaRegister() {
/* Basic. */
lua_register( L, "RL_GuiLabel", lguiGuiLabel );
lua_register( L, "RL_GuiButton", lguiGuiButton );
lua_register( L, "RL_GuiLabelButton", lguiGuiLabelButton );
lua_register( L, "RL_GuiToggle", lguiGuiToggle );
lua_register( L, "RL_GuiToggleGroup", lguiGuiToggleGroup );
lua_register( L, "RL_GuiCheckBox", lguiGuiCheckBox );
lua_register( L, "RL_GuiComboBox", lguiGuiComboBox );
lua_register( L, "RL_GuiTextBox", lguiGuiTextBox );
lua_register( L, "RL_GuiTextBoxMulti", lguiGuiTextBoxMulti );
lua_register( L, "RL_GuiSpinner", lguiGuiSpinner );
@@ -852,8 +858,12 @@ void luaRegister() {
lua_register( L, "RL_GuiProgressBar", lguiGuiProgressBar );
lua_register( L, "RL_GuiScrollBar", lguiGuiScrollBar );
lua_register( L, "RL_GuiDropdownBox", lguiGuiDropdownBox );
lua_register( L, "RL_GuiStatusBar", lguiGuiStatusBar );
lua_register( L, "RL_GuiDummyRec", lguiGuiDummyRec );
lua_register( L, "RL_GuiGrid", lguiGuiGrid );
/* Advanced. */
lua_register( L, "RL_GuiListView", lguiGuiListView );
lua_register( L, "RL_GuiListViewEx", lguiGuiListViewEx );
lua_register( L, "RL_GuiMessageBox", lguiGuiMessageBox );
lua_register( L, "RL_GuiTextInputBox", lguiGuiTextInputBox );
lua_register( L, "RL_GuiColorPicker", lguiGuiColorPicker );

View File

@@ -13,7 +13,7 @@
/*
> RL_GuiEnable()
Enable gui controls ( Global state )
Enable gui controls ( global state )
*/
int lguiGuiEnable( lua_State *L ) {
GuiEnable();
@@ -24,7 +24,7 @@ int lguiGuiEnable( lua_State *L ) {
/*
> RL_GuiDisable()
Disable gui controls ( Global state )
Disable gui controls ( global state )
*/
int lguiGuiDisable( lua_State *L ) {
GuiDisable();
@@ -35,7 +35,7 @@ int lguiGuiDisable( lua_State *L ) {
/*
> RL_GuiLock()
Lock gui controls ( Global state )
Lock gui controls ( global state )
*/
int lguiGuiLock( lua_State *L ) {
GuiLock();
@@ -46,7 +46,7 @@ int lguiGuiLock( lua_State *L ) {
/*
> RL_GuiUnlock()
Unlock gui controls ( Global state )
Unlock gui controls ( global state )
*/
int lguiGuiUnlock( lua_State *L ) {
GuiUnlock();
@@ -54,6 +54,72 @@ int lguiGuiUnlock( lua_State *L ) {
return 0;
}
/*
> locked = RL_GuiIsLocked()
Check if gui is locked ( global state )
- Success return bool
*/
int lguiGuiIsLocked( lua_State *L ) {
lua_pushboolean( L, GuiIsLocked() );
return 0;
}
/*
> success = RL_GuiFade( float alpha )
Set gui controls alpha ( global state ), alpha goes from 0.0f to 1.0f
- Failure return false
- Success return true
*/
int lguiGuiFade( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiFade( float alpha )" );
lua_pushboolean( L, false );
return 1;
}
GuiFade( lua_tonumber( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_GuiSetState( int state )
Set gui state ( global state )
- Failure return false
- Success return true
*/
int lguiGuiSetState( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSetState( int state )" );
lua_pushboolean( L, false );
return 1;
}
GuiSetState( lua_tointeger( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> state = RL_GuiGetState()
Get gui state ( global state )
- Success return int
*/
int lguiGuiGetState( lua_State *L ) {
lua_pushinteger( L, GuiGetState() );
return 1;
}
/*
## Gui - Font
*/
@@ -337,6 +403,30 @@ int lguiGuiButton( lua_State *L ) {
return 1;
}
/*
> clicked = RL_GuiLabelButton( Rectangle bounds, string text )
Label button control, show true when clicked
- Failure return nil
- Success return boolean
*/
int lguiGuiLabelButton( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiLabelButton( Rectangle bounds, string text )" );
lua_pushnil( L );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
lua_pushboolean( L, GuiLabelButton( bounds, text ) );
return 1;
}
/*
> active = RL_GuiToggle( Rectangle bounds, string text, bool active )
@@ -415,6 +505,32 @@ int lguiGuiCheckBox( lua_State *L ) {
return 1;
}
/*
> active = RL_GuiComboBox( Rectangle bounds, string text, int active )
Combo Box control, returns selected item index
- Failure return nil
- Success return int
*/
int lguiGuiComboBox( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiComboBox( Rectangle bounds, string text, int active )" );
lua_pushnil( L );
return 1;
}
int active = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
lua_pushinteger( L, GuiComboBox( bounds, text, active ) );
return 1;
}
/*
> pressed, text = RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )
@@ -699,6 +815,84 @@ int lguiGuiDropdownBox( lua_State *L ) {
return 2;
}
/*
> success = RL_GuiStatusBar( Rectangle bounds, string text )
Status Bar control, shows info text
- Failure return false
- Success return true
*/
int lguiGuiStatusBar( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiStatusBar( Rectangle bounds, string text )" );
lua_pushboolean( L, false );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
GuiStatusBar( bounds, text );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_GuiDummyRec( Rectangle bounds, string text )
Dummy control for placeholders
- Failure return false
- Success return true
*/
int lguiGuiDummyRec( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiDummyRec( Rectangle bounds, string text )" );
lua_pushboolean( L, false );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
GuiDummyRec( bounds, text );
lua_pushboolean( L, true );
return 1;
}
/*
> cell = RL_GuiGrid( Rectangle bounds, string text, float spacing, int subdivs )
Grid control, returns mouse cell position
- Failure return false
- Success return Vector2
*/
int lguiGuiGrid( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiGrid( Rectangle bounds, string text, float spacing, int subdivs )" );
lua_pushboolean( L, false );
return 1;
}
int subdivs = lua_tointeger( L, -1 );
lua_pop( L, 1 );
float spacing = lua_tonumber( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
uluaPushVector2( L, GuiGrid( bounds, text, spacing, subdivs ) );
return 1;
}
/*
## Gui - Advanced
*/
@@ -732,6 +926,39 @@ int lguiGuiListView( lua_State *L ) {
return 2;
}
/*
> itemIndex, scrollIndex, focus = RL_GuiListViewEx( Rectangle bounds, string text, int focus, int scrollIndex, int active )
List View with extended parameters, returns selected list item index, scroll index and focus
- Failure return nil
- Success return int, int, int
*/
int lguiGuiListViewEx( lua_State *L ) {
if ( !lua_istable( L, -5 ) || !lua_isstring( L, -4 ) || !lua_isnumber( L, -3 )
|| !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiListViewEx( Rectangle bounds, string text, int focus, int scrollIndex, int active )" );
lua_pushnil( L );
return 1;
}
int active = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int scrollIndex = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int focus = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int count = 0;
const char **text = GuiTextSplit( lua_tostring( L, -1 ), &count, NULL );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
lua_pushinteger( L, GuiListViewEx( bounds, text, count, &focus, &scrollIndex, active ) );
lua_pushinteger( L, scrollIndex );
lua_pushinteger( L, focus );
return 3;
}
/*
> buttonIndex = RL_GuiMessageBox( Rectangle bounds, string title, string message, string buttons )