Skip to content
Merged
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
133 changes: 133 additions & 0 deletions daslib/implot_boost.das
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,139 @@ def public with_subplots(title : string; rows : int; cols : int; size : float2;
}
}

// Begin a group of axis-aligned plots, run the body if it began, always End it.
def public with_aligned_plots(group_id : string; blk : block) {
if (BeginAlignedPlots(group_id)) { // native default vertical = true
invoke(blk)
EndAlignedPlots()
}
}
Comment thread
borisbat marked this conversation as resolved.
def public with_aligned_plots(group_id : string; vertical : bool; blk : block) {
if (BeginAlignedPlots(group_id, vertical)) {
invoke(blk)
EndAlignedPlots()
}
}

// ===== Style scopes (Push/Pop — always balanced) =====

// Push a colormap for the body; auto-colored items + heatmaps inside sample from it.
def public with_colormap(cmap : ImPlotColormap; blk : block) {
PushColormap(cmap)
invoke(blk)
PopColormap(1)
}

// Push one ImPlotCol color override (e.g. ImPlotCol.Line) for the body.
def public with_style_color(idx : ImPlotCol; col : float4; blk : block) {
PushStyleColor(idx, col)
invoke(blk)
PopStyleColor(1)
}

// Push one ImPlotStyleVar override for the body — float / int / float2 forms.
def public with_style_var(idx : ImPlotStyleVar; value : float; blk : block) {
PushStyleVar(idx, value)
invoke(blk)
PopStyleVar(1)
}
def public with_style_var(idx : ImPlotStyleVar; value : int; blk : block) {
PushStyleVar(idx, value)
invoke(blk)
PopStyleVar(1)
}
def public with_style_var(idx : ImPlotStyleVar; value : float2; blk : block) {
PushStyleVar(idx, value)
invoke(blk)
PopStyleVar(1)
}

// Clip drawing to the plot area (optionally expanded by `expand` px) for the body.
def public with_plot_clip_rect(blk : block) {
PushPlotClipRect() // native default expand = 0
invoke(blk)
PopPlotClipRect()
}
Comment thread
borisbat marked this conversation as resolved.
def public with_plot_clip_rect(expand : float; blk : block) {
PushPlotClipRect(expand)
invoke(blk)
PopPlotClipRect()
}

// ===== Popup & drag-and-drop scopes (body runs iff Begin succeeded) =====

// A legend popup (default right mouse button); body emits its contents.
def public with_legend_popup(label_id : string; blk : block) {
if (BeginLegendPopup(label_id)) { // native default mouse button = right
invoke(blk)
EndLegendPopup()
}
}
Comment thread
borisbat marked this conversation as resolved.
def public with_legend_popup(label_id : string; mouse_button : int; blk : block) {
if (BeginLegendPopup(label_id, mouse_button)) {
invoke(blk)
EndLegendPopup()
}
}

// Drag-drop SOURCE on the last item / the whole plot / an axis.
def public with_drag_drop_source_item(label_id : string; blk : block) {
if (BeginDragDropSourceItem(label_id)) { // native default flags = 0
invoke(blk)
EndDragDropSource()
}
}
Comment thread
borisbat marked this conversation as resolved.
def public with_drag_drop_source_item(label_id : string; flags : int; blk : block) {
if (BeginDragDropSourceItem(label_id, flags)) {
invoke(blk)
EndDragDropSource()
}
}
def public with_drag_drop_source_plot(blk : block) {
if (BeginDragDropSourcePlot()) { // native default flags = 0
invoke(blk)
EndDragDropSource()
}
}
Comment thread
borisbat marked this conversation as resolved.
def public with_drag_drop_source_plot(flags : int; blk : block) {
if (BeginDragDropSourcePlot(flags)) {
invoke(blk)
EndDragDropSource()
}
}
def public with_drag_drop_source_axis(axis : ImAxis; blk : block) {
if (BeginDragDropSourceAxis(axis)) { // native default flags = 0
invoke(blk)
EndDragDropSource()
}
}
Comment thread
borisbat marked this conversation as resolved.
def public with_drag_drop_source_axis(axis : ImAxis; flags : int; blk : block) {
if (BeginDragDropSourceAxis(axis, flags)) {
invoke(blk)
EndDragDropSource()
}
}

// Drag-drop TARGET on the whole plot / an axis / the legend.
def public with_drag_drop_target_plot(blk : block) {
if (BeginDragDropTargetPlot()) {
invoke(blk)
EndDragDropTarget()
}
}
def public with_drag_drop_target_axis(axis : ImAxis; blk : block) {
if (BeginDragDropTargetAxis(axis)) {
invoke(blk)
EndDragDropTarget()
}
}
def public with_drag_drop_target_legend(blk : block) {
if (BeginDragDropTargetLegend()) {
invoke(blk)
EndDragDropTarget()
}
}

// ===== Axis setup =====

def public setup_axes(x_label : string; y_label : string) {
Expand Down
74 changes: 74 additions & 0 deletions tests/integration/test_v1_scopes.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
options gen2

require imgui
require imgui/imgui_harness
require imgui/imgui_containers_builtin
require imgui/imgui_implot_boost
require implot
require math

// Headless smoke for the v1 (imgui_implot_boost) RAII scope wrappers. v1 has no
// snapshot hook, so there is nothing to query — instead this exercises every paired
// scope (Begin/End and Push/Pop) for several frames and passes iff it renders
// crash-free: an unbalanced Push/Pop or a missed End would trip an ImGui assert.
// Run: daslang.exe -load_module .../dasImgui -load_module .../dasImguiImplot \
// tests/integration/test_v1_scopes.das -- --headless --headless-frames 12

[export]
def main : int {
harness_init("implot v1 scopes smoke", 900, 700)
var ctx = implot::CreateContext()
let sin_data <- [for (i in range(120)); double(sin(float(i) * 0.05f))]
let cos_data <- [for (i in range(120)); double(cos(float(i) * 0.05f))]
var rc = 1
var done = false
while (harness_begin_frame()) {
harness_new_frame()
window(W, (text = "v1 scopes", closable = false, flags = ImGuiWindowFlags.None)) {
// Push/Pop style scopes wrap a group of axis-aligned plots (Begin/End scope).
with_style_var(ImPlotStyleVar.LineWeight, 2.0f) {
with_aligned_plots("aligned") {
with_plot("p1", float2(-1.0f, 280.0f), ImPlotFlags.None) {
setup_axes("x", "y")
with_colormap(ImPlotColormap.Viridis) {
plot_line("sin", sin_data)
}
with_style_color(ImPlotCol.Line, float4(1.0f, 0.5f, 0.2f, 1.0f)) {
plot_line("cos", cos_data)
}
with_plot_clip_rect() {
plot_scatter("pts", sin_data)
}
// Conditional scopes: Begin returns false headless (no input), so the
// body is skipped and End is correctly not called — exercises the guard.
with_legend_popup("##leg") {}
with_drag_drop_source_item("src") {}
with_drag_drop_source_plot() {}
with_drag_drop_source_axis(ImAxis.X1) {}
with_drag_drop_target_plot() {}
with_drag_drop_target_axis(ImAxis.X1) {}
with_drag_drop_target_legend() {}
}
with_plot("p2", float2(-1.0f, 280.0f), ImPlotFlags.None) {
setup_axes("x", "y")
plot_bars("bars", cos_data)
}
}
}
}
harness_end_frame()
if (!done && harness_frame_count() >= 6) {
done = true
print("PASS: v1 scope wrappers rendered crash-free for {harness_frame_count()} frames\n")
rc = 0
request_exit()
}
}
harness_shutdown()
unsafe {
if (ctx != null) {
DestroyContext(ctx)
}
}
return rc
}
Loading