--- libbirdfont/Table.vala
+++ libbirdfont/Table.vala
@@ -20,8 +20,9 @@
/** Table functions. */
public abstract class Table : FontDisplay {
- int scroll = 0;
- int visible_rows = 0;
+ double scroll = 0;
+ double page_height = 0;
+
WidgetAllocation allocation = new WidgetAllocation ();
Gee.ArrayList<int> column_width = new Gee.ArrayList<int> ();
@@ -30,12 +31,8 @@
public abstract void selected_row (Row row, int column, bool delete_button);
public override void draw (WidgetAllocation allocation, Context cr) {
- double y = 0;
- int s = 0;
bool color = (scroll + 1 % 2) == 0;
-
- layout ();
-
+
if (allocation.width != this.allocation.width
|| allocation.height != this.allocation.height) {
this.allocation = allocation;
@@ -43,7 +40,7 @@
update_scrollbar ();
}
- visible_rows = (int) (allocation.height / 18.0);
+ layout ();
cr.save ();
Theme.color (cr, "Background 1");
@@ -52,9 +49,15 @@
cr.restore ();
foreach (Row r in get_rows ()) {
- if (s++ >= scroll) {
- draw_row (allocation, cr, r, y, color, true);
- y += 25 * MainWindow.units;
+ if (scroll < r.y < scroll + allocation.height
+ || scroll < r.y + r.get_height () < scroll + allocation.height) {
+
+ if (r.is_headline) {
+ draw_headline (allocation, cr, r, r.y - scroll);
+ } else {
+ draw_row (allocation, cr, r, r.y - scroll, color, true);
+ }
+
color = !color;
}
}
@@ -69,6 +72,7 @@
column_width.add (0);
}
+ page_height = 0;
foreach (Row row in get_rows ()) {
return_if_fail (row.columns <= column_width.size);
@@ -84,7 +88,25 @@
column_width.set (i, width);
}
}
+
+ row.y = page_height;
+ page_height += row.get_height ();
}
+ }
+
+ private void draw_headline (WidgetAllocation allocation, Context cr,
+ Row row, double y) {
+
+ Text t;
+
+ cr.save ();
+ Theme.color (cr, "Foreground 1");
+ t = row.get_column (0);
+ t.widget_x = 40 * MainWindow.units;;
+ t.widget_y = y + 45 * MainWindow.units;
+ t.draw (cr);
+ cr.restore ();
+
}
private void draw_row (WidgetAllocation allocation, Context cr,
@@ -131,8 +153,6 @@
}
public override void button_release (int button, double ex, double ey) {
- int s = 0;
- double y = 0;
double x = 0;
int column = -1;
Row? selected = null;
@@ -141,34 +161,32 @@
if (button != 1) {
return;
}
-
+
foreach (Row r in get_rows ()) {
- if (s++ >= scroll) {
- if (y <= ey <= y + 25 * MainWindow.units) {
+ if (r.y <= ey + scroll <= r.y + r.get_height ()) {
+
+ x = 0;
+ for (int i = 0; i < r.columns; i++) {
+ return_if_fail (0 <= i < column_width.size);
- x = 0;
- for (int i = 0; i < r.columns; i++) {
- return_if_fail (0 <= i < column_width.size);
-
- if (x <= ex < x + column_width.get (i)) {
- column = i;
- }
-
- x += column_width.get (i);
+ if (x <= ex < x + column_width.get (i)) {
+ column = i;
}
- over_delete = (ex < 18 && r.has_delete_button ());
-
- if (over_delete) {
- column = -1;
- }
-
- selected = r;
-
- break;
+ x += column_width.get (i);
+ }
+
+ over_delete = (ex < 18 && r.has_delete_button ());
+
+ if (over_delete) {
+ column = -1;
}
- y += 25 * MainWindow.units;
+ if (!r.is_headline) {
+ selected = r;
+ }
+
+ break;
}
}
@@ -185,14 +203,13 @@
}
public override void scroll_wheel_down (double x, double y) {
- int nrows = get_rows ().size;
- scroll += 3;
+ scroll += 30;
- if (scroll > nrows - visible_rows) {
- scroll = (int) (nrows - visible_rows);
+ if (scroll > page_height - allocation.height) {
+ scroll = page_height - allocation.height;
}
- if (visible_rows > nrows) {
+ if (allocation.height > page_height) {
scroll = 0;
}
@@ -201,7 +218,7 @@
}
public override void scroll_wheel_up (double x, double y) {
- scroll -= 3;
+ scroll -= 30;
if (scroll < 0) {
scroll = 0;
@@ -212,23 +229,20 @@
}
public override void update_scrollbar () {
- uint rows = get_rows ().size;
-
- if (rows == 0 || visible_rows == 0) {
+ if (page_height == 0 || allocation.height >= page_height) {
MainWindow.set_scrollbar_size (0);
MainWindow.set_scrollbar_position (0);
} else {
- MainWindow.set_scrollbar_size ((double) visible_rows / rows);
- MainWindow.set_scrollbar_position ((double) scroll / rows);
+ MainWindow.set_scrollbar_size (allocation.height / page_height);
+ MainWindow.set_scrollbar_position (scroll / (page_height - allocation.height));
}
}
public override void scroll_to (double percent) {
- uint rows = get_rows ().size;
- scroll = (int) (percent * rows);
+ scroll = percent * page_height;
- if (scroll > rows - visible_rows) {
- scroll = (int) (rows - visible_rows);
+ if (scroll > page_height) {
+ scroll = (int) (page_height - allocation.height);
}
redraw_area (0, 0, allocation.width, allocation.height);