103 lines
2.0 KiB
Crystal
103 lines
2.0 KiB
Crystal
module ImGui::Helper
|
|
# @example
|
|
# draw_table(title: "manpower", headers: {"Infra", "Ajust", "Lock"}) do
|
|
# infra_hash.keys.each do |infra_id, infra|
|
|
# draw_line(infra)
|
|
# end
|
|
# end
|
|
def draw_table(title : String, headers, &block)
|
|
columns_amount = headers.size
|
|
if ImGui.begin_table(title, columns_amount)
|
|
ImGui.table_next_row
|
|
ImGui.table_next_column
|
|
headers.each do |header|
|
|
ImGui.text header
|
|
ImGui.table_next_column
|
|
end
|
|
|
|
yield
|
|
|
|
ImGui.end_table
|
|
end
|
|
end
|
|
|
|
# @example
|
|
# v = storage[someid]
|
|
# ptr = pointerof(v)
|
|
# draw_table_line(
|
|
# someid,
|
|
# ->{
|
|
# if ImGui.slider_float(
|
|
# label: "absolute####{infra.id}",
|
|
# v: ptr,
|
|
# v_min: 0.0f32,
|
|
# v_max: 10.0f32,
|
|
# flags: (
|
|
# ImGui::ImGuiSliderFlags::NoRoundToFormat |
|
|
# ImGui::ImGuiSliderFlags::Logarithmic
|
|
# ),
|
|
# )
|
|
# store[someid] = v
|
|
# end
|
|
# },
|
|
# "some labels",
|
|
# )
|
|
def draw_table_line(*columns : String | Proc)
|
|
draw_table_line
|
|
columns.each do |column|
|
|
draw_table_cell(column)
|
|
end
|
|
end
|
|
|
|
# @example
|
|
# draw_table_line
|
|
# draw_table_cell id
|
|
# draw_table_cell name
|
|
# draw_table_cell somevalue
|
|
# draw_table_line
|
|
#
|
|
def draw_table_line
|
|
ImGui.table_next_row
|
|
# print "\n"
|
|
end
|
|
|
|
# @example
|
|
# draw_table_line
|
|
# draw_table_cell id
|
|
# draw_table_cell -> { ImGui.text "label" }
|
|
def draw_table_cell(cell : String | Proc)
|
|
draw_table_cell
|
|
if cell.is_a?(String)
|
|
# print cell
|
|
ImGui.text cell
|
|
else
|
|
# print cell.call
|
|
cell.call
|
|
end
|
|
end
|
|
|
|
# @example
|
|
# draw_table_cell do
|
|
# someaction(someid) if ImGui.button("build####{someid}")
|
|
# end
|
|
def draw_table_cell(&block)
|
|
draw_table_cell
|
|
# print "YIELD"
|
|
yield
|
|
end
|
|
|
|
# @example
|
|
# draw_table_line
|
|
# draw_table_cell
|
|
# ImGui.text cell
|
|
def draw_table_cell
|
|
ImGui.table_next_column
|
|
# print "|"
|
|
end
|
|
|
|
# def draw_table_next_line
|
|
# ImGui.table_next_row
|
|
# end
|
|
|
|
end
|