Comments (8)
Hi guys!
These last days I was fighting with a bug. Today I found it was caused by a typo — I missed a !
before a boolean expression 😅
Now I'm trying to clean the code, but I want to share with you this screenshot:
I tested the border-radius feature using fills and strokes with alpha. I also tested the clipChildren property — that's why you can see those little green rectangles. I compared it with the non-border-radius version of the rectangle, and here are the results.
Thank you very much for your support, guys :)
Greetings!
from ocanvas.
It’s a great idea! I don’t have the time to add such a thing though, but if you or anyone else is up for it I’d be happy to take it in! 👍
from ocanvas.
I saw this issue and it looks quite interesting to me. I was thinking in something like:
const rectangle = ocanvas.display.rectangle({
// define it as a single number...
borderRadius: 10, // px unit assumed
// ... or define it as a border-radius CSS string...
borderRadius: '10px',
borderRadius: '10px 5px',
borderRadius: '10px 5px 20px',
borderRadius: '10px 5px 20px 15px',
borderRadius: '10 5 20 15', // px unit assumed
borderRadius: '10%', // percentage relative to width/height
borderRadius: '10px 50%', // mixing px and percentages
// ... or define it as an array instead of an space-separated string...
borderRadius: [10, 5, 20, 15],
borderRadius: ['10%', '5%'],
borderRadius: ['10px', '5%'],
// ... or define it like an object in a more JS way...
borderRadius: {
topLeft: 10,
topRight: '5',
bottomRight: '20px',
bottomLeft: '15%'
// not specified corners will be assumed to be 0px
}
});
I think it's better to name it as borderRadius
instead of radius
in order to prevent confusion with Polygon
's radius
property. In fact, Polygon
may have a borderRadius
in the future as well. In addition, boderRadius
is familiar for all who know the border-radius
CSS property.
@darlanmendonca I would like to implement this feature, unless you want to do it by yourself. After all, it's your idea :)
from ocanvas.
I agree, borderRadius
would be a better name. It would also be nice if it was defined as numbers, to allow the property to be animated for example. Maybe follow the naming of React Native which I guess takes its naming from CSS.
borderRadius
borderTopLeftRadius
borderTopRightRadius
borderBottomLeftRadius
borderBottomRightRadius
The shapes supported in oCanvas also handle hit detection for mouse/touch within the edge of the shape, so it would also be great if hit detection handled the rounded corners :)
from ocanvas.
Hi guys!
I was working in this feature the last few days. It's almost done, but inside and outside strokes are giving me some headaches 😅
@koggdal I saw that you draw 2 rectangles: one for the fill (using rect()
function) and another one for the stroke (using strokeRect()
function). That's giving me some problems when I try to draw a round border and an inside stroke at the same time. A picture is worth a thousand words:
As you see, there are some pixels being drawn outside the stroke. After trying hard to fix it, I arrived to the conclusion that maybe it's better to draw one single rectangle for the fill and the stroke when a border-radius has to be drawn. The width and the height of the rectangle will be calculated considering the strokePosition
and strokeWidth
properties. Do you see any problem in this?
When no border-radius has to be drawn, rect()
and strokeRect()
functions are used as usual in order to get a best performance (when a border-radius has to be drawn, I have to draw the rectangle manually using the arcTo()
function). Do you agree? :)
Cheers!
from ocanvas.
Awesome!
Not sure I fully understand what you mean by drawing a single rectangle? You can definitely use a fill to simulate the stroke, if that's what you mean :)
Optimizing the case of no border radius sounds good 👍
Btw, not sure of the state of that screenshot, but the inner edge of the stroke should also have a border radius, right?
from ocanvas.
@nestorrente sorry by delay, as time to show you, I could't do anything about it until now
@koggdal if I understand right, the print above is with bad render of borderRadius in red, is a result of draw tww rectangles, instead one.
if is helpful yet, my suggestion is draw a single rectangle, as you @nestorrente say above.
"
When no border-radius has to be drawn, rect() and strokeRect() functions are used as usual in order to get a best performance (when a border-radius has to be drawn, I have to draw the rectangle manually using the arcTo() function).
" - @nestorrente
I can't see any problems about draw a single rectangle with arcTo, in cases with borderRadius, and simple rect() and strokeRect() when not have borderRadius, since that feature draw rect
with or without borderRadius, be a single function, looks. good
but @nestorrente you are very ahead with this feature, go ahead :D
from ocanvas.
Great work! Let's continue the discussion in the PR! :)
from ocanvas.
Related Issues (20)
- text function? HOT 1
- text-decoration HOT 1
- getOrigin for fllipse widgets returns wrong value HOT 1
- getOrigin method for ellipse widget calculates wrong values HOT 2
- can't use the scale
- Ellipse widget: mouse events at wrong position, when ellipse origin is "left", "top" HOT 2
- text lineHeight
- Request for a new display object "freeform"
- Canvas zoom operation support HOT 3
- hava a function like getImageData? HOT 2
- zIndex is not work HOT 3
- about letter-spacing HOT 1
- Please help. How to draw dashed line? searched docs did not find anywhere. HOT 1
- addchild() will redraw everything? HOT 1
- Get new coordinate after drag and drop HOT 1
- I think performance is the biggest problem of ocanvas HOT 1
- Does it support webGL backend ? HOT 1
- transformPointerPosition gives incorrect coordinates when the context is scaled HOT 1
- correct hook to vue directives HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocanvas.