Skip to content

Commit

Permalink
tabview and textview render when empty, textview highlights -- for al…
Browse files Browse the repository at this point in the history
…l search results
  • Loading branch information
rcoreilly committed Sep 16, 2018
1 parent 51f5889 commit 7eb9647
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 110 deletions.
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -97,8 +97,6 @@ Currently at a **pre-beta** level (**DON'T RECOMMEND USING RIGHT NOW** -- come b
* drag on textview should prevent DND -- dnd not getting "processed"

* TextView:
+ array of select regions -- for search fill 'em all up! draw in a loop with bounds-checking
+ draw bg at least even when empty -- blank proj should look like something is there
+ losing line numbers when typing new text, in some select cases
+ word-level functions: forward, back, delete etc. ctrl+ backspace is back.
+ optimize wraparound multi-span rendering -- if no change in start of line, don't re render!
Expand Down
18 changes: 18 additions & 0 deletions giv/tabview.go
Expand Up @@ -38,6 +38,15 @@ var TabViewProps = ki.Props{
"height": units.NewValue(10, units.Em),
}

// NTabs returns number of tabs
func (tv *TabView) NTabs() int {
fr := tv.Frame()
if fr == nil {
return 0
}
return len(fr.Kids)
}

// AddTab adds a widget as a new tab, with given tab label, and returns the
// index of that tab
func (tv *TabView) AddTab(widg gi.Node2D, label string) int {
Expand Down Expand Up @@ -221,6 +230,9 @@ func (tv *TabView) InitTabView() {
if len(tv.Kids) == 2 {
return
}
if tv.Sty.Font.Size.Val == 0 { // not yet styled
tv.StyleLayout()
}
updt := tv.UpdateStart()
tv.Lay = gi.LayoutVert

Expand All @@ -229,6 +241,7 @@ func (tv *TabView) InitTabView() {
tabs.SetStretchMaxWidth()
// tabs.SetStretchMaxHeight()
tabs.SetMinPrefWidth(units.NewValue(10, units.Em))
tabs.SetProp("height", units.NewValue(1.8, units.Em))
tabs.SetProp("overflow", "hidden") // no scrollbars!
tabs.SetProp("padding", units.NewValue(0, units.Px))
tabs.SetProp("margin", units.NewValue(0, units.Px))
Expand Down Expand Up @@ -277,6 +290,11 @@ func (tv *TabView) RenumberTabs() {
}
}

func (tv *TabView) Style2D() {
tv.InitTabView()
tv.Layout.Style2D()
}

////////////////////////////////////////////////////////////////////////////////////////
// TabButton

Expand Down
26 changes: 19 additions & 7 deletions giv/textbuf.go
Expand Up @@ -94,25 +94,27 @@ func (tb *TextBuf) Text() []byte {
return tb.Txt
}

// Refresh signals any views to refresh views
func (tb *TextBuf) Refresh() {
tb.TextBufSig.Emit(tb.This, int64(TextBufNew), tb.Txt)
}

// todo: use https://github.com/andybalholm/crlf to deal with cr/lf etc --
// internally just use lf = \n

// New initializes a new buffer with n blank lines
func (tb *TextBuf) New(nlines int) {
if cap(tb.Lines) >= nlines {
tb.Lines = tb.Lines[:nlines]
} else {
tb.Lines = make([][]rune, nlines)
if nlines == 1 {
tb.Lines[0] = []rune("")
}
tb.Lines = make([][]rune, nlines)
if nlines == 1 {
tb.Lines[0] = []rune("")
}
if cap(tb.ByteOffs) >= nlines {
tb.ByteOffs = tb.ByteOffs[:nlines]
} else {
tb.ByteOffs = make([]int, nlines)
}
tb.NLines = nlines
tb.Refresh()
}

// Open loads text from a file into the buffer
Expand Down Expand Up @@ -367,6 +369,16 @@ type TextRegion struct {
End TextPos
}

// NewTextRegionLen makes a new TextRegion from a starting point and a length
// along same line
func NewTextRegionLen(start TextPos, len int) TextRegion {
reg := TextRegion{}
reg.Start = start
reg.End = start
reg.End.Ch += len
return reg
}

var TextRegionZero = TextRegion{}

// TextBufEdit describes an edit action to a buffer -- this is the data passed
Expand Down

0 comments on commit 7eb9647

Please sign in to comment.