Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: VID dynamic layout

From: henrikmk::gmail at: 13-Jan-2010 10:35

On Wed, Jan 13, 2010 at 9:14 AM, Thorsten Moeller <tmoeller-fastmail.fm> wrote:
> lay-spec: [ > =A0 =A0across space 4x4 > =A0 =A0backdrop effect compose [gradient 1x0 (white) (silver) > =A0 =A0 =A0 =A0] > =A0 =A0return > =A0 =A0style pgr progress 270 green > ] > > foreach line result [ > =A0 =A0append lay-spec compose [ > =A0 =A0 =A0 =A0(make-lbl-name to-word line/3 set-word!) text bold 200 (form > =A0 =A0 =A0 =A0line/3) > =A0 =A0 =A0 =A0pgr > =A0 =A0 =A0 =A0return > =A0 =A0] > ] > > I thought in the foreach loop there must be somthing like if line > 80 > [PG1: pgr orange and PG1/data: line/ 16] . That doesn't seem to work.
You can do that. I don't know which column gives you the data, so I'm just using line/5 and I'm assuming it's a decimal between 0 and 1: foreach line result [ append lay-spec compose [ (make-lbl-name to-word line/3 set-word!) text bold 200 (form line/3) pgr (line/5) ( case [ line/5 < 0.5 [green] line/5 < 0.7 [yellow] line/5 < 0.9 [red] ] ) return ] ] There is at least one other way to do it, and that is to duplicate and modify the progress style, so that it knows what color it needs to draw, when you give it a specific value. That gives a cleaner and smaller layout, by abstracting the color decision away from the layout, but it requires that you redo or append to the progress style function. If you end up doing a lot of customization, it makes sense to move the color evaluation to the style, rather than building a huge layout. You need to dig out the 'init part of the progress style. 'init is run as the layout is created: probe get in get-style 'progress 'init which gives: [ if image? image [ if none? size [size: image/size] if size/y < 0 [size/y: size/x * image/size/y / image/size/x effect: insert copy effect 'fit] if color [effect: join effect ['colorize color]] ] if none? size [size: 100x100] pane: make bar [] pane/size: size either size/x > size/y [pane/size/x: 1] [pane/size/y: 1] if colors [color: first colors pane/color: second colors] ] Now you need to modify that code and build a derivative style. We can shave it down a little bit, since you probably don't need images: stylize/master [ pgr: progress [ init: [ if none? size [size: 100x100] pane: make bar [] pane/size: size either size/x > size/y [pane/size/x: 1][pane/size/y: 1] ; here we decide it. COLORS is two colors. The first gives foreground, the second gives background. (At least I think, swap it around if it doesn't work) if not number? data [data: 0] ; for safety if colors [ colors/1: case [ data < 0.5 [green] data < 0.7 [yellow] data < 0.9 [red] ] ] if colors [color: first colors pane/color: second colors] ] ] ] Then your loop would appear like this: foreach line result [ append lay-spec compose [ (make-lbl-name to-word line/3 set-word!) text bold 200 (form line/3) pgr (line/5) return ] ] Nice and clean. Code is untested. -- Regards, Henrik Mikael Kristensen