diff --git a/examples/paint/canvas.go b/examples/paint/canvas.go index f091017d..ad34cf56 100644 --- a/examples/paint/canvas.go +++ b/examples/paint/canvas.go @@ -156,6 +156,7 @@ func CanvasWidget() g.Widget { inpos := image.Point{mousepos.X - scr.X, mousepos.Y - scr.Y} if imgui.IsMouseClickedBool(imgui.MouseButtonLeft) { was_drawing = true + canvas.UndoIndexes = append(canvas.UndoIndexes, len(canvas.DrawCommands)) lastTo = image.Point{0, 0} buffer = append(buffer, DrawCommand{Tool: current_tool, Color: current_color, BrushSize: brush_size, From: inpos, To: inpos}) lastTo = inpos diff --git a/examples/paint/toolbar.go b/examples/paint/toolbar.go index 756900e1..f660d806 100644 --- a/examples/paint/toolbar.go +++ b/examples/paint/toolbar.go @@ -140,7 +140,17 @@ func ButtonColorMaker() *g.RowWidget { current_tool = 1 } imgui.SameLine() - imgui.ImageButton("##undo_tool", undoButtonImg.Texture().ID(), sz.Mul(1.7)) + if imgui.ImageButton("##undo_tool", undoButtonImg.Texture().ID(), sz.Mul(1.7)) { + if len(canvas.UndoIndexes) > 0 { + lastUndoIndex := canvas.UndoIndexes[len(canvas.UndoIndexes)-1] + uind := canvas.UndoIndexes[:len(canvas.UndoIndexes)-1] + dc := canvas.DrawCommands[:lastUndoIndex] + canvas.Backend.ForceRelease() + canvas, _ = NewCanvas(canvasDetectedHeight) + canvas.UndoIndexes = uind + canvas.DrawCommands = dc + } + } imgui.SameLine() if imgui.ImageButton("##clear_tool", clearButtonImg.Texture().ID(), sz.Mul(1.7)) { canvas.Backend.ForceRelease()