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

Accessing OnSelected method of Checkbox in a table #31

Closed
copiesofcopies opened this issue Sep 24, 2014 · 11 comments
Closed

Accessing OnSelected method of Checkbox in a table #31

copiesofcopies opened this issue Sep 24, 2014 · 11 comments

Comments

@copiesofcopies
Copy link

I am building a table out of this struct:

type DisplayAccount struct {
    Enabled bool
    Name    string
}

Here is the code:

// Assemble table of accounts
accounts := make([]DisplayAccount, len(config.Accounts))

// Pull accounts from config file
for i, account := range config.Accounts {
    enabled := account.Enabled
    acctName := strings.Join([]string{account.Name, account.Server}, "@")
    accounts[i] = DisplayAccount{enabled, acctName}
}   

// Populate table
accountTable := ui.NewTable(reflect.TypeOf(accounts[0]))
accountTable.Lock()
e := accountTable.Data().(*[]DisplayAccount)
*e = accounts
accountTable.Unlock()

How do I access the OnSelected method of each "Enabled" field in accountTable?

@andlabs
Copy link
Owner

andlabs commented Sep 24, 2014

That would be an OnChecked(), but I haven't implemented that yet. I could...

(Are you on Windows, by the way?)

@copiesofcopies
Copy link
Author

I'm on Debian/GNOME. I didn't realize it wasn't implemented yet. My problem was that when I tried to access the Checkbox object, I only succeeded in accessing the Enabled bool from the DisplayAccounts struct. Is there a way to access the Checkbox (even though I can't get the method I'm looking for).

@andlabs
Copy link
Owner

andlabs commented Sep 25, 2014

Could you be a little more clear? When the user checks the checkbox, the structure itself is changed for you...

@copiesofcopies
Copy link
Author

I understand that ui.NewTable() creates a Checkbox from the Enabled bool in the DisplayAccount struct. What I don't understand is how, in the code, I access the "checked" or "unchecked" value of that Checkbox. I can use the Table's Selected() and OnSelected() methods to see when I particular row is selected, but I do not know how to determine if a Checkbox embedded in a row is checked.

@andlabs
Copy link
Owner

andlabs commented Sep 25, 2014

Oh! You acquire the RLock and examine the boolean field of the structure. The Table code changes that field's value for you.

@copiesofcopies
Copy link
Author

Ok, that makes sense. But if I want to call some function when that value changes, I probably need to start a goroutine to watch the bool for changes, right?

@andlabs
Copy link
Owner

andlabs commented Sep 25, 2014

No; I'll need to add an OnChecked() to Table. Will add soon (tomorrow?)

@copiesofcopies
Copy link
Author

Thanks for the explanation! Looking forward to having access to OnChecked(), but I'm not in a huge hurry -- I have plenty of other work to do before I need it too badly :)

@andlabs
Copy link
Owner

andlabs commented Oct 18, 2014

Just a quick update: once I finish the newctrl/ stuff I'm going to start doing a rewrite of Table on Windows to use an entirely custom control; once that's feature-complete I can add these features.

@andlabs
Copy link
Owner

andlabs commented Feb 21, 2015

I guess not

First the event system would need to be overhauled to allow passing the checked row and column in. But the current implementation of package ui is already being stretched too thin to be stable. I plan on redoing the backend a third (and hopefully) final time, so I'm not interested in doing any major changes to the backend just yet.

I could add these as methods to Table, but I'd rather not have too many API breaking changes at once. One other thing I want to do is switch to a more generic model interface-based system (with the current struct-based system as an implementation provided by package ui instead). I would need to figure out how this would work with that.

I still need to add this, but we'll see when...

@andlabs
Copy link
Owner

andlabs commented Mar 23, 2018

Replaced with andlabs/libui#310.

@andlabs andlabs closed this as completed Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants