How to do dynamic drawing from inside of VID - red

I have some code that is supposed to do some drawing from inside VID. People have suggested using the draw block for using it inside VID. I am trying to do that here, but perhaps not correctly.
Here is some code that shows the basic idea of what I am trying to do.
Red [Needs: 'View]
Consolas: make font! [size: 11 name: "Consolas" style: 'bold]
win: [ size 600x400
a: area 460x400 rate 0:0:3 on-time [
a/draw [
font Consolas
text 10x20 "Miter"
text 170x20 "Round"
text 330x20 "Bevel"
]
]
]
view win
This code does not create any errors, but does not do any drawing.
How can I change the code to actually do the drawing?
The key here is that I am trying to do drawing conditionally based on other factors which will help to determine what is supposed to be drawn. But if I can't get this working, there's no hope for adding in logic.

Here is a correct version of your code:
Red [Needs: 'View]
Consolas: make font! [size: 11 name: "Consolas" style: 'bold]
view [
size 600x400
a: base 460x400 draw [
font Consolas
text 10x20 "Miter"
text 170x20 "Round"
text 330x20 "Bevel"
]
]
I have made the following changes:
area creates a text area native widget that does not support drawing, so it is replaced by base which is the generic face supporting drawing.
rate 0:0:3 and on-time handler together create a timer that will evaluate the handler every 3 seconds, so irrelevant here.
a/draw is not the correct syntax for specifying a draw block as option to a face definition in VID.
The win: word setting has been removed, and the VID block is fed to view directly for sake of simplicity in this case.
You can join our Gitter help room if you need more help in learning Red and its GUI system.

Related

Unity UI Canvas & SetPass calls & TextMeshProUGUI order

I am trying to minimize SetPass calls in Unity canvas.
Consider the following example:
The rendering in canvas happens layer by layer. The rendering sequence can be like the following:
Red squares (+1 set pass call)
Text "1" and yellow squares (+2 set pass call)
Text "2" and pink square (+2 set pass call)
Text "3" (+1 set pass call)
Or, it might be a little better:
Red squares (+1 set pass call)
Yellow squares and then text "1" (+1 set pass call)
Pink square and then texts "2" and "3" (+2 set pass calls)
Because of this, drawing is switching from default image material to text material and back. The result of this drawing will produce at least 4 draw calls, instead of 2. Even though only 2 materials are in use. This example also assumes that Red, Yellow, and Pink squares weren't batched.
Question: is there a way to ensure that text will be always drawn on top?
Notes:
TextMeshPro UI material (mobile-overlay) doesn't help here.
Unity 2019.3.12.f1
All texts are actually placed as last layers (e.g. there is nothing drawing on top of them).
Batching helps sometimes. However, complex UI might use several materials. Since my intention is to always draw text over everything, isn't there a general solution for this?
Z-order makes drawing order even worse and switching between materials happens more frequently.

Netlogo, Altering the location of label

I am just curious if it's possible to alter the location of the labels in NetLogo. For example in the image below the word "La Grande Soufriere", is it possible to move it above the breed instead of below (as you can see it gets in the way of the other agents. Another case is the Habitants PMA (Actual name is Vieux Habitants) but only half of its name has appeared since the rest of its off-screen. I tried to manually type on a close-by patch but since I have used a fill color, it doesn't appear at all (it's covered by the fill color if you know what I mean). Does anyone have a solution for this?
I am just curious if it's possible to alter the location of the labels in NetLogo.
The short answer is that it is not possible.
The slightly longer answer is that there are ways around it, but they're not very satisfying.
If you want to alter the horizontal location, you can pad your label with spaces at the end or the beginning of the string to move it left or right, respectively.
If you want to alter the vertical location, or have more control over it, you can always create a "dummy" turtle to display the label. You can hide the dummy turtle without hidding its label by setting the size of the turtle to zero or by creating an empty turtle shape and using that for it.
I don't think it matters in your case, since you seem to want to label only stationary turtles, but if you wanted a dummy to move with a particular turtle, you can create a hidden link between them and tie them.
There might be other creative ways to deal with labels (and I'd be curious to read about them in other answers), but that's all I can think of for now.

Avoid text clipping of symbols in Mapbox GL JS

I have defined some symbols with text properties to act as a label for some other symbols. With the text-halo property I tried to make a background for the text. However, when zoomed out, the text starts clipping and becomes quite unreadable. Example below:
The layout of these four symbols is defined as follows:
'text-font': ['Open Sans Regular'],
'text-field': '{metadata}',
'symbol-placement': 'point',
'text-size': 20,
'text-allow-overlap': true,
'text-offset': [0, -2],
'text-anchor': 'top'
And the paint property of the symbols:
'text-halo-color': '#fff',
'text-halo-width': 5
I want the label on top covering the others completely, like the behaviour of a z-index in CSS. Any ideas? I already tried a dozen combinations of all the possible property values but can't seem to find anything.
As you have noticed, all halos are drawn first, then text. So a halo will never cover the text of another layer. This behaviour is intentional, and has been discussed here.
The obvious workaround would be to not use text-allow-overlap, and find some other solution to whatever problem you were trying to solve using that.

Cairo graphics: Engrave a text in a figure and also making it transparently

I have a question regarding Cairo codings (http://cairographics.org/).
I have a filled rectangle (cairo_fill (cr)), how can I cut a hole in the middle of it representing for example the letter "S"?
So basically, I want to "engrave" text in that rectangle but also making the text transparent (like cutting a hole in the rectangle).
Anyone have any tips?
Set the fill rule to even-odd and use cairo_text_path() to get the shape of the letter "S", then cairo_fill() as you do now.

Word Styles to get two elements to share same background/border

Within MS Word 2013 I am trying to create a text element plus a list underneath it, all wrapped inside a coloured border with background shading (see image). The attached image shows the text in plain form.
I would like to place a blue border around both the title and the list. I can achieve this by placing both objects within a 1x1 table and applying colouring rules to the cell, but semantically this seems bad (I'm from an HTML development background where it is very wrong!)
When I edit a Style rule to create the border/background, it works well until I create the list, then it goes badly wrong. Is it possible to achieve the output of the table cell approach by only using a style rule and no table?
After a day of experimentation, the closest I can get is by doing the following:
Create a style rule called Tips Heading based on Normal, then set it to be Bold with a blue background.
Create another style rule called Tips List based on List Paragraph, and set it to have a blue background.
Unfortunately the List cannot be indented because the background colour also indents. The border is also affected in this manner, so I ignored the border and indentation. It works really well and is semantically well structured.