mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Fixes #39. Unfocused tab problem solved
This commit is contained in:
		
							parent
							
								
									b5e88d5c16
								
							
						
					
					
						commit
						00504c43ff
					
				@ -20,7 +20,7 @@ type Widget struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func NewWidget(builtAt, version string) *Widget {
 | 
					func NewWidget(builtAt, version string) *Widget {
 | 
				
			||||||
	widget := Widget{
 | 
						widget := Widget{
 | 
				
			||||||
		TextWidget: wtf.NewTextWidget(" System ", "system", false),
 | 
							TextWidget: wtf.NewTextWidget(" Build ", "system", false),
 | 
				
			||||||
		BuiltAt:    builtAt,
 | 
							BuiltAt:    builtAt,
 | 
				
			||||||
		Version:    version,
 | 
							Version:    version,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								wtf.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								wtf.go
									
									
									
									
									
								
							@ -201,7 +201,7 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	FocusTracker = wtf.FocusTracker{
 | 
						FocusTracker = wtf.FocusTracker{
 | 
				
			||||||
		App:     app,
 | 
							App:     app,
 | 
				
			||||||
		Idx:     0,
 | 
							Idx:     -1,
 | 
				
			||||||
		Widgets: Widgets,
 | 
							Widgets: Widgets,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -17,9 +17,11 @@ type FocusTracker struct {
 | 
				
			|||||||
// Next sets the focus on the next widget in the widget list. If the current widget is
 | 
					// Next sets the focus on the next widget in the widget list. If the current widget is
 | 
				
			||||||
// the last widget, sets focus on the first widget.
 | 
					// the last widget, sets focus on the first widget.
 | 
				
			||||||
func (tracker *FocusTracker) Next() {
 | 
					func (tracker *FocusTracker) Next() {
 | 
				
			||||||
	tracker.blur(tracker.Idx)
 | 
						if tracker.widgetHasFocus() {
 | 
				
			||||||
	tracker.increment()
 | 
							tracker.blur(tracker.Idx)
 | 
				
			||||||
	tracker.focus(tracker.Idx)
 | 
							tracker.increment()
 | 
				
			||||||
 | 
							tracker.focus(tracker.Idx)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// None removes focus from the currently-focused widget.
 | 
					// None removes focus from the currently-focused widget.
 | 
				
			||||||
@ -30,9 +32,11 @@ func (tracker *FocusTracker) None() {
 | 
				
			|||||||
// Prev sets the focus on the previous widget in the widget list. If the current widget is
 | 
					// Prev sets the focus on the previous widget in the widget list. If the current widget is
 | 
				
			||||||
// the last widget, sets focus on the last widget.
 | 
					// the last widget, sets focus on the last widget.
 | 
				
			||||||
func (tracker *FocusTracker) Prev() {
 | 
					func (tracker *FocusTracker) Prev() {
 | 
				
			||||||
	tracker.blur(tracker.Idx)
 | 
						if tracker.widgetHasFocus() {
 | 
				
			||||||
	tracker.decrement()
 | 
							tracker.blur(tracker.Idx)
 | 
				
			||||||
	tracker.focus(tracker.Idx)
 | 
							tracker.decrement()
 | 
				
			||||||
 | 
							tracker.focus(tracker.Idx)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (tracker *FocusTracker) Refocus() {
 | 
					func (tracker *FocusTracker) Refocus() {
 | 
				
			||||||
@ -104,6 +108,10 @@ func (tracker *FocusTracker) increment() {
 | 
				
			|||||||
// widgetHasFocus returns true if one of the widgets currently has the app's focus,
 | 
					// widgetHasFocus returns true if one of the widgets currently has the app's focus,
 | 
				
			||||||
// false if none of them do (ie: perhaps a modal dialog currently has it instead)
 | 
					// false if none of them do (ie: perhaps a modal dialog currently has it instead)
 | 
				
			||||||
func (tracker *FocusTracker) widgetHasFocus() bool {
 | 
					func (tracker *FocusTracker) widgetHasFocus() bool {
 | 
				
			||||||
 | 
						if tracker.Idx < 0 {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, widget := range tracker.Widgets {
 | 
						for _, widget := range tracker.Widgets {
 | 
				
			||||||
		if widget.TextView() == tracker.App.GetFocus() {
 | 
							if widget.TextView() == tracker.App.GetFocus() {
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user