On 03.01.2013 05:47, Denton Thomas wrote:

> For both of you (Ian, Albrecht), here is my solution. It includes a test 
> sequence that produces some random buttons, and lets the client dynamically 
> change the size of the scrollbar. I wanted to allow a dynamic box style 
> change for the scroll group, but it didn't work for some reason ... it just 
> wouldn't redraw in the new style (???). I'm on 1.3.0 - I think I should just 
> update to the newest release.
>
> Thanks in advance for any advice - this will certainly be helpful in my 
> current project.

I tried your test case, and it seemed to work mostly.

Concerning the scrollbar size changes, here's a diff that makes
it work. I put the scroll_ widget in the user_data argument to
access it in the callback and set the scrollbar size. Note that
you changed the global scrollbar size variable, whereas my patch
changes only that of this particular scroll widget.

diff --git a/Track_Focus_Scroll-Main.cpp b/Track_Focus_Scroll-Main.cpp
index cb89b47..0360aef 100644
--- a/Track_Focus_Scroll-Main.cpp
+++ b/Track_Focus_Scroll-Main.cpp
@@ -186,8 +186,9 @@ void set_scrollbar_size_cb_(Fl_Widget *src, void *dat) {

    int x = atoi(((Fl_Int_Input *)src)->value());

-  Fl::scrollbar_size(x);
-  printf("Set scrollbar size to %d\n", x);
+  Fl_Scroll *scroll = (Fl_Scroll *)dat;
+  scroll->scrollbar_size(x); scroll->redraw();
+  printf("Set scrollbar size to %d\n", x); fflush(stdout);
  }

  void setup() {
@@ -238,7 +239,7 @@ void setup() {
    s = new Fl_Int_Input(scroll_->x() + scroll_->w() + 10, scroll_->y(), 
50, 35, "scrollbar size");
      s->labelsize(9);
      s->align(FL_ALIGN_TOP);
-    s->callback(set_scrollbar_size_cb_, NULL);
+    s->callback(set_scrollbar_size_cb_, scroll_);

    win_->resizable(scroll_);
    win_->end();

I don't really understand what you mean with "I wanted to allow a 
dynamic box style change for the scroll group, but it didn't work for 
some reason ... it just wouldn't redraw in the new style (???)".

I assume that the problem was triggering the redraw(), and the solution
is in my patch. Or was this something else?

I also experimented a little more to remove some artifacts when
the focus leaves the scroll widget and/or comes back to it. My
time doesn't allow more comments now, I'm just posting another
diff that should be applied after the first one. Just try to
understand what it does, and experiment with the diff's in it.
It's not perfect, and maybe some of the changes would turn out
to be useless... just take it as a base for more own experiments.

diff --git a/Track_Focus_Scroll-Main.cpp b/Track_Focus_Scroll-Main.cpp
index 0360aef..f042f66 100644
--- a/Track_Focus_Scroll-Main.cpp
+++ b/Track_Focus_Scroll-Main.cpp
@@ -45,12 +45,14 @@ class Track_Focus_Scroll : public Fl_Scroll {
    /** if Fl_Scroll:handle() manages event && Fl::focus() changes, call
      adjust_scroll_() to manage scroll bars */
    int handle(int event) {
+    if(!contains(Fl::focus())) focus_tracker_ = 0;
+    // if(event == FL_UNFOCUS) focus_tracker_ = 0;
      int ret = Fl_Scroll::handle(event);
+    if(!contains(Fl::focus())) focus_tracker_ = 0;

-    if((event == FL_KEYBOARD) || (event == FL_PUSH)) {
+    if((event == FL_KEYBOARD) || (event == FL_SHORTCUT) || (event == 
FL_PUSH)) {
        if(ret && scroll_to_focus_()) redraw();
      }
-
      return ret;
    }

@@ -65,17 +67,20 @@ class Track_Focus_Scroll : public Fl_Scroll {
    */
    int test_focus_() {
      // if widget is not a widget inside of the scroll group, end.
-    if(focus_tracker_ == Fl::focus()) return 0;
+    if(focus_tracker_ && (focus_tracker_ == Fl::focus())) return 0;

      // record new focus ...
      if(focus_tracker_) focus_tracker_->color(FL_BLUE);
      focus_tracker_ = Fl::focus();
-    focus_tracker_->color(FL_RED);

      if((!focus_tracker_->inside(this)) ||
         (focus_tracker_ == &scrollbar) || (focus_tracker_ == 
&hscrollbar) ||
-       focus_tracker_->inside(&scrollbar) || 
focus_tracker_->inside(&hscrollbar))
+       focus_tracker_->inside(&scrollbar) || 
focus_tracker_->inside(&hscrollbar)) {
+      focus_tracker_ = 0;
        return 0;
+    }
+
+    focus_tracker_->color(FL_RED);

      return 1; // scroll to it!


Hth

Albrecht

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to