summary refs log tree commit diff stats
path: root/tests/manyloc/named_argument_bug/main.nim
blob: 7676744280114b0212fe843fddada42e5c1f7ebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import
  tri_engine/config,
  tri_engine/math/vec,
  tri_engine/math/circle,
  tri_engine/gfx/gl/primitive,
  tri_engine/gfx/tex,
  tri_engine/gfx/color,
  tri_engine/tri_engine,
  gui

var isRunning = true

block:
  var renderer = newRenderer(w=10, h=10)

  var primitive = newPrimitiveCircle(0.3.TR, color=white(0.5, 0.8), z=15)
  renderer.addPrimitive(primitive)

  var verts = newVert((min: newV2xy(-0.4), size: newV2xy(0.3)))
  var primitive2 = newPrimitive(verts, color=red(0.5, 0.8), z=10)
  renderer.addPrimitive(primitive2)

  var mainMenuWidget = newWidget(wtImg, wlBg, rect=(newV2xy(-1.0), newV2xy(2.0)))
class="kr">function redo_event(State) if State.next_history <= #State.history then --? print('restoring history', State.next_history+1) local result = State.history[State.next_history] State.next_history = State.next_history+1 return result end end -- Copy all relevant global state. -- Make copies of objects; the rest of the app may mutate them in place, but undo requires immutable histories. function snapshot(State, s,e) -- Snapshot everything by default, but subset if requested. assert(s) if e == nil then e = s end assert(#State.lines > 0) if s < 1 then s = 1 end if s > #State.lines then s = #State.lines end if e < 1 then e = 1 end if e > #State.lines then e = #State.lines end -- compare with App.initialize_globals local event = { screen_top=deepcopy(State.screen_top1), selection=deepcopy(State.selection1), cursor=deepcopy(State.cursor1), current_drawing_mode=Drawing_mode, previous_drawing_mode=State.previous_drawing_mode, lines={}, start_line=s, end_line=e, -- no filename; undo history is cleared when filename changes } -- deep copy lines without cached stuff like text fragments for i=s,e do local line = State.lines[i] if line.mode == 'text' then table.insert(event.lines, {mode='text', data=line.data}) elseif line.mode == 'drawing' then local points=deepcopy(line.points) --? print('copying', line.points, 'with', #line.points, 'points into', points) local shapes=deepcopy(line.shapes) --? print('copying', line.shapes, 'with', #line.shapes, 'shapes into', shapes) table.insert(event.lines, {mode='drawing', y=line.y, h=line.h, points=points, shapes=shapes, pending={}}) --? table.insert(event.lines, {mode='drawing', y=line.y, h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}}) else print(line.mode) assert(false) end end return event end function patch(lines, from, to) --? if #from.lines == 1 and #to.lines == 1 then --? assert(from.start_line == from.end_line) --? assert(to.start_line == to.end_line) --? assert(from.start_line == to.start_line) --? lines[from.start_line] = to.lines[1] --? return --? end assert(from.start_line == to.start_line) for i=from.end_line,from.start_line,-1 do table.remove(lines, i) end assert(#to.lines == to.end_line-to.start_line+1) for i=1,#to.lines do table.insert(lines, to.start_line+i-1, to.lines[i]) end end function patch_placeholders(line_cache, from, to) assert(from.start_line == to.start_line) for i=from.end_line,from.start_line,-1 do table.remove(line_cache, i) end assert(#to.lines == to.end_line-to.start_line+1) for i=1,#to.lines do table.insert(line_cache, to.start_line+i-1, {}) end end -- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080 function deepcopy(obj, seen) if type(obj) ~= 'table' then return obj end if seen and seen[obj] then return seen[obj] end local s = seen or {} local result = setmetatable({}, getmetatable(obj)) s[obj] = result for k,v in pairs(obj) do result[deepcopy(k, s)] = deepcopy(v, s) end return result end function minmax(a, b) return math.min(a,b), math.max(a,b) end