The Battle for Wesnoth  1.17.17+dev
horizontal_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2023
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 
22 
23 namespace gui2
24 {
25 namespace implementation
26 {
27 struct builder_horizontal_scrollbar;
28 }
29 
30 // ------------ WIDGET -----------{
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * A horizontal scrollbar is a widget that shows a horizontal scrollbar.
36  * This widget is most of the time used in a container to control the scrolling of its contents.
37  *
38  * The resolution for a horizontal scrollbar also contains the following keys:
39  * Key |Type |Default |Description
40  * -------------------------|------------------------------------|---------|-------------
41  * 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.
42  * 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.
43  * left_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the left which can't be used by the positioner.
44  * right_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the right which can't be used by the positioner.
45  * The following states exist:
46  * * state_enabled - the horizontal scrollbar is enabled.
47  * * state_disabled - the horizontal scrollbar is disabled.
48  * * state_pressed - the left mouse button is down on the positioner of the horizontal scrollbar.
49  * * state_focussed - the mouse is over the positioner of the horizontal scrollbar.
50  */
52 {
54 
55 public:
57 
58 private:
59  /** Inherited from scrollbar_base. */
60  virtual unsigned get_length() const override
61  {
62  return get_width();
63  }
64 
65  /** Inherited from scrollbar_base. */
66  virtual unsigned minimum_positioner_length() const override;
67 
68  /** Inherited from scrollbar_base. */
69  virtual unsigned maximum_positioner_length() const override;
70 
71  /** Inherited from scrollbar_base. */
72  virtual unsigned offset_before() const override;
73 
74  /** Inherited from scrollbar_base. */
75  virtual unsigned offset_after() const override;
76 
77  /** Inherited from scrollbar_base. */
78  virtual bool on_positioner(const point& coordinate) const override;
79 
80  /** Inherited from scrollbar_base. */
81  virtual int on_bar(const point& coordinate) const override;
82 
83  /** Inherited from scrollbar_base. */
84  virtual bool in_orthogonal_range(const point& coordinate) const override;
85 
86  /** Inherited from scrollbar_base. */
87  virtual int get_length_difference(const point& original, const point& current) const override
88  {
89  return current.x - original.x;
90  }
91 
92 public:
93  /** Static type getter that does not rely on the widget being constructed. */
94  static const std::string& type();
95 
96 private:
97  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
98  virtual const std::string& get_control_type() const override;
99 };
100 
101 // }---------- DEFINITION ---------{
102 
104 {
105  explicit horizontal_scrollbar_definition(const config& cfg);
106 
108  {
109  explicit resolution(const config& cfg);
110 
113 
114  unsigned left_offset;
115  unsigned right_offset;
116  };
117 };
118 
119 // }---------- BUILDER -----------{
120 
121 namespace implementation
122 {
123 
125 {
126  explicit builder_horizontal_scrollbar(const config& cfg);
127 
129 
130  virtual std::unique_ptr<widget> build() const override;
131 };
132 
133 } // namespace implementation
134 
135 // }------------ END --------------
136 
137 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
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:326
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