Skip to content

Commit 016fbc1

Browse files
committed
add tiling_area::tiles_resized_handler
1 parent 71e0717 commit 016fbc1

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/ruis/widget/group/tiling_area.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ruis::real minimal_tile_size_pp = 30;
3030
const ruis::real dragger_size_pp = 5;
3131
} // namespace
3232

33-
namespace {
33+
namespace ruis::internal {
3434
class dragger : public ruis::gap
3535
{
3636
bool grabbed = false;
@@ -126,6 +126,8 @@ class dragger : public ruis::gap
126126
this->next_widget->resize_by(-delta_vec);
127127
this->next_widget->move_by(delta_vec);
128128

129+
this->owner.notify_tiles_resized();
130+
129131
return true;
130132
}
131133

@@ -136,8 +138,14 @@ class dragger : public ruis::gap
136138
}
137139

138140
if (this->is_hovered() || grabbed) {
139-
this->arrows_cursor_iter = this->context.get().cursor_stack.push(
140-
this->owner.is_vertical() ? ruis::mouse_cursor::up_down_arrow : ruis::mouse_cursor::left_right_arrow
141+
this->arrows_cursor_iter = this->context.get().cursor_stack.push( //
142+
[&]() {
143+
if (this->owner.is_vertical()) {
144+
return ruis::mouse_cursor::up_down_arrow;
145+
} else {
146+
return ruis::mouse_cursor::left_right_arrow;
147+
}
148+
}()
141149
);
142150
} else {
143151
this->context.get().cursor_stack.pop(this->arrows_cursor_iter);
@@ -151,7 +159,7 @@ class dragger : public ruis::gap
151159
}
152160
}
153161
};
154-
} // namespace
162+
} // namespace ruis::internal
155163

156164
tiling_area::tiling_area(
157165
utki::shared_ref<ruis::context> context, //
@@ -283,7 +291,7 @@ void tiling_area::on_lay_out()
283291
// add missing draggers
284292
while (this->size() - 1 < num_draggers) {
285293
this->push_back(
286-
utki::make_shared<dragger>(
294+
utki::make_shared<internal::dragger>(
287295
this->context, //
288296
*this,
289297
this->params.dragger_color
@@ -300,7 +308,7 @@ void tiling_area::on_lay_out()
300308

301309
ASSERT(index < this->content().size())
302310

303-
auto& dragger = dynamic_cast<::dragger&>(i->get());
311+
auto& dragger = dynamic_cast<internal::dragger&>(i->get());
304312

305313
dragger.prev_widget = this->content().children()[index].to_shared_ptr();
306314
dragger.next_widget = this->content().children()[index + 1].to_shared_ptr();
@@ -312,6 +320,8 @@ void tiling_area::on_lay_out()
312320
dragger_pos[long_index] = round(dragger.next_widget->rect().p[long_index] - this->dragger_size / 2);
313321
dragger.move_to(dragger_pos);
314322
}
323+
324+
this->notify_tiles_resized();
315325
}
316326

317327
ruis::vector2 tiling_area::measure(const ruis::vector2& quotum) const
@@ -347,6 +357,13 @@ ruis::vector2 tiling_area::measure(const ruis::vector2& quotum) const
347357
return ret;
348358
}
349359

360+
void tiling_area::notify_tiles_resized()
361+
{
362+
if (this->tiles_resized_handler) {
363+
this->tiles_resized_handler(*this);
364+
}
365+
}
366+
350367
utki::shared_ref<ruis::tiling_area> make::tiling_area(
351368
utki::shared_ref<ruis::context> context, //
352369
ruis::tiling_area::all_parameters params,

src/ruis/widget/group/tiling_area.hpp

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

2828
namespace ruis {
2929

30+
namespace internal {
31+
class dragger;
32+
} // namespace internal
33+
3034
/**
3135
* @brief Tiling area.
3236
* The tile_area arranges its content widgets (tiles) either vertially or horizontally.
@@ -39,6 +43,8 @@ class tiling_area :
3943
public content_wrapping,
4044
private ruis::container
4145
{
46+
friend class ruis::internal::dragger;
47+
4248
public:
4349
/**
4450
* @brief Minimal size of a tile in logitudinal direction of the tiling_area.
@@ -78,7 +84,14 @@ class tiling_area :
7884
// do nothing
7985
}
8086

87+
/**
88+
* @brief Tiles resized handler.
89+
* Invoked when tiles of the tile area have changed their sizes.
90+
*/
91+
std::function<void(tiling_area&)> tiles_resized_handler;
92+
8193
private:
94+
void notify_tiles_resized();
8295
};
8396

8497
namespace make {

0 commit comments

Comments
 (0)