Skip to content

Commit 1f57d26

Browse files
committed
modernize aspect_ratio_proxy test app
1 parent 042d00a commit 1f57d26

File tree

11 files changed

+288
-191
lines changed

11 files changed

+288
-191
lines changed

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@
5454
],
5555
"preLaunchTask": "build-dbg"
5656
},
57+
{
58+
"name": "(gdb) aspect_ratio_proxy",
59+
"type": "cppdbg",
60+
"request": "launch",
61+
"program": "${workspaceFolder}/tests/aspect_ratio_proxy/out/dbg/tests",
62+
"args": [],
63+
"stopAtEntry": false,
64+
"cwd": "${workspaceFolder}/tests/aspect_ratio_proxy",
65+
"environment": [
66+
{
67+
"name": "LD_LIBRARY_PATH",
68+
"value": "../../src/out/dbg:../harness/modules/ruisapp/src/out/rel_no_install:../harness/modules/ruis-render-opengl/src/out/rel_no_install"
69+
}
70+
],
71+
"externalConsole": false,
72+
"MIMode": "gdb",
73+
"setupCommands": [
74+
{
75+
"description": "Enable pretty-printing for gdb",
76+
"text": "-enable-pretty-printing",
77+
"ignoreFailures": true
78+
}
79+
],
80+
"preLaunchTask": "build-dbg"
81+
},
5782
{
5883
"name": "(gdb) busy",
5984
"type": "cppdbg",

.vscode/tasks.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@
9494
"group": "build"
9595
},
9696
{
97-
"label": "run-ratio_proxy",
97+
"label": "run-aspect_ratio_proxy",
9898
"type": "shell",
99-
"command": "make run-ratio_proxy",
99+
"command": "make run-aspect_ratio_proxy",
100100
"problemMatcher": [],
101101
"group": "build"
102102
},
103103
{
104-
"label": "run-ratio_proxy-dbg",
104+
"label": "run-aspect_ratio_proxy-dbg",
105105
"type": "shell",
106-
"command": "make run-ratio_proxy config=dbg",
106+
"command": "make run-aspect_ratio_proxy config=dbg",
107107
"problemMatcher": [],
108108
"group": "build"
109109
},

src/ruis/gui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4848
#include "widget/label/image_mouse_cursor.hpp"
4949
#include "widget/label/spinner.hpp"
5050
#include "widget/label/text.hpp"
51+
#include "widget/proxy/aspect_ratio_proxy.hpp"
5152
#include "widget/proxy/click_proxy.hpp"
5253
#include "widget/proxy/key_proxy.hpp"
5354
#include "widget/proxy/min_proxy.hpp"
54-
#include "widget/proxy/ratio_proxy.hpp"
5555
#include "widget/proxy/resize_proxy.hpp"
5656
#include "widget/slider/scroll_bar.hpp"
5757

@@ -225,7 +225,7 @@ gui::gui(const utki::shared_ref<ruis::context>& context) :
225225
// proxy
226226
this->context.get().inflater.register_widget<mouse_proxy>("mouse_proxy");
227227
this->context.get().inflater.register_widget<click_proxy>("click_proxy");
228-
this->context.get().inflater.register_widget<ratio_proxy>("ratio_proxy");
228+
this->context.get().inflater.register_widget<aspect_ratio_proxy>("aspect_ratio_proxy");
229229
this->context.get().inflater.register_widget<key_proxy>("key_proxy");
230230
this->context.get().inflater.register_widget<resize_proxy>("resize_proxy");
231231
this->context.get().inflater.register_widget<min_proxy>("min_proxy");
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
ruis - GUI framework
3+
4+
Copyright (C) 2012-2025 Ivan Gagis <[email protected]>
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 "aspect_ratio_proxy.hpp"
23+
24+
using namespace ruis;
25+
26+
aspect_ratio_proxy::aspect_ratio_proxy(const utki::shared_ref<ruis::context>& c, const tml::forest& desc) :
27+
ruis::widget(c, desc)
28+
{
29+
for (const auto& p : desc) {
30+
if (!is_property(p)) {
31+
continue;
32+
}
33+
34+
if (p.value == "ratio") {
35+
this->params.x_above_y = get_property_value(p).to_float();
36+
}
37+
}
38+
}
39+
40+
aspect_ratio_proxy::aspect_ratio_proxy(
41+
utki::shared_ref<ruis::context> context, //
42+
aspect_ratio_proxy::all_parameters params
43+
) :
44+
widget(
45+
std::move(context), //
46+
std::move(params.layout_params),
47+
std::move(params.widget_params)
48+
),
49+
params(std::move(params.aspect_ratio_params))
50+
{}
51+
52+
void aspect_ratio_proxy::set_aspect_ratio(real x_above_y)
53+
{
54+
if (this->params.x_above_y == x_above_y) {
55+
return;
56+
}
57+
58+
this->params.x_above_y = x_above_y;
59+
this->invalidate_layout();
60+
}
61+
62+
ruis::vector2 aspect_ratio_proxy::measure(const ruis::vector2& quotum) const
63+
{
64+
if (quotum.is_negative()) {
65+
return {0, 0};
66+
}
67+
68+
if (quotum.x() < 0) {
69+
return ruis::vector2(
70+
quotum.y() * this->params.x_above_y, //
71+
quotum.y()
72+
);
73+
}
74+
75+
if (quotum.y() < 0) {
76+
return ruis::vector2(
77+
quotum.x(), //
78+
quotum.x() / this->params.x_above_y
79+
);
80+
}
81+
82+
return quotum;
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
ruis - GUI framework
3+
4+
Copyright (C) 2012-2025 Ivan Gagis <[email protected]>
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 "../widget.hpp"
25+
26+
namespace ruis {
27+
28+
class aspect_ratio_proxy : virtual public widget
29+
{
30+
public:
31+
struct parameters {
32+
real x_above_y = 1;
33+
};
34+
35+
private:
36+
parameters params;
37+
38+
public:
39+
aspect_ratio_proxy(const utki::shared_ref<ruis::context>& c, const tml::forest& desc);
40+
41+
struct all_parameters {
42+
layout_parameters layout_params;
43+
widget::parameters widget_params;
44+
parameters aspect_ratio_params;
45+
};
46+
47+
aspect_ratio_proxy(
48+
utki::shared_ref<ruis::context> context, //
49+
all_parameters params
50+
);
51+
52+
aspect_ratio_proxy(const aspect_ratio_proxy&) = delete;
53+
aspect_ratio_proxy& operator=(const aspect_ratio_proxy&) = delete;
54+
55+
aspect_ratio_proxy(aspect_ratio_proxy&&) = delete;
56+
aspect_ratio_proxy& operator=(aspect_ratio_proxy&&) = delete;
57+
58+
~aspect_ratio_proxy() override = default;
59+
60+
void set_aspect_ratio(real x_above_y);
61+
62+
real get_aspect_ratio() const noexcept
63+
{
64+
return this->params.x_above_y;
65+
}
66+
67+
ruis::vector2 measure(const ruis::vector2& quotum) const override;
68+
};
69+
70+
namespace make {
71+
inline utki::shared_ref<ruis::aspect_ratio_proxy> aspect_ratio_proxy(
72+
utki::shared_ref<ruis::context> context, //
73+
ruis::aspect_ratio_proxy::all_parameters params
74+
)
75+
{
76+
return utki::make_shared<ruis::aspect_ratio_proxy>(
77+
std::move(context), //
78+
std::move(params)
79+
);
80+
}
81+
} // namespace make
82+
83+
} // namespace ruis

src/ruis/widget/proxy/ratio_proxy.cpp

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/ruis/widget/proxy/ratio_proxy.hpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)