Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Need some help with colour picker
Pages: [1] Print
Author Topic: Need some help with colour picker  (Read 1211 times)
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Need some help with colour picker
« on: March 08, 2007, 01:00:31 PM »

Hello All

Complete REBOL (programming in general) novice here.

Using REBOL/View 1.3.2.4.2 7-Dec-2005 Core 2.6.3
and RebGUI "RebGUI widget tour" 0.4.40
on linux (puppy 213)

I am in need of some help/advice from those who know the score.

After umpteen fruitless searches (google) i am left with no option
but to post this,so please excuse my Newbity.

First let me explain.

   THE FOLLOWING WAS DONE PURELY AS AN EDUCATIONAL EXERCISE.

What i am trying to achieve is a little widget that allows the user
to select (from a drop-down list) a colour that is then displayed in a box
below the drop-down list.
This widget will contain 6 of the above mentioned (drop-down list/box combo's)
across the window.
A sort of Colours Pick n Mix

In fact such a widget (almost) exists in the RebGUI tour.r ,on the List tab.

So without further ado, i set about chopping the tour.r file (hope that is allowed)
to try and get it down to something like i require.
I also added extra colours to the drop-down list.

Now its nearly there, albeit still in need of a few tweaks here and there.


My main problem is this.

Select any colour in any list (of the 6),and ONLY the box below list 6 is changing colour.

if you run the following code, you will see what i mean.

Code:
REBOL []

#include %rebgui.r

unless value? 'ctx-rebgui [
either exists? %rebgui-ctx.r [do %rebgui-ctx.r] [do %rebgui.r]
]

fonts: reduce [font-sans-serif font-fixed font-serif "verdana"]

do show-tour: make function! [] [

display rejoin [""] [
group-box "Choose Window Colour" data [
button-size 20
after 2
button "window" [if var: request-color [ctx-rebgui/colors/window: var   unview show-tour]] box 10x5 edge [color: black] ctx-rebgui/colors/window
] return

text "Select From List" return

group-box "Colour-1" data [
drop-list 30 "Select Colour 1" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 red
]

group-box "Colour-2" data [
drop-list 30 "Select Colour 2" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 yellow
]

group-box "Colour-3" data [
drop-list 30 "Select Colour 3" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 green
]

group-box "Colour-4" data [
drop-list 30 "Select Colour 4" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 blue
]

group-box "Colour-5" data [
drop-list 30 "Select Colour 5" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 silver
]

group-box "Colour-6" data [
drop-list 30 "Select Colour 6" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color ex-drop-list to word! face/text] return

ex-drop-list: box 30x50 papaya
]
]
]

do-events


My Questions are:

   1. How do i get each box to display the colour chosen from the list immediately above it. ?
   
   2. How would i go about getting the box's to actually touch each other. ?
      (so there is no window colour showing between them).


Sorry if this seems rather simple, but maybe its me who is simple, as i cannot get it to work

Anyhow hope somebody may be able to help

TIA.      ARU
Logged
Ashley
Newbie
*
Offline Offline

Posts: 37


View Profile
Re: Need some help with colour picker
« Reply #1 on: March 08, 2007, 04:37:06 PM »

The problem you are having is that each of your box's is refereed to as ex-drop-list. Try naming them distinctly, for example:

Code:
box-1: box 30x50 red
...
box-2: box 30x50 green
...
etc

and make sure that the drop-lists's refer to the correct box, for example your first drop-list would now read something like:

Code:
drop-list 30 "Select Colour 1" data ["aqua" ...] [show-color box-1 to word! face/text]

As for getting the boxes to touch each other, try playing around with the following directives (margin, space and tight) one at a time:

Code:
display "Test" [
    margin 0x0
    space 0x0
    tight
    field
    field
    return
    field
    field
]
Logged
Anton
Jr. Member
**
Offline Offline

Posts: 66

Rebol veteran


View Profile WWW
Re: Need some help with colour picker
« Reply #2 on: March 08, 2007, 07:26:48 PM »

Here's a one-liner which doesn't use any variables. The drop-list refers to the box as the face after itself in the parent face. You can duplicate the drop-list and box pair as many times as you want without introducing any variables (words) to reference them.

Code:
display "" [drop-list "colour 1" data [aqua beige blue brown][set in select face/parent-face/pane face 'color get to-word face/text show face/parent-face] box 25x25] do-events

Of course, you must make sure that there is a face after the drop-list otherwise the drop-list action will break.
Logged
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Re: Need some help with colour picker
« Reply #3 on: March 09, 2007, 05:47:38 AM »

Hello again

Ashley.
Thankyou for your advice regarding naming of the box's, it worked a treat mate. Cool
I had tried something similar but that never worked.
As to playing with (margin, space and tight) well im still playing with that.

Anton.
Thankyou also mate, i like your one-liner but i dont seem to be able to get it
to work right  Embarrassed Embarrassed.Im not sure on what code i need in order to have several of these
across the window.
Whatever i try i end up with only one of these (list/box pairs) displaying.

Could you please give me an example of ALL the code i would need for several
drop-down list/box pairs across the window.

I get a little confused with it all, like i said im a complete newb at this
but its got me hooked already.

Thanks to you both again

ARU

EDIT

I have just noticed that if i change the colour of any/all of the six box's
AND THEN change the window colour,ALL six box's return to their original colours.

Could anyone enlighten me as to whats happening please ?

My REVISED code is below

Code:
REBOL []

#include %rebgui.r

unless value? 'ctx-rebgui [
either exists? %rebgui-ctx.r [do %rebgui-ctx.r] [do %rebgui.r]
]

fonts: reduce [font-sans-serif font-fixed font-serif "verdana"]

do show-tour: make function! [] [

display rejoin [""] [
group-box "Choose Window Colour" data [
button-size 20
after 2
button "window" [if var: request-color [ctx-rebgui/colors/window: var   unview show-tour]] box 10x5 edge [color: black] ctx-rebgui/colors/window
] return

box black 210x1 return

text "Select Required Colours From Lists"
return
space 5x0
pad 2

drop-list 30 "Select Colour 1" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-1 to word! face/text]

drop-list 30 "Select Colour 2" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-2 to word! face/text]

drop-list 30 "Select Colour 3" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-3 to word! face/text]

drop-list 30 "Select Colour 4" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-4 to word! face/text]

drop-list 30 "Select Colour 5" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-5 to word! face/text]

drop-list 30 "Select Colour 6" data ["aqua" "beige" "blue" "brown" "coffee" "cyan" "gold" "green" "khaki" "linen" "maroon" "navy" "olive" "papaya" "pink" "reblue" "red" "silver" "snow" "teal" "water" "white" "base-color" "black" "brick" "coal" "crimson" "forest" "gray" "ivory" "leaf" "magenta" "mint" "oldrab" "orange" "pewter" "purple" "rebolor" "sienna" "sky" "tan" "violet" "wheat" "yellow"] [show-color box-6 to word! face/text] return

space 0x0
box-1: box 35x50 red
box-2: box 35x50 yellow
box-3: box 35x50 green
box-4: box 35x50 blue
box-5: box 35x50 silver
box-6: box 35x50 papaya


]
]

do-events



Yes i think im having fun  Roll Eyes Roll Eyes

TIA   ARU
« Last Edit: March 09, 2007, 02:47:37 PM by AllRebbedUp » Logged
Anton
Jr. Member
**
Offline Offline

Posts: 66

Rebol veteran


View Profile WWW
Re: Need some help with colour picker
« Reply #4 on: March 14, 2007, 10:08:43 AM »

Here's a rewrite of your code that works.
I've auto-generated the list of named colours (not quite the same as your list).
(Rebgui drop-list automatically converts the words in the colours block to a block of strings.)
The method I used in the one-liner didn't work in your case as your drop-list / colour box pairs were separated by 6 faces in your layout. My demo code assumes each drop-list is followed directly by a colour box. So I've changed the SELECT to a PICK .. 6 <-- (skipping 6 faces). You will have to change this number if you increase or decrease the number of drop-list/box pairs in your layout, otherwise each drop-list will be targetting the wrong face.
(Probably there's a way to set the layout direction in rebgui to vertical instead of horizontal, and we can use the simpler SELECT again.)
Code:
colours: []
foreach word first system/words [
if all [
value? in system/words word
tuple? get in system/words word
][
append colours word
]
]

drop-list-action: [
set in pick find/tail face/parent-face/pane face 6 'color get to-word face/text
show face/parent-face
]

display "" compose/only [
group-box "Choose Window Colour" data [
button-size 20
after 2
button "window" [
if var: request-color [
ctx-rebgui/colors/window: var
show face/parent-face/parent-face
;unview
;show-tour
]
] box 10x5 edge [color: black] ctx-rebgui/colors/window

] return

box black 210x1 return

text "Select Required Colours From Lists"
return
space 5x0
pad 2

drop-list 30 "Select Colour 1" data (colours) (drop-list-action)
drop-list 30 "Select Colour 2" data (colours) (drop-list-action)
drop-list 30 "Select Colour 3" data (colours) (drop-list-action)
drop-list 30 "Select Colour 4" data (colours) (drop-list-action)
drop-list 30 "Select Colour 5" data (colours) (drop-list-action)
drop-list 30 "Select Colour 6" data (colours) (drop-list-action)
return

space 0x0
box-1: box 35x50 red
box-2: box 35x50 yellow
box-3: box 35x50 green
box-4: box 35x50 blue
box-5: box 35x50 silver
box-6: box 35x50 papaya
]
do-events
Note the COMPOSE/ONLY which expands the COLOURS and DROP-LIST-ACTION blocks into the layout block.
Logged
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Re: Need some help with colour picker
« Reply #5 on: March 18, 2007, 09:15:51 AM »

Hello Anton

Apologies for the delay in replying, but i got so carried away playing with
REBOL that i forgot to check back here.

Thankyou so much for your time and effort in giving me your code example,
im sure it will get used in future projects that i attempt.

I am trying to gather together as much documentation, tutorials etc that i can
find (rebol related).

But it is difficult to piece it all together (for us newbies).

What with mention of RebGUI, Draw, VID, List-View etc.  (very very confusing) Roll Eyes Roll Eyes Roll Eyes

However this will not deter me from trying to understand it all eventually.

So for my next project, i am looking to make a Diary/Calendar/Database type of
prog that keeps a daily record for a gardener (the missus).

Any pointers are very welcome from anybody.

Again Thankyou Anton

TIA ARU

Logged
Brock
Newbie
*
Offline Offline

Posts: 14


View Profile
Re: Need some help with colour picker
« Reply #6 on: March 18, 2007, 12:05:03 PM »

Hi ARU,
So many projects so little time.  I was going to do the same thing for my mother-in-law.  Maybe I can help you find some things or give ideas or collaborate.  I've been lurking here for years and am at best just above newbie as I don't spend too much time actually coding.
Cheers, and good luck with your project.
Brock
Logged
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Re: Need some help with colour picker
« Reply #7 on: March 19, 2007, 07:07:13 AM »

Hello Brock

Maybe I can help you find some things or give ideas or collaborate.

Cheers, and good luck with your project.
Brock

Thankyou for your offer and kind words, you never know i may at somepoint PM you when i get stuck.
( if thats ok with you of course)
Which will probably be sooner than later i reckon.

ARU

Logged
Brock
Newbie
*
Offline Offline

Posts: 14


View Profile
Re: Need some help with colour picker
« Reply #8 on: March 19, 2007, 09:52:36 PM »

ARU, that is fine of course.
« Last Edit: March 19, 2007, 09:54:18 PM by Brock » Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Need some help with colour picker
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 06:54:55 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4139 Members
Latest Member: DietaVato

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc