mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-24 10:27:18 +00:00
remove find_widget.hpp
This commit is contained in:
parent
298065e1bd
commit
f5906d6224
@ -431,7 +431,6 @@
|
||||
<Unit filename="../../src/global.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field-fwd.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/find_widget.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/exception.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.hpp" />
|
||||
|
@ -509,7 +509,6 @@
|
||||
<Unit filename="../../src/global.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field-fwd.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/find_widget.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/exception.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.hpp" />
|
||||
|
@ -504,7 +504,6 @@
|
||||
<Unit filename="../../src/global.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field-fwd.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/field.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/find_widget.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/exception.hpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.cpp" />
|
||||
<Unit filename="../../src/gui/auxiliary/iterator/iterator.hpp" />
|
||||
|
@ -1997,7 +1997,6 @@
|
||||
46F92D0A2174F6A300602C1C /* iterator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = iterator.hpp; sourceTree = "<group>"; };
|
||||
46F92D0B2174F6A300602C1C /* exception.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = exception.hpp; sourceTree = "<group>"; };
|
||||
46F92D0C2174F6A300602C1C /* walker_grid.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = walker_grid.hpp; sourceTree = "<group>"; };
|
||||
46F92D0D2174F6A300602C1C /* find_widget.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = find_widget.hpp; sourceTree = "<group>"; };
|
||||
46F92D0E2174F6A300602C1C /* tips.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = tips.hpp; sourceTree = "<group>"; };
|
||||
46F92D102174F6A300602C1C /* field-fwd.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "field-fwd.hpp"; sourceTree = "<group>"; };
|
||||
46F92D122174F6A300602C1C /* generator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = generator.cpp; sourceTree = "<group>"; };
|
||||
@ -4012,7 +4011,6 @@
|
||||
children = (
|
||||
46F92D102174F6A300602C1C /* field-fwd.hpp */,
|
||||
46F92CFD2174F6A300602C1C /* field.hpp */,
|
||||
46F92D0D2174F6A300602C1C /* find_widget.hpp */,
|
||||
46F92D002174F6A300602C1C /* iterator */,
|
||||
46F92CFC2174F6A300602C1C /* tips.cpp */,
|
||||
46F92D0E2174F6A300602C1C /* tips.hpp */,
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/auxiliary/field-fwd.hpp"
|
||||
#include "gui/widgets/styled_widget.hpp"
|
||||
#include "gui/widgets/selectable_item.hpp"
|
||||
@ -75,7 +74,7 @@ public:
|
||||
void attach_to_window(window& window)
|
||||
{
|
||||
assert(!widget_);
|
||||
widget_ = find_widget<styled_widget>(&window, id(), false, mandatory_);
|
||||
widget_ = window.find_widget<styled_widget>(id(), false, mandatory_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2007 - 2024
|
||||
by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "global.hpp"
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
#include "utils/const_clone.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the first parent of a widget with a certain type.
|
||||
*
|
||||
* @param child The widget to get the parent from,
|
||||
* @tparam T The class of the widget to return.
|
||||
*
|
||||
* @returns The parent widget.
|
||||
*/
|
||||
template <class T>
|
||||
T& get_parent(widget& child)
|
||||
{
|
||||
T* result;
|
||||
widget* w = &child;
|
||||
do {
|
||||
w = w->parent();
|
||||
result = dynamic_cast<T*>(w);
|
||||
|
||||
} while(w && !result);
|
||||
|
||||
assert(result);
|
||||
return *result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a widget with the wanted id.
|
||||
*
|
||||
* This template function doesn't return a pointer to a generic widget but
|
||||
* returns the wanted type and tests for its existence if required.
|
||||
*
|
||||
* @param widget The widget test or find a child with the wanted
|
||||
* id.
|
||||
* @param id The id of the widget to find.
|
||||
* @param must_be_active The widget should be active, not all widgets
|
||||
* have an active flag, those who don't ignore
|
||||
* flag.
|
||||
* @param must_exist The widget should be exist, the function will
|
||||
* fail if the widget doesn't exist or is
|
||||
* inactive and must be active. Upon failure a
|
||||
* wml_error is thrown.
|
||||
*
|
||||
* @returns The widget with the id.
|
||||
*/
|
||||
template <class T>
|
||||
NOT_DANGLING T* find_widget(utils::const_clone_ptr<widget, T> widget,
|
||||
const std::string& id,
|
||||
const bool must_be_active,
|
||||
const bool must_exist)
|
||||
{
|
||||
T* result = dynamic_cast<T*>(widget->find(id, must_be_active));
|
||||
VALIDATE(!must_exist || result, missing_widget(id));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a widget with the wanted id.
|
||||
*
|
||||
* This template function doesn't return a reference to a generic widget but
|
||||
* returns a reference to the wanted type
|
||||
*
|
||||
* @param widget The widget test or find a child with the wanted
|
||||
* id.
|
||||
* @param id The id of the widget to find.
|
||||
* @param must_be_active The widget should be active, not all widgets
|
||||
* have an active flag, those who don't ignore
|
||||
* flag.
|
||||
*
|
||||
* @returns The widget with the id.
|
||||
*/
|
||||
template <class T>
|
||||
NOT_DANGLING T& find_widget(utils::const_clone_ptr<widget, T> widget,
|
||||
const std::string& id,
|
||||
const bool must_be_active)
|
||||
{
|
||||
return *find_widget<T>(widget, id, must_be_active, true);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void on_widget(utils::const_clone_ptr<widget, T> parent, const std::string& id, std::function<void(T&)> func)
|
||||
{
|
||||
if(auto widget = find_widget<T>(parent, id, false, false)) {
|
||||
func(*widget);
|
||||
}
|
||||
}
|
||||
} // namespace gui2
|
@ -18,7 +18,6 @@
|
||||
#include "gui/dialogs/help_browser.hpp"
|
||||
|
||||
#include "game_config_manager.hpp"
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/image.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user