4 Star 20 Fork 4

七叶 / atk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
place.go 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
七叶 提交于 2018-06-13 22:47 . add placeframe
// Copyright 2018 visualfc. All rights reserved.
package tk
import (
"fmt"
"strings"
)
func PlaceAttrAnchor(anchor Anchor) *LayoutAttr {
v := anchor.String()
if v == "" {
return nil
}
return &LayoutAttr{"anchor", v}
}
func PlaceAttrBorderMode(mode BorderMode) *LayoutAttr {
v := mode.String()
if v == "" {
return nil
}
return &LayoutAttr{"bordermode", v}
}
func PlaceAttrWidth(size int) *LayoutAttr {
return &LayoutAttr{"width", size}
}
func PlaceAttrHeight(size int) *LayoutAttr {
return &LayoutAttr{"height", size}
}
func PlaceAttrRelWidth(size float64) *LayoutAttr {
return &LayoutAttr{"relwidth", size}
}
func PlaceAttrRelHeight(size float64) *LayoutAttr {
return &LayoutAttr{"relheight", size}
}
func PlaceAttrX(location int) *LayoutAttr {
return &LayoutAttr{"x", location}
}
func PlaceAttrY(location int) *LayoutAttr {
return &LayoutAttr{"y", location}
}
func PlaceAttrRelX(location float64) *LayoutAttr {
return &LayoutAttr{"relx", location}
}
func PlaceAttrRelY(location float64) *LayoutAttr {
return &LayoutAttr{"rely", location}
}
func PlaceAttrInMaster(w Widget) *LayoutAttr {
if !IsValidWidget(w) {
return nil
}
return &LayoutAttr{"in", w.Id()}
}
var (
placeAttrKeys = []string{
"anchor",
"bordermode",
"x", "y",
"relx", "rely",
"width", "height",
"relwidth", "relheight",
"in",
}
)
func Place(widget Widget, attributes ...*LayoutAttr) error {
if !IsValidWidget(widget) {
return ErrInvalid
}
var attrList []string
for _, attr := range attributes {
if attr == nil || !isValidKey(attr.key, placeAttrKeys) {
continue
}
attrList = append(attrList, fmt.Sprintf("-%v {%v}", attr.key, attr.value))
}
script := fmt.Sprintf("place %v", widget.Id())
if len(attrList) > 0 {
script += " " + strings.Join(attrList, " ")
}
return eval(script)
}
func PlaceRemove(widget Widget) error {
if !IsValidWidget(widget) {
return ErrInvalid
}
widget = checkLayoutWidget(widget)
return eval("place forget " + widget.Id())
}
Go
1
https://gitee.com/visualfc/atk.git
git@gitee.com:visualfc/atk.git
visualfc
atk
atk
572ab07f9a00

搜索帮助