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

How to change an existing button's colour

 [1/17] from: warren:howsoft at: 30-Jan-2008 12:47


Hi All, Perhaps somebody would be kind enough to help out a Rebol noob who is completely lost. Using RebGUI, I have found out how to change an existing button's colour as follows: ------------------------------ Rebol[] unless value? 'ctx-rebgui [do-thru http://www.dobeash.com/RebGUI/rebgui.r] display "RebGUI Example" [ text"Click on the WORLD button" mybut: button "Hello" red button "World" on-click [mybut/color: blue show mybut] ] do-events ------------------------------ I want to do something similar in normal Rebol code, but nothing I try seems to work. Any help would be greatly appreciated. Thanks. Regards, Bob Warren

 [2/17] from: brock::kalef::innovapost::com at: 30-Jan-2008 10:34


view layout[button "Hi" red blue] Were you only expecting the button to change colour during the button press?

 [3/17] from: warren:howsoft at: 30-Jan-2008 14:13


Hi Brock, No, I want to change the colour of the button "mybut" programmatically without clicking on it. In other words, I want to do EXACTLY what I am doing successfully in the RebGUI version. Regards, Bob ----------------------------- Brock Kalef wrote:

 [4/17] from: petr:krenzelok:seznam:cz at: 30-Jan-2008 17:33


Bob Warren napsal(a):
> Hi All, > Perhaps somebody would be kind enough to help out a Rebol noob who is
<<quoted lines omitted: 15>>
> Any help would be greatly appreciated. > Thanks.
Eh, long time I did not do that in VID, but you could try following. Generally in VID, you can specify your color inline b: btn red green "OK" font-color blue ; beware, this does not work for 'button style You can study your style using "probe get-style 'button". You can see, there is face/color, face/colors, face/effect, face/effects. As you can see, old button is colored using following code (I might be wrong) if not any [effect effects] [ either color [ effects: reduce [ reduce ['gradient 0x1 color + 32 color - 32] either all [block? colors colors/2] [ reduce ['gradient 0x-1 colors/2 + 32 color/2 - 32] ] [ reduce ['gradient 0x-1 color + 32 color - 32] ] ] ] [ effects: [ [gradient 0x1 66.120.192 44.80.132] [gradient 0x-1 66.120.192 44.80.132] ] ] ] view layout [b: button "OK" [probe reduce [b/color b/colors b/effect b/effects]]] or ->> view layout [b: btn red green "OK" font-color yellow [probe reduce [b/color b/colors b/effect b/effects]]] [none [255.0.0 0.255.0] [colorize 0.255.0 128 extend 14] none] Now you can experiment with slots. As it is normal series, you might succesfully replace elements, e.g.: Maybe VID gurus step-in and they will be able to help you some more ... cheers, -pekr-

 [5/17] from: brock:kalef:innovapost at: 30-Jan-2008 11:46


I'm getting closer, but can't quite put my finger on it. I can see a very slight change in brightness of the red button when I press the blue button. So it's closer, but still a long way away view lay: layout[ b1: button "Hello" red b2: button "World" [b1/effects: ['color black] show b1] ]

 [6/17] from: kpeters:otaksoft at: 30-Jan-2008 9:00


Here you go, Bob: The code also shows you how to dis-/enable a btn as well in one go. HTH Kai ;------------------------------------------------------------------ disable: func[ butt [object!] flag [logic!]] [ if all [ flag butt/color = gray ][ exit ] ; don't disable twice ; either flag [ butt/user-data: butt/colors/1 butt/colors: reduce [ gray gray ] butt/color: gray show butt butt/feel: none ] [ butt/feel: svvf/btn butt/color: butt/user-data butt/colors: reduce [ butt/user-data butt/user-data ] show butt ] ] ;----------------------------------------------------------------- form: center-face layout [ btn-a: btn "Enable bottom button" [ disable btn-c false ] btn-b: btn "Disable bottom button" [ disable btn-c true ] btn-c: btn "Say hello" [ notify "Hi there!" ] sky colors [ sky sky ] ] ;----------------------------------------------------------------- view form do-events

 [7/17] from: brock:kalef:innovapost at: 30-Jan-2008 12:00


Closer yet... This changes the gradient and the colour. view lay: layout[ b1: button "Hello" red b2: button "World" [b1/effects: reduce ['gradient 0x-1 blue + 32 blue - 32] b1/text: "Changed" show b1] ]

 [8/17] from: ammon:johnson:gma:il at: 30-Jan-2008 10:01


b1/colors/1: blue Or something to that effect... On Jan 30, 2008 9:46 AM, Brock Kalef <brock.kalef-innovapost.com> wrote:
> I'm getting closer, but can't quite put my finger on it. I can see a > very slight change in brightness of the red button when I press the blue
<<quoted lines omitted: 6>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- I contend that we are both atheists, I just believe in one less god than you do. When you understand why you dismiss all other possible gods, then you will know why I dismiss yours. -- Stephen F. Roberts

 [9/17] from: warren:howsoft at: 30-Jan-2008 15:14


Thanks for the ideas, Petr. I'll study them as well as a noob can. But I think you're right: it might take a guru to sort out this "simple" little problem - so easily done in RebGUI. Regards, Bob Petr Krenzelok wrote:

 [10/17] from: warren:howsoft at: 30-Jan-2008 15:53


You've cracked it Kai! (All I've got to do now is to break my own head to analyze exactly how it works!) So near and so simple, Brock! Now if only we can get rid of the gradient effect ... You were right, Ammon: see Kai's solution. Thanks a lot, guys! Best, Bob Kai Peters wrote:

 [11/17] from: ammon:johnson:gmai:l at: 30-Jan-2008 11:01


I'm a little suprised I was right. I haven't touched VID in 2 years. My REBOL usage has moved entirely to back end server scripts... On Jan 30, 2008 10:53 AM, Bob Warren <warren-howsoft.com> wrote:
> You've cracked it Kai! > (All I've got to do now is to break my own head to analyze exactly how
<<quoted lines omitted: 47>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- I contend that we are both atheists, I just believe in one less god than you do. When you understand why you dismiss all other possible gods, then you will know why I dismiss yours. -- Stephen F. Roberts

 [12/17] from: warren:howsoft at: 30-Jan-2008 16:44


Kai: When you get a spare minute, would you mind showing me how to: 1) Change the button colour to a pure red 2) Cut out the button disabling I've only managed to produce a pink button so far, and as for the cutting out of the disabling, I've made no progress at all! Thanks, Bob Kai Peters wrote:

 [13/17] from: petr:krenzelok:seznam:cz at: 30-Jan-2008 20:02


Bob Warren napsal(a):
> Kai: > > When you get a spare minute, would you mind showing me how to: > > 1) Change the button colour to a pure red > 2) Cut out the button disabling >
as for disabling facec - there is another option - http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=disable-face.r -pekr-

 [14/17] from: gregg:pointillistic at: 30-Jan-2008 12:23


Hi Bob, BW> 1) Change the button colour to a pure red BW> 2) Cut out the button disabling The color changing may be not what you want due to the effect block a the btn uses. The tricky part about messing with that, is that you need to know more about the internals. As an example, uncomment the line that changes the effect to nothing. You can see all the source for the btn style by doing:
>> probe get-style 'btn
To avoid the disabling, you want to leave the /feel facet alone. change-color: func [butt [object!] color [tuple! none!]] [ either all [color color <> butt/colors/1] [ butt/user-data: butt/colors/1 butt/colors: reduce [color color] butt/color: color ][ butt/color: butt/user-data butt/colors: reduce [butt/user-data butt/user-data] ] ;butt/effect: copy [] show butt ] ;----------------------------------------------------------------- form: center-face layout [ btn-a: btn "Make it red" [change-color btn-c red] btn-b: btn "Reset its color" [change-color btn-c none] btn-c: btn "Say hello" [ notify "Hi there!" ] sky colors [ sky sky ] ] ;----------------------------------------------------------------- view form do-events -- Gregg

 [15/17] from: warren:howsoft at: 30-Jan-2008 19:31


That's great stuff, Gregg. Many thanks! It would be nice if the upcoming Rebol release took a leaf out of the RebGUI book with regard to this aspect (so easy to achieve in other languages too). As it stands, it's hardly for beginner's! Personally, I'm only CAPABLE of doing simple things in simple ways! Changing the text and font etc. of an existing button is very easy, so the fact that changing the colour is so difficult is rather inconsistent. I could never have worked it out myself. Anyway, the info I now have should enable me to continue with my current programming project with considerably less hassle, thanks to the help I have received. Grats, Bob Gregg Irwin wrote:

 [16/17] from: gregg:pointillistic at: 30-Jan-2008 14:46


Hi Bob, BW> Changing the text and font etc. of an existing button is very BW> easy, so the fact that changing the colour is so difficult is BW> rather inconsistent. I could never have worked it out myself. This is a known problem, and the designers are working hard to develop a system that is flexible, powerful, and easy to use. No small feat. When I first got into REBOL, I just did simple UIs in VID, then I started wanting to control things more, and hit the same issues you are. Now I either keep things very simple--a lot of the things I thought I wanted to do were really force of habit, and I've gotten along fine without them--or create styles that do what I want. -- Gregg

 [17/17] from: gregg::pointillistic::com at: 30-Jan-2008 14:59


Hi Bob, Addendum to last message: BW> Changing the text and font etc. of an existing button is very BW> easy, so the fact that changing the colour is so difficult is BW> rather inconsistent. Part of the reason for this is that other languages and UI widgets have fairly limited capabilities, as far as appearance. With REBOL, you can use the graphics pipeline, draw commands, set custom edges (which, themselves, are completely customizable), embed images, and more. The problem is that there are so many ways to do things, that you don't know how a particular style does it without analyzing the source. Another "problem" is that the whole UI system is very dense, in code terms, so there's a lot of neat stuff going on that minimizes the code, but makes it harder to understand. I think the entire VID system, at the mezzanine level, is around 4K LOC. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted