{"id":20128514,"url":"https://github.com/cococry/leif","last_synced_at":"2025-05-15T02:05:39.942Z","repository":{"id":167626188,"uuid":"643250890","full_name":"cococry/leif","owner":"cococry","description":"Minimal, configurable \u0026 GPU accelerated Immediate Mode UI Library written with modern OpenGL","archived":false,"fork":false,"pushed_at":"2024-11-17T20:16:20.000Z","size":5893,"stargazers_count":911,"open_issues_count":15,"forks_count":40,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-06T21:06:46.403Z","etag":null,"topics":["gui","imgui","minimal","modern","opengl"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cococry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-20T15:13:34.000Z","updated_at":"2025-04-05T12:02:30.000Z","dependencies_parsed_at":"2023-07-10T03:00:19.674Z","dependency_job_id":"f4a0524f-c589-4836-9b8b-d75fcd6ccce5","html_url":"https://github.com/cococry/leif","commit_stats":null,"previous_names":["cococry/leif"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cococry%2Fleif","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cococry%2Fleif/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cococry%2Fleif/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cococry%2Fleif/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cococry","download_url":"https://codeload.github.com/cococry/leif/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799905,"owners_count":21163400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gui","imgui","minimal","modern","opengl"],"created_at":"2024-11-13T20:27:27.369Z","updated_at":"2025-04-13T23:50:18.129Z","avatar_url":"https://github.com/cococry.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leif\n\n## Highlights\n\nLeif is UI in C/C++ made easy. The library is designed to be really easy to setup and provide maximal functionality.\nAll of that while retaining a concise and readable codebase.\n\n#### Theming \u0026 Styling support\nThe library comes with a fully-featured property system where each UI element can be customized\nto your liking. Every visible part of your UI can be configured in no time.\n\n#### Exposed Rendering API\nLeif comes with a very performant inhouse batch renderer. The renderers drawing API is fully exposed \nto the user. This expands the scope of application of the library a lot as you can also utilize it\nfor various non-UI components of your project. \n\n#### Exposed State\nThe UI state of leif is nearly completly exposed to the user which, with the rendering system, \nmakes it really easy to add new UI components client-side.\n\n#### Complete Input-Handling System\nThe library contains an input subsystem that can be utilized by the user for various different \ntasks (eg. is_key_down, is_mouse_button_released, etc.) which makes development a whole lot easier.\n\n\n### Dependencies\n\n| Dependency         |  Reason of Usage    |\n| ----------------|-------------|\n| [glad](https://github.com/Dav1dde/glad) | Loading OpenGL functions |\n| [stb_image](https://github.com/nothings/stb/blob/master/stb_image.h) | Loading image files into memory |\n| [stb_image_resize2](https://github.com/nothings/stb/blob/master/stb_image_resize2.h) | Resizing images |\n| [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) | Loading font glyphs from font files |\n| [cglm](https://github.com/recp/cglm) | Linear Algebra Math | \n| [*GLFW](https://github.com/glfw/glfw) | Handling windowing, input etc. | \n\n*: This library is an optional library and will be replacable with other libraries\n\n\n## Installation\n\nInstalling the library is made very easy by the use of an install script:\n```console\ngit clone https://github.com/cococry/leif\ncd leif\n./install.sh\n```\n\n## Usage\n\nInitialize Leif before using and after creating a window with your windowing backend:\n```c\nlf_init_glfw(displayWidth, displayHeight, glfwWindow);\n```\n\nWithin the main loop of your program, call the lf_begin() and lf_end() functions within which you can render UI elements.\n\n#### Simple hello-world application with GLFW for windowing\n```c\n#include \u003cGLFW/glfw3.h\u003e\n#include \u003cleif/leif.h\u003e\n\nint main() {\n  glfwInit();\n  GLFWwindow* window = glfwCreateWindow(800, 600, \"Hello\", NULL, NULL);\n\n  glfwMakeContextCurrent(window);\n\n  lf_init_glfw(800, 600, window);\n\n  while(!glfwWindowShouldClose(window)) {\n    glClear(GL_COLOR_BUFFER_BIT);\n    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);\n\n    lf_begin();\n\n    lf_text(\"Hello, Leif!\");\n\n    lf_end();\n    glfwSwapBuffers(window);\n    glfwPollEvents();\n  }\n  lf_terminate();\n  glfwDestroyWindow(window);\n  glfwTerminate();\n}\n```\n\u003cimg src=\"https://github.com/cococry/Leif/blob/main/branding/ui-elements.png\" width=375px/\u003e \n\n#### Hello-World Plus\n```c\n#include \u003cGLFW/glfw3.h\u003e\n#include \u003cleif/leif.h\u003e\n\nstatic int winw = 800, winh = 800;\n\nstatic void resizecb(GLFWwindow* window, int w, int h) {\n  winw = w;\n  winh = h;\n  glViewport(0, 0, w, h);\n  // Resize the leif display on window resize\n  lf_resize_display(w, h);\n}\n\nint main() {\n  glfwInit();\n  GLFWwindow* window = glfwCreateWindow(winw, winh, \"Hello\", NULL, NULL);\n\n  glfwMakeContextCurrent(window);\n\n  glfwSetFramebufferSizeCallback(window, resizecb);\n\n  lf_init_glfw(winw, winh, window);\n\n  // Loading a bigger font (replace /home/cococry with your user)\n  LfFont bigfont = lf_load_font(\"/home/cococry/.leif/assets/fonts/inter.ttf\", 50);\n\n  while(!glfwWindowShouldClose(window)) {\n    glClear(GL_COLOR_BUFFER_BIT);\n    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);\n\n    // Starting leif context\n    lf_begin();\n\n    const char* text = \"Hello, Leif!\";\n    const char* btntext = \"Exit\";\n\n    // Defining properties of the button\n    LfUIElementProps btnprops = lf_get_theme().button_props;\n    btnprops.margin_left = 0.0f; btnprops.margin_top = 15.0f; btnprops.border_width = 0.0f; btnprops.corner_radius = 9.0f;\n    btnprops.text_color = LF_WHITE;\n    btnprops.color = (LfColor){90, 90, 90, 255};\n\n    // Beginnig a new container\n    {\n      // Styling the container (setting corner radius)\n      LfUIElementProps props = lf_get_theme().div_props;\n      props.corner_radius = 10.0f;\n      lf_push_style_props(props);\n\n      // Positioning the container in the center\n      float width = 400.0f, height = 400.0f;\n      lf_div_begin(((vec2s){(winw - width) / 2.0f, (winh - height) / 2.0f}), ((vec2s){width, height}), false);\n\n      // Popping the container's props again\n      lf_pop_style_props();\n    }\n\n    /* Text */\n    {\n      // Setting big font\n      lf_push_font(\u0026bigfont);\n      // Center the text horizontally\n      lf_set_ptr_x_absolute((winw - lf_text_dimension(text).x) / 2.0f);\n      // Center the text (and button) vertically\n      lf_set_ptr_y_absolute((winh - (lf_text_dimension(text).y + lf_text_dimension(btntext).y + btnprops.padding * 2.0f + btnprops.margin_top)) / 2.0f);\n\n      // Remove any margin\n      LfUIElementProps props = lf_get_theme().text_props;\n      props.margin_left = 0.0f; props.margin_right = 0.0f;\n      // Push the style props\n      lf_push_style_props(props);\n\n      // Render the text\n      lf_text(text);\n\n      // Pop the style props\n      lf_pop_style_props();\n\n      // Unsetting big font\n      lf_pop_font();\n    }\n\n    // Advance into the next line\n    lf_next_line();\n\n    /* Exit Button */\n    {\n      const float width = 180.0f;\n\n      lf_push_style_props(btnprops);\n      // Center the button horizontally\n      lf_set_ptr_x_absolute((winw - (width + btnprops.padding * 2.0f)) / 2.0f);\n\n      // Rendering a button with fixed scale (-1 stands for \"use normal height\")\n      if(lf_button_fixed(btntext, width, -1) == LF_CLICKED) {\n        // Closing the window when you pressed the button\n        glfwSetWindowShouldClose(window, 1);\n      }\n\n      lf_pop_style_props();\n    }\n\n    // Ending the container\n    lf_div_end();\n\n    // Ending leif context\n    lf_end();\n\n    glfwSwapBuffers(window);\n    glfwPollEvents();\n  }\n\n  lf_terminate();\n  glfwDestroyWindow(window);\n  glfwTerminate();\n}\n```\n\n\u003cimg src=\"https://github.com/cococry/Leif/blob/main/branding/styling-elements.png\" width=375px/\u003e \n\n## Building your project\n\nTo build your project, link it with leif and its depdencies.\n```console\ngcc -o project project.c -lleif -lglfw -lm -lGL -lclipboard\n```\n\n## Real world usage\n\nBut how does the leif library perform in real applications? I am currently working on a music player called [lyssa](https://github.com/cococry/lyssa). The frontend of the player\nis written entirely with leif. You can see a brief look at of the application below.\n\n\u003cimg src=\"https://github.com/cococry/lyssa/blob/main/branding/lyssa-showcase.png\" width=\"1000px\"/\u003e \n\nA [task management app](https://github.com/cococry/todo) that i also wrote with the leif library:\n\u003cimg src=\"https://github.com/cococry/todo/blob/main/branding/todo-showcase.png\" width=\"1000px\"/\u003e \n\n## Contributing\n\nYou can contribute to Leif by:\n  - [Fixing bugs or contributing to features](https://github.com/cococry/lyssa/issues)\n  - [Changing features or adding new functionality](https://github.com/cococry/lyssa/pulls)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcococry%2Fleif","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcococry%2Fleif","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcococry%2Fleif/lists"}