Edzard Egberts wrote:
Am 22.01.2010 04:53, schrieb leowang:
So does it means the browser widget can't adjust the item height? :o(

My posting was not completely braindead - in fact changing the textsize
adjusts item height and works by pressing a button. [...]

In any case the size (height) of each item is calculated internally,
and you can't set a general item size, nor can you set an individual
item's height.

It can be done though with textsize(), as Edzard wrote, but currently
it's a mess. It doesn't work as expected. :-(

In FLTK 1 it works okay, /if/ you set the textsize() /before/ adding
items to the browser. Once you have added items to the browser,
changing the textsize doesn't calculate internal sizes, and therefore
the scrollbars are not synchronized, and you can see strange effects.

I made a private patch for FLTK 1.1 some time ago, but it was
[take one or more of:] {ineffective | a hack | special for my app.},
and so I never promoted it for an official release. Maybe this can
be done better. I'll think about it and see what I can do for
FLTK 1.3 - probably filing an STR would be the best for now.

I also just did a quick test with FLTK 2, and I saw even stranger
effects. It looks like the size is not calculated correctly for
single items, and the scrollbar problems look similar. I wouldn't
expect anybody to change this for FLTK 2 in the near future.

Test cases:

FLTK 1.3: use attached browser_textsize.diff to patch test/browser.cxx,
run it and use the "swap"(+) and "sort"(-) buttons to change the
textsize().

FLTK 2.0: use attached browser_textsize_2.diff to patch
test/browser.cxx, run it and use the up-arrow(+) and down-arow(-)
buttons on the right side to change the textsize().

Have fun ;-)

To the OP: sorry, there's not much hope for FLTK 2. But after
all it's open source, and if you want to use FLTK 2, you can
still try to fix it yourself.

Albrecht
Index: browser.cxx
===================================================================
--- browser.cxx (revision 7017)
+++ browser.cxx (working copy)
@@ -106,6 +106,11 @@
 }
 
 void swap_cb(Fl_Widget *, void *) {
+
+  browser->textsize(browser->textsize()+1);
+  browser->redraw();
+  printf ("swap: ++textsize() = %d\n",browser->textsize()); fflush(stdout);
+
   int a = -1, b = -1;
   for ( int t=0; t<browser->size(); t++ ) {    // find two selected items
     if ( browser->selected(t) ) {
@@ -119,7 +124,10 @@
 }
 
 void sort_cb(Fl_Widget *, void *) {
-  browser->sort(FL_SORT_ASCENDING);
+  // browser->sort(FL_SORT_ASCENDING);
+  browser->textsize(browser->textsize()-1);
+  browser->redraw();
+  printf ("sort: --textsize() = %d\n",browser->textsize()); fflush(stdout);
 }
 
 int main(int argc, char **argv) {
@@ -134,6 +142,9 @@
   browser->callback(b_cb);
   // browser->scrollbar_right();
   //browser->has_scrollbar(Fl_Browser::BOTH_ALWAYS);
+  
+  // browser->textsize(36);    // *** enable this for testing
+
   if (!browser->load(fname)) {
     int done = 0;
 #ifdef _MSC_VER
Index: browser.cxx
===================================================================
--- browser.cxx (revision 6921)
+++ browser.cxx (working copy)
@@ -71,6 +71,21 @@
       fltk::message("Column %d selected\n", b->selected_column()+1);
 }
 
+
+void cb_inc(Widget*, void* ptr) {
+  Browser* tree = (Browser*) ptr;
+  tree->textsize(tree->textsize()+1);
+  tree->redraw();
+  printf ("inc: ++textsize() = %d\n",(int)tree->textsize()); fflush(stdout);
+}
+
+void cb_dec(Widget*, void* ptr) {
+  Browser* tree = (Browser*) ptr;
+  tree->textsize(tree->textsize()-1);
+  tree->redraw();
+  printf ("dec: --textsize() = %d\n",(int)tree->textsize()); fflush(stdout);
+}
+
 void cb_remove(Widget*, void* ptr) {
   Browser* tree = (Browser*) ptr;
   if (tree->type() & Browser::IS_MULTI) {
@@ -228,6 +243,7 @@
   Browser tree(10, 10, 260, 180);
   tree.indented(1);
   tree.callback(cb_test);
+  // tree.textsize(30);                // *** add this for testing ***
 
   browser = &tree;
   tree.column_widths(widths);
@@ -239,6 +255,14 @@
   Button add_paper_button(5, 224, 80, 22, "Add Paper");
   add_paper_button.callback((Callback*)cb_add_paper, (void *)&tree);
 
+  
+  Button inc_button(255, 200, 22, 22, "@8>");
+  inc_button.callback((Callback*)cb_inc, (void *)&tree);
+
+  Button dec_button(255, 224, 22, 22, "@2>");
+  dec_button.callback((Callback*)cb_dec, (void *)&tree);
+
+
   Button add_folder_button(5, 248, 80, 22, "Add Folder");
   add_folder_button.callback((Callback*)cb_add_folder, (void *)&tree);
 
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to