-
Notifications
You must be signed in to change notification settings - Fork 0
/
layers.nim
243 lines (199 loc) · 6.63 KB
/
layers.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#
import gintro/[gtk4, gobject, gio, glib, cairo]
import times
var qt = "GTKLV" & $epochTime()
if g_quark_try_string(qt) != 0:
qt = "NGIQ" & $epochTime()
let CVquark: int = quark_from_static_string(qt) # caution, do not use name Quark!
type
XLayers {.pure.} = enum # will become user extendable
line, rect, pad, hole, circ, text, trace, path, attr, net, pin
const
LayerNames = ["Ground", "Power", "Signal", "Remark", "Net", "Pin"]
type
LayerRow* = object
name*: string
style*: string
group*: string
locked*: bool
visible*: bool
var
layers* = newSeq[LayerRow](LayerNames.len)
selectedLayer: int
proc initLayers =
for i, el in mpairs(layers):
el.name = LayerNames[i]
el.style = "default"
el.group = "G"
el.visible = true
proc findLayer*(name: string): int =
if name.len == 0:
return selectedLayer
result = -1
for i, el in layers:
if el.name == name:
return i
type
ColumnViewGObject = ref object of gobject.Object
proc onSelectionChanged(self: SelectionModel; pos: int; nItems: int) =
selectedLayer = cast[SingleSelection](self).getSelected
echo "onSelectionChanged"
#echo pos, nItems
#echo typeof(cast[SingleSelection](self).getModel)
echo "bbb ", self.getSelection.maximum
proc onLayerNameChanged(w: Text) =
let row = cast[int](w.getQdata(CVquark))
layers[row].name = w.text
proc onStyleNameChanged(w: Text) =
let row = cast[int](w.getQdata(CVquark))
layers[row].style = w.text
proc onGroupNameChanged(w: Text) =
let row = cast[int](w.getQdata(CVquark))
layers[row].group = w.text
proc onLockedChanged(w: CheckButton) =
let row = cast[int](w.getQdata(CVquark))
layers[row].locked = w.active
echo layers
proc onVisibilityChanged(w: CheckButton) =
let row = cast[int](w.getQdata(CVquark))
layers[row].visible = w.active
proc draw(d: DrawingArea; cr: cairo.Context; w, h: int) =
echo "draw", w, " ", h
cr.setSource(1, 0, 0)
cr.paint
proc setup0(f: SignalListItemFactory; item: Object) =
let l = newLabel()
cast[ListItem](item).setChild(l)
proc setup1(f: SignalListItemFactory; item: Object) =
let l = newText()
l.connect("activate", onLayerNameChanged)
cast[ListItem](item).setChild(l)
proc setup2(f: SignalListItemFactory; item: Object) =
let l = newText()
l.connect("activate", onStyleNameChanged)
cast[ListItem](item).setChild(l)
proc setup3(f: SignalListItemFactory; item: Object) =
let l = newText()
l.connect("activate", onGroupNameChanged)
cast[ListItem](item).setChild(l)
proc setup4(f: SignalListItemFactory; item: Object) =
let l = newCheckButton()
l.connect("toggled", onLockedChanged)
cast[ListItem](item).setChild(l)
proc setup5(f: SignalListItemFactory; item: Object) =
let l = newCheckButton()
l.connect("toggled", onVisibilityChanged)
cast[ListItem](item).setChild(l)
proc setup6(f: SignalListItemFactory; item: Object) =
let l = newDrawingArea()
l.setContentWidth(4)
l.setContentHeight(4)
l.setDrawFunc(draw)
cast[ListItem](item).setChild(l)
proc bind0(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = Label(item.getChild())
l.text = $item.getPosition
proc bind1(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = Text(item.getChild())
l.setQdata(CVquark, cast[pointer](item.getPosition))
l.text = layers[item.getPosition].name
proc bind2(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = Text(item.getChild())
l.setQdata(CVquark, cast[pointer](item.getPosition))
l.text = layers[item.getPosition].style
proc bind3(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = Text(item.getChild())
l.setQdata(CVquark, cast[pointer](item.getPosition))
l.text = layers[item.getPosition].group
proc bind4(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = CheckButton(item.getChild())
l.setQdata(CVquark, cast[pointer](item.getPosition))
l.setActive(layers[item.getPosition].locked)
proc bind5(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = CheckButton(item.getChild())
l.setQdata(CVquark, cast[pointer](item.getPosition))
l.setActive(layers[item.getPosition].visible)
proc bind6(f: SignalListItemFactory; item: Object) =
let item = cast[ListItem](item)
let l = DrawingArea(item.getChild())
# e.g. double click on item
proc onColumnViewActivate(cv: ColumnView, pos:int) =
echo "onColumnViewActivate"
proc createLayersWidget*: ScrolledWindow =
initLayers()
let cv = newColumnView()
###cv.setHexpand
#cv.setSingleClickActivate(false)
cv.addCssClass("data-table") # [.column-separators][.rich-list][.navigation-sidebar][.data-table]
let c0 = newColumnViewColumn()
c0.title = "#"
let f0 = newSignalListItemFactory()
f0.connect("setup", setup0)
f0.connect("bind", bind0)
c0.setFactory(f0)
cv.appendColumn(c0)
let c1 = newColumnViewColumn()
c1.title = "Layer "
let f1 = newSignalListItemFactory()
f1.connect("setup", setup1)
f1.connect("bind", bind1)
c1.setFactory(f1)
cv.appendColumn(c1)
let c2 = newColumnViewColumn()
c2.title = "Style "
###c2.setExpand
let f2 = newSignalListItemFactory()
f2.connect("setup", setup2)
f2.connect("bind", bind2)
c2.setFactory(f2)
cv.appendColumn(c2)
let c3 = newColumnViewColumn()
c3.title = "Group"
let f3 = newSignalListItemFactory()
f3.connect("setup", setup3)
f3.connect("bind", bind3)
c3.setFactory(f3)
cv.appendColumn(c3)
let c4 = newColumnViewColumn()
c4.title = "L."
let f4 = newSignalListItemFactory()
f4.connect("setup", setup4)
f4.connect("bind", bind4)
c4.setFactory(f4)
cv.appendColumn(c4)
let c5 = newColumnViewColumn()
c5.title = "V."
let f5 = newSignalListItemFactory()
f5.connect("setup", setup5)
f5.connect("bind", bind5)
c5.setFactory(f5)
cv.appendColumn(c5)
let c6 = newColumnViewColumn()
#c6.title = "V."
let f6 = newSignalListItemFactory()
f6.connect("setup", setup6)
f6.connect("bind", bind6)
c6.setFactory(f6)
cv.appendColumn(c6)
cv.connect("activate", onColumnViewActivate)
let gtype = gObjectGetType()
var listStore = gio.newListStore(gtype)
for i in 0 .. LayerNames.high:
let o = newObjectv(ColumnViewGObject, gtype, 0, nil)
#o.name = Names[i]#.sample
#o.age = rand(18 .. 95)
listStore.append(o)
let model = cast[SelectionModel](newSingleSelection(cast[ListModel](listStore)))
model.connect("selection-changed", onSelectionChanged)
cv.setModel(model)
result = newScrolledWindow()
#result.setMinContentWidth(2000)
#result.setSizeRequest(800, -1)
result.setPolicy(PolicyType.never, PolicyType.automatic)
result.setChild(cv)