A tiny, portable, immediate-mode UI library written in ANSI C

Related tags

GUI microui
Overview

microui

A tiny, portable, immediate-mode UI library written in ANSI C

Features

  • Tiny: around 1100 sloc of ANSI C
  • Works within a fixed-sized memory region: no additional memory is allocated
  • Built-in controls: window, scrollable panel, button, slider, textbox, label, checkbox, wordwrapped text
  • Works with any rendering system that can draw rectangles and text
  • Designed to allow the user to easily add custom controls
  • Simple layout system

Example

example

if (mu_begin_window(ctx, "My Window", mu_rect(10, 10, 140, 86))) {
  mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);

  mu_label(ctx, "First:");
  if (mu_button(ctx, "Button1")) {
    printf("Button1 pressed\n");
  }

  mu_label(ctx, "Second:");
  if (mu_button(ctx, "Button2")) {
    mu_open_popup(ctx, "My Popup");
  }

  if (mu_begin_popup(ctx, "My Popup")) {
    mu_label(ctx, "Hello world!");
    mu_end_popup(ctx);
  }

  mu_end_window(ctx);
}

Screenshot

screenshot

Browser Demo

Usage

  • See doc/usage.md for usage instructions
  • See the demo directory for a usage example

Notes

The library expects the user to provide input and handle the resultant drawing commands, it does not do any drawing itself.

Contributing

The library is designed to be lightweight, providing a foundation to which you can easily add custom controls and UI elements; pull requests adding additional features will likely not be merged. Bug reports are welcome.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

Comments
  • Hash function

    Hash function "Cannot convert from 'const void *' to 'const unsigned char *'"

    I'm running into an issue when building microui in a C++ project in visual studio 2019.

    The two errors that show are one in the hash() function: "Cannot convert from 'const void *' to 'const unsigned char *'"

    And another in the mu_next_command() function: "Cannot convert from 'void *' to 'mu_Command *'"

    Any idea what might be going wrong?

    opened by WillCecil 4
  • Trying to get a window container within another window

    Trying to get a window container within another window

    Right now, all I'm trying to do is get a parent window container from within a child window. I thought this was accomplished through the 'mu_get_container' function but it doesn't seem to be presenting me with a valid container. The code is as follows:

    if(mu_begin_window(ctx, "Parent Window", mu_rect(200, 100, 300, 400)))
        {
            if(mu_begin_window(ctx, "Child Window1", mu_rect(0, 0, 200, 200)))
            {
                mu_Container* currentWin = mu_get_container(ctx, "Child Window1");//This does not work
                mu_Container* cnt = mu_get_current_container(ctx);//This works and returns Child Window1
                
                if(mu_begin_window(ctx, "Child Window2", mu_rect(0, 200, 200, 200)))
                {
                    mu_Container* parentWin = mu_get_container(ctx, "Child Window1");//This does not work. Returns empty container
                    
                    mu_end_window(ctx);
                };
                
                mu_end_window(ctx);
            };
            
            mu_end_window(ctx);
        };
    

    Am I doing something wrong? When is mu_get_container suppose to be used then?

    opened by bogez57 3
  • Not a bug: thanks for microui :)

    Not a bug: thanks for microui :)

    Hi, just wanted to let you know that I've created a little microui sample on top of my cross-platform headers, here's the standard sample running in WebAssembly:

    https://floooh.github.io/sokol-html5/wasm/sgl-microui-sapp.html

    I need to improve a few input handling things (mobile touch input, and figuring out a better way to map my library's mouse-wheel input to yours), but these are minor things.

    Also the default font atlas doesn't look too good on a high-dpi display when rendered at half resolution (I've had the same issues with Dear ImGui when using a TTF font, but Dear ImGui's default font looks fine in such situations, if a bit "low-tec": https://floooh.github.io/sokol-html5/wasm/imgui-sapp.html.

    But anyway, these are minor issues, and not an issue with microui. Thanks for that neat little library :)

    opened by floooh 3
  • fix problems of resizing

    fix problems of resizing

    Let me explain the point. The resize opertion in demo is like that currently: gif0 If the cursor's position may make the window's size too small, its size won't shrink more. That's all right. But the window's size enlarge as soon as the cursor move backward rather than keep its size until the cursor move out of the original press position, which windows in other GUI platforms perform. gif1 I revise some code and this is the effect: gif2 I add two members into mu_Context so that more than one mu_Context could work on the same process. the modifications does not destroy the library's lightweight and fixed-sized memory region.

    opened by chirsz-ever 3
  • How can you resize microui window dynamically?

    How can you resize microui window dynamically?

    Hi, I want to resize microui window when whole SDL2 window is resized.

    basically I'd expect code below to work, but microui window size stays the same. SDL_GetWindowSize(window, &width, &height); if (mu_begin_window(mu, MAIN_WINDOW_NAME, mu_rect(0, 0, width, height)))

    Am I doing it wrong? How can I resize microui window?

    opened by tomaszte 2
  • Keyboard controls?

    Keyboard controls?

    It seems a pointer device is needed to use the microui interfaces.

    I'd be interested in keyboard control, I suppose this would also mean tab order would be useful.

    Thanks for all your work!

    opened by gingerbeardman 2
  • improve demo code

    improve demo code

    • use Makefile as build system
    • add .gitignore
    • split demo code to separate files
    • split platform code and render
    • refactor atlas.inl as a separate font
    • make the demo window resizable
    • delete atlas texture when opengl shutdown
    • add glfw3 implemention
    opened by chirsz-ever 2
  • How do I know if microui consumed an event?

    How do I know if microui consumed an event?

    If the user drags a microui slider in a window, I don't want the drag to affect the content underneath the window. imgui has WantCaptureKeyboard, WantCaptureMouse, etc for this purpose but I can't find the corollary mechanism in microui.

    By the way thanks for this library, it's truly beautiful.

    opened by prideout 2
  • Allow to choose popup position

    Allow to choose popup position

    Allows to choose where will the popup appear - the position. That enable us to create widgets like window menu bar or context menu with sub menu items or notification popups where you want to have full control where in the main window will the popup appear. PR also updates demo application how to use popup widget.

    The Makefile/shell script change allows to compile and run demo application on MacOS.

    opened by czertbytes 2
  • Unicode support?

    Unicode support?

    Looking at @floooh's browser demo https://floooh.github.io/sokol-html5/wasm/sgl-microui-sapp.html, when I type eg. the § character into the input for the log window and click the submit button, what looks like a deformed copy of the sprite sheet for the font appears.

    Not sure if this is just because the demo isn't written to support unicode, or a bug? Feel free to close this issue if the former is the case.

    opened by bmcorser 2
  • Missing texture generator

    Missing texture generator

    First thanks for microui, I am using it as debugging interface for my little app. I noticed that it's missing a way to generate the texutre used for the demo. I believe you have used the atlas code to do that, but the steps needed are missing. Could you please add them in the READM.md file ?

    On a side note, is there a reason for choosing the supply Id based on hashed pointers rather than simple id increments ? This forces the pointers to reference memory allocated on heap, and would break the logic if they are allocated on stack.

    opened by eloraiby 2
  • Question: Running demo on windows

    Question: Running demo on windows

    Forgive as I am new to C and just messing around breaking things as I learn.

    Is it possible to run the demo on windows? It seems the compiler does not like the SDL2 library.

    ./build.sh: line 13: sdl2-config: command not found
    main.c:1:10: fatal error: SDL2/SDL.h: No such file or directory
        1 | #include <SDL2/SDL.h>
          |          ^~~~~~~~~~~~
    

    I have tried downloading the SDL2 library and including but I cannot seem to get this to work. Would anyone be kind enough to instruct me how to get this to work?

    opened by ryanalbrecht 1
  • Fix msvc warnings

    Fix msvc warnings

    The Microsoft C compiler at warning level 3 (/W3) complains about various integer casts. I assume microui doesn't intend to handle the cases where these casts would overflow. I think it's worth making the casts explicit, to express that this is the intended behavior.

    opened by outerpassage 0
  • GDI demo

    GDI demo

    Added a GDI (native win32) demo. Tried to keep it as close to the SDL demo as I could.

    -Even if its not merged, might be useful to some one. -Two build scripts, one for msys2, one for msbuild. -Mostly the same, except no bitmap support/icons, these are done with text.

    image

    opened by nlapinski 0
  • Textbox improvements!

    Textbox improvements!

    Hi, thanks for this awesome lib!

    One thing that i felt was missing was proper textbox navigation, being able to correct a character without having to delete the entire thing

    So i spent some time and managed to come up with something:

    https://user-images.githubusercontent.com/44361234/147188029-caad8964-5768-4e6c-869c-dee355282a0b.mp4

    Please let me know if you want to see more improvement to the code, so i can submit a PR!

    Changes:

    struct mu_Context {
      //. ..
      /* input state */
      // ...
      char input_text[32];
    +  int input_text_written;
    };
    
     /* reset input state */
      ctx->key_pressed = 0;
      ctx->input_text[0] = '\0';
    +  ctx->input_text_written = 0;
    
    void mu_input_text(mu_Context *ctx, const char *text) {
      int len = strlen(ctx->input_text);
      int size = strlen(text) + 1;
      expect(len + size <= (int) sizeof(ctx->input_text));
      memcpy(ctx->input_text + len, text, size);
    +  ctx.input_text_written += (size - 1);
    }
    

    And here is how the new function looks like:

    We basically introduce a new argument to the textbox_raw function A pointer to an int so we can track the index, and user can specific where the index should start

    int mu_textbox_raw(mu_Context *ctx, char *buf, int bufsz, int *index, mu_Id id, mu_Rect r,
      int opt)
    {
      int res = 0;
      mu_update_control(ctx, id, r, opt | MU_OPT_HOLDFOCUS);
    
      if (ctx->focus == id) {
        /* handle text input */
        int len = strlen(buf);
        int n = mu_min(bufsz - len - 1, (int) strlen(ctx->input_text));
        int i = *index;
        int needMove = len - i;
        if (n > 0) {
          if (needMove > 0) {
            memmove(buf + i + n, buf + i, needMove);
          }
          memcpy(buf + i, ctx->input_text, n);
          len += n;
          buf[len] = '\0';
          res |= MU_RES_CHANGE;
        }
        /* handle backspace */
        if (ctx->key_pressed & MU_KEY_BACKSPACE && len > 0) {
          /* skip utf-8 continuation bytes */
          while ((buf[--len] & 0xc0) == 0x80 && len > 0);
          
          (*index)--;
          memmove(buf + (*index), buf + (*index) + 1, len - (*index) + 1);
          buf[len] = '\0';
          res |= MU_RES_CHANGE;
        }
        /* handle return */
        if (ctx->key_pressed & MU_KEY_RETURN) {
          mu_set_focus(ctx, 0);
          res |= MU_RES_SUBMIT;
        }
        if (ctx.key_pressed & KEY_LEFT)
        {
          (*index)--;
        }
        else if (ctx.key_pressed & KEY_RIGHT)
        {
          (*index)++;
        }
        if ((*index) < 0) (*index) = 0;
        if (*index >= len) (*index) = len;
      } else {
        int len = strlen(buf);
        (*index) = len;
      }
    
      /* draw */
      mu_draw_control_frame(ctx, id, r, MU_COLOR_BASE, opt);
      if (ctx->focus == id) {
        mu_Color color = ctx->style->colors[MU_COLOR_TEXT];
        mu_Font font = ctx->style->font;
        int textw = ctx->text_width(font, buf, (*index));
        int texth = ctx->text_height(font);
        int ofx = r.w - ctx->style->padding - textw - 1;
        int textx = r.x + mu_min(ofx, ctx->style->padding);
        int texty = r.y + (r.h - texth) / 2;
        mu_push_clip_rect(ctx, r);
        mu_draw_text(ctx, font, buf, -1, mu_vec2(textx, texty), color);
        mu_draw_rect(ctx, mu_rect(textx + textw, texty, 1, texth), color);
        mu_pop_clip_rect(ctx);
      } else {
        mu_draw_control_text(ctx, buf, r, MU_COLOR_TEXT, opt);
      }
      
      (*index)+=ctx->input_text_written;
      return res;
    }
    
    opened by ryuukk 3
  • How to port to another low level access graphic control

    How to port to another low level access graphic control

    Hello. This is not an issue. Just a question looking for a link or help: How I do port this great project to another lower framebuffer layer? I see that it depends on SDL y GL it seems. I have just a memory buffer for drawing pixeles (it is a little experiment on Xinu operating system using vga in protected mode x86). So I do not have neither SDL nor GL. But I can draw pixels (or of course, copy a memory drawing buffer to screen for example). Should I modify the renderer.* files? Others? Any help on how to modify the current demo for a new screen control would be appreciated.

    opened by zrafa 4
Owner
null
A single-header ANSI C immediate mode cross-platform GUI library

Nuklear This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed a

Immediate Mode UIs, Nuklear, etc. 6.3k Dec 2, 2022
raygui is a simple and easy-to-use immediate-mode-gui library.

raygui is a simple and easy-to-use immediate-mode-gui library.

Ray 1.9k Nov 28, 2022
ImTui: Immediate Mode Text-based User Interface C++ Library

ImTui is an immediate mode text-based user interface library. Supports 256 ANSI colors and mouse/keyboard input.

Georgi Gerganov 2.1k Nov 30, 2022
FlatUI is a immediate mode C++ GUI library for games and graphical applications.

FlatUI is a immediate mode C++ GUI library for games and graphical applications. Go to our landing page to browse our documentation.

Google 611 Nov 28, 2022
The HorusUI library allows you to quickly develop GUIs for your applications by leveraging the ease of use provided by immediate mode GUI concepts.

Immediate Mode Graphical User Interface for Tools OVERVIEW The HorusUI library allows you to quickly develop GUIs for your applications by leveraging

null 132 Nov 18, 2022
This is a collection of widgets and utilities for the immediate mode GUI (imgui) that I am developing for the critic2 GUI

ImGui Goodies This is a collection of widgets and utilities for the immediate mode GUI (imgui) that I am developing for the critic2 GUI. Currently, th

null 95 Nov 19, 2022
This is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui.

cimgui This is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui. All imgui.h functions are programm

Victor Bombi 22 Jul 5, 2021
Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui

ImGuizmo Latest stable tagged version is 1.83. Current master version is 1.84 WIP. What started with the gizmo is now a collection of dear imgui widge

Cedric Guillemet 2.2k Nov 25, 2022
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 10.4k Dec 2, 2022
libui-ng: a portable GUI library for C

libui-ng: a portable GUI library for C Fork of andlabs/libui. This README is being written. Status See CHANGELOG.md Old announcements can be found in

null 246 Dec 4, 2022
QtLottie is a tiny C++ library that can render Adobe® After Effects™ animations exported as JSON with Bodymovin.

QtLottie QtLottie is a tiny C++ library that can render Adobe® After Effects™ animations exported as JSON with Bodymovin. Features Support many After

Yuhang Zhao 29 Nov 29, 2022
A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs.

webview for golang and c/c++ A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. The goal of the project is to

polevpn 21 Dec 3, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Nim bindings, Haskell, C# bindings and Java bindings available.

webview 10.7k Nov 26, 2022
Neutralinojs is a lightweight and portable desktop application development framework

Neutralinojs is a lightweight and portable desktop application development framework. It lets you develop lightweight cross-platform desktop applications using JavaScript, HTML and CSS.

Neutralinojs 6.2k Nov 26, 2022
Clight GUI written in Qt.

CLight GUI Clight GUI written in Qt. Huge thanks to @FedeDP for writing Clight and Clightd, the daemons upon which this is built on.

null 61 Nov 25, 2022
Nvui: A NeoVim GUI written in C++ and Qt

Nvui: A NeoVim GUI written in C++ and Qt

Rohit Pradhan 1.6k Dec 6, 2022
ChessBurger is a modern chess GUI written by Progmaster.

ChessBurger ChessBurger is a modern chess GUI written in C++. The reason I started working on a new chess GUI, is because the GUIs out there are somew

Progmaster 1 Nov 9, 2021
A wallpaper changer using Wallhaven api. Written with C++/CLR, only 0.5 MB and have a GUI.

WHaven Wallpaper WHaven Wallpaper is a desktop wallpaper change program for change your wallpapers directly from wallhaven. Features You have a search

null 2 Aug 1, 2022
Elements C++ GUI library

Elements C++ GUI library Introduction Elements is a lightweight, fine-grained, resolution independent, modular GUI library. Elements is designed with

Cycfi Research 2.4k Nov 30, 2022