shithub: mycel

Download patch

ref: eeb069251719e5c5e23c018f59ca8b158b3afb13
parent: 5c9c01c88b125f9235fd0c3722aa2c1ff5f7472f
author: Philip Silva <philip.silva@protonmail.com>
date: Sun Dec 12 10:12:06 EST 2021

More responsive input fields when using absolute positioning

- also remove double formatting from logging :-)
- nil check in rectangle

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -1724,7 +1724,7 @@
 }
 
 func (b *Browser) get(uri *url.URL, isNewOrigin bool) (buf []byte, contentType opossum.ContentType, err error) {
-	log.Infof(fmt.Sprintf("Get %v", uri.String()))
+	log.Infof("Get %v", uri.String())
 	req, err := http.NewRequest("GET", uri.String(), nil)
 	if err != nil {
 		return
--- a/browser/duitx/label.go
+++ b/browser/duitx/label.go
@@ -171,6 +171,9 @@
 }
 
 func (ui *Label) Rect() draw.Rectangle {
+	if ui == nil {
+		return draw.Rectangle{}
+	}
 	return draw.Rectangle{
 		ui.orig,
 		ui.orig.Add(ui.size),
--- a/browser/duitx/place.go
+++ b/browser/duitx/place.go
@@ -37,7 +37,7 @@
 
 	kidsReversed []*duit.Kid
 	size         image.Point
-	img          *draw.Image
+	imgs         []*draw.Image
 	force        bool
 }
 
@@ -65,28 +65,72 @@
 		return
 	}
 	self.Draw = duit.Clean
-	if ui.img == nil || ui.Kids[0].R.Size() != ui.img.R.Size() {
+	if ui.imgs == nil || ui.Kids[0].R.Size() != ui.imgs[0].R.Size() {
 		var err error
-		if ui.img != nil {
-			ui.img.Free()
-			ui.img = nil
+		if ui.imgs != nil {
+			for _, i := range ui.imgs {
+				i.Free()
+			}
+			ui.imgs = nil
 		}
 		if ui.Kids[0].R.Dx() == 0 || ui.Kids[0].R.Dy() == 0 {
 			return
 		}
-		ui.img, err = dui.Display.AllocImage(ui.Kids[0].R, draw.ARGB32, false, 0x00000000)
-		if err != nil {
-			log.Errorf("allocimage: %v", err)
-			return
+		ui.imgs = make([]*draw.Image, len(ui.Kids))
+		for i, k := range ui.Kids {
+			ui.imgs[i], err = dui.Display.AllocImage(k.R, draw.ARGB32, false, 0x00000000)
+			if err != nil {
+				log.Errorf("allocimage: %v", err)
+				return
+			}
+			k.Draw = duit.Dirty
 		}
 		self.Draw = duit.DirtyKid
 	}
 	if self.Draw == duit.DirtyKid || ui.force {
-		duit.KidsDraw(dui, self, ui.Kids, ui.size, ui.Background, ui.img, image.ZP, m, true)
+		kidsDraw(dui, self, ui.Kids, ui.size, ui.Background, ui.imgs, image.ZP, m, false)
 		self.Draw = duit.Clean
 		ui.force = false
 	}
-	img.Draw(ui.img.R.Add(orig), ui.img, nil, image.ZP)
+	for _, i := range ui.imgs {
+		if i != nil {
+			img.Draw(i.R.Add(orig), i, nil, image.ZP)
+		}
+	}
+}
+
+func kidsDraw(dui *duit.DUI, self *duit.Kid, kids []*duit.Kid, uiSize image.Point, bg *draw.Image, imgs []*draw.Image, orig image.Point, m draw.Mouse, force bool) {
+	debugDraw(dui, self)
+
+	force = force || self.Draw == duit.Dirty
+	if force {
+		self.Draw = duit.Dirty
+	}
+
+	if bg == nil {
+		bg = dui.Background
+	}
+	if force {
+		// TODO: consider resetting other backgrounds also
+		imgs[0].Draw(rect(uiSize).Add(orig), bg, nil, image.ZP)
+	}
+	for i, k := range kids {
+		if !force && k.Draw == duit.Clean {
+			continue
+		}
+		if !force && k.Draw == duit.Dirty {
+			imgs[i].Draw(k.R.Add(orig), bg, nil, image.ZP)
+		}
+
+		mm := m
+		mm.Point = mm.Point.Sub(k.R.Min)
+		if force {
+			k.Draw = duit.Dirty
+		}
+		k.UI.Draw(dui, k, imgs[i], orig.Add(k.R.Min), mm, force)
+		k.Draw = duit.Clean
+	}
+	self.Draw = duit.Clean
 }
 
 func (ui *Place) result(dui *duit.DUI, self *duit.Kid, r *duit.Result) {