The Battle for Wesnoth  1.17.0-dev
horizontal_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 widget* build() const override;
131 };
132 
133 } // namespace implementation
134 
135 // }------------ END --------------
136 
137 } // namespace gui2
Base class for a scroll bar.
Definition: scrollbar.hpp:41
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
A horizontal scrollbar is a widget that shows a horizontal scrollbar.
Base class for all widgets.
Definition: widget.hpp:49
int x
x coordinate.
Definition: point.hpp:45
Generic file dialog.
Definition: field-fwd.hpp:23
Holds a 2D point.
Definition: point.hpp:24
virtual int get_length_difference(const point &original, const point &current) const override
Inherited from scrollbar_base.
virtual unsigned get_length() const override
Inherited from scrollbar_base.
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.