Skip to content

Commit 581e261

Browse files
committed
table_list resize cells
1 parent 156e9fb commit 581e261

File tree

4 files changed

+89
-28
lines changed

4 files changed

+89
-28
lines changed

src/ruis/widget/group/list.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ class list :
3636
// NOTE: order of virtual public and private declarations here matters for clang due to some bug,
3737
// see
3838
// http://stackoverflow.com/questions/42427145/clang-cannot-cast-to-private-base-while-there-is-a-public-virtual-inheritance
39+
// UPDATE 2025-07-29: private container inheritance changed to be public.
3940
virtual public widget,
40-
public container, // TODO: does it have to be public container? can be changed to private?
41+
// inherit container publicly because sometimes it is needed to access current visible child widgets of the list
42+
public container,
4143
public oriented,
4244
public list_providable
4345
{

src/ruis/widget/group/table_list.cpp

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

2626
using namespace ruis;
2727

28-
namespace {
28+
namespace ruis::internal {
2929
class provider : public list_provider
3030
{
3131
public:
@@ -48,7 +48,7 @@ class provider : public list_provider
4848
{
4949
auto cells = this->table_list_provider.get().get_row_widgets(index);
5050

51-
// TODO: size cells
51+
this->owner.arrange_list_item_cells(cells);
5252

5353
// clang-format off
5454
return make::container(this->context,
@@ -65,7 +65,7 @@ class provider : public list_provider
6565
// clang-format on
6666
}
6767
};
68-
} // namespace
68+
} // namespace ruis::internal
6969

7070
namespace {
7171
utki::shared_ref<ruis::tiling_area> make_headers_widget(
@@ -89,9 +89,41 @@ utki::shared_ref<ruis::tiling_area> make_headers_widget(
8989
table_list::table_list(
9090
utki::shared_ref<ruis::context> context, //
9191
all_parameters params
92+
) :
93+
table_list(
94+
make_headers_widget(
95+
context, //
96+
std::move(params.table_list_params.column_headers)
97+
),
98+
// clang-format off
99+
ruis::make::list(context,
100+
{
101+
.layout_params{
102+
.dims = {ruis::dim::fill, ruis::dim::fill},
103+
.weight = 1
104+
},
105+
.list_providable_params{
106+
.provider = [&]() -> utki::shared_ref<list_provider> {
107+
return utki::make_shared<internal::provider>(
108+
*this,
109+
std::move(params.table_list_params.provider)
110+
);
111+
}()
112+
}
113+
}
114+
),
115+
// clang-format on
116+
params
117+
)
118+
{}
119+
120+
table_list::table_list(
121+
utki::shared_ref<tiling_area> headers, //
122+
utki::shared_ref<list> rows_list,
123+
all_parameters& params
92124
) :
93125
ruis::widget(
94-
std::move(context), //
126+
headers.get().context, //
95127
std::move(params.layout_params),
96128
std::move(params.widget_params)
97129
),
@@ -104,29 +136,39 @@ table_list::table_list(
104136
}
105137
},
106138
{
107-
make_headers_widget(this->context,
108-
std::move(params.table_list_params.column_headers)
109-
),
110-
ruis::make::list(this->context,
111-
{
112-
.layout_params{
113-
.dims = {ruis::dim::fill, ruis::dim::fill},
114-
.weight = 1
115-
},
116-
.list_providable_params{
117-
.provider = [&]() -> utki::shared_ref<list_provider> {
118-
return utki::make_shared<::provider>(
119-
*this,
120-
std::move(params.table_list_params.provider)
121-
);
122-
}()
123-
}
124-
}
125-
)
139+
headers,
140+
rows_list
126141
}
127-
)
128-
// clang-format on
129-
{}
142+
),
143+
// clang-format on
144+
headers_tiling_area(std::move(headers)),
145+
table_rows_list(std::move(rows_list))
146+
{
147+
this->headers_tiling_area.get().tiles_resized_handler = [this](auto& ta) {
148+
for (auto& child : this->table_rows_list.get().children()) {
149+
auto* c = dynamic_cast<ruis::container*>(&child.get());
150+
ASSERT(c)
151+
this->arrange_list_item_cells(c->children());
152+
}
153+
};
154+
}
155+
156+
void table_list::arrange_list_item_cells(ruis::semiconst_widget_list& cells)
157+
{
158+
real pos = 0;
159+
for (auto [c, h] : utki::views::zip(cells, this->headers_tiling_area.get().content().children())) {
160+
auto md = c.get().measure({
161+
h.get().rect().d.x(),
162+
-1 //
163+
});
164+
c.get().resize(md);
165+
c.get().move_to({
166+
pos,
167+
0 //
168+
});
169+
pos += md.x();
170+
}
171+
}
130172

131173
utki::shared_ref<ruis::table_list> make::table_list(
132174
utki::shared_ref<ruis::context> context, //

src/ruis/widget/group/table_list.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
#include "../container.hpp"
2525

2626
#include "list.hpp"
27+
#include "tiling_area.hpp"
2728

2829
namespace ruis {
2930

31+
namespace internal {
32+
class provider;
33+
} // namespace internal
34+
3035
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this, "std::enable_shared_from_this is public via widget inheritance")
3136
class table_list :
3237
virtual public widget, //
3338
private container
3439
{
40+
friend class ruis::internal::provider;
41+
3542
public:
3643
/**
3744
* @brief A class for accessing the tree data model.
@@ -89,6 +96,16 @@ class table_list :
8996
);
9097

9198
private:
99+
table_list(
100+
utki::shared_ref<tiling_area> ta, //
101+
utki::shared_ref<list> l,
102+
all_parameters& params
103+
);
104+
105+
void arrange_list_item_cells(ruis::semiconst_widget_list& cells);
106+
107+
utki::shared_ref<tiling_area> headers_tiling_area;
108+
utki::shared_ref<list> table_rows_list;
92109
};
93110

94111
namespace make {

tests/app2/src/table_list_window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ utki::shared_ref<ruis::widget> make_table_list_window(
9494
ruis::widget_list get_row_widgets(size_t index) override{
9595
return {
9696
m::text(this->context, {}, U"Hi!"s),
97-
m::text(this->context, {}, U"How are you?"s),
97+
m::text(this->context, {.widget_params{.clip = true}}, U"How are you?"s),
9898
m::text(this->context, {}, U"Fine!"s)
9999
};
100100
}

0 commit comments

Comments
 (0)