diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/render/flex_layout_render_object.cpp | 30 | ||||
| -rw-r--r-- | src/ui/window.cpp | 15 | 
2 files changed, 33 insertions, 12 deletions
| diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp index 0093f1ad..a9841813 100644 --- a/src/ui/render/flex_layout_render_object.cpp +++ b/src/ui/render/flex_layout_render_object.cpp @@ -161,15 +161,15 @@ Size FlexLayoutRenderObject::OnMeasureContent(const Size& available_size) {  }  void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) { -  auto calculate_anchor = [](Alignment alignment, float start_point, +  auto calculate_anchor = [](int alignment, float start_point,                               float total_length,                               float content_length) -> float {      switch (alignment) { -      case Alignment::Start: +      case internal::align_start:          return start_point; -      case Alignment::Center: +      case internal::align_center:          return start_point + (total_length - content_length) / 2.0f; -      case Alignment::End: +      case internal::align_end:          return start_point + total_length - content_length;        default:          return 0; @@ -184,8 +184,9 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {        actual_content_width += child->GetPreferredSize().width;      } -    const float content_anchor_x = calculate_anchor( -        content_main_align_, 0, content_rect.width, actual_content_width); +    const float content_anchor_x = +        calculate_anchor(static_cast<int>(content_main_align_), 0, +                         content_rect.width, actual_content_width);      float anchor_x = 0;      for (int i = 0; i < children.size(); i++) { @@ -199,8 +200,10 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {          real_anchor_x = content_rect.GetRight() - real_anchor_x;        child->Layout(Rect{            real_anchor_x, -          calculate_anchor(child_layout_data_[i].alignment, content_rect.top, -                           content_rect.height, size.height), +          calculate_anchor( +              static_cast<int>(child_layout_data_[i].cross_alignment.value_or( +                  this->item_cross_align_)), +              content_rect.top, content_rect.height, size.height),            size.width, size.height});        anchor_x += size.width; @@ -211,8 +214,9 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {        actual_content_height = child->GetPreferredSize().height;      } -    const float content_anchor_y = calculate_anchor( -        content_main_align_, 0, content_rect.height, actual_content_height); +    const float content_anchor_y = +        calculate_anchor(static_cast<int>(content_main_align_), 0, +                         content_rect.height, actual_content_height);      float anchor_y = 0;      for (int i = 0; i < children.size(); i++) { @@ -227,8 +231,10 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {        }        child->Layout(Rect{            real_anchor_y, -          calculate_anchor(child_layout_data_[i].alignment, content_rect.left, -                           content_rect.width, size.width), +          calculate_anchor( +              static_cast<int>(child_layout_data_[i].cross_alignment.value_or( +                  this->item_cross_align_)), +              content_rect.left, content_rect.width, size.width),            size.width, size.height});        anchor_y += size.height; diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 2215826a..4a1bc108 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -147,6 +147,21 @@ render::RenderObject* Window::GetRenderObject() const {    return render_object_.get();  } +void Window::Relayout() { this->render_object_->MeasureAndLayout(); } + +void Window::InvalidateLayout() { +  if (!need_layout_) { +    platform::native::IUiApplication::GetInstance()->InvokeLater( +        [resolver = this->CreateResolver()] { +          if (const auto window = resolver.Resolve()) { +            window->Relayout(); +            window->need_layout_ = false; +          } +      }); +    need_layout_ = true; +  } +} +  bool Window::RequestFocusFor(Control* control) {    assert(control != nullptr);  // The control to request focus can't be null.                                 // You can set it as the window. | 
