Skip to content

Commit

Permalink
feat: adapt TextField for raylib, WIP on ToggleMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabaut committed Sep 5, 2024
1 parent 5a8161d commit 247b48c
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 16 deletions.
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define the package name and version
AC_INIT([sprites4curses], [0.4.8], [[email protected]])
AC_INIT([sprites4curses], [0.4.9-dev], [[email protected]])

# Verify automake version and enable foreign option
AM_INIT_AUTOMAKE([foreign -Wall])
Expand All @@ -20,7 +20,7 @@ AM_CONDITIONAL([S4C_ANIMATE_BUILD], [test "$enable_animate" = "yes"])
AC_ARG_ENABLE([gui],
[AS_HELP_STRING([--enable-gui], [Enable gui extension header])],
[enable_gui=$enableval],
[enable_gui=no])
[enable_gui=yes])
AM_CONDITIONAL([S4C_GUI_BUILD], [test "$enable_gui" = "yes"])

AC_ARG_ENABLE([animate_raylib],
Expand Down Expand Up @@ -107,7 +107,7 @@ AM_CONDITIONAL([LINUX_BUILD], [test "$build_linux" = "yes"])
# Set a default version number if not specified externally
AC_ARG_VAR([VERSION], [Version number])
if test -z "$VERSION"; then
VERSION="0.4.8"
VERSION="0.4.9-dev"
fi

# Output variables to the config.h header
Expand Down
2 changes: 1 addition & 1 deletion documentation/s4c.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "sprites4curses"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "0.4.8"
PROJECT_NUMBER = "0.4.9-dev"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
57 changes: 56 additions & 1 deletion s4c-demo/demo_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
#ifdef S4C_GUI_H_
int textfield_main(void)
{
#ifndef S4C_RAYLIB_EXTENSION
// Initialize ncurses
initscr();
cbreak(); // Disable line buffering
noecho(); // Don't echo input to screen
#else
const int screenWidth = 800;
const int screenHeight = 450;

InitWindow(screenWidth, screenHeight, "s4c demo_gui for raylib");
SetTargetFPS(60);
#endif // S4C_RAYLIB_EXTENSION

// Define the dimensions and position of the window
int height = 5;
Expand All @@ -43,10 +51,15 @@ int textfield_main(void)
size_t max_size = 10;
char* prompt = "Start typing";

#ifndef S4C_RAYLIB_EXTENSION
TextField txt_field = new_TextField_centered_(&warn_TextField, my_linters, n_linters, linter_args, max_size, height, width, COLS, LINES, prompt, S4C_GUI_MALLOC, S4C_GUI_CALLOC, NULL);
#else
TextField txt_field = new_TextField_centered_(&warn_TextField, my_linters, n_linters, linter_args, max_size, height*10, width*10, screenWidth, screenHeight, prompt, GRAY, RED, S4C_GUI_MALLOC, S4C_GUI_CALLOC, NULL);
#endif // S4C_RAYLIB_EXTENSION

use_clean_TextField(txt_field);

#ifndef S4C_RAYLIB_EXTENSION
use_clean_TextField(txt_field);
// Print the input back to the screen
mvprintw(LINES/2 +1, (COLS - strlen("You entered: ")) / 2, "You entered: %s", get_TextField_value(txt_field));
mvprintw(LINES/2 +2, (COLS - strlen("len: ")) / 2, "len: %i", get_TextField_len(txt_field));
Expand All @@ -55,9 +68,32 @@ int textfield_main(void)

// Wait for user input before exiting
getch();
#else
assert(txt_field != NULL);
clear_TextField(txt_field);
while (!WindowShouldClose()) {
// Update
update_TextField(txt_field);
BeginDrawing();
// Draw
ClearBackground(WHITE);
draw_TextField(txt_field);
EndDrawing();
}
/*
fprintf(stderr, "You entered: {%s}\n", get_TextField_value(txt_field));
fprintf(stderr, "Len: {%i}\n", get_TextField_len(txt_field));
fprintf(stderr, "Lint result: {%s}\n", (lint_TextField(txt_field) ? "pass" : "fail"));
*/
#endif // S4C_RAYLIB_EXTENSION

free_TextField(txt_field);

#ifndef S4C_RAYLIB_EXTENSION
endwin();
#else
CloseWindow();
#endif // S4C_RAYLIB_EXTENSION

return 0;
}
Expand Down Expand Up @@ -86,16 +122,22 @@ const char* my_format(int val)

int togglemenu_main(size_t argc, char** argv)
{
#ifndef S4C_RAYLIB_EXTENSION
// Initialize ncurses
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
#endif // S4C_RAYLIB_EXTENSION

// Define the dimensions and position of the textfield window
int height = 5;
int width = 30;
#ifndef S4C_RAYLIB_EXTENSION
int start_y = (LINES/2) +3;
#else
int start_y = 2;
#endif // S4C_RAYLIB_EXTENSION
int start_x = 2;

size_t txt_max_size_1 = 10;
Expand All @@ -117,22 +159,35 @@ int togglemenu_main(size_t argc, char** argv)
int num_toggles = sizeof(toggles) / sizeof(toggles[0]);
ToggleMenu toggle_menu = {0};

#ifndef S4C_RAYLIB_EXTENSION
if (argc > 2) {
toggle_menu = new_ToggleMenu_with_mouse(toggles, num_toggles, &default_ToggleMenu_mousehandler__);
} else {
toggle_menu = new_ToggleMenu(toggles, num_toggles);
}
#else
toggle_menu = new_ToggleMenu(toggles, num_toggles);
#endif // S4C_RAYLIB_EXTENSION

#ifndef S4C_RAYLIB_EXTENSION
toggle_menu.statewin_height = LINES;
toggle_menu.statewin_width = COLS/2;
toggle_menu.statewin_start_x = COLS/2;
#else
toggle_menu.statewin_height = 50;
toggle_menu.statewin_width = 50;
toggle_menu.statewin_start_x = 50;
#endif // S4C_RAYLIB_EXTENSION
toggle_menu.statewin_start_y = 0;
toggle_menu.statewin_boxed = true;
toggle_menu.statewin_label = sidewin_label;
toggle_menu.key_up = 'j';
toggle_menu.key_down = 'k';
handle_ToggleMenu(toggle_menu);

#ifndef S4C_RAYLIB_EXTENSION
endwin(); // End ncurses
#endif // S4C_RAYLIB_EXTENSION
free_ToggleMenu(toggle_menu);
return 0;
}
Expand Down
Loading

0 comments on commit 247b48c

Please sign in to comment.