ref: 48f456d1bab800c0707427c9c12bc0657236d330
parent: 21f3bf505510debd8a7921a26fdbd47ae79d28e1
author: Philip Silva <philip.silva@protonmail.com>
date: Thu Feb 11 18:13:38 EST 2021
input: more flexible handling of (max) width
--- a/browser/browser.go
+++ b/browser/browser.go
@@ -239,6 +239,10 @@
zs := duit.Space{}
w := n.Width()
h := n.Height()
+ mw, err := n.CssPx("max-width")
+ if err != nil {
+ log.Printf("max-width: %v", err)
+ }
if bg, err := n.BoxBackground(); err == nil {
i = bg
@@ -253,7 +257,7 @@
log.Errorf("margin: %v", err)
}
- if w == 0 && h == 0 && i == nil && m == zs && p == zs {
+ if w == 0 && h == 0 && mw == 0 && i == nil && m == zs && p == zs {
return nil, false
}
@@ -261,6 +265,7 @@
Kids: duit.NewKids(ui),
Width: w,
Height: h,
+ MaxWidth: mw,
Background: i,
Margin: m.Topleft(),
Padding: p,
@@ -360,34 +365,32 @@
func NewInputField(n *nodes.Node) *Element {
t := attr(*n.DomSubtree, "type")
- return NewElement(
- &duit.Box{
- Kids: duit.NewKids(&duit.Field{
- Font: n.Font(),
- Placeholder: attr(*n.DomSubtree, "placeholder"),
- Password: t == "password",
- Text: attr(*n.DomSubtree, "value"),
- Changed: func(t string) (e duit.Event) {
- setAttr(n.DomSubtree, "value", t)
- e.Consumed = true
- return
- },
- Keys: func(k rune, m draw.Mouse) (e duit.Event) {
- if k == 10 {
- browser.submit(n.Ancestor("form").DomSubtree, nil)
- return duit.Event{
- Consumed: true,
- NeedLayout: true,
- NeedDraw: true,
- }
- }
- return
- },
- }),
- MaxWidth: 200,
+ if n.Css("width") == "" && n.Css("max-width") == "" {
+ n.SetCss("max-width", "200px")
+ }
+ f := &duit.Field{
+ Font: n.Font(),
+ Placeholder: attr(*n.DomSubtree, "placeholder"),
+ Password: t == "password",
+ Text: attr(*n.DomSubtree, "value"),
+ Changed: func(t string) (e duit.Event) {
+ setAttr(n.DomSubtree, "value", t)
+ e.Consumed = true
+ return
},
- n,
- )
+ Keys: func(k rune, m draw.Mouse) (e duit.Event) {
+ if k == 10 {
+ browser.submit(n.Ancestor("form").DomSubtree, nil)
+ return duit.Event{
+ Consumed: true,
+ NeedLayout: true,
+ NeedDraw: true,
+ }
+ }
+ return
+ },
+ }
+ return NewElement(f, n)
}
func NewTextArea(n *nodes.Node) *Element {
--- a/domino/domino.go
+++ b/domino/domino.go
@@ -117,7 +117,7 @@
func srcLoader(fn string) ([]byte, error) {
path := filepath.FromSlash(fn)
- if !strings.Contains(path, "/domino-lib/") || !strings.HasSuffix(path, ".js") {
+ if !strings.Contains(path, "domino-lib/") || !strings.HasSuffix(path, ".js") {
return nil, require.ModuleFileDoesNotExistError
}
data, err := ioutil.ReadFile(path)