leonsal пре 8 година
родитељ
комит
b53afc3611
1 измењених фајлова са 22 додато и 21 уклоњено
  1. 22 21
      gui/table.go

+ 22 - 21
gui/table.go

@@ -23,7 +23,7 @@ const (
 type Table struct {
 type Table struct {
 	Panel                                // Embedded panel
 	Panel                                // Embedded panel
 	styles       *TableStyles            // pointer to current styles
 	styles       *TableStyles            // pointer to current styles
-	cols         []TableColumn           // array of columns descriptors
+	cols         []*TableColumn          // array of columns descriptors
 	colmap       map[string]*TableColumn // maps column id to column descriptor
 	colmap       map[string]*TableColumn // maps column id to column descriptor
 	firstRow     int                     // index of the first visible row
 	firstRow     int                     // index of the first visible row
 	lastRow      int                     // index of the last visible row
 	lastRow      int                     // index of the last visible row
@@ -113,26 +113,30 @@ func NewTable(width, height float32, cols []TableColumn) (*Table, error) {
 
 
 	// Checks columns descriptors
 	// Checks columns descriptors
 	t.colmap = make(map[string]*TableColumn)
 	t.colmap = make(map[string]*TableColumn)
-	t.cols = make([]TableColumn, len(cols))
-	copy(t.cols, cols)
-	for i := 0; i < len(t.cols); i++ {
-		c := &t.cols[i]
-		if c.Format == "" {
-			c.Format = "%v"
-		}
-		c.order = i
+	t.cols = make([]*TableColumn, 0)
+	for i := 0; i < len(cols); i++ {
+		// Make a copy of the column descriptor argument and saves its pointer
+		c := cols[i]
+		t.cols = append(t.cols, &c)
+		// Column id must not be empty
 		if c.Id == "" {
 		if c.Id == "" {
 			return nil, fmt.Errorf("Column with empty id")
 			return nil, fmt.Errorf("Column with empty id")
 		}
 		}
+		// Column id must be unique
 		if t.colmap[c.Id] != nil {
 		if t.colmap[c.Id] != nil {
 			return nil, fmt.Errorf("Column with duplicate id")
 			return nil, fmt.Errorf("Column with duplicate id")
 		}
 		}
-		t.colmap[c.Id] = c
+		// Sets default format and order
+		if c.Format == "" {
+			c.Format = "%v"
+		}
+		c.order = i
+		t.colmap[c.Id] = &c
 	}
 	}
 
 
 	// Create header panels
 	// Create header panels
 	for i := 0; i < len(t.cols); i++ {
 	for i := 0; i < len(t.cols); i++ {
-		c := &t.cols[i]
+		c := t.cols[i]
 		c.header = NewPanel(0, 0)
 		c.header = NewPanel(0, 0)
 		t.applyHeaderStyle(c.header)
 		t.applyHeaderStyle(c.header)
 		c.label = NewLabel(c.Name)
 		c.label = NewLabel(c.Name)
@@ -166,7 +170,7 @@ func (t *Table) ShowHeader(show bool) {
 	}
 	}
 	t.showHeader = show
 	t.showHeader = show
 	for i := 0; i < len(t.cols); i++ {
 	for i := 0; i < len(t.cols); i++ {
-		c := &t.cols[i]
+		c := t.cols[i]
 		c.header.SetVisible(t.showHeader)
 		c.header.SetVisible(t.showHeader)
 	}
 	}
 	t.recalc()
 	t.recalc()
@@ -204,11 +208,9 @@ func (t *Table) ShowAllColumns() {
 			recalc = true
 			recalc = true
 		}
 		}
 	}
 	}
-	log.Error("ShowAllColumns:%v", recalc)
 	if !recalc {
 	if !recalc {
 		return
 		return
 	}
 	}
-	log.Error("ShowAllColumns:%v DO", recalc)
 	t.recalcHeader()
 	t.recalcHeader()
 	// Recalculates all rows
 	// Recalculates all rows
 	for ri := 0; ri < len(t.rows); ri++ {
 	for ri := 0; ri < len(t.rows); ri++ {
@@ -296,6 +298,12 @@ func (t *Table) SetColFormat(id, format string) error {
 	return nil
 	return nil
 }
 }
 
 
+// AddRow adds a new row at the end of the table with the specified values
+func (t *Table) AddRow(values map[string]interface{}) {
+
+	t.InsertRow(len(t.rows), values)
+}
+
 // InsertRow inserts the specified values in a new row at the specified index
 // InsertRow inserts the specified values in a new row at the specified index
 func (t *Table) InsertRow(row int, values map[string]interface{}) {
 func (t *Table) InsertRow(row int, values map[string]interface{}) {
 
 
@@ -435,12 +443,6 @@ func (t *Table) removeRow(row int) {
 	//}
 	//}
 }
 }
 
 
-// AddRow adds a new row at the end of the table with the specified values
-func (t *Table) AddRow(values map[string]interface{}) {
-
-	t.InsertRow(len(t.rows), values)
-}
-
 // onMouseEvent process subscribed mouse events
 // onMouseEvent process subscribed mouse events
 func (t *Table) onMouse(evname string, ev interface{}) {
 func (t *Table) onMouse(evname string, ev interface{}) {
 
 
@@ -717,7 +719,6 @@ func (t *Table) recalcRow(trow *tableRow) {
 		cell := trow.cells[c.order]
 		cell := trow.cells[c.order]
 		if c.Hidden {
 		if c.Hidden {
 			cell.SetVisible(false)
 			cell.SetVisible(false)
-			log.Error("HIDDEN COLUMNS")
 			continue
 			continue
 		}
 		}
 		// Sets cell position and size
 		// Sets cell position and size