One way is to, at the start of the layout, get the difference between NWjs's OUTER window measurements and C2's INNER window (canvas) measurements.
Save the resulting values in two global variabls.
Then when you set the window's OUTER size via the NWjs actions, give the INNER pixel size you want, plus the extra margin size you stored in the global variables earlier.
I've included a commented example capx showing the solution in action.
Download example capx
(In the capx, you can press "1" or "2" on the keyboard to set either the OUTER or INNER window size to 256 x 256.)