The Battle for Wesnoth  1.17.0-dev
horizontal_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 
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 widget* build() const override;
130 };
131 
132 } // namespace implementation
133 
134 // }------------ END --------------
135 
136 } // namespace gui2
Base class for a scroll bar.
Definition: scrollbar.hpp:40
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:48
int x
x coordinate.
Definition: point.hpp:44
Generic file dialog.
Definition: field-fwd.hpp:22
Holds a 2D point.
Definition: point.hpp:23
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:392
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:59
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.