Skip to content

Commit c4e24a7

Browse files
committed
gap can draw rectangle
1 parent dca519d commit c4e24a7

File tree

7 files changed

+81
-12
lines changed

7 files changed

+81
-12
lines changed

src/ruis/widget/base/color_widget.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525

2626
using namespace ruis;
2727

28-
color_widget::color_widget(utki::shared_ref<ruis::context> context, parameters params) :
28+
color_widget::color_widget(
29+
utki::shared_ref<ruis::context> context,
30+
parameters params //
31+
) :
2932
widget(std::move(context), {}, {}),
3033
params(std::move(params))
3134
{}

src/ruis/widget/base/color_widget.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class color_widget : public virtual widget
4747
parameters params;
4848

4949
protected:
50-
color_widget(utki::shared_ref<ruis::context> context, parameters params);
50+
color_widget(
51+
utki::shared_ref<ruis::context> context,
52+
parameters params //
53+
);
5154

5255
public:
5356
color_widget(const color_widget&) = delete;

src/ruis/widget/label/gap.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

2424
using namespace ruis;
2525

26-
gap::gap(utki::shared_ref<ruis::context> context, all_parameters params) :
27-
widget(std::move(context), std::move(params.layout_params), std::move(params.widget_params))
26+
gap::gap(
27+
utki::shared_ref<ruis::context> context,
28+
all_parameters params //
29+
) :
30+
widget(
31+
std::move(context),
32+
std::move(params.layout_params),
33+
std::move(params.widget_params) //
34+
),
35+
color_widget(
36+
this->context,
37+
std::move(params.color_params) //
38+
)
2839
{}
40+
41+
void gap::render(const mat4& matrix) const
42+
{
43+
if (this->get_current_color().is_undefined()) {
44+
return;
45+
}
46+
47+
// draw rectangle
48+
auto& r = this->context.get().renderer.get();
49+
50+
ruis::matrix4 matr(matrix);
51+
matr.scale(this->rect().d);
52+
53+
r.shaders().color_pos->render(
54+
matr, //
55+
r.obj().pos_quad_01_vao.get(),
56+
this->get_current_color().to_vec4f()
57+
);
58+
}

src/ruis/widget/label/gap.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#pragma once
2323

24-
#include "../widget.hpp"
24+
#include "../base/color_widget.hpp"
2525

2626
namespace ruis {
2727

28-
class gap : virtual public widget
28+
class gap : public color_widget
2929
{
3030
public:
3131
struct all_parameters {
3232
layout_parameters layout_params;
3333
widget::parameters widget_params;
34+
color_widget::parameters color_params = {
35+
.color = {},
36+
.disabled_color = {} //
37+
};
3438
};
3539

36-
gap(utki::shared_ref<ruis::context> context, all_parameters params);
40+
gap(
41+
utki::shared_ref<ruis::context> context,
42+
all_parameters params //
43+
);
44+
45+
void render(const mat4& matrix) const override;
3746
};
3847

3948
namespace make {
40-
inline utki::shared_ref<ruis::gap> gap(utki::shared_ref<ruis::context> context, ruis::gap::all_parameters params)
49+
inline utki::shared_ref<ruis::gap> gap(
50+
utki::shared_ref<ruis::context> context, //
51+
ruis::gap::all_parameters params
52+
)
4153
{
4254
return utki::make_shared<ruis::gap>( //
4355
std::move(context),

src/ruis/widget/label/rectangle.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,31 @@ rectangle::rounded_corners_texture::rounded_corners_texture(
380380

381381
void rectangle::update_rounded_corners_texture()
382382
{
383-
if (!this->params.rounded_corners) {
383+
if (std::find_if(
384+
this->params.corner_radius.begin(),
385+
this->params.corner_radius.end(),
386+
[](const auto& e) {
387+
return !e.get().is_undefined();
388+
}
389+
) == this->params.corner_radius.end())
390+
{
384391
this->rounded_corners_tex.reset();
385392
return;
386393
}
387394

395+
// std::array<real, 4> actual_corner_radius;
396+
// std::transform(
397+
// this->params.corner_radius.begin(),
398+
// this->params.corner_radius.end(),
399+
// actual_corner_radius.begin(),
400+
// [this](const auto& r) -> real {
401+
// if (r.get().is_undefined()) {
402+
// return 0;
403+
// }
404+
// return r.get().get(this->context);
405+
// } //
406+
// );
407+
388408
auto borders = this->get_actual_borders();
389409

390410
// TODO: develop algorithm to go through cache from time to time and drop zombie textures

src/ruis/widget/label/rectangle.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class rectangle :
3737
{
3838
public:
3939
struct parameters {
40-
bool rounded_corners = false;
40+
// TODO: comment
41+
sides<styled<length>> corner_radius;
4142
};
4243

4344
private:

tests/app2/src/rectangles_window.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ utki::shared_ref<ruis::widget> make_rectangles_window(
8686
.color = 0xff800000
8787
},
8888
.rectangle_params{
89-
.rounded_corners = true
89+
.corner_radius = {0, 3_pp, 5_pp, 10_pp}
9090
}
9191
},
9292
{
@@ -111,7 +111,7 @@ utki::shared_ref<ruis::widget> make_rectangles_window(
111111
}
112112
},
113113
.rectangle_params{
114-
.rounded_corners = true
114+
.corner_radius = {3_pp}
115115
},
116116
.rectangle_button_params{
117117
// TODO:

0 commit comments

Comments
 (0)