Rebol text fields - checking values and changing colors - rebol

In the following prototype test code, I'm trying to create a comparison system that compares two fields, and colors them depending on whether they are equal or not.
comparecolors: [
either answer-user/text = answer-correct/text [
answer-user/font/color: green
answer-correct/font/color: green
show answer-user
show answer-correct
][
answer-user/font/color: red
answer-correct/font/color: black
show answer-user
show answer-correct
]
]
view layout [
answer: field [
answer-user/text: copy answer/text
do comparecolors
show answer
focus answer
show answer-user
]
label "Compare"
answer-user: info
answer-correct: info
across
text-list "Hello" "Goodbye" "Boy" "Girl" "Soldier" [
answer-correct/text: copy value
do comparecolors
show answer-correct
]
]
Some problems I am having:
The green color is affecting all the fields instead of just the ones I am specifying.
The red color is not working when the two fields are not equal.
The system does not check for none! value (I know it is not written so in the above code, but I tried some ways that didn't work, so I don't really know how to go about it).

Whenever you see multiple fields affected when you change the attribute of only one, it means that VID has made an optimization so that all those fields are sharing the same data structure, and in this the same font structure. So, we need to force VID to allocate a new font structure like this:
change-colors: func [ user [object!] correct [object!]
/local u c
][
set [ u c ]
either user/text = correct/text [
[ green green ]
][
[ red black ]
]
user/font/color: get u
correct/font/color: get c
show [ user correct ]
]
view layout [
answer: field [
answer-user/text: copy answer/text
change-colors answer-user answer-correct
focus answer
] font-color black
label "Compare"
answer-user: info font-color black
answer-correct: info font-color black
across
text-list "Hello" "Goodbye" "Boy" "Girl" "Soldier" [
answer-correct/text: copy value
change-colors answer-user answer-correct
]
]

Related

elm-mdl: How to push a record from tab X into the model of tab Y and update tab Y view?

I'm using the demo codebase of elm-mdl as a starting point for my elm project. I have a situation where I need to click a button on one tab (e.g. "tab X") and mutate the state of a different tab (e.g. "tab Y").
Every way I've wired it up so far does not work. This seems like an odd case because the parent of all tabs (e.g. Layout) in the demo codebase is "Demo". It seems in my case that the dependency graph become convoluted because the effect would reach across "Demo" children.
How can this be done? I'm running 0.18.0.
https://github.com/debois/elm-mdl/tree/v8/demo
I've done an example playing around with what I've understand from your question.
I think your issue have to be that you are not passing the model through your tabs , so they are not rendering data related to the current state, instead you should be taking data from the initial model which always keeps inmutable.
Starting from the example code you should have this:
view : Model -> Html Msg
view model =
Tabs.render Mdl
[ 0 ]
model.mdl
[ Tabs.ripple
, Tabs.onSelectTab SelectTab
, Tabs.activeTab model.tab
]
[ Tabs.label
[ Options.center ]
[ Icon.i "info_outline"
, Options.span [ css "width" "4px" ] []
, text "About tabs"
]
, Tabs.label
[ Options.center ]
[ Icon.i "code"
, Options.span [ css "width" "4px" ] []
, text "Example"
]
]
[ case model.tab of
0 ->
tab0 model
_ ->
defaultTab model
]
My working example is here

request-date in a rebol2 vid application

Can someone tell me why the following code is not working? It is supposed to set the date in a field when it loads, then allow the date to be changed by clicking on the field. I'm using rebol/view 2.7.8 on linux. Actually, I think this code used to work years ago when I was using MS Windows, but not under linux for some reason.
drl
rebol []
trace true
out: layout [
style dater txt bold right [trans-date/date: copy (form now/date)] 48x24
dater "T-Date:" trans-date: field 80x24 (form now/date) feel [
engage: func [face action event][
if action = 'up [
lv-dat: request-date/date/offset (now/date) 450x375
if lv-dat <> none [
trans-date/text: form lv-dat
show trans-date
]
]
]
show trans-date
]
]
view out
Here is a cleaned up version of your code:
Rebol []
out: layout compose/deep [
style dater txt bold right 48x24
dater "T-Date:"
trans-date: field 80x24 (form now/date) feel [
engage: func [face action event][
if action = 'up [
lv-dat: request-date/date/offset (now/date) 450x375
if lv-dat [
face/text: form lv-dat
show face
]
]
]
]
]
view out
The main issue was the missing compose/deep call to evaluate the paren expressions before layout is called. However, that approach is not the usual way to initialize face properties, you should rather put init code in a do section of the VID block, like this:
Rebol []
out: layout [
style dater txt bold right 48x24
dater "T-Date:"
trans-date: field 80x24 feel [
engage: func [face action event][
if action = 'up [
lv-dat: request-date/date/offset now/date 450x375
if lv-dat [
face/text: form lv-dat
show face
]
]
]
]
do [trans-date/text: form now/date]
]
view out
Hope this helps.

netlogo: comparing variable of two different turtle

I am trying to compare variable of "capabilities" and "prevalues" on the same patch. If number on value = one of number on resource list, then do something.
This is what I have:
capabilities-own [ resource ]
prevalues-own [ value ]
to setup
clear-all
......
ask capabilities
[ set resource (list 1 2)]
ask prevalues
[set value ((random 4) + 1)]
....
reset-ticks
end
to compare
ask capabilities-here
[if any? prevalues-here
[ ask one-of prevalues-here
[ ifelse ( value = one-of resource)
[ move-to one-of patches with [pcolor = red] ]
[die]
]]]
But I got
RUNTIME ERROR: PREVALUES breed does not own variable RESOURCE
I also try to use other code, like this :
to compare
ask capabilities-here
[ ifelse prevalues-here with [value] = one-of [resource] of myself
[ move-to one-of patches with [pcolor = red] ]
[die]]
end
It results RUNTIME ERROR : WITH expected true/false....
Appreciates your kindly help
Thanks
Your line ifelse (value = one-of resource) is causing the first problem. resource is an agent variable for capabilities, but you haven't told NetLogo which capability's resource to compare the prevalue's value to. A turtle is aware of its own agent variables and the patch variables for the patch it is on, but if you want to get something from another turtle, you have to explicitly say so.
Also, do you want it to randomly select one value from the list of resources, or do you just want to check the value appears somewhere in the list?
I think you want something like this (not tested):
to compare
ask capabilities-here
[ if any? prevalues-here
[ ask one-of prevalues-here
[ ifelse member? value ([resource] of myself)
[ move-to one-of patches with [pcolor = red] ]
[ die ]
]]]
This assumes you want to check if it's in the list at all, which is what I think you mean from your first paragraph. If you want to randomly select an item from the list and check if it matches that, you will need something more like:
[ let this-resource one-of [resource] of myself
ask one-of prevalues-here
[ ifelse value = this-resource

REBOL 3 - How to update a layout that has already been viewed?

I'm trying to add a field to a layout after it has been viewed
view/no-wait m: [field "hello"]
insert tail m 'field
insert tail m "hello"
update-face m
** Script error: update-face does not allow block! for its face argument
I want to update the whole layout, not just the field or some part of it. If I try to use
view m, it opens a new window. Do I just have to un-view it and then view again?
You can use the LAYOUT function in R3-GUI as well. See the example below:
view/no-wait m: layout [field "hello"]
;We need to get the BACKDROP container which is first sub-face in the WINDOW face
m: first faces? m
append-content m [
field "world"
]
do-events
Ofcourse there are also other ways how to handle layout content dynamically.
Try this example from Richard
REBOL [
Title: "Layouts example #20"
Author: "Richard Smolak"
Version: "$Id: layouts-20.r3 852 2010-10-07 13:28:26Z cyphre $"
]
stylize [
tbox: hpanel [
about: "Simple rectangular box."
facets: [
init-hint: 200x200
min-hint: 0x0
max-hint: guie/max-pair
break-after: 1
]
options: [
init-hint: [pair!]
]
actors: [
on-make: [
append face/options [
content: [
button "hello" on-action [print "hello"]
button "world" on-action [print "hello"]
]
]
do-actor/style face 'on-make none 'hpanel
]
]
draw: [
pen red
fill-pen blue
box 0x0 (viewport-box/bottom-right - 1)
]
]
]
view [
test: tbox
button "clear"
on-action [
clear-content test
]
button "set"
on-action [
set-content test [
button "test"
field "the best"
]
]
button "insert"
on-action [
insert-content test bind/set probe reduce [to-set-word copy/part random "abcdefgh" 2 'button join "button #" 1 + length? test/gob] 'system
]
button "append"
on-action [
append-content test reduce ['button join "button #" 1 + length? test/gob]
]
button "remove 2 faces at pos 3"
on-action [
remove-content/pos/part test 3 2
]
]
so the words you're looking for are append-content and insert-content which take a face and a block as parameters where the block contains the definition of another face.
I don't know view yet, but I have a hint. The first line sets "m" to the block [field "hello"]. Check to see what "update-face" expects...

RavenDb faceted search with filtered out facet ranges included

I want to ask if there is a way in RavenDb to execute a faceted search but get also the facets which were filtered out.
Example:
Let's have a Car entity with properties Color : string and Status : enum(New,Used).
When I search for Red cars I would also like to get counts in all other colors. Similarly if I search for Used cars I want to see also count of new cars.
If I have everything unchecked:
UI
Color: [ ] Red (5) [ ] Blue (7) [ ] White (15)
Status: [ ] Used (20) [ ] New (7)
C#
session.Query<Car, Cars_Index>().ToFacets("facets/Cars");
I get the proper result.
But once I filter for both Color and Status I get very limited results:
UI
Color: [x] Red (3)
Status: [x] Used (3)
C#
session.Query<Car, Cars_Index>()
.Where(a => a.Status == CarStatus.Used)
.Where(a => a.Color == "Red")
.ToFacets("facets/Cars");
Response (JSON):
{ "Color": [ { "Range": "Red", "Count": 3 } ], "Status" : [ { "Range": "Used", "Count": 3 } ] }
What I do currently I issue a separate query for each facet:
var colorFacet = session.Query<Car, Cars_Index>()
.Where(a => a.Status == CarStatus.Used)
.ToFacets("facets/Cars");
var statusFacet = session.Query<Car, Cars_Index>()
.Where(a => a.Color == "Red")
.ToFacets("facets/Cars");
What I would like to achieve:
UI
Color: [x] Red (3) [ ] Blue (4) [ ] White (12)
Status: [x] Used (3) [ ] New (7)
So get the number of Red Used cars, Blue Used cars, White used cars and User red cars and New red cars. So the user has an immediate feedback what will happen when he clicks a checkbox.
Which with growing number and variability of facets becomes unmanageable. Is there a way how to set it up, that it can be executed in one request/query.
Thanks
That isn't how facets are working with RavenDB (or in general, for that matter).
You look at facets based on your current query, not intersection of all the facets.