From a5525a1b73a88862c86430d77f640a2826ad8dc2 Mon Sep 17 00:00:00 2001 From: Yahm3 <240418541@tut4life.ac.za> Date: Sun, 17 May 2026 16:06:28 +0200 Subject: [PATCH 1/3] build: Updated nob.c to create a build.h file in the include dir and also removed some duplicate code --- nob.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/nob.c b/nob.c index 3f2bb57..807f370 100644 --- a/nob.c +++ b/nob.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "nob.h" typedef struct { @@ -18,6 +19,7 @@ bool to_files(const char*[SOURCE_FILE_COUNT], StringList*, const char*, const ch bool build_object_files(const char*[SOURCE_FILE_COUNT], StringList, StringList*); bool build_library(StringList); bool build_example(void); +bool generate_build_h(); int main(int argc, char** argv) { NOB_GO_REBUILD_URSELF(argc, argv); @@ -29,6 +31,10 @@ int main(int argc, char** argv) { nob_mkdir_if_not_exists("./build"); + if(!generate_build_h()){ + return 1; + } + StringList src_files = {0}; if (!to_files(source_file_names, &src_files, "src", "cpp")) { nob_log(NOB_ERROR, "Failed to make source files"); @@ -41,11 +47,6 @@ int main(int argc, char** argv) { return 1; } - if (!build_object_files(source_file_names, src_files, &object_files)) { - nob_log(NOB_ERROR, "Failed to build sources into object files"); - return 1; - } - if (!build_library(object_files)) { nob_log(NOB_ERROR, "Failed to build final library artifacts"); return 1; @@ -84,9 +85,14 @@ bool build_example(void) { nob_cmd_append(&cmd, "main.cpp"); nob_cmd_append(&cmd, "-o", "main.exe"); nob_cmd_append(&cmd, libs, "-Lbuild/"); + +#if defined(_WIN32) || defined (_WIN64) nob_cmd_append(&cmd, "-lrasen", "-lraylib", "-lm", "-lwinmm", "-lgdi32", "-lopengl32", "-lole32", "-lcomdlg32"); +#else + nob_cmd_append(&cmd, "-lrasen", "-lraylib", "-lm", "-lGL", "-lpthread", "-ldl", "-lrt", "-lX11"); +#endif nob_log(NOB_INFO, "Building example"); if (!nob_cmd_run(&cmd)) { @@ -127,9 +133,13 @@ bool build_library(StringList object_files) { nob_cmd_append(&cmd, "-o", shared_object_name); nob_cmd_append(&cmd, libs); + +#if defined(_WIN32) || defined (_WIN64) nob_cmd_append(&cmd, "-lraylib", "-lm", "-lwinmm", "-lgdi32", "-lopengl32", "-lgdi32", "-lopengl32", "-lole32", "-lcomdlg32"); - +#else + /* nob_cmd_append(&cmd, "-lraylib", "-lm", "-lGL", "-lpthread", "-ldl", "-lrt", "-lX11"); */ +#endif nob_log(NOB_INFO, "Creating .a file [%s]", static_object_name); @@ -181,6 +191,9 @@ bool build_object_files(const char* names[SOURCE_FILE_COUNT], StringList source_ for (uint64_t i = 0; i < SOURCE_FILE_COUNT; ++i) { Nob_Cmd cmd = {0}; nob_cmd_append(&cmd, "g++"); +#if !defined(_WIN32) || (_WIN64) + nob_cmd_append(&cmd, "-fPIC"); +#endif nob_cmd_append(&cmd, "-o"); nob_cmd_append(&cmd, object_files->items[i]); nob_cmd_append(&cmd, "-c"); @@ -212,3 +225,40 @@ bool to_files(const char* names[SOURCE_FILE_COUNT], StringList* source_files, co return true; } +bool generate_build_h(){ + time_t t = time(NULL); + struct tm tm = *localtime(&t); + nob_mkdir_if_not_exists("./include"); + + const char *path = "./include/build.h"; + nob_log(NOB_INFO,"Generating %s", path); + + FILE *f = fopen(path,"w"); + if(f == NULL){ + nob_log(NOB_ERROR,"Failed to open %s for writing", path); + return false; + } + Nob_String_Builder sb = {0}; + nob_sb_appendf(&sb, "#ifndef __BUILD_DATE__\n\n"); + nob_sb_appendf(&sb, "#define __BUILD_DATE__ \"%d-%02d-%02d %02d:%02d:%02d\"\n", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + + char* os = NULL; +#if defined(__linux__) || defined(__unix__) + char* user = getenv("USER"); + os = "Linux/Unix"; +#elif defined(_WIN32) || defined(_WIN64) + os = "Windows"; +#endif + + nob_sb_appendf(&sb, "#define __BUILD_BY__ \"%s\"\n", user); + nob_sb_appendf(&sb, "#define __BUILD_OS__ \"%s\"\n", os); + + nob_sb_appendf(&sb,"\n#endif // RASEN_BUILD_H\n"); + fwrite(sb.items,1,sb.count,f); + + nob_da_free(sb); + fclose(f); + nob_log(NOB_INFO,"Successfully generated %s", path); + return true; +} From 060e9569c32a718f920ac4c4070f6399cf48f618 Mon Sep 17 00:00:00 2001 From: Yahm3 <240418541@tut4life.ac.za> Date: Sun, 17 May 2026 18:34:52 +0200 Subject: [PATCH 2/3] feat: added MenuBar --- include/MenuBar.h | 26 ++++++++++++++++++++++++++ src/MenuBar.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 include/MenuBar.h create mode 100644 src/MenuBar.cpp diff --git a/include/MenuBar.h b/include/MenuBar.h new file mode 100644 index 0000000..e956ced --- /dev/null +++ b/include/MenuBar.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class MenuBar : public Container { + public: + MenuBar(); + ~MenuBar() {}; + + void update(float) override; + void draw() override; + + + WIDGET_CONSTRUCT(MenuBar); + WIDGET_CONSTRUCT_PARENT(MenuBar); + std::string m_text; + bool on_click = false; + + protected: + + private: + unsigned int m_bar_height = 30;// I read that MenuBar is usually a fixed height +}; + diff --git a/src/MenuBar.cpp b/src/MenuBar.cpp new file mode 100644 index 0000000..d06bba2 --- /dev/null +++ b/src/MenuBar.cpp @@ -0,0 +1,35 @@ +#include "MenuBar.h" + +MenuBar::MenuBar() { + this->set_margin(4); + this->set_spacing(10); +} + +void MenuBar::update(float dt) { + unsigned int screen_width = GetScreenWidth(); + + this->set_location(0, 0); + this->set_size(screen_width, m_bar_height); + + unsigned int current_x = this->margin(); + unsigned int center_y_offset = this->margin(); + + for (Widget *child : children()) { + if (child->height() < m_bar_height) { + center_y_offset = (m_bar_height - child->height()) / 2; + } + + child->set_location(current_x, center_y_offset); + + child->update(dt); + current_x += child->width() + this->spacing(); + } +} + +void MenuBar::draw() { + DrawRectangleRec(this->bounding_rect(), LIGHTGRAY); + DrawLine(0, m_bar_height, GetScreenWidth(), m_bar_height, LIGHTGRAY); + for (Widget *child : children()) { + child->draw(); + } +} From d1f0f53d4d6a47649ffd08bc2e4aef03d16c00da Mon Sep 17 00:00:00 2001 From: Yahm3 <240418541@tut4life.ac.za> Date: Sun, 17 May 2026 18:35:52 +0200 Subject: [PATCH 3/3] test: updated the nob.c file and added the test in main.cpp --- main.cpp | 21 +++++++++++++++++++++ nob.c | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 45c5368..dd70e4c 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,26 @@ int main(int argc, char** argv) { window->set_title("Hello, from c++"); // window->set_resizable(true); + auto menu_bar = MenuBar::construct(window); + + auto file_btn = Button::construct(menu_bar); + file_btn->set_text("Edit"); + file_btn->on_click([](auto event) { + PopupDialog::show("Menu Action", "You clicked the Edit button on the MenuBar!"); + }); + + auto edit_btn = Button::construct(menu_bar); + edit_btn->set_text("Edit"); + edit_btn->on_click([](auto event) { + PopupDialog::show("Menu Action", "You clicked the Edit button on the MenuBar!"); + }); + + auto help_btn = Button::construct(menu_bar); + help_btn->set_text("Help"); + help_btn->on_click([](auto event) { + PopupDialog::show("Menu Action", "You clicked the Help button on the MenuBar!"); + }); + auto desktop = window->desktop(); desktop->on_draw([](Rectangle desktop_rect) { auto x = desktop_rect.width / 2; diff --git a/nob.c b/nob.c index 807f370..bd6d476 100644 --- a/nob.c +++ b/nob.c @@ -13,7 +13,7 @@ typedef struct { } StringList; -#define SOURCE_FILE_COUNT 15 // Modify this when adding a new files to the list of files +#define SOURCE_FILE_COUNT 16 // Modify this when adding a new files to the list of files bool to_files(const char*[SOURCE_FILE_COUNT], StringList*, const char*, const char*); bool build_object_files(const char*[SOURCE_FILE_COUNT], StringList, StringList*); @@ -26,7 +26,7 @@ int main(int argc, char** argv) { const char* source_file_names[SOURCE_FILE_COUNT] = { "Application", "Button", "CheckBox", "ComboBox", "Container", "Desktop", "InputDialog", "Label","MessageDialog", "Panel", "PopupDialog", "Slider", "Widget", "Window", - "tinyfiledialogs" + "tinyfiledialogs","MenuBar" }; nob_mkdir_if_not_exists("./build");