ref: d3e6d77f14753eaf7f39cbf6a812a9edf15b4f69
parent: 9b3da20bf6742f96cea453e54bc88a8d2ac0541c
author: Philip Silva <philip.silva@protonmail.com>
date: Tue Jul 5 06:51:24 EDT 2022
improve sizings and QueryRef - dynamical window size - fix query ref - make small buttons more clickable
--- a/browser/browser.go
+++ b/browser/browser.go
@@ -202,7 +202,7 @@
return nil, fmt.Errorf("serialize: %w", err)
}
log.Printf("newImage: xml: %v", xml)
- i, err = img.Svg(dui, xml, n.Width(), n.Height())
+ i, err = img.Svg(dui, xml, dui.Scale(n.Width()), dui.Scale(n.Height()))
if err != nil {
return nil, fmt.Errorf("img svg %v: %v", xml, err)
}
@@ -220,8 +220,9 @@
if i, cached = imageCache[src]; !cached {
mw, _ := n.CssPx("max-width")
- w := n.Width()
- h := n.Height()
+ mw = dui.Scale(mw)
+ w := dui.Scale(n.Width())
+ h := dui.Scale(n.Height())
i, err = img.Load(dui, browser, src, mw, w, h, false)
if err != nil {
return nil, fmt.Errorf("load image: %w", err)
@@ -434,7 +435,10 @@
// Make boxes use full size for image backgrounds
box, ok := el.UI.(*duitx.Box)
if ok && box.Width > 0 && box.Height > 0 {
- uiSize := image.Point{X: box.Width, Y: box.Height}
+ uiSize := image.Point{
+ X: dui.Scale(box.Width),
+ Y: dui.Scale(box.Height),
+ }
duit.KidsDraw(dui, self, box.Kids, uiSize, box.Background, img, orig, m, force)
} else {
el.UI.Draw(dui, self, img, orig, m, force)
@@ -465,7 +469,7 @@
//duit.KidsLayout(dui, self, box.Kids, true)
el.UI.Layout(dui, self, sizeAvail, force)
- self.R = image.Rect(0, 0, box.Width, box.Height)
+ self.R = image.Rect(0, 0, dui.Scale(box.Width), dui.Scale(box.Height))
} else {
el.UI.Layout(dui, self, sizeAvail, force)
}
@@ -672,7 +676,7 @@
y := m.Point.Y
maxX := self.R.Dx()
maxY := self.R.Dy()
- border := 5 > x || x > (maxX-5) || 5 > y || y > (maxY-5)
+ border := 1 > x || x > (maxX-1) || 1 > y || y > (maxY-1)
if l, ok := el.UI.(*Label); ok && l != nil {
fromLabel = l.Label
@@ -903,17 +907,21 @@
} else {
kid.UI.Layout(dui, kid, sizeAvail, true)
if t, err := el.n.CssPx("top"); err == nil {
+ t = dui.Scale(t)
kid.R.Min.Y += t
kid.R.Max.Y += t
} else if b, err := el.n.CssPx("bottom"); err == nil {
+ b = dui.Scale(b)
h := kid.R.Max.X
kid.R.Min.Y = sizeAvail.Y - b
kid.R.Max.Y = sizeAvail.Y - h
}
if l, err := el.n.CssPx("left"); err == nil {
+ l = dui.Scale(l)
kid.R.Max.X += l
kid.R.Min.X += l
} else if r, err := el.n.CssPx("right"); err == nil {
+ r = dui.Scale(r)
w := kid.R.Max.X
kid.R.Max.X = sizeAvail.X - r
kid.R.Min.X = sizeAvail.X - w
--- a/cmd/opossum/main.go
+++ b/cmd/opossum/main.go
@@ -193,6 +193,7 @@
return fmt.Errorf("new dui: %w", err)
}
dui.Debug = dbg
+ resize()
style.Init(dui)
v = NewNav()
@@ -219,6 +220,9 @@
case e := <-dui.Inputs:
//log.Infof("e=%v", e)
dui.Input(e)
+ if e.Type == duit.InputResize {
+ resize()
+ }
case loc = <-b.LocCh:
log.Infof("loc=%v", loc)
@@ -335,4 +339,10 @@
func finalize() {
js.Stop()
os.Exit(1)
+}
+
+func resize() {
+ size := dui.Display.ScreenImage.R.Size()
+ style.WindowWidth = size.X/dui.Scale(1)
+ style.WindowHeight = size.Y/dui.Scale(1)
}
--- a/nodes/nodes.go
+++ b/nodes/nodes.go
@@ -288,7 +288,7 @@
if c == n {
break
}
- if c.Type() == html.ElementNode && c.Data() == n.Data() {
+ if c.Type() == html.ElementNode {
i++
}
}
--- a/nodes/nodes_test.go
+++ b/nodes/nodes_test.go
@@ -35,7 +35,38 @@
nt := NewNodeTree(doc, style.Map{}, make(map[*html.Node]style.Map), nil)
p := nt.Children[0].Children[1].Children[0]
a := p.Children[2]
- if q := a.QueryRef(); q != "p:nth-child(1) > a:nth-child(1)" {
+ if q := a.QueryRef(); q != "p:nth-child(1) > a:nth-child(3)" {
+ t.Fatalf("%v", q)
+ }
+}
+
+func TestQueryRef2(t *testing.T) {
+ buf := strings.NewReader(`
+ <html>
+ <body>
+ <header>
+ <div class="header-left">
+ </div>
+ <div class="header-right">
+ </div>
+ <div class="hamburger-menu active">
+ <ul>
+ </ul>
+ <a href="#" class="close">Close</a>
+ </div>
+ </header>
+ </body>
+ </html>`)
+ doc, err := html.Parse(buf)
+ if err != nil {
+ t.Fatalf(err.Error())
+ }
+ nt := NewNodeTree(doc, style.Map{}, make(map[*html.Node]style.Map), nil)
+ t.Logf("%v", nt.Children[0].Children[1].Children[0].Data())
+ div3 := nt.Children[0].Children[1].Children[0].Children[2]
+ t.Logf("%v", div3.Data())
+ a := div3.Children[1]
+ if q := a.QueryRef(); q != "header:nth-child(1) > div:nth-child(3) > a:nth-child(2)" {
t.Fatalf("%v", q)
}
}