登录
首页 >  Golang >  Go问答

获取屏幕坐标的方法

来源:stackoverflow

时间:2024-03-14 16:27:25 148浏览 收藏

欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《获取屏幕坐标的方法》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!

问题内容

我在文档中使用 golang.org/x/exp/shiny/screen 包,它说创建屏幕的基本用法是:

func main() {
    driver.main(func(s screen.screen) {
        w, err := s.newwindow(nil)
        if err != nil {
            handleerror(err)
            return
        }
        defer w.release()

        for {
            switch e := w.nextevent().(type) {
            case lifecycle.event:
                if e.to == lifecycle.stagedead {
                    return
                }
                etc
            case etc:
                etc
            }
        }
    })
}

如何获取屏幕的位置?

在定义中,它表示该结构由以下部分组成

type NewWindowOptions struct {
    // Width and Height specify the dimensions of the new window. If Width
    // or Height are zero, a driver-dependent default will be used for each
    // zero value dimension.
    Width, Height int

    // Title specifies the window title.
    Title string
}

所以我正在考虑得到这个 widthheight


解决方案


根据您想要实现的目标,我假设您可以重用示例 https://github.com/golang/exp/blob/master/shiny/example/basic/main.go 中的某些部分

以下是您可能感兴趣的摘录:

var sz size.Event
for {
    e := w.NextEvent()

    switch e := e.(type) {
        //...
        // Basically wait for the resize event...
        case size.Event:
            // Save the latest size so later you could read it as sz.Bounds()
            sz = e 
        // ...
}
...

sz.bounds() 返回:https://godoc.org/image#Rectangle,希望它的 minmax 点是绝对位置。

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>