Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 47 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ option(DEBUG "Build with debugging information" OFF)

# ==== External Dependencies ====

# utfcpp
include(FetchContent)
FetchContent_Declare(
utfcpp
GIT_REPOSITORY https://github.com/nemtrif/utfcpp.git
GIT_TAG v4.0.6
)
FetchContent_MakeAvailable(utfcpp)

# Freetype (./external/freetype/lib ./external/freetype/include ./external/freetype/bin)
set(CMAKE_PREFIX_PATH "${EXTERNAL_DIR}/freetype" ${CMAKE_PREFIX_PATH})
find_package(Freetype REQUIRED)
if(NOT FREETYPE_FOUND)
message(FATAL_ERROR "Freetype not found")
endif()
message(STATUS "Found Freetype: ${FREETYPE_INCLUDE_DIRS}")
message(STATUS " - Freetype Libraries: ${FREETYPE_LIBRARIES}")
set(FREETYPE_DLL_DIR "${FREETYPE_INCLUDE_DIRS}/../bin")
message(STATUS " - Freetype DLL Directory: ${FREETYPE_DLL_DIR}")

# OpenSSL
find_package(OpenSSL REQUIRED)
if(NOT OpenSSL_FOUND)
Expand All @@ -35,9 +55,8 @@ message(STATUS " - OpenSSL Libraries: ${OPENSSL_LIBRARIES}")
set(OPENSSL_DLL_DIR "${OPENSSL_INCLUDE_DIR}/../bin")
message(STATUS " - OpenSSL DLL Directory: ${OPENSSL_DLL_DIR}")

# GLAD
add_library(glad STATIC ${EXTERNAL_DIR}/glad/src/glad.c)
target_include_directories(glad PUBLIC ${EXTERNAL_DIR}/glad/include)
# DirectX SDK (using Windows SDK)
# DirectX 10 components are included in Windows SDK, no need for separate find_package

# Native File Dialog Extended
add_subdirectory(${EXTERNAL_DIR}/nativefiledialog-extended)
Expand Down Expand Up @@ -67,31 +86,39 @@ set(MARKDOWN_RENDERER
${EXTERNAL_DIR}/imgui_md/imgui_md.cpp
)

# ImGuiTextSelect
set(IMGUI_TEXT_SELECT
${EXTERNAL_DIR}/ImGuiTextSelect/textselect.cpp
)

# ==== ImGui Configuration ====
set(IMGUI_SOURCES
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
${IMGUI_DIR}/misc/freetype/imgui_freetype.cpp
${IMGUI_DIR}/backends/imgui_impl_win32.cpp
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
${IMGUI_DIR}/backends/imgui_impl_dx10.cpp # Changed from OpenGL3 to DirectX 10
)

# ==== Font Definitions ====
set(FONT_DEFINITIONS
IMGUI_FONT_PATH_INTER_REGULAR="fonts/Inter-Regular.ttf"
IMGUI_FONT_PATH_FIRACODE_REGULAR="fonts/FiraCode-Regular.ttf"
IMGUI_FONT_PATH_INTER_BOLD="fonts/Inter-Bold.ttf"
IMGUI_FONT_PATH_INTER_BOLDITALIC="fonts/Inter-BoldItalic.ttf"
IMGUI_FONT_PATH_INTER_ITALIC="fonts/Inter-Italic.ttf"
IMGUI_FONT_PATH_FIRACODE_REGULAR="fonts/FiraCode-Regular.ttf"
IMGUI_FONT_PATH_CODICON="fonts/codicon.ttf"
IMGUI_FONT_PATH_NOTO_EMOJI="fonts/seguiemj-1.35-flat.ttf"
)

# ==== Kolosal Library ====
add_library(kolosal_lib STATIC
${IMGUI_SOURCES}
${MARKDOWN_RENDERER}
${IMGUI_TEXT_SELECT}
)

# Set definitions
Expand All @@ -105,7 +132,6 @@ target_compile_definitions(kolosal_lib PUBLIC
target_include_directories(kolosal_lib PUBLIC
${IMGUI_DIR}
${IMGUI_DIR}/backends
${EXTERNAL_DIR}/glad/include
${EXTERNAL_DIR}/icons
${EXTERNAL_DIR}/nlohmann
${EXTERNAL_DIR}/nativefiledialog-extended/src/include
Expand All @@ -114,43 +140,44 @@ target_include_directories(kolosal_lib PUBLIC
${EXTERNAL_DIR}/md4c/src
${EXTERNAL_DIR}/imgui_md
${EXTERNAL_DIR}/imspinner
${EXTERNAL_DIR}/ImGuiTextSelect
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/assets
${CMAKE_SOURCE_DIR}/kolosal-server/include
${FREETYPE_INCLUDE_DIRS}
${CURL_INCLUDE_DIR}
)

# Platform-specific library dependencies
if(WIN32)
target_link_libraries(kolosal_lib PUBLIC
glad
nfd
Dwmapi
UxTheme
Shcore
opengl32
d3d10 # DirectX 10 library
dxgi # DXGI library
user32
gdi32
shell32
OpenSSL::SSL
utf8cpp
${FREETYPE_LIBRARIES}
${CURL_LIBRARIES}
)

target_compile_definitions(kolosal_lib PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GLAD
UNICODE
${FONT_DEFINITIONS}
KOLOSAL_LOGO_PATH="assets/logo.png"
)
else()
target_link_libraries(kolosal_lib PUBLIC
glad
nfd
OpenSSL::SSL
)

target_compile_definitions(kolosal_lib PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GLAD
${FONT_DEFINITIONS}
KOLOSAL_LOGO_PATH="assets/logo.png"
)
Expand Down Expand Up @@ -234,4 +261,13 @@ add_custom_command(
"${EXTERNAL_DIR}/genta-personal/bin/InferenceEngineLibVulkan.dll"
"$<TARGET_FILE_DIR:KolosalDesktop>"
COMMENT "Copying Inference Engine DLLs to output directory"
)

# Copy Freetype DLLs
add_custom_command(
TARGET KolosalDesktop POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${FREETYPE_DLL_DIR}/freetype.dll"
"$<TARGET_FILE_DIR:KolosalDesktop>"
COMMENT "Copying Freetype DLLs to output directory"
)
10 changes: 10 additions & 0 deletions external/ImGuiTextSelect/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
indent_size = 4
12 changes: 12 additions & 0 deletions external/ImGuiTextSelect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Desktop configuration files
desktop.ini
.DS_Store

# Build and cache
.cache/
.xmake/
build/

# IDE directories
.vs/
.vscode/
21 changes: 21 additions & 0 deletions external/ImGuiTextSelect/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-2025 Aidan Sun and the ImGuiTextSelect contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions external/ImGuiTextSelect/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ImGuiTextSelect Changelog

This document tracks the changes between ImGuiTextSelect versions. Dates are written in the MM/DD/YYYY format.

## Unreleased

### Bug Fixes

- Fixed crash when text is empty (#7). Thanks @twixuss!

## 1.1.5 (04/16/2025)

### Improvements

- Added native support for C++17 (#4). Thanks @jonkwl!
- Added functionality to keep selecting when cursor is outside the window (#5). Thanks @twixuss!

## 1.1.4 (02/14/2025)

### Improvements

- Improved newline handling for triple-click selection.

### Bug Fixes

- Fixed UB when selecting empty lines. The newline character is now included in the selection rectangle and copied text.

## 1.1.3 (11/02/2024)

### Improvements

- Added the missing `#pragma once` in the header file.
- Changed uses of `size_t` to `std::size_t`.
- Removed dependency on `std::pair` and `<utility>`.
- Improved word boundary detection: double-clicking a sequence of boundary characters now selects all of them instead of just one.

## 1.1.2 (08/09/2024)

### Removals

- Removed support for Dear ImGui versions older than v1.90.7. (`ImGuiMod_Shortcut` was replaced with `ImGuiMod_Ctrl`)

## 1.1.1 (05/31/2024)

This is a patch release which addresses the breaking changes in Dear ImGui v1.90.7. It is backwards compatible with previous Dear ImGui versions.

### Improvements

- Updated the use of `ImGui::Shortcut()` and `ImGuiMod_Ctrl`.

## 1.1.0 (05/24/2024)

### Additions

- Added a full example program.
- Added automatic newline insertion for multiline copying.
- The lines that you pass to ImGuiTextSelect no longer need to end with newlines for multiline copying to work.

### Improvements

- Removed `#include <string>` from the header file.

### Bug Fixes

- Fixed a crash when compiling on the debug configuration with MSVC (#2). Thanks @taki640!

## 1.0.0 (01/08/2024)

Initial release of ImGuiTextSelect.
Binary file added external/ImGuiTextSelect/docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions external/ImGuiTextSelect/docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# ImGuiTextSelect

This is a text selection implementation for Dear ImGui, originally part of [WhaleConnect](https://github.com/WhaleConnect/whaleconnect).

Released under the MIT License.

![Demo](demo.gif)

## Features

- Double-click: Select word
- Triple-click: Select line
- Shift-click: Select range
- Keyboard shortcuts for copy (Ctrl+C/Cmd+C) and select all (Ctrl+A/Cmd+A)
- Automatic scrolling for selecting text outside the window's visible area
- Integration in context menus
- UTF-8 text support

## Dependencies

- [Dear ImGui](https://github.com/ocornut/imgui)
- [utfcpp](https://github.com/nemtrif/utfcpp) (For UTF-8 handling)
- C++17 or later

## Integration

Copy `textselect.cpp` and `textselect.hpp` into your project, and update your build settings to compile `textselect.cpp`. Also, copy utfcpp into your project so it can be included as `<utf8.h>`. (utfcpp is a header-only library so it does not need to be compiled.)

To apply text selection to a window:

1. `#include "textselect.hpp"`
2. Create a `TextSelect` instance for your window
3. Call `.update()` on your `TextSelect` instance in your window's render loop

See below for an example.

## Notes

- Only left-to-right text is supported
- Double-click selection only handles word boundary characters in Latin Unicode blocks
- Each line must be the same height (word wrapping is not supported)
- You should have `ImGuiWindowFlags_NoMove` set in either your window or a child window containing the text so mouse drags can be used to select text instead of moving the window
- The accessor functions (`getLineAtIdx`, `getNumLines`) should not contain side effects or heavy computations as they can potentially be called multiple times per frame

ImGuiTextSelect works well for text-only windows such as a console/log output or code display.

Some discussion on highlightable text in Dear ImGui: [GitHub issue](https://github.com/ocornut/imgui/issues/950)

## Example Usage

See [the example code](example/main.cpp) for a full program using ImGuiTextSelect. The example is compiled with the [xmake](https://xmake.io) build system.

```cpp
#include <string_view>
#include <vector>

#include "textselect.hpp"

// ---------- At the beginning of your program: ----------

// The lines to show in the window
// You will need to supply TextSelect instances with functions that:
// 1. Take a line number (starting from 0) and return that line in an std::string_view
// 2. Return the total number of lines in the window
// A vector is a convenient way to fulfill the above requirements, but you may use whatever you like.
std::vector<std::string_view> lines{
"Line 1",
"Line 2",
"Line 3",
"A longer line",
"Text selection in Dear ImGui",
"UTF-8 characters Ë ⑤ 三【 】┌──┐"
};

std::string_view getLineAtIdx(size_t idx) {
return lines[idx];
}

size_t getNumLines() {
return lines.size();
}

// Create a TextSelect instance
TextSelect textSelect{ getLineAtIdx, getNumLines };

// ---------- In the main render loop: ----------

// Create a window to contain the text
ImGui::SetNextWindowSize({ 300, 200 });
ImGui::Begin("Text selection");

// Create a child window with the "NoMove" flag
// This allows mouse drags to select text (instead of moving the window), while still
// allowing the window to be moved from the title bar.
ImGui::BeginChild("text", {}, 0, ImGuiWindowFlags_NoMove);

// Display each line
for (const auto& line : lines) {
ImGui::TextUnformatted(line.data());
}

// Update TextSelect instance (all text selection is handled in this method)
textSelect.update();

// Register a context menu (optional)
// The TextSelect class provides the hasSelection, copy, and selectAll methods
// for manual control.
if (ImGui::BeginPopupContextWindow()) {
ImGui::BeginDisabled(!textSelect.hasSelection());
if (ImGui::MenuItem("Copy", "Ctrl+C")) {
textSelect.copy();
}
ImGui::EndDisabled();

if (ImGui::MenuItem("Select all", "Ctrl+A")) {
textSelect.selectAll();
}
ImGui::EndPopup();
}

ImGui::EndChild();
ImGui::End();
```
Loading
Loading