Added GAction example
This commit is contained in:
parent
00a254887d
commit
92f788236e
5 changed files with 110 additions and 5 deletions
|
|
@ -136,13 +136,22 @@ proc paint(this: PDA) =
|
|||
destroy(cr) # we can also manually destroy the context here, but GC would do it for us
|
||||
|
||||
proc dareaConfigureCallback(darea: DrawingArea; event: EventConfigure; this: PDA): bool =
|
||||
this.updateAdjustments(0, 0)
|
||||
#this.updateAdjustments(0, 0)
|
||||
(this.dataX, this.dataY, this.dataWidth,
|
||||
this.dataHeight) = this.extents() # query user defined size
|
||||
this.fullScale = min(this.darea.allocatedWidth.float / this.dataWidth,
|
||||
this.darea.allocatedHeight.float / this.dataHeight)
|
||||
this.paint
|
||||
|
||||
proc hscrollbarSizeAllocateCallback(s: Scrollbar; r: gdk.Rectangle; pda: PDA) =
|
||||
pda.hadjustment.setUpper(r.width.float * pda.userZoom)
|
||||
pda.hadjustment.setPageSize(r.width.float)
|
||||
|
||||
proc vscrollbarSizeAllocateCallback(s: Scrollbar; r: gdk.Rectangle; pda: PDA) =
|
||||
pda.vadjustment.setUpper(r.height.float * pda.userZoom)
|
||||
pda.vadjustment.setPageSize(r.height.float)
|
||||
|
||||
|
||||
proc updateAdjustmentsAndPaint(this: PDA; dx, dy: float) =
|
||||
this.updateAdjustments(dx, dy)
|
||||
this.paint
|
||||
|
|
@ -246,6 +255,8 @@ proc newPDA: PDA =
|
|||
result.vscrollbar = newScrollbar(Orientation.vertical, result.vadjustment)
|
||||
result.hscrollbar.setHExpand
|
||||
result.vscrollbar.setVExpand
|
||||
result.hscrollbar.connect("size-allocate", hscrollbarSizeAllocateCallback, result)
|
||||
result.vscrollbar.connect("size-allocate", vscrollbarSizeAllocateCallback, result)
|
||||
result.attach(result.darea, 0, 0, 1, 1)
|
||||
result.attach(result.vscrollbar, 1, 0, 1, 1)
|
||||
result.attach(result.hscrollbar, 0, 1, 1, 1)
|
||||
|
|
|
|||
27
examples/gaction.nim
Normal file
27
examples/gaction.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# https://wiki.gnome.org/HowDoI/GAction
|
||||
# nim c gaction.nim
|
||||
import gintro/[gtk, glib, gobject, gio]
|
||||
|
||||
proc saveCb(action: SimpleAction; v: Variant) =
|
||||
echo "saveCb"
|
||||
|
||||
proc appActivate(app: Application) =
|
||||
let window = newApplicationWindow(app)
|
||||
let action = newSimpleAction("save")
|
||||
discard action.connect("activate", saveCB)
|
||||
window.actionMap.addAction(action)
|
||||
let button = newButton()
|
||||
button.label = "Save"
|
||||
window.add(button)
|
||||
button.setActionName("win.save")
|
||||
var h: cstringArray = allocCstringArray(["<Control><Shift>S"])
|
||||
setAccelsForAction(app, "win.save", h)
|
||||
deallocCStringArray(h)
|
||||
showAll(window)
|
||||
|
||||
proc main =
|
||||
let app = newApplication("org.gtk.example")
|
||||
connect(app, "activate", appActivate)
|
||||
discard run(app)
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue