-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A radio pane shows a list of values with only a single value selected. A title headlines the list of values.
- Loading branch information
1 parent
ef361a3
commit 74a1c75
Showing
16 changed files
with
421 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package setting | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Radio struct { | ||
Title string | ||
Values []string | ||
Index int | ||
|
||
focus bool | ||
} | ||
|
||
func (r *Radio) Render(styles Styles) string { | ||
var str []string | ||
|
||
switch r.focus { | ||
case true: | ||
str = append(str, styles.settingTitleSelected.Render(r.Title)) | ||
default: | ||
str = append(str, styles.settingTitle.Render(r.Title)) | ||
} | ||
|
||
for idx, val := range r.Values { | ||
if idx == r.Index { | ||
v := styles.settingSelected.Render(val) | ||
str = append(str, fmt.Sprintf("%v %v", styles.settingDotFilled, v)) | ||
|
||
continue | ||
} | ||
|
||
v := styles.setting.Render(val) | ||
str = append(str, fmt.Sprintf("%v %v", styles.settingDotEmpty, v)) | ||
} | ||
|
||
return strings.Join(str, "\n") | ||
} | ||
|
||
func (r *Radio) Focus() { | ||
r.focus = true | ||
} | ||
|
||
func (r *Radio) Blur() { | ||
r.focus = false | ||
} | ||
|
||
func (r *Radio) Value() string { | ||
return r.Values[r.Index] | ||
} | ||
|
||
func (r *Radio) Next() { | ||
if r.Index >= len(r.Values)-1 { | ||
r.Index = 0 | ||
return | ||
} | ||
|
||
r.Index++ | ||
} | ||
|
||
func (r *Radio) Previous() { | ||
if r.Index <= 0 { | ||
r.Index = len(r.Values) - 1 | ||
return | ||
} | ||
|
||
r.Index-- | ||
} | ||
|
||
func (r *Radio) Select(i int) { | ||
r.Index = i | ||
} | ||
|
||
func (r *Radio) Type() Type { | ||
return TypeRadio | ||
} | ||
|
||
func ToRadio(p Paner) *Radio { | ||
r, _ := p.(*Radio) | ||
|
||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.