The Battle for Wesnoth  1.19.7+dev
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
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 
20 
23 class game_config_view;
24 namespace editor {
25 
26 class editor_toolkit;
27 
28 /**
29  * List of starting locations and location ids. Shows a single-column list, with buttons to add
30  * new items to the list and to jump to that location on the map.
31  */
33 
34 public:
35 
37 
38 
39  virtual sdl_handler_vector handler_members() override;
40 
41  void set_start_item(std::size_t index) override { items_start_ = index; }
42 
43  std::size_t start_num(void) override { return items_start_; }
44 
45  /** Menu expanding for palette group list */
46  void expand_palette_groups_menu(std::vector<config>& items, int i) override
47  {
48  items.erase(items.begin() + i);
49  }
50 
51  virtual void set_group(std::size_t /*index*/) override {}
52  virtual void next_group() override {}
53  virtual void prev_group() override {}
54  virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
55 
56  /** Called by draw_manager to validate layout before drawing. */
57  virtual void layout() override;
58  /** Called by widget::draw() */
59  virtual void draw_contents() override;
60 
61  /**
62  * Update the size of this widget.
63  *
64  * Use if the size_specs have changed.
65  */
66  void adjust_size(const SDL_Rect& target) override;
67 
68  virtual bool scroll_up() override;
69  virtual bool can_scroll_up() override;
70  virtual bool scroll_down() override;
71  virtual bool can_scroll_down() override;
72 
73  virtual void swap() override {}
74  virtual bool supports_swap() override { return false; }
75 
76  std::string get_help_string() const { return ""; }
77 
78  /** Return the currently selected item. */
79  const std::string& selected_item() const { return selected_item_; }
80 
81  virtual void select_item(const std::string& item_id);
82  virtual std::vector<std::string> action_pressed() const override;
83  void add_item(const std::string& id);
85  void hide(bool hidden) override;
86 
87 private:
88  /** Scroll the editor-palette to the top. */
89  void scroll_top();
90 
91  virtual bool is_selected_item(const std::string& id);
92 
93  /** Return the number of items in the palette. */
94  std::size_t num_items() override;
95  /**
96  * Return the number of GUI elements that can show items. Some of these may be hidden, if there
97  * are more of them than items to show, or if the palette has been scrolled to the bottom.
98  */
99  std::size_t num_visible_items();
100 protected:
101 
103  // the height of a row, the size of an item including borders.
105 
106 protected:
107  // the current scrolling position
108  std::size_t items_start_;
109 
110 private:
111  std::string selected_item_;
112  std::vector<std::string> items_;
114  std::vector<location_palette_item> buttons_;
115  std::unique_ptr<location_palette_button> button_add_;
116  std::unique_ptr<location_palette_button> button_delete_;
117  std::unique_ptr<location_palette_button> button_goto_;
119 };
120 
121 
122 } //end namespace editor
List of starting locations and location ids.
virtual bool can_scroll_down() override
std::unique_ptr< location_palette_button > button_goto_
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
std::vector< std::string > items_
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
void scroll_top()
Scroll the editor-palette to the top.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
void hide(bool hidden) override
void set_start_item(std::size_t index) override
std::vector< location_palette_item > buttons_
std::size_t num_items() override
Return the number of items in the palette.
const std::string & selected_item() const
Return the currently selected item.
virtual bool can_scroll_up() override
virtual void next_group() override
std::size_t start_num(void) override
virtual void draw_contents() override
Called by widget::draw()
virtual void prev_group() override
void add_item(const std::string &id)
virtual bool is_selected_item(const std::string &id)
std::string get_help_string() const
virtual bool supports_swap() override
Whether the hotkey system should the enable GUI button connected to swap().
virtual const std::vector< item_group > & get_groups() const override
std::unique_ptr< location_palette_button > button_add_
virtual sdl_handler_vector handler_members() override
virtual void swap() override
For tools which support fg and bg items, exchange the two items.
virtual std::vector< std::string > action_pressed() const override
std::size_t num_visible_items()
Return the number of GUI elements that can show items.
virtual void set_group(std::size_t) override
void expand_palette_groups_menu(std::vector< config > &items, int i) override
Menu expanding for palette group list.
virtual void select_item(const std::string &item_id)
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
std::unique_ptr< location_palette_button > button_delete_
location_palette(editor_display &gui, editor_toolkit &toolkit)
A class grating read only view to a vector of config objects, viewed as one config with all children ...
bool hidden() const
Definition: widget.cpp:161
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:182
std::size_t i
Definition: function.cpp:1029
Manage the empty-palette in the editor.
Definition: action.cpp:31
General purpose widgets.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70