Skip to content

Commit 33214dd

Browse files
committed
add rectangle_text_input_line
1 parent c16909e commit 33214dd

3 files changed

Lines changed: 189 additions & 2 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
ruis - GUI framework
3+
4+
Copyright (C) 2012-2026 Ivan Gagis <igagis@gmail.com>
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/* ================ LICENSE END ================ */
21+
22+
#include "rectangle_text_input_line.hpp"
23+
24+
#include <utki/debug.hpp>
25+
26+
using namespace ruis;
27+
28+
rectangle_text_input_line::rectangle_text_input_line(
29+
utki::shared_ref<ruis::context> context, //
30+
all_parameters params,
31+
ruis::string text
32+
) :
33+
rectangle_text_input_line(
34+
context,
35+
params,
36+
ruis::make::text_input_line(
37+
context, //
38+
{
39+
.layout_params = std::move(params.text_input_line_params.layout_params),
40+
.widget_params = std::move(params.text_input_line_params.widget_params),
41+
.text_widget_params = std::move(params.text_input_line_params.text_widget_params),
42+
.color_params = std::move(params.text_input_line_params.color_params)
43+
},
44+
std::move(text)
45+
)
46+
)
47+
{}
48+
49+
rectangle_text_input_line::rectangle_text_input_line(
50+
utki::shared_ref<ruis::context>& context, //
51+
all_parameters& params,
52+
utki::shared_ref<ruis::text_input_line> text_input_line
53+
) :
54+
widget(
55+
std::move(context), //
56+
std::move(params.layout_params),
57+
std::move(params.widget_params)
58+
),
59+
// Initialize rectangle first so it adds the text_input_line as a child
60+
// clang-format off
61+
rectangle(
62+
this->context,
63+
{
64+
.container_params = std::move(params.container_params),
65+
.padding_params = std::move(params.padding_params),
66+
.color_params = std::move(params.color_params),
67+
.rectangle_params = {
68+
.corner_radii = std::move(params.rectangle_params.corner_radii),
69+
.stroke_width = std::move(params.rectangle_params.stroke_width),
70+
// stroke_color = primary color from style
71+
.stroke_color = this->context.get().style().get_color_primary(),
72+
// fill color will be set from color_widget's color (background from style)
73+
}
74+
},
75+
{
76+
text_input_line
77+
}
78+
),
79+
// clang-format on
80+
decorated_widget<ruis::text_input_line>(
81+
this->context, //
82+
text_input_line.get()
83+
)
84+
{
85+
// Set fill color to background color from style
86+
this->set_color(this->context.get().style().get_color_background());
87+
}
88+
89+
void rectangle_text_input_line::on_focus_change()
90+
{
91+
this->decorated_widget<ruis::text_input_line>::get_decorated().on_focus_change();
92+
}
93+
94+
utki::shared_ref<ruis::rectangle_text_input_line> ruis::make::rectangle_text_input_line(
95+
utki::shared_ref<ruis::context> context, //
96+
ruis::rectangle_text_input_line::all_parameters params,
97+
ruis::string text
98+
)
99+
{
100+
return utki::make_shared<ruis::rectangle_text_input_line>(
101+
std::move(context), //
102+
std::move(params),
103+
std::move(text)
104+
);
105+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
ruis - GUI framework
3+
4+
Copyright (C) 2012-2026 Ivan Gagis <igagis@gmail.com>
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/* ================ LICENSE END ================ */
21+
22+
#pragma once
23+
24+
#include "../../base/decorated_widget.hpp"
25+
#include "../../label/rectangle.hpp"
26+
#include "../text_input_line.hpp"
27+
28+
namespace ruis {
29+
30+
/**
31+
* @brief Text input line widget with a rectangle background.
32+
* This widget combines a rectangle (with stroke and fill colors from style)
33+
* and a text_input_line as its child.
34+
*/
35+
class rectangle_text_input_line :
36+
virtual public widget, //
37+
private rectangle,
38+
public decorated_widget<text_input_line>
39+
{
40+
public:
41+
struct parameters {
42+
// Additional parameters can be added here if needed
43+
};
44+
45+
struct all_parameters {
46+
layout::parameters layout_params;
47+
widget::parameters widget_params;
48+
container::parameters container_params;
49+
padding::parameters padding_params;
50+
color_widget::parameters color_params;
51+
rectangle::parameters rectangle_params;
52+
text_input_line::all_parameters text_input_line_params;
53+
};
54+
55+
private:
56+
rectangle_text_input_line(
57+
utki::shared_ref<ruis::context>& context, //
58+
all_parameters& params,
59+
utki::shared_ref<ruis::text_input_line> text_input_line
60+
);
61+
62+
public:
63+
rectangle_text_input_line(
64+
utki::shared_ref<ruis::context> context, //
65+
all_parameters params,
66+
ruis::string text
67+
);
68+
69+
void on_focus_change() override;
70+
};
71+
72+
namespace make {
73+
utki::shared_ref<ruis::rectangle_text_input_line> rectangle_text_input_line(
74+
utki::shared_ref<ruis::context> context, //
75+
ruis::rectangle_text_input_line::all_parameters params,
76+
ruis::string text
77+
);
78+
} // namespace make
79+
80+
} // namespace ruis

‎src/ruis/widget/label/rectangle.hpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ class rectangle :
5050
*/
5151
styled<length> stroke_width;
5252

53+
// stroke_color is red by default to make it easily noticable if it is used without being set to some other color
54+
static constexpr ruis::color default_stroke_color = ruis::color(0xff, 0, 0, 0xff);
55+
5356
/**
5457
* @brief Stroke color of the rectangle.
5558
*/
56-
// stroke_color is red by default to make it easily noticable if it is used without being set to some other color
57-
styled<ruis::color> stroke_color = ruis::color(0xff, 0, 0, 0xff);
59+
styled<ruis::color> stroke_color = default_stroke_color;
5860
};
5961

6062
private:

0 commit comments

Comments
 (0)