Fix scroll bar when n_items < max

main
En Yi 2025-01-22 22:54:55 +08:00
parent 451b099ec4
commit 96a6ccff39
3 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#include "gui.h"
#include "raylib.h"
#include <string.h>
#include <stdio.h>
#define RAYGUI_MAX_CONTROLS 16 // Maximum number of standard controls
#define RAYGUI_MAX_PROPS_BASE 16 // Maximum number of standard properties
@ -669,11 +670,14 @@ void vert_scrollarea_set_item_dims(VertScrollArea_t* scroll_area, unsigned int i
bool vert_scrollarea_n_items(VertScrollArea_t* scroll_area, unsigned int n_items) {
if (n_items >= scroll_area->max_items) return false;
//scroll_area->n_items = n_items;
//scroll_area->scroll_bounds.y = n_items * (scroll_area->item_height + scroll_area->item_padding);
//scroll_area->scroll_pos =
// (scroll_area->scroll_pos > scroll_area->scroll_bounds.y ) ?
// scroll_area->scroll_bounds.y : (scroll_area->scroll_pos;
// Due to OpenGL convention where y is -1 downwards,
// The scroll bar is set to decreases the scroll_pos when going down
// This value is used as the offset when rendering, which results in correctly
// give the illusion of 'scrolling down'
// So, adjust the minimum bound which is the height of the items that are not shown
scroll_area->n_items = n_items;
scroll_area->scroll_bounds.x =
(scroll_area->max_items - n_items)* (scroll_area->item_height + scroll_area->item_padding) + scroll_area->item_padding;
return true;
}

View File

@ -25,7 +25,6 @@ typedef struct VertScrollArea {
unsigned int item_padding;
float scroll_pos;
float max_scroll_bounds;
Vector2 scroll_bounds;
UIComp_t scroll_bar;

View File

@ -130,8 +130,7 @@ void init_level_select_scene(LevelSelectScene_t* scene)
ClearBackground(BLANK);
if (scene->data.level_pack != NULL)
{
scene->data.scroll_area.n_items = scene->data.level_pack->n_levels;
//vert_scrollarea_n_items(&scene->data.scroll_area, scene->data.level_pack->n_levels);
vert_scrollarea_n_items(&scene->data.scroll_area, scene->data.level_pack->n_levels);
for (unsigned int i = 0; i < scene->data.level_pack->n_levels; ++i)
{
vert_scrollarea_insert_item(&scene->data.scroll_area, scene->data.level_pack->levels[i].level_name, i);