diff options
| -rw-r--r-- | API.md | 8 | ||||
| -rw-r--r-- | ReiLua_API.lua | 9 | ||||
| -rw-r--r-- | changelog | 1 | ||||
| -rw-r--r-- | examples/raygui_lib/main.lua | 7 | ||||
| -rw-r--r-- | examples/resources/lib/raygui.lua | 67 | ||||
| -rw-r--r-- | include/raygui.h | 4 | ||||
| -rw-r--r-- | include/rgui.h | 1 | ||||
| -rw-r--r-- | src/lua_core.c | 1 | ||||
| -rw-r--r-- | src/rgui.c | 18 |
9 files changed, 108 insertions, 8 deletions
@@ -8841,6 +8841,14 @@ Grid control, returns mouse cell position --- +> value = RL.GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue ) + +Scroll bar control + +- Success return int + +--- + ## Gui - Advance controls set --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 9d7158f..9e8b678 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -6006,6 +6006,15 @@ function RL.GuiDummyRec( bounds, text ) end ---@return any mouseCell function RL.GuiGrid( bounds, text, spacing, subdivs, mouseCell ) end +---Scroll bar control +---- Success return int +---@param bounds table +---@param value integer +---@param minValue integer +---@param maxValue integer +---@return any value +function RL.GuiScrollBar( bounds, value, minValue, maxValue ) end + -- Gui - Advance controls set ---List View control, returns selected list item index @@ -26,6 +26,7 @@ KEY CHANGES: - ADDED: RLGL Hello triangle example. - ADDED: Rest of rlRenderBatch functions. - ADDED: DrawTextureNPatchRepeat. + - ADDED: GuiScrollBar and made it puplic in raygui.h. DETAILED CHANGES: - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua index 01cf49b..0c3b559 100644 --- a/examples/raygui_lib/main.lua +++ b/examples/raygui_lib/main.lua @@ -301,6 +301,13 @@ function RL.init() "Color Panel", 1.0 ) + local scrollbar = Gui:GuiScrollBar( + Rect:new( 50, 760, 256, 16 ), + 0, + 0, + 256, + function( self ) print( "Scrollbar value: ", self.value ) end + ) end function RL.process( delta ) diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua index a9e314d..d28e9d9 100644 --- a/examples/resources/lib/raygui.lua +++ b/examples/resources/lib/raygui.lua @@ -892,7 +892,7 @@ function Slider:draw() _, self.value = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue ) if self.value ~= oldValue then - self._parentscrolling = true + self._parent.scrolling = true if self.callback ~= nil then self.callback( self ) @@ -939,7 +939,7 @@ function SliderBar:draw() _, self.value = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue ) if self.value ~= oldValue then - self._parentscrolling = true + self._parent.scrolling = true if self.callback ~= nil then self.callback( self ) @@ -1144,7 +1144,7 @@ function ListView:draw() _, self.scrollIndex, self.active = RL.GuiListView( self.bounds, self.text, self.scrollIndex, self.active ) if self.scrollIndex ~= oldScrollIndex then - self._parentscrolling = true + self._parent.scrolling = true end if oldActive ~= self.active and self.callback ~= nil then self.callback( self ) @@ -1194,7 +1194,7 @@ function ListViewEx:draw() _, self.scrollIndex, self.active, self.focus = RL.GuiListViewEx( self.bounds, self.text, self.scrollIndex, self.active, self.focus ) if self.scrollIndex ~= oldScrollIndex then - self._parentscrolling = true + self._parent.scrolling = true end if oldActive ~= self.active and self.callback ~= nil then self.callback( self ) @@ -1349,7 +1349,7 @@ function ColorPicker:draw() self.color = Color:new( color ) if self.color ~= oldColor then - self._parentscrolling = true + self._parent.scrolling = true if self.callback ~= nil then self.callback( self ) @@ -1433,7 +1433,7 @@ function ColorBarAlpha:draw() _, self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha ) if self.alpha ~= oldAlpha then - self._parentscrolling = true + self._parent.scrolling = true if self.callback ~= nil then self.callback( self ) @@ -1489,6 +1489,51 @@ function ColorBarHue:setPosition( pos ) self.bounds.y = pos.y end +-- ColorBarHue. + +--- Color Bar Hue control +local GuiScrollBar = {} +GuiScrollBar.__index = GuiScrollBar + +function GuiScrollBar:new( bounds, value, minValue, maxValue, callback ) + local object = setmetatable( {}, self ) + object._parent = nil + + object.bounds = bounds:clone() + object.value = value + object.minValue = minValue + object.maxValue = maxValue + object.callback = callback + + object.visible = true + object.disabled = false + + return object +end + +function GuiScrollBar:process() + return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) +end + +function GuiScrollBar:draw() + local oldValue = self.value + -- Note. Scrollbar style should be determined by the control that uses it. + self.value = RL.GuiScrollBar( self.bounds, self.value, self.minValue, self.maxValue ) + + if self.value ~= oldValue then + self._parent.scrolling = true + + if self.callback ~= nil then + self.callback( self ) + end + end +end + +function GuiScrollBar:setPosition( pos ) + self.bounds.x = pos.x + self.bounds.y = pos.y +end + -- Raygui class. local Raygui = {} @@ -2002,4 +2047,14 @@ function Raygui:ColorBarHue( bounds, text, value, callback ) return self:addElement( ColorBarHue:new( bounds, text, value, callback ) ) end +---@param bounds Rectangle +---@param value integer +---@param minValue integer +---@param maxValue integer +---@param callback function|nil +---@return table ColorBarHue +function Raygui:GuiScrollBar( bounds, value, minValue, maxValue, callback ) + return self:addElement( GuiScrollBar:new( bounds, value, minValue, maxValue, callback ) ) +end + return Raygui diff --git a/include/raygui.h b/include/raygui.h index f8349aa..816cd94 100644 --- a/include/raygui.h +++ b/include/raygui.h @@ -1475,7 +1475,7 @@ static const char **GuiTextSplit(const char *text, char delimiter, int *count, i static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV -static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll bar control, used by GuiScrollPanel() +int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll bar control, used by GuiScrollPanel() static void GuiTooltip(Rectangle controlRec); // Draw tooltip using control rec position static Color GuiFade(Color color, float alpha); // Fade color by an alpha factor @@ -5137,7 +5137,7 @@ static Vector3 ConvertHSVtoRGB(Vector3 hsv) } // Scroll bar control (used by GuiScrollPanel()) -static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) +int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) { GuiState state = guiState; diff --git a/include/rgui.h b/include/rgui.h index 92f9df4..7f2641b 100644 --- a/include/rgui.h +++ b/include/rgui.h @@ -54,6 +54,7 @@ int lguiGuiProgressBar( lua_State *L ); int lguiGuiStatusBar( lua_State *L ); int lguiGuiDummyRec( lua_State *L ); int lguiGuiGrid( lua_State *L ); +int lguiGuiScrollBar( lua_State *L ); /* Advance controls set. */ int lguiGuiListView( lua_State *L ); int lguiGuiListViewEx( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index 0da51dc..45ea370 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1940,6 +1940,7 @@ void luaRegister() { assingGlobalFunction( "GuiStatusBar", lguiGuiStatusBar ); assingGlobalFunction( "GuiDummyRec", lguiGuiDummyRec ); assingGlobalFunction( "GuiGrid", lguiGuiGrid ); + assingGlobalFunction( "GuiScrollBar", lguiGuiScrollBar ); /* Advance controls set. */ assingGlobalFunction( "GuiListView", lguiGuiListView ); assingGlobalFunction( "GuiListViewEx", lguiGuiListViewEx ); @@ -765,6 +765,24 @@ int lguiGuiGrid( lua_State *L ) { } /* +> value = RL.GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue ) + +Scroll bar control + +- Success return int +*/ +int lguiGuiScrollBar( lua_State *L ) { + Rectangle bounds = uluaGetRectangle( L, 1 ); + int value = luaL_checkinteger( L, 2 ); + int minValue = luaL_checkinteger( L, 3 ); + int maxValue = luaL_checkinteger( L, 4 ); + + lua_pushinteger( L, GuiScrollBar( bounds, value, minValue, maxValue ) ); + + return 1; +} + +/* ## Gui - Advance controls set */ |
