Add proper level selection actions
Internal Changelog: - Scroll area will auto scroll to make selection completely visiblemain
parent
41f3656ba1
commit
eff3d090df
17
engine/gui.c
17
engine/gui.c
|
@ -678,12 +678,25 @@ void vert_scrollarea_render(VertScrollArea_t* scroll_area)
|
||||||
scroll_area->display_area.width,
|
scroll_area->display_area.width,
|
||||||
scroll_area->display_area.height
|
scroll_area->display_area.height
|
||||||
};
|
};
|
||||||
float selection_y = scroll_area->curr_selection * (scroll_area->item_height + scroll_area->item_padding) + scroll_area->item_padding;
|
float selection_y = scroll_area->curr_selection * (scroll_area->item_height + scroll_area->item_padding) + scroll_area->item_padding - (scroll_area->scroll_bounds.y - scroll_area->scroll_pos);
|
||||||
|
|
||||||
DrawRectangle(
|
DrawRectangle(
|
||||||
scroll_area->display_area.x, scroll_area->display_area.y + selection_y - (scroll_area->scroll_bounds.y - scroll_area->scroll_pos),
|
scroll_area->display_area.x,
|
||||||
|
scroll_area->display_area.y + selection_y,
|
||||||
scroll_area->canvas.texture.width, scroll_area->item_height,
|
scroll_area->canvas.texture.width, scroll_area->item_height,
|
||||||
Fade(BLUE, 0.7)
|
Fade(BLUE, 0.7)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Auto adjust scroll based on selection
|
||||||
|
if (selection_y < 0)
|
||||||
|
{
|
||||||
|
scroll_area->scroll_pos -= selection_y;
|
||||||
|
}
|
||||||
|
else if (selection_y + scroll_area->item_height + scroll_area->item_padding > scroll_area->display_area.height)
|
||||||
|
{
|
||||||
|
scroll_area->scroll_pos -= selection_y + scroll_area->item_height + scroll_area->item_padding - scroll_area->display_area.height;
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 draw_pos = {scroll_area->display_area.x, scroll_area->display_area.y};
|
Vector2 draw_pos = {scroll_area->display_area.x, scroll_area->display_area.y};
|
||||||
draw_rec.height *= -1;
|
draw_rec.height *= -1;
|
||||||
DrawTextureRec(
|
DrawTextureRec(
|
||||||
|
|
|
@ -4,12 +4,6 @@
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define FONT_SIZE 30
|
|
||||||
#define TEXT_PADDING 3
|
|
||||||
#define TEXT_HEIGHT (FONT_SIZE+TEXT_PADDING)
|
|
||||||
#define DISPLAY_AREA_HEIGHT 400
|
|
||||||
#define SCROLL_TOTAL_HEIGHT 800
|
|
||||||
#define HIDDEN_AREA_HEIGHT (SCROLL_TOTAL_HEIGHT - DISPLAY_AREA_HEIGHT)
|
|
||||||
static void level_select_render_func(Scene_t* scene)
|
static void level_select_render_func(Scene_t* scene)
|
||||||
{
|
{
|
||||||
LevelSelectSceneData_t* data = &(CONTAINER_OF(scene, LevelSelectScene_t, scene)->data);
|
LevelSelectSceneData_t* data = &(CONTAINER_OF(scene, LevelSelectScene_t, scene)->data);
|
||||||
|
@ -25,17 +19,21 @@ static void level_select_do_action(Scene_t* scene, ActionType_t action, bool pre
|
||||||
switch(action)
|
switch(action)
|
||||||
{
|
{
|
||||||
case ACTION_UP:
|
case ACTION_UP:
|
||||||
if (pressed)
|
if (!pressed)
|
||||||
{
|
{
|
||||||
data->scroll_area.scroll_pos += 3;
|
if (data->scroll_area.curr_selection > 0)
|
||||||
data->scroll_area.scroll_pos = Clamp(data->scroll_area.scroll_pos,data->scroll_area.scroll_bounds.x, data->scroll_area.scroll_bounds.y);
|
{
|
||||||
|
data->scroll_area.curr_selection--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_DOWN:
|
case ACTION_DOWN:
|
||||||
if (pressed)
|
if (!pressed)
|
||||||
{
|
{
|
||||||
data->scroll_area.scroll_pos -= 3;
|
if (data->scroll_area.curr_selection < data->scroll_area.n_items - 1)
|
||||||
data->scroll_area.scroll_pos = Clamp(data->scroll_area.scroll_pos,data->scroll_area.scroll_bounds.x, data->scroll_area.scroll_bounds.y);
|
{
|
||||||
|
data->scroll_area.curr_selection++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_EXIT:
|
case ACTION_EXIT:
|
||||||
|
@ -66,6 +64,10 @@ static void level_select_do_action(Scene_t* scene, ActionType_t action, bool pre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define FONT_SIZE 30
|
||||||
|
#define TEXT_PADDING 3
|
||||||
|
#define DISPLAY_AREA_HEIGHT 400
|
||||||
|
#define SCROLL_TOTAL_HEIGHT 800
|
||||||
void init_level_select_scene(LevelSelectScene_t* scene)
|
void init_level_select_scene(LevelSelectScene_t* scene)
|
||||||
{
|
{
|
||||||
init_scene(&scene->scene, &level_select_do_action);
|
init_scene(&scene->scene, &level_select_do_action);
|
||||||
|
@ -80,6 +82,7 @@ void init_level_select_scene(LevelSelectScene_t* scene)
|
||||||
ClearBackground(BLANK);
|
ClearBackground(BLANK);
|
||||||
if (scene->data.level_pack != NULL)
|
if (scene->data.level_pack != NULL)
|
||||||
{
|
{
|
||||||
|
scene->data.scroll_area.n_items = scene->data.level_pack->n_levels;
|
||||||
for (unsigned int i = 0; i < scene->data.level_pack->n_levels; ++i)
|
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);
|
vert_scrollarea_insert_item(&scene->data.scroll_area, scene->data.level_pack->levels[i].level_name, i);
|
||||||
|
|
Loading…
Reference in New Issue