~eliasnaur/gio-patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] widget: add some utility methods on Editor

Details
Message ID
<20200205145223.66869-1-larry@theclapp.org>
DKIM signature
missing
Download raw message
Patch: +15 -0
- Focused: returns whether editor is focused
- CaretPos: returns the text line & column number, and the x & y pixel
  coordinates of the caret.

  Note: Returns them in that order. Which seems odd: line & column is
  basically "y, x", but then the pixel coordinates are x & y.  So
  wondering if swapping line & column in CaretPos (and possibly in
  Editor.layoutCaret which it calls) would be appropriate?
- NumLines: returns the number of text lines in the editor

Signed-off-by: Larry Clapp <larry@theclapp.org>
---
 widget/editor.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/widget/editor.go b/widget/editor.go
index 0e41c89..0af965b 100644
--- a/widget/editor.go
+++ b/widget/editor.go
@@ -224,6 +224,11 @@ func (e *Editor) Focus() {
	e.requestFocus = true
}

// Focused returns whether the editor is focused or not.
func (e *Editor) Focused() bool {
	return e.focused
}

// Layout lays out the editor.
func (e *Editor) Layout(gtx *layout.Context, sh text.Shaper, font text.Font, size unit.Value) {
	// Flush events from before the previous frame.
@@ -456,6 +461,10 @@ func (e *Editor) layoutText(s text.Shaper) ([]text.Line, layout.Dimensions) {
	return lines, dims
}

func (e *Editor) CaretPos() (carLine, carCol int, x fixed.Int26_6, y int) {
	return e.layoutCaret()
}

func (e *Editor) layoutCaret() (carLine, carCol int, x fixed.Int26_6, y int) {
	var idx int
	var prevDesc fixed.Int26_6
@@ -647,5 +656,11 @@ func (e *Editor) scrollToCaret() {
	}
}

// NumLines returns the number of lines in the editor.
func (e *Editor) NumLines() int {
	e.makeValid()
	return len(e.lines)
}

func (s ChangeEvent) isEditorEvent() {}
func (s SubmitEvent) isEditorEvent() {}
-- 
2.23.0
Details
Message ID
<C0EWBBWT3Q14.S4IMFZ8HJTGL@testmac>
In-Reply-To
<20200205145223.66869-1-larry@theclapp.org> (view parent)
DKIM signature
missing
Download raw message
On Wed Feb 5, 2020 at 9:52 AM, Larry Clapp wrote:
> - Focused: returns whether editor is focused
> - CaretPos: returns the text line & column number, and the x & y pixel
> coordinates of the caret.
>
> 
> Note: Returns them in that order. Which seems odd: line & column is
> basically "y, x", but then the pixel coordinates are x & y. So
> wondering if swapping line & column in CaretPos (and possibly in
> Editor.layoutCaret which it calls) would be appropriate?

Other than having many return values, how often is both the text
position (line, column) and absolute position (x, y) needed?
It seems to me CaretPos should be split into CaretPos (line, column) and
CaretCoords (x, y). Better names welcome.

> - NumLines: returns the number of text lines in the editor
>
Details
Message ID
<CAE_4BPA8WYmwsi-fjdoVb_fuLwcHHiKefokyqzsjAT6a86D9ZQ@mail.gmail.com>
In-Reply-To
<C0EWBBWT3Q14.S4IMFZ8HJTGL@testmac> (view parent)
DKIM signature
missing
Download raw message
Done.  See v2.


On Thu, Feb 6, 2020 at 2:17 AM Elias Naur <mail@eliasnaur.com> wrote:
>
> On Wed Feb 5, 2020 at 9:52 AM, Larry Clapp wrote:
> > - Focused: returns whether editor is focused
> > - CaretPos: returns the text line & column number, and the x & y pixel
> > coordinates of the caret.
> >
> >
> > Note: Returns them in that order. Which seems odd: line & column is
> > basically "y, x", but then the pixel coordinates are x & y. So
> > wondering if swapping line & column in CaretPos (and possibly in
> > Editor.layoutCaret which it calls) would be appropriate?
>
> Other than having many return values, how often is both the text
> position (line, column) and absolute position (x, y) needed?
> It seems to me CaretPos should be split into CaretPos (line, column) and
> CaretCoords (x, y). Better names welcome.
>
> > - NumLines: returns the number of text lines in the editor
> >