Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

dinau/CImGuiTextSelect

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CImGuiTextSelect


This project introduces C API to ImGuiTextSelect to use it with other languages and a simple demo program with C.

Link: Dear ImGui

Prerequisites


  • Windows OS 11 or later

    1. Install MSys2/MinGW (Windows OS)

    2. Install packages

      pacman -S mingw-w64-ucrt-x86_64-{gcc,glfw,pkg-config} make
  • Linux: Ubuntu / Debian families

    1. Install packages

      $ sudo apt install gcc lib{opengl-dev,gl1-mesa-dev,glfw3-dev} make pkg-config

Build and run


  1. Download this project.

    git clone --recursive https://github.com/dinau/CImGuiTextSelect
  2. Go to demo folder

    cd CImGuiTextSelect/demo/c
    make run 

Snap shot


alt

Demo program


... snip ...

const char* lines[] = {
    "Line 1",
    "Line 2",
    "Line 3",
    "A longer line",
    "Text selection in Dear ImGui",
    "UTF-8 characters Ë ⑤ 三【 】┌──┐"
};

size_t getNumLines(void* userdata) {
    return sizeof(lines)/sizeof(lines[0]);
}

const char* getLineAtIdx(size_t idx, void* userdata, size_t* out_len){
    if (out_len != NULL){
      *out_len = strlen(lines[idx]);
    }
    return lines[idx];
}

... snip ..

TextSelect* pTextselect = textselect_create(getLineAtIdx, getNumLines, lines, false );

// main event loop
while (!glfwWindowShouldClose(window)) {
  glfwPollEvents();
  
  // start imgui frame
  ImGui_ImplOpenGL3_NewFrame();
  ImGui_ImplGlfw_NewFrame();
  igNewFrame();
  
  // Start CImGuiTextSelect demo
  igBegin("ImGuiTextSelect demo with C", NULL, 0);
    ImVec2 size = {.x = 0, .y = 0};
    igBeginChild_Str("text", size, 0, ImGuiWindowFlags_NoMove);
      size_t num = getNumLines(lines);
        for (size_t i = 0; i < num; ++i) {
            const char* line = getLineAtIdx(i, lines, NULL);
            igTextUnformatted(line, NULL);
        }
      textselect_update(pTextselect);
      if (igBeginPopupContextWindow(NULL, 1)) {
          igBeginDisabled(!textselect_has_selection(pTextselect));
          if (igMenuItem_Bool("Copy", "Ctrl+C", false, true)) {
              textselect_copy(pTextselect);
          }
          igEndDisabled();
  
          if (igMenuItem_Bool("Select all", "Ctrl+A", false, true)) {
              textselect_select_all(pTextselect);
          }
          if (igMenuItem_Bool("Clear selection", NULL, false, true)) {
              textselect_clear_selection(pTextselect);
          }
          igEndPopup();
      }
    igEndChild();
  igEnd();
  
  // render
  igRender();

  ... snip ..
}

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.