Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious.

This commit is contained in:
jussi
2024-04-13 18:44:42 +03:00
parent b96960a1f9
commit 1d66edf4f2
11 changed files with 67 additions and 36 deletions

6
API.md
View File

@@ -6864,7 +6864,7 @@ Get total number of codepoints in a UTF-8 encoded string
---
> codepoint, codepointSize = RL.GetCodepoint( string text )
> codepoint, codepointSize = RL.GetCodepoint( string text, int position )
Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
@@ -6872,7 +6872,7 @@ Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
---
> codepoint, codepointSize = RL.GetCodepointNext( string text )
> codepoint, codepointSize = RL.GetCodepointNext( string text, int position )
Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
@@ -6880,7 +6880,7 @@ Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
---
> codepoint, codepointSize = RL.GetCodepointPrevious( string text )
> codepoint, codepointSize = RL.GetCodepointPrevious( string text, int position )
Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure

View File

@@ -4151,23 +4151,26 @@ function RL.GetCodepointCount( text ) end
---Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
---- Success return int, int
---@param text string
---@param position integer
---@return any codepoint
---@return any codepointSize
function RL.GetCodepoint( text ) end
function RL.GetCodepoint( text, position ) end
---Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
---- Success return int, int
---@param text string
---@param position integer
---@return any codepoint
---@return any codepointSize
function RL.GetCodepointNext( text ) end
function RL.GetCodepointNext( text, position ) end
---Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
---- Success return int, int
---@param text string
---@param position integer
---@return any codepoint
---@return any codepointSize
function RL.GetCodepointPrevious( text ) end
function RL.GetCodepointPrevious( text, position ) end
---Encode one codepoint into UTF-8 byte array
---- Success return string

View File

@@ -37,6 +37,7 @@ DETAILED CHANGES:
- ADDED: PubSub lib.
- ADDED: Raygui lib tree view.
- ADDED: Raygui lib examples file browser.
- CHANGE: Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious.
------------------------------------------------------------------------
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -12,6 +12,8 @@ local LIGHTRENDER_SIZE = 1024 -- Maxinum light size.
local SHADOW_FOV = 45 -- Camera fov for shadow rendering.
local WALL_MESH_HEIGHT = math.tan( RL.DEG2RAD * ( 90 - SHADOW_FOV / 2 ) ) * LIGHTRENDER_SIZE / TILE_SIZE_PX / 2
print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT )
local monitor = 0
local monitorPos = Vector2:new( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:new( RL.GetMonitorSize( monitor ) )
@@ -24,7 +26,7 @@ local lightTexSize = Vector2:new()
local framebuffer = nil
local lightMap = nil -- Final image of all lights.
local lightRender = nil -- RenderTexture for individual light and shadow rendering.
local ambientLight = Color:new( 40, 40, 40, 255 )
local ambientLight = Color:new( 40, 40, 40 )
local wallSegs = {}
local shadowMesh = nil
local lights = {}
@@ -131,10 +133,10 @@ function RL.init()
RL.rlDisableBackfaceCulling()
end
-- Process.
-- Update.
function RL.update( delta )
lights[1].pos = Vector2:new( RL.GetMousePosition() )
lights[1].pos:set( RL.GetMousePosition() )
end
-- Drawing.

View File

@@ -182,7 +182,7 @@ function FileBrowser:new( pos )
return object
end
function FileBrowser:popup( mode, path, callback )
function FileBrowser:popup( mode, path, callback, filters )
self:setPath( path )
self.mode = mode
@@ -191,6 +191,10 @@ function FileBrowser:popup( mode, path, callback )
self.callbacks.ok = callback
end
if filters ~= nil then
self.filterDropdown.text = "All\n"..filters
end
self:setVisible( true )
end
@@ -266,7 +270,7 @@ function FileBrowser:updateList()
-- Search.
if self.searchText == "" or ( 0 < #self.searchText
and self.searchText:lower() == record.name:sub( 1, #self.searchText ):lower() ) then
and -1 < RL.TextFindIndex( record.name:lower(), self.searchText:lower() ) ) then
table.insert( self.files, record )
end
end
@@ -351,7 +355,6 @@ function FileBrowser:setFilter()
end
self:updateList()
print( "self.filter", self.filter )
end
function FileBrowser:setPosition( pos )

View File

@@ -13,22 +13,34 @@ function PubSub:add( name )
self.signals[ name ] = {}
end
function PubSub:remove( name )
if self.signals[ name ] ~= nil then
table.remove( self.signals, name )
end
end
function PubSub:subscribe( name, func )
if self.signals[ name ] ~= nil then
table.insert( self.signals[ name ], func )
end
end
function PubSub:unSubscribe( name, uFunc )
if self.signals[ name ] ~= nil then
for i, func in ipairs( self.signals[ name ] ) do
if func == uFunc then
table.remove( self.signals[ name ], i )
end
end
end
end
function PubSub:publish( name, ... )
if self.signals[ name ] ~= nil then
for _, func in ipairs( self.signals[ name ] ) do
func( ... )
end
end
end
return PubSub

View File

@@ -7,7 +7,8 @@ end
local utillib = {}
function utillib.tableClone( org )
-- Does not work with dictionaries.
function utillib.arrayClone( org )
return { table.unpack( org ) }
end

View File

@@ -1086,7 +1086,7 @@ int ltextGetCodepointCount( lua_State* L ) {
}
/*
> codepoint, codepointSize = RL.GetCodepoint( string text )
> codepoint, codepointSize = RL.GetCodepoint( string text, int position )
Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
@@ -1094,6 +1094,9 @@ Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
*/
int ltextGetCodepoint( lua_State* L ) {
const char* text = luaL_checkstring( L, 1 );
int position = luaL_checkinteger( L, 2 );
text += position;
int codepointSize = 0;
lua_pushinteger( L, GetCodepoint( text, &codepointSize ) );
@@ -1103,7 +1106,7 @@ int ltextGetCodepoint( lua_State* L ) {
}
/*
> codepoint, codepointSize = RL.GetCodepointNext( string text )
> codepoint, codepointSize = RL.GetCodepointNext( string text, int position )
Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
@@ -1111,6 +1114,9 @@ Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
*/
int ltextGetCodepointNext( lua_State* L ) {
const char* text = luaL_checkstring( L, 1 );
int position = luaL_checkinteger( L, 2 );
text += position;
int codepointSize = 0;
lua_pushinteger( L, GetCodepointNext( text, &codepointSize ) );
@@ -1120,7 +1126,7 @@ int ltextGetCodepointNext( lua_State* L ) {
}
/*
> codepoint, codepointSize = RL.GetCodepointPrevious( string text )
> codepoint, codepointSize = RL.GetCodepointPrevious( string text, int position )
Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
@@ -1128,6 +1134,9 @@ Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failu
*/
int ltextGetCodepointPrevious( lua_State* L ) {
const char* text = luaL_checkstring( L, 1 );
int position = luaL_checkinteger( L, 2 );
text += position;
int codepointSize = 0;
lua_pushinteger( L, GetCodepointPrevious( text, &codepointSize ) );