GooCanvasItemModel no error but item view never draw
Open
@pavouk is already working on this.
Since Jan 21, 2021.
- Dominant language
- Lua
- Stars
- 491
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
When i try to use model/view method with GooCanvas, i can not get it working fine to show items.
look at this code:
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 root_model = Goo.CanvasGroupModel:new(nil, nil)
local item_model = Goo.CanvasGroupModel:new(nil, nil)
local rectangle_model = Goo.CanvasRectModel { 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 { text = 'Voila !', x = 20, y = 20, anchor = Goo.GOO_CANVAS_ANCHOR_CENTER,
font = 'source-code bold 12', fill_color = 'red' }
item_model:set_parent(root_model)
rectangle_model:set_parent(item_model)
text_model:set_parent(item_model)
canvas:set_root_item_model(root_model)
local item = canvas:create_item(item_model)
item:ensure_updated()
item:raise()
canvas:update()
local is_visible = item:is_visible() and "yes" or "no" --? print "yes", but never show on canvas
print("item is visible ? "..is_visible)
local vbox = Gtk.VBox:new(6)
vbox:add(tool_bar)
vbox:add(frame)
Gtk.Container.add(win, vbox)
win:show_all()
Gtk.main()
I excpected it to show a rectangle with a content text, but it show nothing (try it) and no error.
define a model with a perent show an error about to not be possible for parent to be writable (but it should be in the goo_canvas API doc...), i read an other one issue there who indicates to use set_parent method (so i do it).
What i do wrong ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.