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

I can't trigger SetCellValue this func #357

Closed
dlgchg opened this issue Jun 6, 2019 · 4 comments
Closed

I can't trigger SetCellValue this func #357

dlgchg opened this issue Jun 6, 2019 · 4 comments

Comments

@dlgchg
Copy link

dlgchg commented Jun 6, 2019

package widget

import (
	"fmt"
	"github.com/andlabs/ui"
	"instabot_gui/gui/db"
	"log"
)

type userTableModelHandler struct {
	Users       []db.UserModel
	CheckStates [50]int
}

func NewUserTableModelHandler() *userTableModelHandler {
	Users := db.Users()
	handler := new(userTableModelHandler)
	handler.Users = Users
	return handler
}

func (u *userTableModelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
	return []ui.TableValue{
		ui.TableInt(1),
		ui.TableString(""),
		ui.TableString(""),
		ui.TableString(""),
	}
}

func (u *userTableModelHandler) NumRows(t *ui.TableModel) int {
	return len(u.Users)
}

func (u *userTableModelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
	if len(u.Users) > 0 {
		userModel := u.Users[row]
		if column == 0 {
			return ui.TableInt(u.CheckStates[row])
		}
		if column == 1 {
			return ui.TableString(userModel.UserName)
		}
		if column == 2 {
			return ui.TableString(userModel.PassWord)
		}
		if column == 3 {
			return ui.TableString(fmt.Sprint(userModel.Status))
		}
	}
	return ui.TableString("")
}

func (u *userTableModelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
        // don't set
	u.CheckStates[row] = int(value.(ui.TableInt))
	log.Println(u.CheckStates)
	m.RowChanged(row)
}


main.go
newUserTableModelHandler := widget.NewUserTableModelHandler()
		newTableModel := ui.NewTableModel(newUserTableModelHandler)
		table := ui.NewTable(&ui.TableParams{
			Model: newTableModel,
			RowBackgroundColorModelColumn:	3,
		})
		table.AppendCheckboxColumn("",
			0, ui.TableModelColumnAlwaysEditable)
		table.AppendTextColumn("name",
			1, ui.TableModelColumnNeverEditable, nil)
		table.AppendTextColumn("password",
			2, ui.TableModelColumnNeverEditable, nil)
		table.AppendTextColumn("type",
			3, ui.TableModelColumnNeverEditable, nil)
@malacalypse
Copy link

Also having this issue: SetCellValue is not called on state change of a checkbox in a table on OSX. This is a serious issue for me.

@silver886
Copy link

Same issue here. Need to use button as a workaround on macOS.

@AndyObtiva
Copy link

+1 for fixing this on the Mac!

I just had to add it to the list of API Gotchas in my new Ruby LibUI DSL project: Glimmer DSL for LibUI

@AndyObtiva
Copy link

Why did you close? Did it get fixed? (I didn't see any code changes)

I just reported on the main libui project.

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

4 participants