Skip to content

Commit d2acf06

Browse files
hugoarnalraysan5
andauthored
[examples] Added core_directory_files (#5230)
* ADDED: example: `core_directory_files` * Follow raylib's conventions * Rework `core_directory_files` example * Removed alternating colors & text on directory * Update screenshot --------- Co-authored-by: Ray <[email protected]>
1 parent af11859 commit d2acf06

File tree

9 files changed

+903
-205
lines changed

9 files changed

+903
-205
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ CORE = \
515515
core/core_custom_frame_control \
516516
core/core_custom_logging \
517517
core/core_delta_time \
518+
core/core_directory_files \
518519
core/core_drop_files \
519520
core/core_high_dpi \
520521
core/core_input_actions \

examples/Makefile.Web

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ CORE = \
515515
core/core_custom_frame_control \
516516
core/core_custom_logging \
517517
core/core_delta_time \
518+
core/core_directory_files \
518519
core/core_drop_files \
519520
core/core_high_dpi \
520521
core/core_input_actions \
@@ -742,6 +743,9 @@ core/core_custom_logging: core/core_custom_logging.c
742743
core/core_delta_time: core/core_delta_time.c
743744
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
744745

746+
core/core_directory_files: core/core_directory_files.c
747+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
748+
745749
core/core_drop_files: core/core_drop_files.c
746750
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
747751

examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ You may find it easier to use than other toolchains, especially when it comes to
1717
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
1818
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
1919

20-
## EXAMPLES COLLECTION [TOTAL: 175]
20+
## EXAMPLES COLLECTION [TOTAL: 176]
2121

22-
### category: core [40]
22+
### category: core [41]
2323

2424
Examples using raylib[core](../src/rcore.c) platform functionality like window creation, inputs, drawing modes and system functionality.
2525

@@ -65,6 +65,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
6565
| [core_render_texture](core/core_render_texture.c) | <img src="core/core_render_texture.png" alt="core_render_texture" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
6666
| [core_undo_redo](core/core_undo_redo.c) | <img src="core/core_undo_redo.png" alt="core_undo_redo" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) |
6767
| [core_input_actions](core/core_input_actions.c) | <img src="core/core_input_actions.png" alt="core_input_actions" width="80"> | ⭐⭐☆☆ | 5.5 | 5.6 | [Jett](https://github.com/JettMonstersGoBoom) |
68+
| [core_directory_files](core/core_directory_files.c) | <img src="core/core_directory_files.png" alt="core_directory_files" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Hugo ARNAL](https://github.com/hugoarnal) |
6869

6970
### category: shapes [26]
7071

@@ -148,7 +149,7 @@ Examples using raylib text functionality, including sprite fonts loading/generat
148149
| [text_writing_anim](text/text_writing_anim.c) | <img src="text/text_writing_anim.png" alt="text_writing_anim" width="80"> | ⭐⭐☆☆ | 1.4 | 1.4 | [Ramon Santamaria](https://github.com/raysan5) |
149150
| [text_rectangle_bounds](text/text_rectangle_bounds.c) | <img src="text/text_rectangle_bounds.png" alt="text_rectangle_bounds" width="80"> | ⭐⭐⭐⭐️ | 2.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
150151
| [text_unicode_emojis](text/text_unicode_emojis.c) | <img src="text/text_unicode_emojis.png" alt="text_unicode_emojis" width="80"> | ⭐⭐⭐⭐️ | 2.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
151-
| [text_unicode_ranges](text/text_unicode_ranges.c) | <img src="text/text_unicode_ranges.png" alt="text_unicode_ranges" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Vlad Adrian](https://github.com/demizdor) |
152+
| [text_unicode_ranges](text/text_unicode_ranges.c) | <img src="text/text_unicode_ranges.png" alt="text_unicode_ranges" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Vadim Gunko](https://github.com/GuvaCode) |
152153
| [text_3d_drawing](text/text_3d_drawing.c) | <img src="text/text_3d_drawing.png" alt="text_3d_drawing" width="80"> | ⭐⭐⭐⭐️ | 3.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
153154
| [text_codepoints_loading](text/text_codepoints_loading.c) | <img src="text/text_codepoints_loading.png" alt="text_codepoints_loading" width="80"> | ⭐⭐⭐☆ | 4.2 | 4.2 | [Ramon Santamaria](https://github.com/raysan5) |
154155
| [text_inline_styling](text/text_inline_styling.c) | <img src="text/text_inline_styling.png" alt="text_inline_styling" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [Wagner Barongello](https://github.com/SultansOfCode) |
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [core] example - directory files
4+
*
5+
* Example complexity rating: [★☆☆☆] 1/4
6+
*
7+
* Example originally created with raylib 5.5, last time updated with raylib 5.6
8+
*
9+
* Example contributed by Hugo ARNAL (@hugoarnal) and reviewed by Ramon Santamaria (@raysan5)
10+
*
11+
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
12+
* BSD-like license that allows static linking with closed source software
13+
*
14+
* Copyright (c) 2025 Hugo ARNAL (@hugoarnal)
15+
*
16+
********************************************************************************************/
17+
18+
#include "raylib.h"
19+
#include <string.h> // Required for: strcpy()
20+
21+
#define MAX_FILEPATH_SIZE 2048
22+
23+
#define RAYGUI_IMPLEMENTATION
24+
#include "../shapes/raygui.h" // Required for GUI controls
25+
26+
//------------------------------------------------------------------------------------
27+
// Program main entry point
28+
//------------------------------------------------------------------------------------
29+
int main(void)
30+
{
31+
// Initialization
32+
//--------------------------------------------------------------------------------------
33+
const int screenWidth = 800;
34+
const int screenHeight = 450;
35+
36+
InitWindow(screenWidth, screenHeight, "raylib [core] example - directory files");
37+
38+
char directory[MAX_FILEPATH_SIZE] = { 0 };
39+
strcpy(directory, GetWorkingDirectory());
40+
FilePathList files = LoadDirectoryFiles(directory);
41+
42+
SetTargetFPS(60);
43+
//--------------------------------------------------------------------------------------
44+
45+
// Main game loop
46+
while (!WindowShouldClose()) // Detect window close button or ESC key
47+
{
48+
// Update
49+
//----------------------------------------------------------------------------------
50+
51+
// Draw
52+
//----------------------------------------------------------------------------------
53+
BeginDrawing();
54+
ClearBackground(RAYWHITE);
55+
56+
DrawText(directory, 100, 40, 20, DARKGRAY);
57+
58+
if (GuiButton((Rectangle){40.0f, 40.0f, 20, 20}, "<"))
59+
{
60+
strcpy(directory, GetPrevDirectoryPath(directory));
61+
UnloadDirectoryFiles(files);
62+
files = LoadDirectoryFiles(directory);
63+
}
64+
65+
for (int i = 0; i < (int)files.count; i++)
66+
{
67+
Color color = Fade(LIGHTGRAY, 0.3f);
68+
69+
if (!IsPathFile(files.paths[i]))
70+
{
71+
if (GuiButton((Rectangle){0.0f, 85.0f + 40.0f*(float)i, screenWidth, 40}, ""))
72+
{
73+
strcpy(directory, files.paths[i]);
74+
UnloadDirectoryFiles(files);
75+
files = LoadDirectoryFiles(directory);
76+
}
77+
}
78+
DrawRectangle(0, 85 + 40*i, screenWidth, 40, color);
79+
80+
DrawText(GetFileName(files.paths[i]), 120, 100 + 40*i, 10, GRAY);
81+
}
82+
EndDrawing();
83+
//----------------------------------------------------------------------------------
84+
}
85+
86+
// De-Initialization
87+
//--------------------------------------------------------------------------------------
88+
UnloadDirectoryFiles(files);
89+
90+
CloseWindow(); // Close window and OpenGL context
91+
//--------------------------------------------------------------------------------------
92+
93+
return 0;
94+
}
2.23 KB
Loading

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ core;core_high_dpi;★★☆☆;5.0;5.5;2025;2025;"Jonathan Marler";@marler8997
4747
core;core_render_texture;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
4848
core;core_undo_redo;★★★☆;5.5;5.6;2025;2025;"Ramon Santamaria";@raysan5
4949
core;core_input_actions;★★☆☆;5.5;5.6;2025;2025;"Jett";@JettMonstersGoBoom
50+
core;core_directory_files;★☆☆☆;5.5;5.6;2025;2025;"Hugo ARNAL";@hugoarnal
5051
shapes;shapes_basic_shapes;★☆☆☆;1.0;4.2;2014;2025;"Ramon Santamaria";@raysan5
5152
shapes;shapes_bouncing_ball;★☆☆☆;2.5;2.5;2013;2025;"Ramon Santamaria";@raysan5
5253
shapes;shapes_bullet_hell;★☆☆☆;5.6;5.6;2025;2025;"Zero";@zerohorsepower

0 commit comments

Comments
 (0)