Support ui::edit callback on start text input
This commit is contained in:
parent
32bb106467
commit
edccbc3ed5
2 changed files with 16 additions and 0 deletions
|
|
@ -52,6 +52,8 @@ namespace psemek::ui
|
|||
using callback_type = std::function<void(std::u32string_view)>;
|
||||
virtual void on_text_entered(callback_type callback, bool signal = true);
|
||||
|
||||
virtual void on_start_input(std::function<void()> callback);
|
||||
|
||||
bool on_event(mouse_move const & e) override;
|
||||
bool on_event(mouse_click const & e) override;
|
||||
bool on_event(key_press const & e) override;
|
||||
|
|
@ -97,6 +99,7 @@ namespace psemek::ui
|
|||
validator_type validator_;
|
||||
|
||||
callback_type on_text_entered_;
|
||||
std::function<void()> on_start_input_;
|
||||
|
||||
struct cached_state
|
||||
{
|
||||
|
|
@ -110,6 +113,7 @@ namespace psemek::ui
|
|||
void on_state_changed();
|
||||
void reset_caret();
|
||||
void post_text_entered() const;
|
||||
void post_start_input() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,11 @@ namespace psemek::ui
|
|||
post_text_entered();
|
||||
}
|
||||
|
||||
void edit::on_start_input(std::function<void()> callback)
|
||||
{
|
||||
on_start_input_ = std::move(callback);
|
||||
}
|
||||
|
||||
bool edit::on_event(mouse_move const & e)
|
||||
{
|
||||
auto m = geom::cast<float>(e.position);
|
||||
|
|
@ -115,6 +120,7 @@ namespace psemek::ui
|
|||
old_text_ = text_;
|
||||
start_text_input();
|
||||
reset_caret();
|
||||
post_start_input();
|
||||
}
|
||||
|
||||
if (cached_state_ && mouse_x_)
|
||||
|
|
@ -426,4 +432,10 @@ namespace psemek::ui
|
|||
}
|
||||
}
|
||||
|
||||
void edit::post_start_input() const
|
||||
{
|
||||
if (on_start_input_)
|
||||
post(on_start_input_);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue