Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/ant.imgui/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function ImGuiAnt.FontAtlasBuild(list)
FontDatas[#FontDatas+1] = FontData
local data, size = fastio.wrap(FontData)()
ImFontConfig.MergeMode = i > 1
ImFontConfig.RasterizerDensity = config.RasterizerDensity
atlas.AddFontFromMemoryTTF(data, size, config.SizePixels, ImFontConfig, glyphRanges(config.GlyphRanges))
end
atlas.Build()
Expand Down
31 changes: 31 additions & 0 deletions tools/editor/pkg/tools.editor/init_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ local widget_utils = require "widget.utils"

local m = ecs.system 'init_system'

local ImGui = require "imgui"
local ImGuiBackend = require "imgui.backend"

local dpi = {min=0.0, max=2.77, value=1, enabled=true}

local function start_fileserver(luaexe, path)
local fsa = require "fileserver_adapter"
fsa.init(luaexe, path)
Expand All @@ -32,11 +37,13 @@ local function init_font()
fonts[#fonts+1] = {
FontPath = "/pkg/ant.resources.binary/font/Alibaba-PuHuiTi-Regular.ttf",
SizePixels = 18,
RasterizerDensity = dpi.value,
GlyphRanges = { 0x0020, 0xFFFF }
}
fonts[#fonts+1] = {
FontPath = "/pkg/tools.editor/resource/fonts/fa-solid-900.ttf",
SizePixels = 16,
RasterizerDensity = dpi.value,
GlyphRanges = {
0xf062, 0xf062, -- ICON_FA_ARROW_UP "\xef\x81\xa2" U+f062
0xf063, 0xf063, -- ICON_FA_ARROW_DOWN "\xef\x81\xa3" U+f063
Expand Down Expand Up @@ -155,6 +162,30 @@ function m:data_changed()

end

function m:start_frame()
-- GetWindowDpiScale/GetMainViewport only availbled in start_frame/end_frame
if dpi.enabled then
local scale = ImGui.GetWindowDpiScale()
if scale == dpi.value then
dpi.enabled = false
end
-- calculate DPI scale
dpi.value = math.max(dpi.min, math.min(dpi.max, scale))
end
end

function m:final()
-- ImGui says: Can not modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()
if dpi.enabled then
-- rebuild font atlas
init_font()
ImGuiBackend.RenderCreateFontsTexture()
dpi.enabled = false

log.warn(string.format('rebuild the font atlas due to the DPI scale changed dpi:1.0->%.2f', dpi.value))
end
end

function m:exit()
if global_data.fileserver and global_data.fileserver.subprocess then
global_data.fileserver.subprocess:wait()
Expand Down