draw cursor in editabletextarea
This commit is contained in:
		
							
								
								
									
										15
									
								
								ui/ui.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ui/ui.go
									
									
									
									
									
								
							@@ -523,12 +523,14 @@ type EditableTextLine struct {
 | 
				
			|||||||
	style      tcell.Style
 | 
						style      tcell.Style
 | 
				
			||||||
	visible    bool
 | 
						visible    bool
 | 
				
			||||||
	cursorPos  int
 | 
						cursorPos  int
 | 
				
			||||||
 | 
						showCursor bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewEditableTextLine(initialText string) *EditableTextLine {
 | 
					func NewEditableTextLine(initialText string) *EditableTextLine {
 | 
				
			||||||
	return &EditableTextLine{
 | 
						return &EditableTextLine{
 | 
				
			||||||
		text:       initialText,
 | 
							text:       initialText,
 | 
				
			||||||
		visible:    true,
 | 
							visible:    true,
 | 
				
			||||||
 | 
							showCursor: true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -547,6 +549,15 @@ func (p *EditableTextLine) Draw(s tcell.Screen) {
 | 
				
			|||||||
	for j, r := range p.text {
 | 
						for j, r := range p.text {
 | 
				
			||||||
		s.SetContent(p.x+j, p.y, r, nil, p.style)
 | 
							s.SetContent(p.x+j, p.y, r, nil, p.style)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						s.ShowCursor(p.x+p.cursorPos, p.y)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *EditableTextLine) SetVisible(b bool) {
 | 
				
			||||||
 | 
						p.visible = b
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *EditableTextLine) SetCursorVisible(b bool) {
 | 
				
			||||||
 | 
						p.showCursor = b
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *EditableTextLine) SetText(t string) {
 | 
					func (p *EditableTextLine) SetText(t string) {
 | 
				
			||||||
@@ -558,6 +569,10 @@ func (p *EditableTextLine) SetText(t string) {
 | 
				
			|||||||
	p.ResetCursor(false)
 | 
						p.ResetCursor(false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *EditableTextLine) Text() string {
 | 
				
			||||||
 | 
						return p.text
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *EditableTextLine) ResetCursor(beginning bool) {
 | 
					func (p *EditableTextLine) ResetCursor(beginning bool) {
 | 
				
			||||||
	if beginning {
 | 
						if beginning {
 | 
				
			||||||
		p.cursorPos = 0
 | 
							p.cursorPos = 0
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user