diff --git a/doc/examples/GdsDemo/demo.gd b/doc/examples/GdsDemo/demo.gd index 1246016..de15fbc 100644 --- a/doc/examples/GdsDemo/demo.gd +++ b/doc/examples/GdsDemo/demo.gd @@ -2,16 +2,32 @@ extends Node var myfloat := [0.0] var mystr := [""] +var values := [2.0, 4.0, 0.0, 3.0, 1.0, 5.0] +var items := ["zero", "one", "two", "three"] +var current_item := [2] +var anim_counter := 0 func _ready(): var io := ImGui.GetIO() io.ConfigFlags |= ImGui.ConfigFlags_ViewportsEnable -func _process(_delta): +func _process(_delta: float) -> void: ImGui.Begin("hello") ImGui.Text("hello from GDScript") ImGui.DragFloat("myfloat", myfloat) ImGui.Text(str(myfloat[0])) ImGui.InputText("mystr", mystr, 32) ImGui.Text(mystr[0]) + + ImGui.PlotHistogram("histogram", values, values.size()) + ImGui.PlotLines("lines", values, values.size()) + ImGui.ListBox("choices", current_item, items, items.size()) + ImGui.Combo("combo", current_item, items) + ImGui.Text("choice = %s" % items[current_item[0]]) ImGui.End() + +func _physics_process(_delta: float) -> void: + anim_counter += 1 + if anim_counter >= 10: + anim_counter = 0 + values.push_back(values.pop_front()) diff --git a/gdext/scripts/gds_bindings.py b/gdext/scripts/gds_bindings.py index 27b1d97..98271a5 100644 --- a/gdext/scripts/gds_bindings.py +++ b/gdext/scripts/gds_bindings.py @@ -180,7 +180,7 @@ def __init__(self, j): class Param: def __init__(self, j): self.name = j["name"] - self.is_array = j["is_array"] + self.is_array = j["is_array"] or self.name == "values" # HACK: because is_array not set self.is_varargs = j["is_varargs"] if not self.is_varargs: self.orig_type = j["type"]["declaration"] diff --git a/gdext/src/ImGuiAPI.h b/gdext/src/ImGuiAPI.h index 8cfa7a3..b32ed2b 100644 --- a/gdext/src/ImGuiAPI.h +++ b/gdext/src/ImGuiAPI.h @@ -82,27 +82,35 @@ struct GdsArray operator T*() { return buf.data(); } }; +// TODO: take PackedFloat32Array parameters instead template <> -struct GdsArray +struct GdsArray { - Array& arr; - std::vector buf; - std::vector ptrs; + std::vector buf; - GdsArray(Array& a) : arr(a), buf(a.size()), ptrs(a.size()) + GdsArray(Array& arr) : buf(arr.size()) { for (int i = 0; i < arr.size(); ++i) { - buf[i] = String(arr[i]).utf8(); - ptrs[i] = buf[i].get_data(); + buf[i] = arr[i]; } } - ~GdsArray() + operator const float*() { return buf.data(); } +}; + +template <> +struct GdsArray +{ + std::vector buf; + std::vector ptrs; + + GdsArray(Array& arr) : buf(arr.size()), ptrs(arr.size()) { for (int i = 0; i < arr.size(); ++i) { - arr[i] = buf[i].get_data(); + buf[i] = String(arr[i]).utf8(); + ptrs[i] = buf[i].get_data(); } }