Rebol 3 What are the available border effects for r3gui? - rebol

I know how to adjust the size of the border within r3gui:
view [
b: box 800x400 red options [
box-model: 'frame border-size: [4x2 2x4]
]
]
But how can I make an ibevel border/edge effect known from R2/View with r3gui?
Rebol2/View example:
view [
box 800x400 red edge [size: 4x4 effect: 'ibevel color: gray]
]

The 'ibevel effect is not directly supported in Rebol3. But you should be able to achieve it using R3-GUI widget style customization using draw dialect:
stylize [
my-box: box [
facets: [
border-colors: [
65.65.65 191.191.191
]
]
draw: [
line-width 1 fixed
pen border-colors/1
fill-pen border-colors/1;
polygon border-box/top-left border-box/top-right (as-pair border-box/top-right/x - border-size/2/1 border-box/top-right/y + border-size/1/2) (border-box/top-left + border-size/1)
(as-pair border-box/bottom-left/x + border-size/1/1 border-box/bottom-left/y - border-size/2/2) border-box/bottom-left
pen border-colors/2 ;
fill-pen border-colors/2
polygon border-box/bottom-right border-box/top-right
(as-pair border-box/top-right/x - border-size/2/1 border-box/top-right/y + border-size/1/2) (as-pair border-box/bottom-right/x - border-size/2/1 border-box/bottom-right/y - border-size/2/2)
(as-pair border-box/bottom-left/x + border-size/1/1 border-box/bottom-left/y - border-size/2/2) border-box/bottom-left
]
]
]
view [
my-box 300x300 red options [
border-size: [4x2 2x4]
]
my-box 300x300 red options [
border-size: [4x8 12x24]
border-colors: [0.0.255 0.255.0]
]
]

Related

Elm img attribute too many arguments

I am extremely new to Elm, and I am encountering a problem which frustrates me to no end.
Here is my code:
view : Model -> Html Msg
view model =
img [src "Img1.png", width 300, height 300] []
div []
[ input [ onInput ChangeUserInput ] []
, button [ onClick SaveText ] [ text "Save" ]
, button [ onClick Clear ] [ text "Clear" ]
, h1 [] [text model.userInput]
]
And the error I receive is that
The `img` function expects 2 arguments, but it got 5 instead
I think its parsing the div tag arguments as img arguments, but I can't figure out how to fix it.
Your view function needs to return a single HTML element. At the moment it seems you are trying to return two elements: an img and a div. The div and its two arguments are being picked up as arguments to the img because there is nothing in your code that Elm can use to identify the end of the list of arguments to pass to the img function.
You will need to wrap them both in an element that contains them, for example, another div:
view : Model -> Html Msg
view model =
div []
[ img [ src "Img1.png", width 300, height 300 ] []
, div []
[ input [ onInput ChangeUserInput ] []
, button [ onClick SaveText ] [ text "Save" ]
, button [ onClick Clear ] [ text "Clear" ]
, h1 [] [ text model.userInput ]
]
]

Customizing the visible vuetify pagination buttons

I'm using the vuetify pagination and the code looks something like this:
<v-pagination
v-model="page"
:length="n"
total-visible="7"
></v-pagination>
Where n is greater than 7, if you're on the first few pages, it'll show the first few pages and the last few pages. I don't want it to show the last few pages.
Also, say you're on page 14 of n, it'll show the first page, pages 13-15, and the nth page. I want it to show +/- some range of pages around page 14 (range of 2 would mean 12-16 are visible). At a min, I'd want to show just the next and previous buttons.
What it does:
< [ 1 ] [ 2 ] [ 3 ] ... [ n -2 ] [ n-1 ] [ n ] >
< [ 1 ] ... [ k-1 ] [ k ] [ k+1 ] ... [ n ] >
What I want:
< [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] ... >
< ... [ k-1 ] [ k ] [ k+1 ] ... >
~OR~
< >
I added the following to the component and it "worked":
<style scoped>
/deep/ .v-pagination__item{
display: none;
}
/deep/ .v-pagination__more{
display: none;
}
</style>
...where "worked" means only the next/previous arrows are visible.

Rebol text fields - checking values and changing colors

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
]
]

Text and caret in VID or R3-Gui

A simple example:
If I type #"w" in style "area" how do I get an #"z"? (ex. "qwerty ww" -> "qzerty zz")
As you want the conversion on the fly, you can either modify R3-GUI before loading. So load r3-gui.r3 down to your local directory. Then you add the line if key == #"w" [key: #"z"] to the function do-text-key, so it looks like
do-text-key: funct [
"Process text face keyboard events."
face [object!]
event [event! object!]
key
] [
text-key-map/face: face
text-key-map/shift?: find event/flags 'shift
if no-edit: not tag-face? face 'edit [
key: any [select/skip text-key-map/no-edit key 2 key]
]
either char? key [
if key == #"w" [key: #"z"]
text-key-map/key: key
switch/default key bind text-key-map/chars 'event [
unless no-edit [
insert-text-face face key
]
]
] [
if find event/flags 'control [
key: any [select text-key-map/control key key]
]
text-key-map/key: key
switch/default key text-key-map/words [return event]
]
none
]
Probably the official way would be to use on-key wih Rebol3
load-gui
view [
a: area on-key [ ; arg: event
if arg/type = 'key [
if arg/key == #"w" [arg/key: #"z"]
]
do-actor/style face 'on-key arg face/style
]
]
And finally a way to do this with Rebol2 on the fly
key-event: func [face event] [
if event/type = 'key [
if all [event/key = #"w" ] [
append a/text #"z"
focus a
view w
return false
]
]
event
]
insert-event-func :key-event
view w: layout [
a: area
]
After reading some files of r3-gui (text-caret.r3, text-cursor.r3, text-edit.r3, text-keys.r3, text.r3) and the editor, I found a solution that allows me to insert not only a character but also string:
do %r3-gui.r3
insertText-moveCursor-updateFace: func [
face
string
n-move
][
insert-text-face face string
move-cursor face 'left n-move false
update-text-caret face
see-caret face
show-later face
]
i-m-u: :insertText-moveCursor-updateFace
view [
area on-key [
either arg/type = 'key [
switch/default arg/key [
#"w" [i-m-u face/names/text-box "z" 0]
#"[" [i-m-u face/names/text-box "[]" 1]
#"$" [i-m-u face/names/text-box "func [] []" 4]
] [
;switch/default
do-actor/style face 'on-key arg face/style
]
] [
;arg/type != 'key
do-actor/style face 'on-key arg face/style
]
]
]
Area is a compound styles. It is composed of a text-box and a scroller. They are contained in face/names.

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...