diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index a1eaee4..0a18b56 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -36,8 +36,8 @@ int main() { // Initialization //--------------------------------------------------------------------------------------- - int screenWidth = 600; - int screenHeight = 600; + int screenWidth = 690; + int screenHeight = 540; InitWindow(screenWidth, screenHeight, "raygui - controls test suite"); @@ -83,6 +83,8 @@ int main() int comboBoxActive = 1; int toggleGroupActive = 0; + + Vector2 viewScroll = { 0, 0 }; //---------------------------------------------------------------------------------- // Custom GUI font loading @@ -148,6 +150,8 @@ int main() sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, NULL, sliderBarValue, 0, 100, true); progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true); + viewScroll = GuiScrollPanel((Rectangle){ 560, 25, 100, 160 }, (Rectangle){ 560, 25, 100, 400 }, viewScroll); + //GuiEnable(); GuiUnlock(); //---------------------------------------------------------------------------------- diff --git a/src/raygui.h b/src/raygui.h index 18e305d..fad3c97 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -729,7 +729,62 @@ RAYGUIDEF void GuiPanel(Rectangle bounds) // NOTE: bounds define the view area, content defines size of internal data RAYGUIDEF Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll) { - // TODO: Implement scroll panel control + GuiControlState state = guiState; + + // Update control + //-------------------------------------------------------------------- + if ((state != GUI_STATE_DISABLED) && !guiLocked) + { + Vector2 mousePoint = GetMousePosition(); + + // Check button state + if (CheckCollisionPointRec(mousePoint, bounds)) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED; + else state = GUI_STATE_FOCUSED; + + viewScroll.y += GetMouseWheelMove()*10; + if (viewScroll.y > 0) viewScroll.y = 0; + if (viewScroll.y < (bounds.height - content.height)) viewScroll.y = bounds.height - content.height; + } + } + //-------------------------------------------------------------------- + + // Draw control + //-------------------------------------------------------------------- + DrawRectangleRec(bounds, RAYWHITE); + + switch (state) + { + case GUI_STATE_NORMAL: + { + DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_NORMAL)), guiAlpha)); + + } break; + case GUI_STATE_FOCUSED: + { + DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), guiAlpha)); + + } break; + case GUI_STATE_PRESSED: + { + DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), guiAlpha)); + + } break; + case GUI_STATE_DISABLED: + { + DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_DISABLED)), guiAlpha)); + + } break; + default: break; + } + + DrawRectangle(content.x, content.y + viewScroll.y, content.width, content.height, Fade(RED, 0.4f)); + + // Draw scroll bar + DrawRectangle(bounds.x + bounds.width - 11, bounds.y + 1, 10, bounds.height - 2, LIGHTGRAY); + DrawRectangle(bounds.x + bounds.width - 11, bounds.y - (bounds.height/content.height)*viewScroll.y, 10, (bounds.height/content.height)*bounds.height, DARKGRAY); + //-------------------------------------------------------------------- return viewScroll; } @@ -2256,7 +2311,6 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl // Update control //-------------------------------------------------------------------- - // All the elements fit inside ListView and dont need scrollbar. if (visibleElements >= count) { @@ -2291,6 +2345,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl auxActive--; if ((useScrollBar) && (auxActive < startIndex)) startIndex--; } + pressedKey = true; } else if (IsKeyPressed(KEY_DOWN)) @@ -2300,6 +2355,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl auxActive++; if ((useScrollBar) && (auxActive >= endIndex)) startIndex++; } + pressedKey = true; } @@ -2324,6 +2380,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl } endIndex = startIndex + visibleElements; + if (endIndex > count) endIndex = count; } } @@ -2335,24 +2392,22 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl state = GUI_STATE_FOCUSED; if (IsMouseButtonPressed(0)) pressed = true; - int wheel = GetMouseWheelMove(); - if (wheel) + startIndex -= GetMouseWheelMove(); + + if (startIndex < 0) startIndex = 0; + else if (startIndex > (count - (endIndex - startIndex))) { - startIndex -= wheel; - if (startIndex < 0) startIndex = 0; - else if (startIndex > (count - (endIndex - startIndex))) - { - startIndex = count - (endIndex - startIndex); - } - pressed = true; + startIndex = count - (endIndex - startIndex); } + + pressed = true; } } else { if (!CheckCollisionPointRec(mousePoint, bounds)) { - if (IsMouseButtonPressed(0) || GetMouseWheelMove() != 0) pressed = true; + if (IsMouseButtonPressed(0) || (GetMouseWheelMove() != 0)) pressed = true; } }