Skip to content

Commit

Permalink
Simplify atomics with CAS operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 6, 2024
1 parent cb0202e commit 9830d0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
12 changes: 4 additions & 8 deletions internal/widget/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ func (w *Base) Visible() bool {

// Show this widget so it becomes visible
func (w *Base) Show() {
if w.Visible() {
return
if !w.hidden.CompareAndSwap(true, false) {
return // Visible already
}

w.hidden.Store(false)

impl := w.super()
if impl == nil {
return
Expand All @@ -96,12 +94,10 @@ func (w *Base) Show() {

// Hide this widget so it is no longer visible
func (w *Base) Hide() {
if !w.Visible() {
return
if !w.hidden.CompareAndSwap(false, true) {
return // Hidden already
}

w.hidden.Store(true)

impl := w.super()
if impl == nil {
return
Expand Down
14 changes: 5 additions & 9 deletions widget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (w *BaseWidget) MinSize() fyne.Size {

r := cache.Renderer(impl)
if r == nil {
return fyne.NewSize(0, 0)
return fyne.Size{}
}

return r.MinSize()
Expand Down Expand Up @@ -160,12 +160,10 @@ type DisableableWidget struct {

// Enable this widget, updating any style or features appropriately.
func (w *DisableableWidget) Enable() {
if !w.Disabled() {
return
if !w.disabled.CompareAndSwap(true, false) {
return // Enabled already
}

w.disabled.Store(false)

impl := w.super()
if impl == nil {
return
Expand All @@ -175,12 +173,10 @@ func (w *DisableableWidget) Enable() {

// Disable this widget so that it cannot be interacted with, updating any style appropriately.
func (w *DisableableWidget) Disable() {
if w.Disabled() {
return
if !w.disabled.CompareAndSwap(false, true) {
return // Disabled already
}

w.disabled.Store(true)

impl := w.super()
if impl == nil {
return
Expand Down

0 comments on commit 9830d0e

Please sign in to comment.