Skip to content

Instantly share code, notes, and snippets.

@jerome-diver
Created January 15, 2021 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerome-diver/b26f98a849b2f805f61e687a1c6ee028 to your computer and use it in GitHub Desktop.
Save jerome-diver/b26f98a849b2f805f61e687a1c6ee028 to your computer and use it in GitHub Desktop.
--[[
Test lgi Lua package with GooCanvas and Modelized items
----]]
local lgi = require 'lgi'
local Goo = lgi.GooCanvas
local Gtk = lgi.Gtk
local win = Gtk.Window { width = 640, height = 500, anchor = Gtk.GTK_WINDOW_TOPLEVEL }
local frame = Gtk.Frame { width = 400, height = 400 }
local canvas = Goo.Canvas { parent = frame, id = 'canvas', width = 300, height = 300 }
win.on_key_press_event = nil
win.on_map_event = function() win.on_map_event = nil end
win.on_destroy = Gtk.main_quit
tool_bar = Gtk.Toolbar { height = 48 }
tool_bar:insert(Gtk.ToolButton { stock_id = 'gtk-quit', on_clicked = function() win:destroy() end }, -1)
local item_grp = Goo.CanvasGroup { parent = canvas.root_item,
x = 0, y = 0,
width = 200, height = 150 }
local rect = Goo.CanvasRect { parent = item_grp,
x = 0, y = 0,
width = 200, height = 150,
line_width = 2,
stroke_color = 'yellow',
fill_color = 'black',
radius_x = 10, radius_y = 10 }
local txt = Goo.CanvasText { parent = item_grp,
text = 'Voila !',
x = 20, y = 20, width = -1,
anchor = Goo.GOO_CANVAS_ANCHOR_CENTER,
font = 'source-code bold 12',
fill_color = 'red' }
item_grp:scale(-1,1)
print("item grp coordinates after scale x(-1) is "..item_grp.x)
item_grp:translate(-200,0)
print("item grp coordinates after translate x(-200) is "..item_grp.x)
item_grp.x = -200
print("item grp coordinates after translate x(-200) is "..item_grp.x)
-- local root_model = Goo.CanvasGroupModel { canvas.root_item_model, x = 0, y = 0, width = 200, height = 150 }
-- local rectangle_model = Goo.CanvasRectModel { root_model, x = 0, y = 0, line_width = 2, width = 200, height = 150,
-- stroke_color = 'yellow', fill_color = 'black', radius_x = 10, radius_y = 10 }
-- local text_model = Goo.CanvasTextModel { root_model, text = 'Voila !', x = 20, y = 20, anchor = Goo.GOO_CANVAS_ANCHOR_CENTER,
-- font = 'source-code bold 12', fill_color = 'red' }
-- canvas:set_root_item_model(root_model)
local vbox = Gtk.VBox:new(6)
vbox:add(tool_bar)
vbox:add(frame)
Gtk.Container.add(win, vbox)
win:show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment