Skip to content

Commit

Permalink
Add setContentSize feature to Window (asticode#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie authored Dec 13, 2021
1 parent 9826cba commit 5317e82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion astilectron.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Versions
const (
DefaultAcceptTCPTimeout = 30 * time.Second
DefaultVersionAstilectron = "0.49.0"
DefaultVersionAstilectron = "0.51.0"
DefaultVersionElectron = "11.4.3"
)

Expand Down
15 changes: 15 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
EventNameWindowCmdMinimize = "window.cmd.minimize"
EventNameWindowCmdMove = "window.cmd.move"
EventNameWindowCmdResize = "window.cmd.resize"
EventNameWindowCmdResizeContent = "window.cmd.resize.content"
EventNameWindowCmdSetBounds = "window.cmd.set.bounds"
EventNameWindowCmdRestore = "window.cmd.restore"
EventNameWindowCmdSetContentProtection = "window.cmd.set.content.protection"
Expand All @@ -50,6 +51,7 @@ const (
EventNameWindowEventMove = "window.event.move"
EventNameWindowEventReadyToShow = "window.event.ready.to.show"
EventNameWindowEventResize = "window.event.resize"
EventNameWindowEventResizeContent = "window.event.resize.content"
EventNameWindowEventRestore = "window.event.restore"
EventNameWindowEventShow = "window.event.show"
EventNameWindowEventUnmaximize = "window.event.unmaximize"
Expand Down Expand Up @@ -470,6 +472,19 @@ func (w *Window) Resize(width, height int) (err error) {
return
}

// ResizeContent resizes the content viewport
func (w *Window) ResizeContent(width, height int) (err error) {
if err = w.ctx.Err(); err != nil {
return
}
w.m.Lock()
w.o.Height = astikit.IntPtr(height)
w.o.Width = astikit.IntPtr(width)
w.m.Unlock()
_, err = synchronousEvent(w.ctx, w, w.w, Event{Name: EventNameWindowCmdResizeContent, TargetID: w.id, WindowOptions: &WindowOptions{Height: astikit.IntPtr(height), Width: astikit.IntPtr(width)}}, EventNameWindowEventResizeContent)
return
}

// SetBounds set bounds of the window
func (w *Window) SetBounds(r RectangleOptions) (err error) {
if err = w.ctx.Err(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestWindow_Actions(t *testing.T) {
var d = newDisplay(&DisplayOptions{Bounds: &RectangleOptions{PositionOptions: PositionOptions{X: astikit.IntPtr(1), Y: astikit.IntPtr(2)}, SizeOptions: SizeOptions{Height: astikit.IntPtr(1), Width: astikit.IntPtr(2)}}}, true)
testObjectAction(t, func() error { return w.MoveInDisplay(d, 3, 4) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdMove+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"x\":4,\"y\":6}}\n", EventNameWindowEventMove)
testObjectAction(t, func() error { return w.Resize(1, 2) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdResize+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"height\":2,\"width\":1}}\n", EventNameWindowEventResize)
testObjectAction(t, func() error { return w.ResizeContent(1, 2) }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdResizeContent+"\",\"targetID\":\""+w.id+"\",\"windowOptions\":{\"height\":2,\"width\":1}}\n", EventNameWindowEventResizeContent)
testObjectAction(t, func() error { return w.Restore() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdRestore+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventRestore)
testObjectAction(t, func() error { return w.Show() }, w.object, wrt, "{\"name\":\""+EventNameWindowCmdShow+"\",\"targetID\":\""+w.id+"\"}\n", EventNameWindowEventShow)
assert.Equal(t, true, w.IsShown())
Expand Down

0 comments on commit 5317e82

Please sign in to comment.