Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Looking for a scrolling list control, or how to create/simulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98876] Re: [mg98828] Re: Looking for a scrolling list control, or how to create/simulate
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Mon, 20 Apr 2009 19:12:30 -0400 (EDT)
  • Reply-to: jfultz at wolfram.com

On Mon, 20 Apr 2009 01:32:49 -0400 (EDT), meitnik wrote:
> OK, here is what I have come up with so far. Any corrections or
>
> improvements? And how do I reuse my custom control outside of the
> current notebook cell? That is how do I "install" it for use in other
> notebook cells? Thanks.
>
> ListField[wd_, tz_, ls_] :=
> DynamicModule[{x},
> ld = Length[ls];
> Framed[
> Pane[
> Column[
> Table[
> With[
> {i = i}
> ,
> Button[Style[ls[[i]], FontSize -> tz], Dynamic[x = ls[[i]]]
> , Appearance -> "None"
> , ImageSize -> {wd, tz + 2}
> , ImageMargins -> 0
> , Alignment -> Left]
> ], {i, lt}
> ], Spacings -> 0
> ]
> , ImageSize -> {wd, Round[(ld*tz/2) + (ld*2) - 4]}
> , ImageMargins -> {{1, 0}, {0, 0}}
> , Scrollbars -> {False, True}
> , AppearanceElements -> None
> ]
> , FrameMargins -> {{1, 0}, {0, -1}}
> ] Dynamic[x]
> ]
>
> mm = {"yes", "no", "Andrew Merit", "Marvin Honks", "Pam Bakes",
> "Marie loves", "Anne jo Ann"};
> ListField[120, 14, mm]

That's not bad.  Aside from a couple of typos, the one bad thing that I
see in there is that the second argument of Button[] should *not* have
Dynamic wrapped around it.  Dynamic has no purpose here, and there's no
guarantee that it would have worked.  Read this post of mine if you wish
to understand further.

http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html

Your interface could be improved by having it draw the currently selected
item.  Here's a modified implementation I created.  However, the
appearance is tailored for Windows...it might not have the right
colors for other platforms.  The magic happens in BaseStyle
(and note that I moved your Style[] command to the BaseStyle option
as well, just to make it cleaner).

ListField[wd_, tz_, ls_] := DynamicModule[{x}, ld = Length[ls];
  Framed[
   Pane[Column[
     Table[With[{i = i}, 
       Button[ls[[i]], x = ls[[i]], Appearance -> None, 
        ImageSize -> {wd, tz + 2}, ImageMargins -> 0, 
        Alignment -> Left, 
        BaseStyle -> 
         Dynamic[
          Join[{"GenericButton", tz}, 
           If[x === ls[[i]], {FontColor -> White, 
             DrawHighlighted -> True}, {}]]]]], {i, ld}], 
     Spacings -> 0], ImageSize -> {wd, Round[(ld*tz/2) + (ld*2) - 4]},
     ImageMargins -> {{1, 0}, {0, 0}}, Scrollbars -> {False, True}, 
    AppearanceElements -> None], FrameMargins -> {{1, 0}, {0, -1}}] ]

Sincerely,
 
John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.






  • Prev by Date: Re: Re: Passing arrays to MathLink without extra memory allocation
  • Next by Date: Re: Plot Axis Unit Conversions
  • Previous by thread: Re: Looking for a scrolling list control, or how to create/simulate
  • Next by thread: Re: Looking for a scrolling list control, or how to create/simulate