Comments (5)
The following example shows how to manually tweak glyph ranges using ImFontGlyphRangesBuilder
APIs.
using CImGui
using CImGui.CSyntax
using CImGui.CSyntax.CStatic
using CImGui.GLFWBackend
using CImGui.OpenGLBackend
using CImGui.GLFWBackend.GLFW
using CImGui.OpenGLBackend.ModernGL
using Printf
@static if Sys.isapple()
# OpenGL 3.2 + GLSL 150
const glsl_version = 150
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 2)
GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # required on Mac
else
# OpenGL 3.0 + GLSL 130
const glsl_version = 130
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 0)
# GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
# GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # 3.0+ only
end
# setup GLFW error callback
error_callback(err::GLFW.GLFWError) = @error "GLFW ERROR: code $(err.code) msg: $(err.description)"
GLFW.SetErrorCallback(error_callback)
# create window
window = GLFW.CreateWindow(1280, 720, "Demo")
@assert window != C_NULL
GLFW.MakeContextCurrent(window)
GLFW.SwapInterval(1) # enable vsync
# setup Dear ImGui context
ctx = CImGui.CreateContext()
# setup Dear ImGui style
CImGui.StyleColorsDark()
# CImGui.StyleColorsClassic()
# CImGui.StyleColorsLight()
# load Fonts
# - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use `CImGui.PushFont/PopFont` to select them.
# - `CImGui.AddFontFromFileTTF` will return the `Ptr{ImFont}` so you can store it if you need to select the font among multiple.
# - If the file cannot be loaded, the function will return C_NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
# - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling `CImGui.Build()`/`GetTexDataAsXXXX()``, which `ImGui_ImplXXXX_NewFrame` below will call.
# - Read 'fonts/README.txt' for more instructions and details.
fonts_dir = joinpath(homedir(), "your-font-file-dir")
fonts = CImGui.GetIO().Fonts
# default_font = CImGui.AddFontDefault(fonts)
# CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "Cousine-Regular.ttf"), 15)
# CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "DroidSans.ttf"), 16)
# CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "Karla-Regular.ttf"), 10)
# CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "ProggyTiny.ttf"), 10)
# CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "Roboto-Medium.ttf"), 16)
# @assert default_font != C_NULL
using CImGui.LibCImGui
ranges = ImVector_ImWchar_create()
ImVector_ImWchar_Init(ranges)
builder = ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()
ImFontGlyphRangesBuilder_AddChar(builder, 'ϕ')
ImFontGlyphRangesBuilder_AddChar(builder, '♐')
ImFontGlyphRangesBuilder_AddRanges(builder, ImFontAtlas_GetGlyphRangesDefault(fonts))
ImFontGlyphRangesBuilder_BuildRanges(builder, ranges)
r = unsafe_wrap(Vector{ImVector_ImWchar}, ranges, 1)
CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "your-font-file-name.ttf"), 16, C_NULL, r[1].Data)
# setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true)
ImGui_ImplOpenGL3_Init(glsl_version)
try
show_demo_window = true
show_another_window = false
clear_color = Cfloat[0.45, 0.55, 0.60, 1.00]
while !GLFW.WindowShouldClose(window)
GLFW.PollEvents()
# start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame()
ImGui_ImplGlfw_NewFrame()
CImGui.NewFrame()
# show the big demo window
show_demo_window && @c CImGui.ShowDemoWindow(&show_demo_window)
# show a simple window that we create ourselves.
# we use a Begin/End pair to created a named window.
@cstatic f=Cfloat(0.0) counter=Cint(0) begin
CImGui.Begin("Hello, world!") # create a window called "Hello, world!" and append into it.
CImGui.Text("This is some useful text.") # display some text
@c CImGui.Checkbox("Demo Window", &show_demo_window) # edit bools storing our window open/close state
@c CImGui.Checkbox("Another Window", &show_another_window)
@c CImGui.SliderFloat("float", &f, 0, 1) # edit 1 float using a slider from 0 to 1
CImGui.ColorEdit3("clear color", clear_color) # edit 3 floats representing a color
CImGui.Button("Button") && (counter += 1)
CImGui.SameLine()
CImGui.Text("counter = $counter")
CImGui.Text(@sprintf("Application average %.3f ms/frame (%.1f FPS)", 1000 / CImGui.GetIO().Framerate, CImGui.GetIO().Framerate))
CImGui.End()
end
# show another simple window.
if show_another_window
@c CImGui.Begin("Another Window", &show_another_window) # pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
CImGui.Text("Hello from another window!")
CImGui.Button("Close Me") && (show_another_window = false;)
CImGui.End()
end
CImGui.Begin("Hello ImGui")
CImGui.Text("ϕ")
CImGui.Text("♐")
CImGui.End()
# rendering
CImGui.Render()
GLFW.MakeContextCurrent(window)
display_w, display_h = GLFW.GetFramebufferSize(window)
glViewport(0, 0, display_w, display_h)
glClearColor(clear_color...)
glClear(GL_COLOR_BUFFER_BIT)
ImGui_ImplOpenGL3_RenderDrawData(CImGui.GetDrawData())
GLFW.MakeContextCurrent(window)
GLFW.SwapBuffers(window)
end
catch e
@error "Error in renderloop!" exception=e
Base.show_backtrace(stderr, catch_backtrace())
finally
ImGui_ImplOpenGL3_Shutdown()
ImGui_ImplGlfw_Shutdown()
ImVector_ImWchar_destroy(ranges)
ImFontGlyphRangesBuilder_destroy(builder)
CImGui.DestroyContext(ctx)
GLFW.DestroyWindow(window)
end
X-ref: https://discourse.julialang.org/t/cimgui-and-special-characters-unicode/49476/11
from cimgui.jl.
# default_font = CImGui.AddFontDefault(fonts) CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "IBMPlexSansKR-Regular.ttf"), 16) # @assert default_font != C_NULL
I guess this should be:
CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "IBMPlexSansKR-Regular.ttf"), 16, C_NULL, CImGui.GetGlyphRangesKorean(fonts))
You could read more docs about fonts here. 😉
from cimgui.jl.
Ok GetGlyphRangesKorean()
works. thank you 👍
from cimgui.jl.
Custom glyph range APIs are not fully wrapped, so currently, there is no easy way to draw all unicode texts. I will revisit this if I have time.
from cimgui.jl.
Custom glyph range APIs are not fully wrapped, so currently, there is no easy way to draw all unicode texts. I will revisit this if I have time.
Now we don't have this limitation as Clang.jl's new generator supports generating getproperty/setproperty!
methods for any cimgui structs. See 36d4c3b .
from cimgui.jl.
Related Issues (20)
- Broken after update HOT 8
- Incomplete overlap HOT 4
- UndefVarError: `igSetScrollYFloat` not defined HOT 1
- Example of integrating a GLMakie plot in a CImGui window (or conversely) HOT 6
- `AddRect()` error: "`ImDrawCornerFlags_All` not defined" HOT 4
- Help / About Dear ImGui / Config/Build information throws an error HOT 1
- Create a CImGui sample application ie running outside of Julia CLI (from PowerShell commandline) HOT 9
- Window dimensions are always reported as 400x400 HOT 2
- Example code doesn't actually run HOT 6
- Input widgets with different IDs conflict with each other? HOT 6
- How can I get ImGuiWindowClass?
- The getproperty and setproperty! method of ImNodesStyle was not provided
- On some Windows machine, got glfwCreateWindow error HOT 5
- Regenerate new wrapper libraries for fresh ImGui and ImPlot versions? HOT 1
- An error occurs when I use ImGuiTextFilter in a package
- SDL Backend Support? HOT 6
- I can not run the demo HOT 5
- ImGuiKey_KeyPadEnter not defined, when running demo HOT 2
- Upgrading Guide: 1.79 to 1.82
- Expand tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cimgui.jl.