The Battle for Wesnoth  1.19.0-dev
horizontal_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
19 
21 
22 namespace gui2
23 {
24 namespace implementation
25 {
26 struct builder_horizontal_scrollbar;
27 }
28 
29 // ------------ WIDGET -----------{
30 
31 /**
32  * @ingroup GUIWidgetWML
33  *
34  * A horizontal scrollbar is a widget that shows a horizontal scrollbar.
35  * This widget is most of the time used in a container to control the scrolling of its contents.
36  *
37  * The resolution for a horizontal scrollbar also contains the following keys:
38  * Key |Type |Default |Description
39  * -------------------------|------------------------------------|---------|-------------
40  * minimum_positioner_length| @ref guivartype_unsigned "unsigned"|mandatory|The minimum size the positioner is allowed to be. The engine needs to know this in order to calculate the best size for the positioner.
41  * maximum_positioner_length| @ref guivartype_unsigned "unsigned"|0 |The maximum size the positioner is allowed to be. If minimum and maximum are the same value the positioner is fixed size. If the maximum is 0 (and the minimum not) there's no maximum.
42  * left_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the left which can't be used by the positioner.
43  * right_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the right which can't be used by the positioner.
44  * The following states exist:
45  * * state_enabled - the horizontal scrollbar is enabled.
46  * * state_disabled - the horizontal scrollbar is disabled.
47  * * state_pressed - the left mouse button is down on the positioner of the horizontal scrollbar.
48  * * state_focussed - the mouse is over the positioner of the horizontal scrollbar.
49  */
51 {
53 
54 public:
56 
57 private:
58  /** Inherited from scrollbar_base. */
59  virtual unsigned get_length() const override
60  {
61  return get_width();
62  }
63 
64  /** Inherited from scrollbar_base. */
65  virtual unsigned minimum_positioner_length() const override;
66 
67  /** Inherited from scrollbar_base. */
68  virtual unsigned maximum_positioner_length() const override;
69 
70  /** Inherited from scrollbar_base. */
71  virtual unsigned offset_before() const override;
72 
73  /** Inherited from scrollbar_base. */
74  virtual unsigned offset_after() const override;
75 
76  /** Inherited from scrollbar_base. */
77  virtual bool on_positioner(const point& coordinate) const override;
78 
79  /** Inherited from scrollbar_base. */
80  virtual int on_bar(const point& coordinate) const override;
81 
82  /** Inherited from scrollbar_base. */
83  virtual bool in_orthogonal_range(const point& coordinate) const override;
84 
85  /** Inherited from scrollbar_base. */
86  virtual int get_length_difference(const point& original, const point& current) const override
87  {
88  return current.x - original.x;
89  }
90 
91 public:
92  /** Static type getter that does not rely on the widget being constructed. */
93  static const std::string& type();
94 
95 private:
96  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
97  virtual const std::string& get_control_type() const override;
98 };
99 
100 // }---------- DEFINITION ---------{
101 
103 {
104  explicit horizontal_scrollbar_definition(const config& cfg);
105 
107  {
108  explicit resolution(const config& cfg);
109 
112 
113  unsigned left_offset;
114  unsigned right_offset;
115  };
116 };
117 
118 // }---------- BUILDER -----------{
119 
120 namespace implementation
121 {
122 
124 {
125  explicit builder_horizontal_scrollbar(const config& cfg);
126 
128 
129  virtual std::unique_ptr<widget> build() const override;
130 };
131 
132 } // namespace implementation
133 
134 // }------------ END --------------
135 
136 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A horizontal scrollbar is a widget that shows a horizontal scrollbar.
virtual bool in_orthogonal_range(const point &coordinate) const override
Inherited from scrollbar_base.
virtual unsigned minimum_positioner_length() const override
Inherited from scrollbar_base.
virtual int on_bar(const point &coordinate) const override
Inherited from scrollbar_base.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
horizontal_scrollbar(const implementation::builder_horizontal_scrollbar &builder)
virtual unsigned offset_before() const override
Inherited from scrollbar_base.
virtual unsigned get_length() const override
Inherited from scrollbar_base.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual bool on_positioner(const point &coordinate) const override
Inherited from scrollbar_base.
virtual unsigned maximum_positioner_length() const override
Inherited from scrollbar_base.
virtual unsigned offset_after() const override
Inherited from scrollbar_base.
virtual int get_length_difference(const point &original, const point &current) const override
Inherited from scrollbar_base.
Base class for a scroll bar.
Definition: scrollbar.hpp:42
unsigned get_width() const
Definition: widget.cpp:328
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
Base class of a resolution, contains the common keys for a resolution.
Holds a 2D point.
Definition: point.hpp:25