Skip to content

Commit bee30c5

Browse files
derek-v-selcritch
andauthored
added saveWindowState / moved writeWindowConfig to onCloseRequest (#127)
* added saveWindowState / moved writeWindowConfig to onCloseRequest issue #114 * Update src/figuro/renderer/opengl.nim * Update src/figuro/renderer/opengl.nim --------- Co-authored-by: Jaremy Creechley <creechley@gmail.com>
1 parent af22b1f commit bee30c5

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/figuro/common/nodes/uinodes.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type
4848
windowStyle*: FrameStyle
4949
theme*: Theme
5050
configFile*: string
51+
saveWindowState*: bool
5152

5253
Figuro* = ref object of Agent
5354
frame*: WeakRef[AppFrame]

src/figuro/renderer/opengl.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ proc configureWindowEvents(renderer: Renderer) =
8383

8484
window.onCloseRequest = proc() =
8585
notice "onCloseRequest"
86+
if renderer.frame[].saveWindowState:
87+
writeWindowConfig(window, winCfgFile)
8688
app.running = false
8789

8890
window.onMove = proc() =
89-
writeWindowConfig(window, winCfgFile)
91+
discard
9092
# debug "window moved: ", pos= window.pos
9193

9294
window.onResize = proc() =

src/figuro/ui/core.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ template connectDefaults*[T](node: T) =
204204
when compiles(SignalTypes.tick(T)):
205205
connect(node, doTick, node, T.tick(), acceptVoidSlot = true)
206206
207-
proc newAppFrame*[T](root: T, size: (UiScalar, UiScalar), style = DecoratedResizable): AppFrame =
207+
proc newAppFrame*[T](root: T, size: (UiScalar, UiScalar), style = DecoratedResizable, saveWindowState = true): AppFrame =
208208
mixin draw
209209
if root == nil:
210210
raise newException(NilAccessDefect, "must set root")
@@ -218,6 +218,7 @@ proc newAppFrame*[T](root: T, size: (UiScalar, UiScalar), style = DecoratedResiz
218218
frame.window.box.w = size[0].UiScalar
219219
frame.window.box.h = size[1].UiScalar
220220
frame.windowStyle = style
221+
frame.saveWindowState = saveWindowState
221222
refresh(root)
222223
return frame
223224

tests/tinput.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ proc draw*(self: Main) {.slot.} =
3535
this.setText "hello world"
3636

3737
var main = Main.new()
38-
var frame = newAppFrame(main, size=(720'ui, 140'ui))
38+
var frame = newAppFrame(main, size=(720'ui, 140'ui), saveWindowState = false)
3939
startFiguro(frame)

0 commit comments

Comments
 (0)