aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pre.hpp3
-rw-r--r--src/system_headers.hpp3
-rw-r--r--src/ui/render/flex_layout_render_object.cpp12
-rw-r--r--src/ui/render/text_render_object.cpp22
4 files changed, 32 insertions, 8 deletions
diff --git a/src/pre.hpp b/src/pre.hpp
index dfa0666c..eefc828d 100644
--- a/src/pre.hpp
+++ b/src/pre.hpp
@@ -4,6 +4,9 @@
#define CRU_DEBUG
#endif
+#define NOMINMAX
+#define WIN32_LEAN_AND_MEAN
+
#ifdef CRU_DEBUG
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
diff --git a/src/system_headers.hpp b/src/system_headers.hpp
index 6cbad697..5517d71a 100644
--- a/src/system_headers.hpp
+++ b/src/system_headers.hpp
@@ -2,9 +2,6 @@
#include "pre.hpp"
//include system headers
-
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windowsx.h>
diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp
index 5383c462..4708d187 100644
--- a/src/ui/render/flex_layout_render_object.cpp
+++ b/src/ui/render/flex_layout_render_object.cpp
@@ -33,8 +33,16 @@ RenderObject* FlexLayoutRenderObject::HitTest(const Point& point) {
return result;
}
}
- return Rect{Point::Zero(), GetSize()}.IsPointInside(point) ? this : nullptr;
-}
+
+ const auto margin = GetMargin();
+ const auto size = GetSize();
+ return Rect{margin.left, margin.top,
+ std::max(size.width - margin.GetHorizontalTotal(), 0.0f),
+ std::max(size.height - margin.GetVerticalTotal(), 0.0f)}
+ .IsPointInside(point)
+ ? this
+ : nullptr;
+} // namespace cru::ui::render
void FlexLayoutRenderObject::OnAddChild(RenderObject* new_child, int position) {
child_layout_data_.emplace(child_layout_data_.cbegin() + position);
diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp
index b90dae71..d57335ad 100644
--- a/src/ui/render/text_render_object.cpp
+++ b/src/ui/render/text_render_object.cpp
@@ -1,5 +1,7 @@
#include "text_render_object.hpp"
+#include <algorithm>
+
#include "exception.hpp"
#include "graph/graph.hpp"
@@ -57,13 +59,27 @@ void TextRenderObject::Draw(ID2D1RenderTarget* render_target) {
}
RenderObject* TextRenderObject::HitTest(const Point& point) {
- return Rect{Point::Zero(), GetSize()}.IsPointInside(point) ? this : nullptr;
+ const auto margin = GetMargin();
+ const auto size = GetSize();
+ return Rect{margin.left, margin.top,
+ std::max(size.width - margin.GetHorizontalTotal(), 0.0f),
+ std::max(size.height - margin.GetVerticalTotal(), 0.0f)}
+ .IsPointInside(point)
+ ? this
+ : nullptr;
}
void TextRenderObject::OnSizeChanged(const Size& old_size,
const Size& new_size) {
- ThrowIfFailed(text_layout_->SetMaxWidth(new_size.width));
- ThrowIfFailed(text_layout_->SetMaxHeight(new_size.height));
+ const auto margin = GetMargin();
+ const auto padding = GetPadding();
+ ThrowIfFailed(text_layout_->SetMaxWidth(
+ std::max(new_size.width - margin.GetHorizontalTotal() -
+ padding.GetHorizontalTotal(),
+ 0.0f)));
+ ThrowIfFailed(text_layout_->SetMaxHeight(std::max(
+ new_size.height - margin.GetVerticalTotal() - padding.GetVerticalTotal(),
+ 0.0f)));
}
Size TextRenderObject::OnMeasureContent(const Size& available_size) {