Skip to content

Commit 156e9fb

Browse files
committed
stuff
1 parent 016fbc1 commit 156e9fb

File tree

13 files changed

+194
-61
lines changed

13 files changed

+194
-61
lines changed

src/ruis/layout/size_layout.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626

2727
using namespace ruis;
2828

29-
void size_layout::lay_out(const vector2& dims, semiconst_widget_list& widgets) const
29+
void size_layout::lay_out(
30+
const vector2& dims, //
31+
semiconst_widget_list& widgets
32+
) const
3033
{
3134
for (const auto& w : widgets) {
3235
if (w.get().is_layout_dirty()) {
33-
auto d = dims_for_widget(w.get(), dims);
36+
using std::max;
37+
auto d = dims_for_widget(
38+
w.get(), //
39+
max(
40+
dims - w.get().rect().p,
41+
{0, 0} //
42+
)
43+
);
3444
w.get().resize(d);
3545
}
3646
}

src/ruis/layout/size_layout.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ namespace ruis {
2828
class size_layout : public trivial_layout
2929
{
3030
public:
31-
void lay_out(const vector2& dims, semiconst_widget_list& widgets) const override;
31+
void lay_out(
32+
const vector2& dims, //
33+
semiconst_widget_list& widgets
34+
) const override;
3235
};
3336

3437
} // namespace ruis

src/ruis/layout/trivial_layout.cpp

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

2626
using namespace ruis;
2727

28-
vector2 trivial_layout::measure(const vector2& quotum, const_widget_list& widgets) const
28+
vector2 trivial_layout::measure(
29+
const vector2& quotum, //
30+
const_widget_list& widgets
31+
) const
2932
{
30-
return max(quotum, 0);
33+
if (quotum.is_positive_or_zero()) {
34+
return quotum;
35+
}
36+
37+
vec2 max_extent(0, 0);
38+
39+
for (const auto& widget : widgets) {
40+
const auto& w = widget.get();
41+
42+
auto extent = w.rect().x2_y2();
43+
44+
using std::max;
45+
max_extent = max(extent, max_extent);
46+
}
47+
48+
vec2 ret;
49+
for (auto [r, q, me] : utki::views::zip(ret, quotum, max_extent)) {
50+
if (q < 0) {
51+
r = me;
52+
} else {
53+
r = q;
54+
}
55+
}
56+
57+
return ret;
3158
}
3259

33-
void trivial_layout::lay_out(const vector2& dims, semiconst_widget_list& widgets) const
60+
void trivial_layout::lay_out(
61+
const vector2& dims, //
62+
semiconst_widget_list& widgets
63+
) const
3464
{
3565
for (auto& w : widgets) {
3666
auto& ww = w.get();

src/ruis/layout/trivial_layout.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ namespace ruis {
2828
class trivial_layout : public layout
2929
{
3030
public:
31-
vector2 measure(const vector2& quotum, const_widget_list& widgets) const override;
32-
33-
void lay_out(const vector2& dims, semiconst_widget_list& widgets) const override;
31+
vector2 measure(
32+
const vector2& quotum, //
33+
const_widget_list& widgets
34+
) const override;
35+
36+
void lay_out(
37+
const vector2& dims, //
38+
semiconst_widget_list& widgets
39+
) const override;
3440
};
3541

3642
} // namespace ruis

src/ruis/widget/base/list_providable.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ class list_providable
119119

120120
virtual ~list_providable() = default;
121121

122-
void set_provider(std::shared_ptr<list_provider> provider);
123-
124122
list_provider* get_provider()
125123
{
126124
return this->params.provider.get();
@@ -132,6 +130,11 @@ class list_providable
132130
}
133131

134132
virtual void handle_model_change() {}
133+
134+
// TODO: make private?
135+
void set_provider(std::shared_ptr<list_provider> provider);
136+
137+
private:
135138
};
136139

137140
} // namespace ruis

src/ruis/widget/group/list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ list::list(
3838
),
3939
ruis::container(this->context, {.container_params = {.layout = layout::trivial}}, {}),
4040
oriented(std::move(params.oriented_params)),
41-
list_providable(std::move(params.providable_params))
41+
list_providable(std::move(params.list_providable_params))
4242
{}
4343

4444
void list::on_lay_out()

src/ruis/widget/group/list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class list :
6060
layout_parameters layout_params;
6161
widget::parameters widget_params;
6262
oriented::parameters oriented_params;
63-
list_providable::parameters providable_params;
63+
list_providable::parameters list_providable_params;
6464
};
6565

6666
list(

src/ruis/widget/group/overlay.cpp

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

2424
#include <utki/config.hpp>
2525

26-
#include "../../context.hpp"
27-
#include "../../layout/pile_layout.hpp"
28-
#include "../../layout/size_layout.hpp"
2926
#include "../container.hpp"
3027
#include "../proxy/mouse_proxy.hpp"
3128

src/ruis/widget/group/table_list.cpp

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

2626
using namespace ruis;
2727

28+
namespace {
29+
class provider : public list_provider
30+
{
31+
public:
32+
table_list& owner;
33+
34+
const utki::shared_ref<table_list::provider> table_list_provider;
35+
36+
provider(table_list& owner, utki::shared_ref<table_list::provider> table_list_provider) :
37+
list_provider(table_list_provider.get().context),
38+
owner(owner),
39+
table_list_provider(std::move(table_list_provider))
40+
{}
41+
42+
size_t count() const noexcept override
43+
{
44+
return this->table_list_provider.get().count();
45+
}
46+
47+
utki::shared_ref<ruis::widget> get_widget(size_t index) override
48+
{
49+
auto cells = this->table_list_provider.get().get_row_widgets(index);
50+
51+
// TODO: size cells
52+
53+
// clang-format off
54+
return make::container(this->context,
55+
{
56+
.layout_params{
57+
.dims = {ruis::dim::max, ruis::dim::min}
58+
},
59+
.container_params{
60+
.layout = ruis::layout::trivial
61+
}
62+
},
63+
std::move(cells)
64+
);
65+
// clang-format on
66+
}
67+
};
68+
} // namespace
69+
2870
namespace {
2971
utki::shared_ref<ruis::tiling_area> make_headers_widget(
3072
const utki::shared_ref<ruis::context>& c, //
3173
ruis::widget_list column_headers
3274
)
3375
{
3476
// clang-format off
35-
return ruis::make::tiling_area(c,
36-
{
37-
.layout_params{
38-
.dims = {ruis::dim::fill, ruis::dim::min}
39-
}
40-
},
41-
std::move(column_headers)
42-
);
77+
return ruis::make::tiling_area(c,
78+
{
79+
.layout_params{
80+
.dims = {ruis::dim::fill, ruis::dim::min}
81+
}
82+
},
83+
std::move(column_headers)
84+
);
4385
// clang-format on
4486
}
4587
} // namespace
@@ -54,30 +96,35 @@ table_list::table_list(
5496
std::move(params.widget_params)
5597
),
5698
// clang-format off
57-
ruis::container(
58-
this->context,
59-
{
60-
.container_params{
61-
.layout = ruis::layout::column
62-
}
63-
},
64-
{
65-
make_headers_widget(this->context,
66-
std::move(params.table_list_params.column_headers)
67-
),
68-
ruis::make::list(this->context,
69-
{
70-
.layout_params{
71-
.dims = {ruis::dim::fill, ruis::dim::fill},
72-
.weight = 1
73-
},
74-
// .list_params{
75-
// .provider = // TODO: make provider
76-
// }
77-
}
78-
)
79-
}
80-
)
99+
ruis::container(
100+
this->context,
101+
{
102+
.container_params{
103+
.layout = ruis::layout::column
104+
}
105+
},
106+
{
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+
)
126+
}
127+
)
81128
// clang-format on
82129
{}
83130

src/ruis/widget/group/table_list.hpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,34 @@ class table_list :
3838
* This class provides access to the tree data model and constructs
3939
* widgets representing the tree items.
4040
*/
41-
class provider : private list_provider
41+
class provider
4242
{
4343
public:
44-
provider(utki::shared_ref<ruis::context> context);
44+
const utki::shared_ref<ruis::context> context;
45+
46+
provider(utki::shared_ref<ruis::context> context) :
47+
context(std::move(context))
48+
{}
49+
50+
provider(const provider&) = delete;
51+
provider& operator=(const provider&) = delete;
52+
53+
provider(provider&&) = delete;
54+
provider& operator=(provider&&) = delete;
55+
56+
virtual ~provider() = default;
57+
58+
virtual size_t count() const noexcept = 0;
4559

4660
/**
47-
* @brief Create a list item widget.
48-
* The table_list will call this mthod when it needs a widget for the given list data item.
49-
* The widget has to be a container.
50-
* Each child widget of the container widget will represent a cell in the table row.
51-
* @param index - index of the item into the list data to create widget for.
52-
* @return A container widget containing table row cell widgets.
61+
* @brief Create table row cell widgets for an item.
62+
* The table_list will call this mthod when it needs widgets for the given list data item.
63+
* A list of widgets is to be created.
64+
* Each child widget will represent a cell in the table row.
65+
* @param index - index of the item into the list data to create widgets for.
66+
* @return A list of widgets for table row cell.
5367
*/
54-
virtual utki::shared_ref<ruis::container> get_container(size_t index) = 0;
68+
virtual widget_list get_row_widgets(size_t index) = 0;
5569
};
5670

5771
struct parameters {
@@ -60,7 +74,7 @@ class table_list :
6074
* These widgets will be put inside of a horizontal ruis::tiling_area.
6175
*/
6276
ruis::widget_list column_headers = {};
63-
std::shared_ptr<table_list::provider> provider;
77+
utki::shared_ref<table_list::provider> provider;
6478
};
6579

6680
struct all_parameters {
@@ -73,6 +87,8 @@ class table_list :
7387
utki::shared_ref<ruis::context> context, //
7488
all_parameters params
7589
);
90+
91+
private:
7692
};
7793

7894
namespace make {

0 commit comments

Comments
 (0)