How to color button in red? - rebol

I tried this code snippet like in rebol:
View [button "colored" 100.0.0]
but the button is still in grey.

Such feature is not supported yet when using native button widget. Though, you can create a custom button easily using the versatile base face type:
view [
base red
on-down [face/color: face/color / 2]
on-up [face/color: face/color * 2]
]
You can also create a new custom style out of that (requires at least Red autobuild from master branch from Jan 3rd, 2019):
view [
style but: base
on-down [face/color: face/color / 2 do-actor face event 'click]
on-up [face/color: face/color * 2]
but "Say hi!" red on-click [print "hi"]
]

Related

Turn on/off mouseOver attribute in elm-ui

I am trying to make a simple game on Elm with elm-ui for my interest, but I stacked how to turn on/off mouseOver attribute.
I made a sample code for my explanation: https://ellie-app.com/9rvqJxz4ypga1
In this code, model has only two status (Myself|Opposite) which represent the turn of the game.
I would like to turn on changing background color of each tiles with mouseOver when model has the same status as the label of the tile.
viewTile is the main code which contains what I want to do.
viewTile : Player -> Model -> Element Msg
viewTile player model =
let
desc =
if player == Myself then
"Myself"
else
"Opposite"
changeMouseOver =
if player == model then
mouseOver [ Bg.color (rgba 1 0.2 0.3 0.5) ]
else
mouseOver []
in
column [ width (px 100), height (px 100), Border.width 1, changeMouseOver ] [ el [ centerX, centerY] ( text <| desc ) ]
For example, if model has "Myself" status, mouseOver will turn on only the tile labeled "Myself" .
In addition, "Change turn" button can change model like Myself <-> Opposite.
This trial showed good result if you clicked this button one time. However if you clicked again (means to recover model to Myself), mouseOver of "Myself" tile do not work.
I tried move the if code from let-in section to external, but it did not also work well.
How should I change the code to work turn on/off mouseOver?
This issue seems to be browser-specific one, I tried this code with Ellie in Safari 13.0.5. Firefox 78.0.2 works fine.

Why do I get error with show window in Rebol/Red?

When I click on button refresh, I get an error
v: [field1 "to refresh" field2 "to refresh"
button "refresh" [show v]]
view v
How can refresh v ?
Update: I don't have error but it doesn't refresh:
test: [
["a1" "b1"]
["a2" "b2"]
]
i: 1
v: layout compose [
field data test/:i/1 field data test/:i/2 button "refresh" [i: i + 1 show v]
]
view v
Show expects a face, not a block.
You want probably something along
v: layout [
f1: field "to refresh"
f2: field "to refresh"
button "refresh" [f1/text: f2/text show v ]
]
To see a change you should type something in the second input field before clicking on the button.
To make something (usefully) working with your update you can use
i: 1
sw: true
v: layout compose [
f1: field data test/:i/1
f2: field data test/:i/2
button "refresh" [
i: pick [1 2] sw: not sw
f1/text: test/:i/1
f2/text: test/:i/2
show v
]
]
show does not load the face definition block again, but the red-gui-system docs say
"Red/View will update both face and graphic objects in realtime as their properties are changed. This is the default behavior, but it can be switched off, when full control over screen updates is desirable. This is achieved by:
system/view/auto-sync?: off
When automatic syncing is turned off, you need to use show function on faces to get the graphic objects updated on screen."
I guess you can get something similar to your intention by destroying the old face object and building a new with the specification block.
test: [
["a1" "b1"]
["a2" "b2"]
]
i: 1
sw: true
vvw: layout v: [
field data test/:i/1
field data test/:i/2
button "refresh" [
i: pick [1 2] sw: not sw
unview vvw
view v
]
]
view vvw
Not sure what you mean by "refresh", but Red's GUI is reactive, you don't need to explicitly tell it to update.
If you just want to update the text data (increment its value) - here's a short working example:
view [f: field "42" button "increment" [f/data: f/data + 1]]
That is, f is assigned to the just created field. On button press - it receives new value, by acessing its data member.

Why does a button hide itself and another differently?

In the following Rebol 2 code, why does button a become visible 5 seconds after it's clicked, while remaining hidden 5 seconds after button b is clicked?
f: does [hide a wait 5]
view layout [
a: button "a" [f]
b: button "b" [f]
]
It looks like a bug that
view layout [
a: button "hide me" [ hide face ]
b: button "hide a" [ hide a ]
]
doesn't work to hide the "a" button unless the hide is called from another button. Your wait 5 must be triggering an update of the layout so that the button disappears.
Instead of wait 5, using do-events (wait []) keeps the button hidden.
view layout [
a: button "hide me" [ hide face do-events ]
b: button "hide a" [ hide a ]
]
When each button is clicked, it is redrawn to look “pressed”, and stays “pressed” until its action has completed. Then, after it's action has completed, the button is redrawn as “unpressed”.
During button a's action, it is hidden, but when its action is completed, it is shown again when it's “unpressed” state is drawn. According to this function summary of hide, hide only “temporarily removes the face from view”, and “The face will become visible again the next time the face is shown either directly or indirectly through one of its parent faces.”
During button b's action, button a is hidden, but when button b's action is completed, it is button b that is redrawn as “unpressed”. At this point, button a is untouched and remained hidden.
Considering Graham Chiu's code:
view layout [
a: button "hide me" [ hide face do-events ]
b: button "hide a" [ hide a ]
]
In this case, the reason why button a remains hidden after being clicked, is that its action doesn't reach completion until the window is closed. If wait 5 represents code which needs to be executed when the button is clicked, it needs to be put before do-events. Otherwise it is not executed until the window is closed.
view layout [
a: button "hide me and print" [
hide face
print "I need to say this when clicked."
do-events
print "I can wait until the window is closed."
]
b: button "hide a" [ hide a ]
]
Some other ways to make a button hide itself can be found on this page under the subheading: “Hiding self”. For example:
view l: layout [b: button [b/show?: false unview/all view l]]

Titanium: How to remove background of Search bar?

How can I remove the background of search bar ? I tried by changing background color but it also changes cancel button's color !!!
Thanks...
The best alternative to this is creating a custom search bar with Ti.UI.textField and Ti.UI.button. Add them both to a view and customize it as you please. Finally, just add an event listener to the button click, and voila!
Take a look at this Module: https://github.com/viezel/NappUI
It extends the properties for several UI Elements, including SearchBar, here is the list.
SearchField BackgroundImage
Custom Cancel button
barColor - background gradient of the button. (similar to navbar)
color - color of the button title
title - change the default Cancel text
font - set the font of the button
Appearance of the keyboard
Disable the search icon
To install it, I recommend you to use the new gitTio command line, this will automatically download the module, install it on the modules folder on Application Support folder and add the proper config line on tiapp.xml.
gittio install -g dk.napp.ui
And here is an example of a SearchBar using the new properties enabled by this Module
var searchBar = Ti.UI.createSearchBar({
searchFieldBackgroundImage:"searchbg.png",
showsScopeBar:true,
scopeButtonTitles:["hello", "yes"],
customCancel:{
barColor:"#333",
color:"#ddd",
title:"Hit me",
font:{
fontSize:16,
fontWeight:"bold",
fontFamily:"Georgia"
}
},
appearance:Titanium.UI.KEYBOARD_APPEARANCE_ALERT,
barColor:"transparent",
disableSearchIcon:true //disables the search icon in the left side
});
If you are talking about the gradient blue, I removed it on my app with:
var searchBox = Ti.UI.createSearchBar({
barColor: '#eee'
});
Hope this helps.
Unfortunately 'barColor' doesn't work. Ti seems to change the color by changing the opacity or hue or something. DannyM's workaround is the best.
I must have wasted a zillion hours making sense of Titanium's background colors, background images, bar colors and their active/inactive cousins.
Conclusion: "Free" software is costly if you count the time you waste on silly bugs and lack of useful documentation.

How to stylize text-list and other elements?

Default Rebol VID style is eye-searing, put bluntly. I started making my own default, but ran into a snag. Namely, how do I specify styles for a sub-element of an element?
good-looking: stylize [
field: field
edge [size: 1x1]
colors [255.255.255 255.255.255]
area: area
edge [size: 1x1]
colors [255.255.255 255.255.255]
text-list: text-list
;text-list/sub-area/edge [size: 1x1]
]
I want all fields to have a thin border, including text-list and others. But I have no idea how to include that rule in the text-list definition.
Also, how to reduce repetition with styles, like with the colors?
I can partly answer your first question. At the REBOL consol, try this...
>> lo: layout [t: text-list]
That both creates a layout and allows the text-list object (t) to be examined using PROBE...
>> probe first t
== [self type offset size span pane text color image effect data edge font para feel saved-area rate show? options parent-face old-offset old-size line-list changes face-flags action state access style alt-action facets related words colors texts images file var keycode reset styles init multi blinker pane-size dirty? help user-data flags doc xy sz iter sub-area sld sn lc picked cnt act slf lines text-pane update resize]
Notice the SUB-AREA there. That's the list area in a text-list. Probe into that and you get...
>> probe first t/sub-area/edge
== [self color image effect size]
>> probe first t/sub-area/edge/size
== 2
So, change SIZE there and view the layout we made...
>> t/sub-area/edge/size: 1x1
== 1x1
>> view lo
The text-list's edge should be thin now. I'm not sure how you achieve that using style, but hopefully this will put you on the right track.
So, first:
layout [X: field]
type? X/edge
type? X/colors
Objects should get re-made to avoid unexpected side-effects on the shared ones.
good-looking: stylize [
field: field with [
edge: make edge [size: 1x1]
colors: copy [255.255.255 255.255.255]
]
area: area with [
edge: make edge [size: 1x1]
colors: copy [255.255.255 255.255.255]
]
text-list: text-list with [
sub-area: make sub-area [
edge: make edge [size: 1x1]
]
]
]