Some days ago I noticed that my Nim cairo drawing demo mentioned here
does not work properly when in Gnome Shell I move the GTK window to the top of screen to switch to fullscreen mode. But when I enlarge the window by grepping right left corner of the window with the mouse all is fine. I have never noticed that before. I stripped down the code to the example below. It opens a window, and when I click into the window with LMB the window is resized. Then scrollbars stop working, I cant move them. But clicking in the window a second time, enlargeing it again to same size, then scrollbars starts to work again. I hope this is the same problem as in my original code – as least I do not really understand that behaviour.
It seems that the critical part is calling setUpper() in the dareaConfigureCallback(). May that be an invalid operation? Well, maybe the Scrollbars are in an invalid state at this time? I have no real idea. This is for
x11-libs/gtk±3.24.8:3::gentoo
Of course I can try to provide a C code version of this code, but I hope that ebassi or the other dev can point me to my error without.
One additional note. To my question about cairo drawingarea examples with zooming/scrolling I got a private reply pointing to GitHub - tschoonj/gtkmm-plplot: a scientific plotting library for Gtkmm leveraging the power of PLplot by its author – private as the discourse thread was already timed out.
import gintro/[gtk, gdk, glib, gobject, gio, cairo]
type
PosAdj = Adjustment
proc newPosAdj: PosAdj =
initAdjustment(result, 0, 0, 200, 10, 10, 100) # value, lower, upper, step_increment, page_increment, page_size
type
PDA = ref object of Grid
darea: DrawingArea
hadjustment: PosAdj
vadjustment: PosAdj
hscrollbar: Scrollbar
vscrollbar: Scrollbar
proc dareaConfigureCallback(darea: DrawingArea; event: EventConfigure; this: PDA): bool =
echo ">>>", this.darea.allocatedWidth
echo ">>>", this.darea.allocatedHeight
this.hadjustment.setUpper(this.darea.allocatedWidth.float)
this.vadjustment.setUpper(this.darea.allocatedHeight.float)
return true
proc buttonPressEvent(darea: DrawingArea; event: EventButton; this: PDA): bool =
let w = gtk.Window(getTopLevel(this))
w.resize(1000, 1200)
proc newPDA: PDA =
initGrid(result)
result.darea = newDrawingArea()
result.darea.setHExpand
result.darea.setVExpand
result.darea.connect("configure-event", dareaConfigureCallback, result)
result.darea.addEvents({EventFlag.buttonPress, EventFlag.buttonRelease,
EventFlag.scroll, button1Motion, button2Motion, pointerMotionHint})
result.darea.connect("button_press_event", buttonPressEvent, result)
result.hadjustment = newPosAdj()
result.vadjustment = newPosAdj()
result.hscrollbar = newScrollbar(Orientation.horizontal, result.hadjustment)
result.vscrollbar = newScrollbar(Orientation.vertical, result.vadjustment)
result.hscrollbar.setHExpand
result.vscrollbar.setVExpand
result.attach(result.darea, 0, 0, 1, 1)
result.attach(result.vscrollbar, 1, 0, 1, 1)
result.attach(result.hscrollbar, 0, 1, 1, 1)
proc appActivate(app: Application) =
let window = newApplicationWindow(app)
window.defaultSize = (800, 600)
let pda = newPDA()
window.add(pda)
showAll(window)
proc newDisplay() =
let app = newApplication("org.gtk.example")
connect(app, "activate", appActivate)
discard run(app)
when isMainModule:
newDisplay()