Skip to content

Commit

Permalink
fix #23 (rpad)
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed May 7, 2022
1 parent 4022dae commit b256a69
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Desktop/imgui_controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ function imgui_control_item(imctx::Ptr, item::Any)
end
end

# code from https://github.com/JuliaLang/julia/blob/master/base/strings/util.jl#L464
function _rpad_use_length_instead_of_textwidth(
s::Union{AbstractChar,AbstractString},
n::Integer,
p::Union{AbstractChar,AbstractString}=' ',
) :: String
n = Int(n)::Int
m = signed(n) - Int(length(s))::Int # textwidth
m 0 && return string(s)
l = length(p) # textwidth
q, r = divrem(m, l)
r == 0 ? string(s, p^q) : string(s, p^q, first(p, r))
end

# CImGui.InputText
function imgui_control_item(imctx::Ptr, item::InputText)
null = '\0'
nullpad_buf = rpad(item.buf, item.buf_size, null)
nullpad_buf = _rpad_use_length_instead_of_textwidth(item.buf, item.buf_size, null)
value = @cstatic_var buf=nullpad_buf begin
changed = CImGui.InputText(item.label, buf, item.buf_size)
end
Expand Down

0 comments on commit b256a69

Please sign in to comment.