Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check with display PoC #5165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions widget/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
// Check widget has a text label and a checked (or unchecked) icon and triggers an event func when toggled
type Check struct {
DisableableWidget
Text string
Text string
// If populated, Display is used when rendering the check. If empty, Text is used.
Display string
Checked bool

OnChanged func(bool) `json:"-"`
Expand Down Expand Up @@ -162,7 +164,11 @@ func (c *Check) CreateRenderer() fyne.WidgetRenderer {

c.propertyLock.RLock()
defer c.propertyLock.RUnlock()
text := canvas.NewText(c.Text, th.Color(theme.ColorNameForeground, v))
display := c.Text
if c.Display != "" {
display = c.Display
}
text := canvas.NewText(display, th.Color(theme.ColorNameForeground, v))
text.Alignment = fyne.TextAlignLeading

focusIndicator := canvas.NewCircle(th.Color(theme.ColorNameBackground, v))
Expand Down Expand Up @@ -284,6 +290,9 @@ func (c *checkRenderer) MinSize() fyne.Size {

c.check.propertyLock.RLock()
text := c.check.Text
if c.check.Display != "" {
text = c.check.Display
}
c.check.propertyLock.RUnlock()
if text != "" {
min.Add(fyne.NewSize(th.Size(theme.SizeNamePadding), 0))
Expand Down Expand Up @@ -340,6 +349,10 @@ func (c *checkRenderer) Refresh() {

// must be called while holding c.check.propertyLock for reading
func (c *checkRenderer) updateLabel() {
if c.check.Display != "" {
c.label.Text = c.check.Display
return
}
c.label.Text = c.check.Text
}

Expand Down
6 changes: 6 additions & 0 deletions widget/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestCheck_Layout(t *testing.T) {

for name, tt := range map[string]struct {
text string
display string
checked bool
disabled bool
}{
Expand All @@ -61,10 +62,15 @@ func TestCheck_Layout(t *testing.T) {
text: "Test",
disabled: true,
},
"with_display": {
text: "Test",
display: "Display",
},
} {
t.Run(name, func(t *testing.T) {
check := &widget.Check{
Text: tt.text,
Display: tt.display,
Checked: tt.checked,
}
if tt.disabled {
Expand Down
12 changes: 12 additions & 0 deletions widget/testdata/check/layout_with_display.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<canvas padded size="150x200">
<content>
<container pos="4,4" size="142x192">
<widget pos="29,78" size="83x35" type="*widget.Check">
<circle pos="2,3" size="28x28"/>
<image pos="6,7" rsc="checkButtonFillIcon" size="iconInlineSize" themed="inputBackground"/>
<image pos="6,7" rsc="checkButtonIcon" size="iconInlineSize" themed="inputBorder"/>
<text pos="32,0" size="51x35">Display</text>
</widget>
</container>
</content>
</canvas>