Skip to content

Commit 46840cf

Browse files
committed
add icon font
1 parent 3b2c474 commit 46840cf

File tree

9 files changed

+9497
-10
lines changed

9 files changed

+9497
-10
lines changed

deps/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ endif()
4141
if(NOT TARGET stb)
4242
add_subdirectory(stb)
4343
endif()
44+
45+
## IconFontCppHeaders
46+
if(NOT TARGET IconFontCppHeaders)
47+
add_subdirectory(IconFontCppHeaders)
48+
endif()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_library(IconFontCppHeaders INTERFACE)
2+
3+
target_include_directories(IconFontCppHeaders INTERFACE "include")

deps/IconFontCppHeaders/README.md

Lines changed: 246 additions & 0 deletions
Large diffs are not rendered by default.

deps/IconFontCppHeaders/include/IconFontCppHeaders/IconsLucide.h

Lines changed: 1661 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Copyright (c) 2017 Juliette Foucaut and Doug Binks
2+
3+
This software is provided 'as-is', without any express or implied
4+
warranty. In no event will the authors be held liable for any damages
5+
arising from the use of this software.
6+
7+
Permission is granted to anyone to use this software for any purpose,
8+
including commercial applications, and to alter it and redistribute it
9+
freely, subject to the following restrictions:
10+
11+
1. The origin of this software must not be misrepresented; you must not
12+
claim that you wrote the original software. If you use this software
13+
in a product, an acknowledgment in the product documentation would be
14+
appreciated but is not required.
15+
2. Altered source versions must be plainly marked as such, and must not be
16+
misrepresented as being the original software.
17+
3. This notice may not be removed or altered from any source distribution.

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ SET(SRCS
250250
## Embedded binary data
251251
render/bindata/bindata_font_lato_regular.cpp
252252
render/bindata/bindata_font_cousine_regular.cpp
253+
render/bindata/bindata_font_lucide_icons.cpp
253254
render/bindata/concrete_seamless.cpp
254255
render/bindata/bindata_clay.cpp
255256
render/bindata/bindata_wax.cpp
@@ -382,3 +383,6 @@ target_include_directories(polyscope PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../incl
382383
# Link settings
383384
target_link_libraries(polyscope PUBLIC imgui glm::glm)
384385
target_link_libraries(polyscope PRIVATE "${BACKEND_LIBS}" stb nlohmann_json::nlohmann_json MarchingCube::MarchingCube)
386+
387+
# For now, make this private, until we are sure we want to commit to it. We may expose it as public in the future.
388+
target_link_libraries(polyscope PRIVATE IconFontCppHeaders)

src/imgui_config.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ unsigned int getCousineRegularCompressedSize();
1212
const unsigned int* getCousineRegularCompressedData();
1313
unsigned int getLatoRegularCompressedSize();
1414
const unsigned int* getLatoRegularCompressedData();
15+
unsigned int getLucideIconsCompressedSize();
16+
const unsigned char* getLucideIconsCompressedData();
1517
} // namespace render
1618

1719
void configureImGuiStyle() {
@@ -84,16 +86,32 @@ std::tuple<ImFont*, ImFont*> loadBaseFonts(ImFontAtlas* fontAtlas) {
8486

8587
float fontSize = 18.0;
8688

87-
{ // add regular font
88-
regularFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(),
89-
render::getLatoRegularCompressedSize(), fontSize);
90-
}
89+
// add regular font
90+
regularFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(),
91+
render::getLatoRegularCompressedSize(), fontSize);
92+
93+
// append icons to regular font
94+
{
95+
ImFontConfig config;
96+
config.MergeMode = true;
97+
config.GlyphMinAdvanceX = fontSize; // make the icon monospaced
98+
99+
// this uses a tip from a helpful github issue to get teh alignment mostly right
100+
// https://github.com/ocornut/imgui/issues/4127#issuecomment-2814162680
91101

92-
{ // add mono font
93-
monoFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(),
94-
render::getCousineRegularCompressedSize(), fontSize);
102+
// Align vertically; the coefficients are specific to the particular icon font we're using.
103+
float font_size_pixels = fontSize; // Or whatever you'd like.
104+
float icon_scaling = 1.0f; // Or whatever you'd like.
105+
config.GlyphOffset = {0.0f, font_size_pixels * (0.5f * icon_scaling - 0.3f)};
106+
107+
fontAtlas->AddFontFromMemoryCompressedTTF(render::getLucideIconsCompressedData(),
108+
render::getLucideIconsCompressedSize(), fontSize, &config);
95109
}
96110

111+
// add mono font
112+
monoFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(),
113+
render::getCousineRegularCompressedSize(), fontSize);
114+
97115
return std::tuple<ImFont*, ImFont*>(regularFont, monoFont);
98116
}
99117

src/polyscope.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "nlohmann/json.hpp"
2424
using json = nlohmann::json;
2525

26+
#include "IconFontCppHeaders/IconsLucide.h"
27+
2628
namespace polyscope {
2729

2830
// Note: Storage for global members lives in state.cpp and options.cpp
@@ -712,9 +714,9 @@ void buildPolyscopeGui() {
712714
ImGui::SetNextWindowPos(ImVec2(internal::imguiStackMargin, internal::imguiStackMargin));
713715
ImGui::SetNextWindowSize(ImVec2(internal::leftWindowsWidth, 0.));
714716

715-
ImGui::Begin("Polyscope", nullptr);
717+
ImGui::Begin("Polyscope ", nullptr);
716718

717-
if (ImGui::Button("Reset View")) {
719+
if (ImGui::Button(ICON_LC_HOUSE " Reset View")) {
718720
view::flyToHomeView();
719721
}
720722
ImGui::SameLine();
@@ -746,7 +748,7 @@ void buildPolyscopeGui() {
746748

747749

748750
ImGui::SameLine();
749-
if (ImGui::Button("Controls")) {
751+
if (ImGui::Button(ICON_LC_CIRCLE_QUESTION_MARK)) {
750752
// do nothing, just want hover state
751753
}
752754
if (ImGui::IsItemHovered()) {

0 commit comments

Comments
 (0)