xtd.forms - Reference Guide  0.1.0
Modern c++17 library containing classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and Linux like Ubuntu operating system.
scrollable_control.h
1 #pragma once
2 #include "control.h"
3 #include "system_information.h"
4 
6 namespace xtd {
8  namespace forms {
9  class scrollable_control : public control {
10  public:
11  virtual bool auto_scroll() const {return this->auto_scroll_;}
12  virtual scrollable_control& auto_scroll(bool auto_scroll) {
13  if (this->auto_scroll_ != auto_scroll) {
14  this->auto_scroll_ = auto_scroll;
15  this->recreate_handle();
16  }
17  return *this;
18  }
19 
20  drawing::size auto_scroll_margin() const {return auto_scroll_margin_;}
21  scrollable_control& auto_scroll_margin(const drawing::size& value) {
22  if (auto_scroll_margin_ != value) {
23  auto_scroll_margin_ = value;
24  on_layout(event_args::empty);
25  }
26  return *this;
27  }
28 
29  drawing::rectangle display_rectangle() const override {return display_rectangle_;}
30 
31  virtual bool hscroll() const {return this->hscroll_;}
32  virtual scrollable_control& hscroll(bool hscroll) {
33  if (this->hscroll_ != hscroll) {
34  this->hscroll_ = hscroll;
35  this->recreate_handle();
36  }
37  return *this;
38  }
39 
40  virtual bool vscroll() const {return this->vscroll_;}
41  virtual scrollable_control& vscroll(bool vscroll) {
42  if (this->vscroll_ != vscroll) {
43  this->vscroll_ = vscroll;
44  this->recreate_handle();
45  }
46  return *this;
47  }
48 
49  protected:
50  scrollable_control() = default;
51 
52  forms::create_params create_params() const override;
53 
54  void on_layout(const event_args& e) override {
55  this->control::on_layout(e);
56  if (auto_scroll_) {
57  display_rectangle_ = client_rectangle_;
58  display_rectangle_.height(display_rectangle_.height() - system_information::horizontal_scroll_bar_height());
59  display_rectangle_.width(display_rectangle_.width() - system_information::vertical_scroll_bar_width());
60  for (auto item : this->controls()) {
61  if (item.get().visible())
62  display_rectangle_ = drawing::rectangle::make_union(display_rectangle_, item.get().bounds());
63  }
64  display_rectangle_.width(display_rectangle_.width() + auto_scroll_margin_.width());
65  display_rectangle_.height(display_rectangle_.height() + auto_scroll_margin_.height());
66  }
67  }
68 
70  bool auto_scroll_ = false;
71  bool hscroll_ = false;
72  bool vscroll_ = false;
73  drawing::rectangle display_rectangle_;
74  drawing::size auto_scroll_margin_;
76  };
77  }
78 }
static int32_t horizontal_scroll_bar_height()
Gets the default height, in pixels, of the horizontal scroll bar.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
virtual control_collection & controls()
Gets the collection of controls contained within the control.
Definition: control.h:307
Definition: scrollable_control.h:9
Defines the base class for controls, which are components with visual representation.
Definition: control.h:60
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.