xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
scrollable_control.h
Go to the documentation of this file.
1 #pragma once
5 #include "control.h"
6 #include "system_information.h"
7 
9 namespace xtd {
11  namespace forms {
18  class forms_export_ scrollable_control : public control {
19  public:
22  virtual bool auto_scroll() const {return auto_scroll_;}
26  virtual scrollable_control& auto_scroll(bool auto_scroll) {
27  if (auto_scroll_ != auto_scroll) {
28  auto_scroll_ = auto_scroll;
29  recreate_handle();
30  }
31  return *this;
32  }
33 
36  drawing::size auto_scroll_margin() const {return auto_scroll_margin_;}
41  if (auto_scroll_margin_ != value) {
42  auto_scroll_margin_ = value;
43  perform_layout();
44  }
45  return *this;
46  }
47 
50  drawing::rectangle display_rectangle() const override {return display_rectangle_;}
51 
54  virtual bool h_scroll() const {return h_scroll_;}
58  virtual scrollable_control& h_scroll(bool h_scroll) {
59  if (h_scroll_ != h_scroll) {
60  h_scroll_ = h_scroll;
61  recreate_handle();
62  }
63  return *this;
64  }
65 
68  virtual bool v_scroll() const {return v_scroll_;}
72  virtual scrollable_control& v_scroll(bool v_scroll) {
73  if (v_scroll_ != v_scroll) {
74  v_scroll_ = v_scroll;
75  recreate_handle();
76  }
77  return *this;
78  }
79 
80  protected:
82  scrollable_control() = default;
83 
84  forms::create_params create_params() const override;
85 
86  void on_layout(const event_args& e) override {
88  if (auto_scroll_) {
89  display_rectangle_ = control::client_rectangle();
90  display_rectangle_.height(display_rectangle_.height() - system_information::horizontal_scroll_bar_height());
91  display_rectangle_.width(display_rectangle_.width() - system_information::vertical_scroll_bar_width());
92  for (auto item : controls()) {
93  if (item.get().visible())
94  display_rectangle_ = drawing::rectangle::make_union(display_rectangle_, item.get().bounds());
95  }
96  display_rectangle_.width(display_rectangle_.width() + auto_scroll_margin_.width());
97  display_rectangle_.height(display_rectangle_.height() + auto_scroll_margin_.height());
98  }
99  }
100 
102  bool auto_scroll_ = false;
103  bool h_scroll_ = false;
104  bool v_scroll_ = false;
105  drawing::rectangle display_rectangle_;
106  drawing::size auto_scroll_margin_;
108  };
109  }
110 }
virtual scrollable_control & v_scroll(bool v_scroll)
Sets a value indicating whether the vertical scroll bar is visible.
Definition: scrollable_control.h:72
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
static int32_t horizontal_scroll_bar_height()
Gets the default height, in pixels, of the horizontal scroll bar.
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual const drawing::rectangle & client_rectangle() const
Gets the rectangle that represents the client area of the control.
virtual bool h_scroll() const
Gets a value indicating whether the horizontal scroll bar is visible.
Definition: scrollable_control.h:54
drawing::size auto_scroll_margin() const
Gets the size of the auto-scroll margin.
Definition: scrollable_control.h:36
virtual void on_layout(const event_args &e)
Raises the control::layout event.
void on_layout(const event_args &e) override
Raises the control::layout event.
Definition: scrollable_control.h:86
Contains xtd::forms::system_information class.
Defines a base class for controls that support auto-scrolling behavior.
Definition: scrollable_control.h:18
scrollable_control & auto_scroll_margin(const drawing::size &value)
Sets the size of the auto-scroll margin.
Definition: scrollable_control.h:40
virtual bool auto_scroll() const
Gets a value indicating whether the container enables the user to scroll to any controls placed outsi...
Definition: scrollable_control.h:22
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
virtual scrollable_control & auto_scroll(bool auto_scroll)
Sets a value indicating whether the container enables the user to scroll to any controls placed outsi...
Definition: scrollable_control.h:26
drawing::rectangle display_rectangle() const override
Gets the rectangle that represents the virtual display area of the control.
Definition: scrollable_control.h:50
Contains xtd::forms::control control.
virtual scrollable_control & h_scroll(bool h_scroll)
Sets a value indicating whether the horizontal scroll bar is visible.
Definition: scrollable_control.h:58
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual bool v_scroll() const
Gets a value indicating whether the vertical scroll bar is visible.
Definition: scrollable_control.h:68