simple_grid_layout.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_BUBBLE_SIMPLE_GRID_LAYOUT_H_
  5. #define ASH_BUBBLE_SIMPLE_GRID_LAYOUT_H_
  6. #include "ash/ash_export.h"
  7. #include "third_party/abseil-cpp/absl/types/optional.h"
  8. #include "ui/gfx/geometry/size.h"
  9. #include "ui/views/layout/layout_manager_base.h"
  10. #include "ui/views/layout/proposed_layout.h"
  11. namespace ash {
  12. // A custom grid layout that facilitates the removal of views from the grid,
  13. // which can change the number of rows required. `views::GridLayout` makes this
  14. // case difficult. `SimpleGridLayout` assumes all children have identical sizes.
  15. class ASH_EXPORT SimpleGridLayout : public views::LayoutManagerBase {
  16. public:
  17. SimpleGridLayout(int column_count, int column_spacing, int row_spacing);
  18. SimpleGridLayout(const SimpleGridLayout&) = delete;
  19. SimpleGridLayout& operator=(const SimpleGridLayout&) = delete;
  20. ~SimpleGridLayout() override;
  21. protected:
  22. // views::LayoutManagerBase:
  23. views::ProposedLayout CalculateProposedLayout(
  24. const views::SizeBounds& size_bounds) const override;
  25. void OnLayoutChanged() override;
  26. private:
  27. gfx::Size GetChildPreferredSize() const;
  28. gfx::Size CalculatePreferredSize() const;
  29. mutable absl::optional<gfx::Size> cached_child_preferred_size_;
  30. const int column_count_;
  31. const int column_spacing_;
  32. const int row_spacing_;
  33. };
  34. } // namespace ash
  35. #endif // ASH_BUBBLE_SIMPLE_GRID_LAYOUT_H_