From 5066dd64940ef293f8dcdcc3d2689a45003ab64b Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 8 Apr 2022 12:36:23 +0300 Subject: [PATCH] Support a separate text bbox in ui::edit --- libs/ui/include/psemek/ui/edit.hpp | 3 +++ libs/ui/source/edit.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libs/ui/include/psemek/ui/edit.hpp b/libs/ui/include/psemek/ui/edit.hpp index cd10e35c..e0c4bbf3 100644 --- a/libs/ui/include/psemek/ui/edit.hpp +++ b/libs/ui/include/psemek/ui/edit.hpp @@ -79,6 +79,8 @@ namespace psemek::ui state_t state() const { return state_; } + void set_text_shape(geom::box const & box); + private: std::u32string text_; font_type font_; @@ -91,6 +93,7 @@ namespace psemek::ui bool caret_visible_ = true; box_shape shape_; + geom::box text_box_; state_t state_ = state_t::normal; diff --git a/libs/ui/source/edit.cpp b/libs/ui/source/edit.cpp index f85f477f..ea37bf7d 100644 --- a/libs/ui/source/edit.cpp +++ b/libs/ui/source/edit.cpp @@ -226,6 +226,7 @@ namespace psemek::ui void edit::reshape(geom::box const & bbox) { shape_.box = bbox; + text_box_ = bbox; } geom::box edit::size_constraints() const @@ -285,26 +286,26 @@ namespace psemek::ui switch (halign_) { case halignment::left: - offset[0] = shape_.box[0].min; + offset[0] = text_box_[0].min; break; case halignment::center: - offset[0] = shape_.box[0].center() - cached_state_->size[0] * 0.5f; + offset[0] = text_box_[0].center() - cached_state_->size[0] * 0.5f; break; case halignment::right: - offset[0] = shape_.box[0].max - cached_state_->size[0]; + offset[0] = text_box_[0].max - cached_state_->size[0]; break; } switch (valign_) { case valignment::top: - offset[1] = shape_.box[1].min; + offset[1] = text_box_[1].min; break; case valignment::center: - offset[1] = shape_.box[1].center() - cached_state_->size[1] * 0.5f; + offset[1] = text_box_[1].center() - cached_state_->size[1] * 0.5f; break; case valignment::bottom: - offset[1] = shape_.box[1].max - cached_state_->size[1]; + offset[1] = text_box_[1].max - cached_state_->size[1]; break; } @@ -338,6 +339,11 @@ namespace psemek::ui } } + void edit::set_text_shape(geom::box const & box) + { + text_box_ = box; + } + void edit::on_state_changed() { cached_state_ = std::nullopt;