andlabs / libui

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Other
10.71k stars 614 forks source link

Geometric Algorithms #541

Open AndyObtiva opened 2 years ago

AndyObtiva commented 2 years ago

In order to do anything of any worth with vector graphics (drawn on an area), such as drag and drop, there is a need to calculate the following:

As such, it only makes sense that the GUI library would provide such algorithms just like Java AWT does; it includes algorithms for testing if a shape contains a point in all shapes. I already make great use of it in Glimmer DSL for SWT.

Since you already make use of such algorithms to render the vector graphics in the GUI, I would imagine that exposing them as part of libui would be a small step from there.

I would greatly appreciate you making such algorithms available.

Thank you again for libui. I have been able to build apps very productively with it using Glimmer DSL for LibUI in Ruby.

AndyObtiva commented 2 years ago

I just wanted to note that I solved my need for geometric algorithms by implementing all of them in a brand new library written in pure Ruby called Perfect Shape.

That said, it is still useful to provide such algorithms in C libui, especially to software engineers from other programming languages who do not have an equivalent of Perfect Shape in their programming language of choice (or they could otherwise switch to Ruby and use Glimmer DSL for LibUI I suppose).

Cheers!

AndyObtiva commented 2 years ago

I already started integrating the geometric algorithm library Perfect Shape into Glimmer DSL for LibUI.

And, it just occurred to me; there is a scenario that Perfect Shape cannot address, which is checking if a point is contained within a drawn Text on Area (though I could approximate it if I knew the font in advance). That requires font-dependent calculations, which libui does not currently offer.

SWT provides something called the textExtent that enables software engineers to check if a point is within the extent (size) of drawn Text (varying depending on configured font). It would be great if the libui C library could provide something similar to begin. But, it would be great if it can go even further than that and let software engineers know if a point is contained within the exact area occupied by the text Glyphs (e.g. point is within all the segments that make up the letter T). That way, I could implement a use-case (mentioned to me just yesterday by a user) of being able to detect if the user is pointing with the mouse at a specific drawn word of text and then change its color or highlight another related word in response.

It would be helpful to include such features in libui for better usage by software engineers and better service for customer needs.

Cheers!

cody271 commented 2 years ago

That requires font-dependent calculations, which libui does not currently offer.

SWT provides something called the textExtent that enables software engineers to check if a point is within the extent (size) of drawn Text (varying depending on configured font). It would be great if the libui C library could provide something similar to begin.

This is already implemented with uiDrawTextLayoutExtents(), which does take the specified layout font into account.

AndyObtiva commented 2 years ago

Ahh. Thanks for pointing that out.

To be honest, I thought extent support existed, but I quickly checked the Golang LibUI docs and didn’t find it there, so then I mistakenly concluded I was wrong about extent support existing in LibUI and commented here.