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

x/mobile: Window always 800x800px #15737

Closed
ghost opened this issue May 18, 2016 · 3 comments
Closed

x/mobile: Window always 800x800px #15737

ghost opened this issue May 18, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented May 18, 2016

I can't seem to resize the viewport with gomobile. It's cumbersome to manually drag the corner of the viewport to match the screen size of an iPhone, so I'm hoping to do it programmatically, but the events seem to be getting overruled.

package main

import (
    _ "image/jpeg"

    "github.com/kr/pretty"

    "golang.org/x/mobile/app"
    "golang.org/x/mobile/event/size"
    "golang.org/x/mobile/geom"
)

func main() {
    pxPerPt := float32(163.0 / 72.0)
    defaultSizeEvent := size.Event{WidthPx: 400, HeightPx: 800, WidthPt: geom.Pt(float32(400) / pxPerPt), HeightPt: geom.Pt(float32(800) / pxPerPt), PixelsPerPt: pxPerPt, Orientation: size.OrientationPortrait}

    app.Main(func(a app.App) {
        a.Send(defaultSizeEvent)
        for e := range a.Events() {
            pretty.Println(e)
        }
    })
}

I ran gomobile build and executed the binary and expected to see a viewport 400px wide by 800px tall. Instead, I always get the default 800x800px viewport. I do not have a device plugged in. Debugging the Events() channel, it looks like 3 Size Events are automatically run after my Size event is processed:

size.Event{WidthPx:400, HeightPx:800, WidthPt:176.68711853027344, HeightPt:353.3742370605469, PixelsPerPt:2.2638888359069824, Orientation:1}
size.Event{WidthPx:800, HeightPx:800, WidthPt:260.63348388671875, HeightPt:260.63348388671875, PixelsPerPt:3.069444417953491, Orientation:0}
size.Event{WidthPx:800, HeightPx:800, WidthPt:260.63348388671875, HeightPt:260.63348388671875, PixelsPerPt:3.069444417953491, Orientation:0}
size.Event{WidthPx:800, HeightPx:800, WidthPt:260.63348388671875, HeightPt:260.63348388671875, PixelsPerPt:3.069444417953491, Orientation:0}
lifecycle.Event{
    From:        0x0,
    To:          0x1,
    DrawContext: &gl.context{
        cptr:          0x0,
        debug:         0,
        workAvailable: 0xc820062240,
        work:          0xc8200622a0,
        retvalue:      0xc820062300,
        cargs:         {
            {},
            {},
            {},
        },
        parg: {
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
        },
    },
}
lifecycle.Event{
    From:        0x1,
    To:          0x2,
    DrawContext: &gl.context{
        cptr:          0x0,
        debug:         0,
        workAvailable: 0xc820062240,
        work:          0xc8200622a0,
        retvalue:      0xc820062300,
        cargs:         {
            {},
            {},
            {},
        },
        parg: {
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
        },
    },
}
lifecycle.Event{
    From:        0x2,
    To:          0x3,
    DrawContext: &gl.context{
        cptr:          0x0,
        debug:         0,
        workAvailable: 0xc820062240,
        work:          0xc8200622a0,
        retvalue:      0xc820062300,
        cargs:         {
            {},
            {},
            {},
        },
        parg: {
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
        },
    },
}
lifecycle.Event{
    From:        0x3,
    To:          0x2,
    DrawContext: &gl.context{
        cptr:          0x0,
        debug:         0,
        workAvailable: 0xc820062240,
        work:          0xc8200622a0,
        retvalue:      0xc820062300,
        cargs:         {
            {},
            {},
            {},
        },
        parg: {
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
            (*gl._Ctype_char)(nil),
        },
    },
}

I also tried setting the viewport using the Viewport() function from https://godoc.org/golang.org/x/mobile/gl#Context, but that did not work either. It appears that an 800x800px viewport is somehow registered into the startup process and there doesn't appear to be an easy way to change that, or am I missing something?

go version go1.6.2 darwin/amd64

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ever/dev/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
@dskinner
Copy link
Member

dskinner commented Jun 1, 2016

By viewport, I assume you're referring to the actual window size. Sending a size.Event will not affect the window size, nor does glViewport. Currently, the window size hints are hardcoded.

@ghost ghost changed the title x/mobile: Viewport always 800x800px x/mobile: Window always 800x800px Jun 2, 2016
@ghost
Copy link
Author

ghost commented Jun 2, 2016

Is there a reason it's hard coded, or is this a good candidate for a patch? I'm interested in developing with GoMobile, but without having a way to adjust the window size to fit common device sizes makes testing difficult.

@ianlancetaylor
Copy link
Contributor

Note that we generally do not use the issue tracker for discussions. See https://golang.org/wiki/Questions .

@ghost ghost closed this as completed Jun 6, 2016
@golang golang locked and limited conversation to collaborators Jun 6, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants