Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SetSize #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,7 @@ func CreateWindow(_, _ int, title string, monitor *Monitor, share *Window) (*Win
width := dom.GetWindow().InnerWidth()
height := dom.GetWindow().InnerHeight()

devicePixelRatio := js.Global.Get("devicePixelRatio").Float()
w.canvas.Width = int(float64(width)*devicePixelRatio + 0.5) // Nearest non-negative int.
w.canvas.Height = int(float64(height)*devicePixelRatio + 0.5) // Nearest non-negative int.
w.canvas.Style().SetProperty("width", fmt.Sprintf("%vpx", width), "")
w.canvas.Style().SetProperty("height", fmt.Sprintf("%vpx", height), "")

if w.framebufferSizeCallback != nil {
// TODO: Callbacks may be blocking so they need to happen asyncronously. However,
// GLFW API promises the callbacks will occur from one thread (i.e., sequentially), so may want to do that.
go w.framebufferSizeCallback(w, w.canvas.Width, w.canvas.Height)
}
if w.sizeCallback != nil {
go w.sizeCallback(w, int(w.canvas.GetBoundingClientRect().Width), int(w.canvas.GetBoundingClientRect().Height))
}
w.SetSize(width, height)
})

document.AddEventListener("keydown", false, func(event dom.Event) {
Expand Down Expand Up @@ -326,7 +313,20 @@ func (w *Window) SetPos(xpos, ypos int) {
}

func (w *Window) SetSize(width, height int) {
fmt.Println("not implemented: SetSize:", width, height)
devicePixelRatio := js.Global.Get("devicePixelRatio").Float()
w.canvas.Width = int(float64(width)*devicePixelRatio + 0.5) // Nearest non-negative int.
w.canvas.Height = int(float64(height)*devicePixelRatio + 0.5) // Nearest non-negative int.
w.canvas.Style().SetProperty("width", fmt.Sprintf("%vpx", width), "")
w.canvas.Style().SetProperty("height", fmt.Sprintf("%vpx", height), "")

if w.framebufferSizeCallback != nil {
// TODO: Callbacks may be blocking so they need to happen asyncronously. However,
// GLFW API promises the callbacks will occur from one thread (i.e., sequentially), so may want to do that.
go w.framebufferSizeCallback(w, w.canvas.Width, w.canvas.Height)
}
if w.sizeCallback != nil {
go w.sizeCallback(w, int(w.canvas.GetBoundingClientRect().Width), int(w.canvas.GetBoundingClientRect().Height))
}
}

// goFullscreenIfRequested performs webkitRequestFullscreen if it was scheduled. It is called only from
Expand Down