|
1 | 1 | #ifndef EKG_LAYOUT_DOCKNIZE_H |
2 | 2 | #define EKG_LAYOUT_DOCKNIZE_H |
3 | 3 |
|
4 | | -#include "ekg/ui/abstract/ui_abstract_widget.hpp" |
5 | | -#include "ekg/util/geometry.hpp" |
| 4 | +#include "ekg/ui/abstract.hpp" |
| 5 | +#include "ekg/math/geometry.hpp" |
| 6 | +#include "ekg/io/layout.hpp" |
6 | 7 |
|
7 | | -/** |
8 | | - * Returns the dimensional extent based in count and the offset (space between rects). |
9 | | - * |
10 | | - * The pixel imperfect issue was solved here... |
11 | | - * For a long time I did not know what was going on with the pixels, |
12 | | - * some solutions I used did not work, then I discovered that all the time |
13 | | - * was this dimension extent with float imprecision loss. |
14 | | - * |
15 | | - * Each pixels represent 1.0f, if the GPU receives pixels with |
16 | | - * (n + f) `n` a non-floating point number and `f` a floating point; |
17 | | - * the rasterizer will jump between pixels, resulting in pixel-imperfect. |
18 | | - * |
19 | | - * The following formula make you understand: |
20 | | - * ( (g - d) - (c * o) ) / c |
21 | | - * |
22 | | - * g = group rect |
23 | | - * d = dimensional extent |
24 | | - * c = amount of widgets with fill property flag until any flag next |
25 | | - * o = UI offset setting |
26 | | - * |
27 | | - * Float-only without the int32_t cast may results in pixel-imperfect |
28 | | - * due the influence of dimensional size of parent rect, font height, font width etc. |
29 | | - * |
30 | | - * - Rina. |
31 | | - **/ |
32 | | -#define ekg_layout_get_dimensional_extent(dimension, extent, offset, count) \ |
33 | | -( \ |
34 | | - (static_cast<int32_t>(dimension) - static_cast<int32_t>(extent) - static_cast<int32_t>(count * offset)) \ |
35 | | -) / static_cast<int32_t>(count) \ |
| 8 | +namespace ekg::layout { |
| 9 | + /** |
| 10 | + * Returns the dimensional extent based in count and the offset (space between rects). |
| 11 | + * |
| 12 | + * The pixel imperfect issue was solved here... |
| 13 | + * For a long time I did not know what was going on with the pixels, |
| 14 | + * some solutions I used did not work, then I discovered that all the time |
| 15 | + * was this dimension extent with float imprecision loss. |
| 16 | + * |
| 17 | + * Each pixels represent 1.0f, if the GPU receives pixels with |
| 18 | + * (n + f) `n` a non-floating point number and `f` a floating point; |
| 19 | + * the rasterizer will jump between pixels, resulting in pixel-imperfect. |
| 20 | + * |
| 21 | + * The following formula make you understand: |
| 22 | + * ( (g - d) - (c * o) ) / c |
| 23 | + * |
| 24 | + * g = group rect |
| 25 | + * d = dimensional extent |
| 26 | + * c = amount of widgets with fill property flag until any flag next |
| 27 | + * o = UI offset setting |
| 28 | + * |
| 29 | + * Float-only without the int32_t cast may results in pixel-imperfect |
| 30 | + * due the influence of dimensional size of parent rect, font height, font width etc. |
| 31 | + * |
| 32 | + * - Rina. |
| 33 | + **/ |
| 34 | + constexpr float transform_dimension_from_extent( |
| 35 | + float dimension, |
| 36 | + float extent, |
| 37 | + float offset, |
| 38 | + int32_t count |
| 39 | + ) { |
| 40 | + return static_cast<float>( |
| 41 | + ( |
| 42 | + static_cast<int32_t>(dimension) |
| 43 | + - |
| 44 | + static_cast<int32_t>(extent) |
| 45 | + - |
| 46 | + static_cast<int32_t>(count * offset) |
| 47 | + ) |
| 48 | + / |
| 49 | + count |
| 50 | + ); |
| 51 | + } |
36 | 52 |
|
37 | | -/** |
38 | | - * Pixel imperfection is a problem for UI widget placements, this macro provides |
39 | | - * correction position for right/bottom based on left/top position. |
40 | | - * |
41 | | - * It is important to understand that is impossible to remove all the pixel |
42 | | - * imperfections, but there are ways to round it, as example, you can place widget |
43 | | - * from a side (left or right, top or bottom) and align with an offset. That is how EKG fix it. |
44 | | - * |
45 | | - * This method calculate the minimum possible position based on left until the pixel |
46 | | - * escape for two or more offsets distance. Instead you use the container width directly |
47 | | - * to calculate right widgets positions, EKG must use the left consistency to get the |
48 | | - * real container (width/height) from the side of left (when using the container width directly |
49 | | - * the position is pixel imperfect). |
50 | | - * |
51 | | - * - Rina. |
52 | | - **/ |
53 | | -#define ekg_layout_get_pixel_perfect_position(side_a, side_b, container_dimension, offset) \ |
54 | | - ekg_min( \ |
55 | | - ( \ |
56 | | - (side_a + (container_dimension - side_a) + offset) \ |
57 | | - - \ |
58 | | - side_b \ |
59 | | - ), \ |
60 | | - side_a \ |
61 | | - ) \ |
| 53 | + /** |
| 54 | + * Pixel imperfection is a problem for UI widget placements, this macro provides |
| 55 | + * correction position for right/bottom based on left/top position. |
| 56 | + * |
| 57 | + * It is important to understand that is impossible to remove all the pixel |
| 58 | + * imperfections, but there are ways to round it, as example, you can place widget |
| 59 | + * from a side (left or right, top or bottom) and align with an offset. That is how EKG fix it. |
| 60 | + * |
| 61 | + * This method calculate the minimum possible position based on left until the pixel |
| 62 | + * escape for two or more offsets distance. Instead you use the container width directly |
| 63 | + * to calculate right widgets positions, EKG must use the left consistency to get the |
| 64 | + * real container (width/height) from the side of left (when using the container width directly |
| 65 | + * the position is pixel imperfect). |
| 66 | + * |
| 67 | + * - Rina. |
| 68 | + **/ |
| 69 | + constexpr float transform_to_pixel_perfect_position( |
| 70 | + float side_a, |
| 71 | + float side_b, |
| 72 | + float container_dimension, |
| 73 | + float offset |
| 74 | + ) { |
| 75 | + return ekg::min_clamp( |
| 76 | + ( |
| 77 | + (side_a + (container_dimension - side_a) + offset) |
| 78 | + - |
| 79 | + (side_b) |
| 80 | + ), |
| 81 | + side_a |
| 82 | + ); |
| 83 | + } |
62 | 84 |
|
63 | | -namespace ekg::layout { |
64 | 85 | class mask { |
65 | 86 | protected: |
66 | 87 | std::vector<ekg::rect_descriptor_t> rect_descriptor_list {}; |
@@ -88,8 +109,8 @@ namespace ekg::layout { |
88 | 109 | * A mid-functional feature to process dock position from widgets. |
89 | 110 | * Note: Recursive. |
90 | 111 | **/ |
91 | | - void docknize( |
92 | | - ekg::ui::abstract_widget *p_parent_widget |
| 112 | + void docknize_widget( |
| 113 | + ekg::ui::abstract *p_parent_widget |
93 | 114 | ); |
94 | 115 | } |
95 | 116 |
|
|
0 commit comments