-
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 toggle pane shows a value that can be set to either on or off. A title is visible above this setting.
- Loading branch information
1 parent
74a1c75
commit 14e8d20
Showing
7 changed files
with
109 additions
and
0 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
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,2 @@ | ||
Title | ||
▣ Enable |
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,59 @@ | ||
package setting | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Toggle struct { | ||
Title string | ||
Enable bool | ||
|
||
focus bool | ||
} | ||
|
||
func (t *Toggle) Render(styles Styles) string { | ||
var str []string | ||
|
||
switch t.focus { | ||
case true: | ||
str = append(str, styles.settingTitleSelected.Render(t.Title)) | ||
default: | ||
str = append(str, styles.settingTitle.Render(t.Title)) | ||
} | ||
|
||
switch t.Enable { | ||
case true: | ||
v := styles.settingSelected.Render("Enable") | ||
str = append(str, fmt.Sprintf("%v %v", styles.settingSquareFilled, v)) | ||
default: | ||
v := styles.setting.Render("Enable") | ||
str = append(str, fmt.Sprintf("%v %v", styles.settingSquareEmpty, v)) | ||
} | ||
|
||
return strings.Join(str, "\n") | ||
} | ||
|
||
func (t *Toggle) Focus() { | ||
t.focus = true | ||
} | ||
|
||
func (t *Toggle) Blur() { | ||
t.focus = false | ||
} | ||
|
||
func (t *Toggle) Value() bool { | ||
return t.Enable | ||
} | ||
|
||
func (t *Toggle) Toggle() { | ||
t.Enable = !t.Enable | ||
} | ||
|
||
func (t *Toggle) Type() Type { | ||
return TypeToggle | ||
} | ||
|
||
func ToToggle(p Paner) *Toggle { | ||
return p.(*Toggle) | ||
} |