Removed widgets under development
parent
c0b2c6fdda
commit
d18b45317a
|
@ -1,62 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/TGUI.hpp>
|
||||
#include <TGUI/Widgets/devel/RichTextLabel.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::RenderWindow window({800,600}, "RichTextLabel widget example");
|
||||
window.setFramerateLimit(60);
|
||||
tgui::Gui gui(window);
|
||||
|
||||
tgui::RichTextLabel::Ptr label = std::make_shared<tgui::RichTextLabel>();
|
||||
label->setText(L"*bold*, ~italic~, _underlined_\n"
|
||||
"#white unicode: áéíóúçÆæÞðë\n"
|
||||
"#red red, #green green, #blue blue\n"
|
||||
"#ff6600 sexy #33ff99 hex #9933ff code #ff33cc support!\n"
|
||||
"#ffff33 ~*_EVERYTHING AT ONCE :D_*~\n"
|
||||
"#white Escaping format characters is supported: \\~\\*\\#\\_");
|
||||
label->setPosition(50, 30);
|
||||
gui.add(label);
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while(window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
gui.handleEvent(event);
|
||||
}
|
||||
|
||||
window.clear();
|
||||
gui.draw();
|
||||
window.display();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/TGUI.hpp>
|
||||
#include <TGUI/Widgets/devel/Table.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::RenderWindow window({800,600}, "Table widget example");
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
tgui::Gui gui(window);
|
||||
|
||||
auto table = std::make_shared<tgui::Table>();
|
||||
table->setSize({780, 580});
|
||||
table->setPosition({10,10});
|
||||
table->setHeaderColumns({"First Name", "Last Name", ""});
|
||||
table->setBackgroundColor({203,201,207});
|
||||
table->setFixedColumnWidth(0, 400);
|
||||
table->setStripesRowsColor({246,246,246}, {233,233,233});
|
||||
gui.add(table);
|
||||
|
||||
auto button = std::make_shared<tgui::Button>();
|
||||
button->setText("Connect");
|
||||
button->setSize({100,30});
|
||||
button->connect("pressed", [](){ std::cout << "Button pressed" << std::endl; });
|
||||
|
||||
auto tableRow = std::make_shared<tgui::TableRow>();
|
||||
tableRow->addItem("Eve");
|
||||
tableRow->addItem("Jackson");
|
||||
tableRow->add(button, true);
|
||||
|
||||
table->add(tableRow);
|
||||
table->addRow({"John", "Doe", "80"});
|
||||
table->addRow({"Adam", "Johnson", "67"});
|
||||
table->addRow({"Jill", "Smith", "50"});
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while(window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
gui.handleEvent(event);
|
||||
}
|
||||
|
||||
window.clear();
|
||||
gui.draw();
|
||||
window.display();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef TGUI_RICH_TEXT_LABEL_HPP
|
||||
#define TGUI_RICH_TEXT_LABEL_HPP
|
||||
|
||||
|
||||
#include <TGUI/Widgets/ClickableWidget.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief RichText widget
|
||||
///
|
||||
/// Based on SFML-RichText (https://bitbucket.org/jacobalbano/sfml-richtext)
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
class TGUI_API RichTextLabel : public ClickableWidget
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::shared_ptr<RichTextLabel> Ptr; ///< Shared widget pointer
|
||||
typedef std::shared_ptr<const RichTextLabel> ConstPtr; ///< Shared constant widget pointer
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Default constructor
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
RichTextLabel();
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Constructor to immediately sets the text and optionally the text size
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
RichTextLabel(const sf::String& text, unsigned int textSize = 30);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Makes a copy of another label
|
||||
///
|
||||
/// @param label The other label
|
||||
///
|
||||
/// @return The new label
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static RichTextLabel::Ptr copy(RichTextLabel::ConstPtr label);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Sets the position of the widget
|
||||
///
|
||||
/// This function completely overwrites the previous position.
|
||||
/// See the move function to apply an offset based on the previous position instead.
|
||||
/// The default position of a transformable widget is (0, 0).
|
||||
///
|
||||
/// @param position New position
|
||||
///
|
||||
/// @see move, getPosition
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setPosition(const Layout2d& position) override;
|
||||
using Transformable::setPosition;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Empty setSize function
|
||||
///
|
||||
/// @warning Setting a size will not do anything for this widget, the size it determined by the contents of this widget
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setSize(const Layout2d& size) override;
|
||||
using Transformable::setSize;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the font of the text in the widget
|
||||
///
|
||||
/// @param font The new font
|
||||
///
|
||||
/// When you don't call this function then the font from the parent widget will be used.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setFont(const Font& font) override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the text
|
||||
///
|
||||
/// @param text The new text
|
||||
///
|
||||
/// When the text is auto-sized (default), then the size of the label will be changed to fit the whole text.
|
||||
///
|
||||
/// @see setAutoSize
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setText(const sf::String& text);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the text
|
||||
///
|
||||
/// @return Text that is currently used
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const sf::String& getText() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the character size of the text
|
||||
///
|
||||
/// @param size The new text size
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextSize(unsigned int size);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the character size of the text
|
||||
///
|
||||
/// @return The current text size
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned int getTextSize() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the background color of the label
|
||||
///
|
||||
/// @param color New background color
|
||||
///
|
||||
/// The background color is transparent by default.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setBackgroundColor(const sf::Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the background color of the label
|
||||
///
|
||||
/// @return Background color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const sf::Color& getBackgroundColor() const;
|
||||
|
||||
|
||||
/// @brief Sets names for color substitutions (for example, ff0000 would be substituted for "red")
|
||||
void addColor(const sf::String& name, const sf::Color& color);
|
||||
|
||||
/// @brief Sets names for color substitutions (for example, ff0000 would be substituted for "red")
|
||||
void addColor(const sf::String& name, unsigned int argbHex);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
|
||||
sf::Color getColor(const sf::String& source) const;
|
||||
sf::Color getColor(unsigned int argbHex) const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Makes a copy of the widget
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<RichTextLabel>(*this);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Draws the widget on the render target.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
|
||||
sf::RectangleShape m_background;
|
||||
|
||||
sf::String m_string;
|
||||
|
||||
unsigned int m_textSize = 30;
|
||||
|
||||
std::map<sf::String, sf::Color> m_colors;
|
||||
std::vector<sf::Text> m_texts;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // TGUI_RICH_TEXT_LABEL_HPP
|
|
@ -1,111 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef TGUI_TABLE_HPP
|
||||
#define TGUI_TABLE_HPP
|
||||
|
||||
#include <TGUI/BoxLayout.hpp>
|
||||
#include <TGUI/Widgets/devel/TableRow.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
class TGUI_API Table: public BoxLayout
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<Table> Ptr; ///< Shared widget pointer
|
||||
typedef std::shared_ptr<const Table> ConstPtr; ///< Shared constant widget pointer
|
||||
|
||||
Table();
|
||||
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<Table>(*this);
|
||||
}
|
||||
|
||||
virtual void setFont(const Font& font) override;
|
||||
void setTextSize(unsigned int size);
|
||||
|
||||
virtual void setSize(const Layout2d& size) override;
|
||||
using Transformable::setSize;
|
||||
|
||||
bool insert(std::size_t index, const tgui::Widget::Ptr& widget, const sf::String& widgetName = "");
|
||||
virtual void add(const tgui::Widget::Ptr& widget, const sf::String& widgetName = "") override;
|
||||
void addRow(const std::vector<std::string>& columns);
|
||||
|
||||
void setHeader(const tgui::TableRow::Ptr& row);
|
||||
void setHeaderColumns(const std::vector<std::string>& columns);
|
||||
// getHeader()
|
||||
|
||||
void setFixedColumnWidth(std::size_t column, float size);
|
||||
void setColumnRatio(std::size_t column, float ratio);
|
||||
|
||||
// virtual void setFixedRowsHeight(float size);
|
||||
|
||||
// void showTableBorders(bool show = true);
|
||||
// void showColumnsBorders(bool show = true);
|
||||
// void setTableBordersColor(const sf::Color& color);
|
||||
// void setColumnsBorder(const sf::Color& color);
|
||||
|
||||
void setRowsColor(const sf::Color& color);
|
||||
void setStripesRowsColor(const sf::Color& evenColor, const sf::Color& oddColor);
|
||||
|
||||
void setTextColor(const sf::Color& color);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
virtual void updateWidgetPositions() override;
|
||||
void calculateLabelHeight();
|
||||
void updateColumnsDelimitatorsPosition();
|
||||
void updateColumnsDelimitatorsSize();
|
||||
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
tgui::TableRow::Ptr m_header = std::make_shared<tgui::TableRow>();
|
||||
|
||||
float m_rowHeight = 20;
|
||||
|
||||
sf::RectangleShape m_tableBorder;
|
||||
sf::RectangleShape m_headerSeparator;
|
||||
std::vector<sf::RectangleShape> m_columnsDelimitators;
|
||||
sf::Color m_bordersColor;
|
||||
|
||||
sf::Color m_rowsOddColor;
|
||||
sf::Color m_rowsEvenColor = sf::Color::Transparent;
|
||||
|
||||
unsigned int m_characterSize = 18;
|
||||
|
||||
sf::Color m_normalTextColor = sf::Color::Black;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // TGUI_TABLE_HPP
|
|
@ -1,82 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef TGUI_TABLE_ITEM_HPP
|
||||
#define TGUI_TABLE_ITEM_HPP
|
||||
|
||||
#include <TGUI/Widgets/Panel.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
class TGUI_API TableItem: public tgui::Panel
|
||||
{
|
||||
public:
|
||||
enum HorizontalAlign
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
None /// internal
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
typedef std::shared_ptr<TableItem> Ptr; ///< Shared widget pointer
|
||||
typedef std::shared_ptr<const TableItem> ConstPtr; ///< Shared constant widget pointer
|
||||
|
||||
TableItem();
|
||||
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<TableItem>(*this);
|
||||
}
|
||||
|
||||
void setItem(const Widget::Ptr& widgetPtr, HorizontalAlign align = Left);
|
||||
Widget::Ptr getItem() { return m_widget; }
|
||||
|
||||
void setHorizontalAlign(HorizontalAlign align);
|
||||
|
||||
void setFont(const Font& font);
|
||||
|
||||
virtual void setSize(const Layout2d& size) override;
|
||||
using Transformable::setSize;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
void updateItem();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
Widget::Ptr m_widget;
|
||||
|
||||
HorizontalAlign m_align = Left;
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // TGUI_TABLE_ITEM_HPP
|
|
@ -1,101 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef TGUI_TABLE_ROW_HPP
|
||||
#define TGUI_TABLE_ROW_HPP
|
||||
|
||||
#include <TGUI/HorizontalLayout.hpp>
|
||||
#include <TGUI/Widgets/Label.hpp>
|
||||
#include <TGUI/Widgets/devel/TableItem.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
class TGUI_API TableRow: public HorizontalLayout
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<TableRow> Ptr; ///< Shared widget pointer
|
||||
typedef std::shared_ptr<const TableRow> ConstPtr; ///< Shared constant widget pointer
|
||||
|
||||
TableRow();
|
||||
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<TableRow>(*this);
|
||||
}
|
||||
|
||||
/// TODO: Maybe return bool and to check if the row has the table columns number
|
||||
void setItem(unsigned int column, const std::string& name, TableItem::HorizontalAlign align = TableItem::None);
|
||||
void setItem(unsigned int column, const std::string& name, const sf::Color& color, TableItem::HorizontalAlign align = TableItem::None);
|
||||
|
||||
void addItem(const std::string& name);
|
||||
void addItem(const std::string& name, const sf::Color& color);
|
||||
void addItems(const std::vector<std::string>& columns, const sf::Color& color, TableItem::HorizontalAlign align = TableItem::None);
|
||||
|
||||
bool insert(std::size_t index, const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, const sf::String& widgetName = "");
|
||||
virtual void add(const tgui::Widget::Ptr& widget, const sf::String& widgetName = "") override;
|
||||
void add(const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, const sf::String& widgetName = "");
|
||||
void add(const tgui::Widget::Ptr& widget, bool fixedHeight, TableItem::HorizontalAlign align = TableItem::None, const sf::String& widgetName = "");
|
||||
|
||||
void setHoverBackgroundColor(const sf::Color& color);
|
||||
void setNormalBackgroundColor(const sf::Color& color);
|
||||
|
||||
// void setHoverTextColor(const sf::Color& color);
|
||||
void setNormalTextColor(const sf::Color& color);
|
||||
|
||||
void setItemsHorizontalAlign(TableItem::HorizontalAlign align);
|
||||
|
||||
void mouseEnteredWidget() override;
|
||||
void mouseLeftWidget() override;
|
||||
|
||||
float getCustomHeight() // internal
|
||||
{
|
||||
return m_customHeight;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
TableItem::Ptr createItem(const std::string& name, TableItem::HorizontalAlign align, const sf::Color& color = sf::Color::Black);
|
||||
TableItem::Ptr createItem(const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, bool fixedHeight = false);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
sf::Color m_normalBackgroundColor;
|
||||
sf::Color m_hoverBackgroundColor = sf::Color::Transparent;
|
||||
|
||||
sf::Color m_normalTextColor;
|
||||
|
||||
TableItem::HorizontalAlign m_align = TableItem::Left;
|
||||
|
||||
float m_customHeight = 0.f;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // TGUI_TABLE_ROW_HPP
|
|
@ -69,10 +69,6 @@ set(TGUI_SRC
|
|||
Widgets/Tabs.cpp
|
||||
Widgets/TextBox.cpp
|
||||
Widgets/ToolTip.cpp
|
||||
#Widgets/devel/RichTextLabel.cpp
|
||||
#Widgets/devel/TableItem.cpp
|
||||
#Widgets/devel/TableRow.cpp
|
||||
#Widgets/devel/Table.cpp
|
||||
)
|
||||
|
||||
# Determine library suffixes depending on static/shared configuration
|
||||
|
|
|
@ -1,401 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/Widgets/devel/RichTextLabel.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Chunk
|
||||
{
|
||||
Chunk()
|
||||
{
|
||||
style = sf::Text::Regular;
|
||||
color = sf::Color::White;
|
||||
endsInNewline = false;
|
||||
}
|
||||
|
||||
sf::String text;
|
||||
unsigned int style;
|
||||
sf::Color color;
|
||||
bool endsInNewline;
|
||||
};
|
||||
|
||||
void newChunk(std::vector<Chunk>& chunks, Chunk*& currentChunk, Chunk& lastChunk)
|
||||
{
|
||||
chunks.push_back(Chunk());
|
||||
currentChunk = &(chunks[chunks.size() - 1]);
|
||||
|
||||
// only carry information over if currentChunk and lastChunk aren't the same
|
||||
// this only happens for the first chunk, but it causes random errors
|
||||
if (chunks.size() > 2)
|
||||
{
|
||||
currentChunk->style = lastChunk.style;
|
||||
currentChunk->color = lastChunk.color;
|
||||
}
|
||||
}
|
||||
|
||||
void processFormatting(Chunk& lastChunk, Chunk* currentChunk, sf::Text::Style style)
|
||||
{
|
||||
if ((lastChunk.style & style) != 0)
|
||||
{
|
||||
currentChunk->style ^= style;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentChunk->style |= style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RichTextLabel::RichTextLabel()
|
||||
{
|
||||
m_callback.widgetType = "RichTextLabel";
|
||||
|
||||
m_background.setFillColor(sf::Color::Transparent);
|
||||
|
||||
m_colors["default"] = sf::Color::White;
|
||||
m_colors["black"] = sf::Color::Black;
|
||||
m_colors["blue"] = sf::Color::Blue;
|
||||
m_colors["cyan"] = sf::Color::Cyan;
|
||||
m_colors["green"] = sf::Color::Green;
|
||||
m_colors["magenta"] = sf::Color::Magenta;
|
||||
m_colors["red"] = sf::Color::Red;
|
||||
m_colors["white"] = sf::Color::White;
|
||||
m_colors["yellow"] = sf::Color::Yellow;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RichTextLabel::RichTextLabel(const sf::String& text, unsigned int textSize) :
|
||||
RichTextLabel{}
|
||||
{
|
||||
m_textSize = textSize;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RichTextLabel::Ptr RichTextLabel::copy(RichTextLabel::ConstPtr label)
|
||||
{
|
||||
if (label)
|
||||
return std::static_pointer_cast<RichTextLabel>(label->clone());
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setPosition(const Layout2d& position)
|
||||
{
|
||||
Widget::setPosition(position);
|
||||
m_background.setPosition(getPosition());
|
||||
setText(m_string);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setSize(const Layout2d&)
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setFont(const Font& font)
|
||||
{
|
||||
Widget::setFont(font);
|
||||
setText(m_string);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setText(const sf::String& string)
|
||||
{
|
||||
m_string = string;
|
||||
|
||||
if (!m_font)
|
||||
return;
|
||||
|
||||
m_texts.clear();
|
||||
|
||||
std::vector<Chunk> chunks;
|
||||
chunks.push_back(Chunk());
|
||||
|
||||
Chunk* currentChunk = &(chunks[0]);
|
||||
bool escaped = false;
|
||||
|
||||
for (std::size_t i = 0; i < m_string.getSize(); ++i)
|
||||
{
|
||||
Chunk& lastChunk = *currentChunk;
|
||||
|
||||
switch (m_string[i])
|
||||
{
|
||||
case '~': // italics
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
currentChunk->text += m_string[i];
|
||||
escaped = false;
|
||||
break;
|
||||
}
|
||||
|
||||
newChunk(chunks, currentChunk, lastChunk);
|
||||
|
||||
processFormatting(lastChunk, currentChunk, sf::Text::Italic);
|
||||
|
||||
currentChunk->color = lastChunk.color;
|
||||
break;
|
||||
}
|
||||
case '*': // bold
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
currentChunk->text += m_string[i];
|
||||
escaped = false;
|
||||
break;
|
||||
}
|
||||
|
||||
newChunk(chunks, currentChunk, lastChunk);
|
||||
|
||||
processFormatting(lastChunk, currentChunk, sf::Text::Bold);
|
||||
|
||||
currentChunk->color = lastChunk.color;
|
||||
break;
|
||||
}
|
||||
case '_': // underline
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
currentChunk->text += m_string[i];
|
||||
escaped = false;
|
||||
break;
|
||||
}
|
||||
|
||||
newChunk(chunks, currentChunk, lastChunk);
|
||||
|
||||
|
||||
processFormatting(lastChunk, currentChunk, sf::Text::Underlined);
|
||||
|
||||
currentChunk->color = lastChunk.color;
|
||||
break;
|
||||
}
|
||||
case '#': // color
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
currentChunk->text += m_string[i];
|
||||
escaped = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// seek forward until the next whitespace
|
||||
std::size_t length = 0;
|
||||
while (!isspace(m_string[++i]))
|
||||
++length;
|
||||
|
||||
newChunk(chunks, currentChunk, lastChunk);
|
||||
currentChunk->color = getColor(m_string.substring(i + 1, length));;
|
||||
break;
|
||||
|
||||
}
|
||||
case '\\': // escape sequence for escaping formatting characters
|
||||
{
|
||||
if (i < m_string.getSize())
|
||||
{
|
||||
switch (m_string[i + 1])
|
||||
{
|
||||
case '~':
|
||||
case '*':
|
||||
case '_':
|
||||
case '#':
|
||||
{
|
||||
escaped = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!escaped)
|
||||
{
|
||||
currentChunk->text += m_string[i];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '\n': // make a new chunk in the case of a newline
|
||||
{
|
||||
currentChunk->endsInNewline = true;
|
||||
newChunk(chunks, currentChunk, lastChunk);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
escaped = false;
|
||||
currentChunk->text += m_string[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sf::String totalString = "";
|
||||
for (std::size_t i = 0; i < chunks.size(); ++i)
|
||||
{
|
||||
if (!chunks[i].endsInNewline && chunks[i].text.getSize() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
totalString += chunks[i].text + (chunks[i].endsInNewline ? "\n" : "");
|
||||
}
|
||||
|
||||
sf::Text text;
|
||||
text.setString(totalString);
|
||||
text.setCharacterSize(m_textSize);
|
||||
text.setPosition(getPosition());
|
||||
text.setFont(*m_font);
|
||||
|
||||
m_size = {text.getLocalBounds().left + text.getLocalBounds().width, text.getLocalBounds().top + text.getLocalBounds().height};
|
||||
m_background.setSize(getSize());
|
||||
|
||||
std::size_t cursor = 0;
|
||||
Chunk* lastChunk = nullptr;
|
||||
for (std::size_t i = 0; i < chunks.size(); ++i)
|
||||
{
|
||||
sf::Text tempText;
|
||||
tempText.setColor(chunks[i].color);
|
||||
tempText.setString(chunks[i].text);
|
||||
tempText.setStyle(chunks[i].style);
|
||||
tempText.setCharacterSize(m_textSize);
|
||||
tempText.setFont(*m_font);
|
||||
|
||||
tempText.setPosition(text.findCharacterPos(cursor));
|
||||
|
||||
if (lastChunk != nullptr && lastChunk->endsInNewline)
|
||||
{
|
||||
tempText.setPosition(0, tempText.getPosition().y + m_font->getLineSpacing(m_textSize));
|
||||
++cursor;
|
||||
}
|
||||
|
||||
m_texts.push_back(tempText);
|
||||
cursor += chunks[i].text.getSize();
|
||||
lastChunk = &chunks[i];
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setTextSize(unsigned int size)
|
||||
{
|
||||
m_textSize = size;
|
||||
setText(m_string);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int RichTextLabel::getTextSize() const
|
||||
{
|
||||
return m_textSize;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::setBackgroundColor(const sf::Color& color)
|
||||
{
|
||||
m_background.setFillColor(color);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const sf::Color& RichTextLabel::getBackgroundColor() const
|
||||
{
|
||||
return m_background.getFillColor();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::addColor(const sf::String& name, const sf::Color& color)
|
||||
{
|
||||
m_colors[name] = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::addColor(const sf::String& name, unsigned int argbHex)
|
||||
{
|
||||
m_colors[name] = getColor(argbHex);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sf::Color RichTextLabel::getColor(const sf::String& source) const
|
||||
{
|
||||
std::map<sf::String, sf::Color>::const_iterator result = m_colors.find(source);
|
||||
if (result == m_colors.end())
|
||||
{
|
||||
unsigned int hex = 0x0;
|
||||
if (!(std::istringstream(source) >> std::hex >> hex))
|
||||
{
|
||||
// Error parsing; return default
|
||||
return sf::Color::White;
|
||||
};
|
||||
|
||||
return getColor(hex);
|
||||
}
|
||||
|
||||
return result->second;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sf::Color RichTextLabel::getColor(unsigned int argbHex) const
|
||||
{
|
||||
argbHex |= 0xff000000;
|
||||
return sf::Color(argbHex >> 16 & 0xFF, argbHex >> 8 & 0xFF, argbHex >> 0 & 0xFF, argbHex >> 24 & 0xFF);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RichTextLabel::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
if (m_background.getFillColor() != sf::Color::Transparent)
|
||||
target.draw(m_background, states);
|
||||
|
||||
for(std::size_t i = 0; i < m_texts.size(); ++i)
|
||||
target.draw(m_texts[i], states);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,305 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/Widgets/devel/Table.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Table::Table()
|
||||
{
|
||||
m_callback.widgetType = "Table";
|
||||
|
||||
/// TODO
|
||||
/*
|
||||
m_tableBorder.setFillColor(sf::Color::Transparent);
|
||||
m_tableBorder.setOutlineColor(sf::Color::Green);
|
||||
m_tableBorder.setOutlineThickness(1);
|
||||
|
||||
m_headerSeparator.setFillColor(sf::Color::Green);
|
||||
//m_headerSeparator.setOutlineThickness(1);
|
||||
*/
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setFont(const Font& font)
|
||||
{
|
||||
BoxLayout::setFont(font);
|
||||
if (getFont())
|
||||
calculateLabelHeight();
|
||||
|
||||
if (m_header)
|
||||
m_header->setFont(font);
|
||||
|
||||
updateWidgetPositions();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setTextSize(unsigned int size)
|
||||
{
|
||||
m_characterSize = size;
|
||||
if (getFont())
|
||||
calculateLabelHeight();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setSize(const Layout2d& size)
|
||||
{
|
||||
BoxLayout::setSize(size);
|
||||
m_headerSeparator.setSize({getSize().x, 1.f});
|
||||
m_tableBorder.setSize(getSize());
|
||||
|
||||
updateColumnsDelimitatorsSize();
|
||||
|
||||
for (auto& widget : m_widgets)
|
||||
widget->setSize(getSize().x, widget->getSize().y);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Table::insert(std::size_t index, const tgui::Widget::Ptr& widget, const sf::String& widgetName)
|
||||
{
|
||||
auto row = std::dynamic_pointer_cast<TableRow>(widget);
|
||||
if (row == nullptr)
|
||||
{
|
||||
row = std::make_shared<tgui::TableRow>();
|
||||
row->add(widget);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_header->getWidgets().size(); ++i)
|
||||
{
|
||||
row->setFixedSize(i, m_header->getFixedSize(i));
|
||||
row->setRatio(i, m_header->getRatio(i));
|
||||
}
|
||||
|
||||
if (m_rowsEvenColor == sf::Color::Transparent)
|
||||
row->setNormalBackgroundColor(m_rowsOddColor);
|
||||
else if (index % 2 == 0)
|
||||
row->setNormalBackgroundColor(m_rowsEvenColor);
|
||||
else
|
||||
row->setNormalBackgroundColor(m_rowsOddColor);
|
||||
|
||||
float customHeight = row->getCustomHeight();
|
||||
row->setSize(getSize().x, (customHeight > m_rowHeight) ? customHeight : m_rowHeight);
|
||||
|
||||
return BoxLayout::insert(index, row, widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::add(const tgui::Widget::Ptr& widget, const sf::String& widgetName)
|
||||
{
|
||||
insert(m_widgets.size(), widget, widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::addRow(const std::vector<std::string>& columns)
|
||||
{
|
||||
auto row = std::make_shared<TableRow>();
|
||||
for (const std::string& column : columns)
|
||||
row->addItem(column, m_normalTextColor);
|
||||
|
||||
insert(m_widgets.size(), row, "");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setHeader(const tgui::TableRow::Ptr& row)
|
||||
{
|
||||
m_header = row;
|
||||
m_header->setParent(this);
|
||||
|
||||
m_columnsDelimitators.resize(row->getWidgets().size() - 1);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setHeaderColumns(const std::vector<std::string>& columns)
|
||||
{
|
||||
m_header->removeAllWidgets();
|
||||
|
||||
for (const std::string& column : columns)
|
||||
m_header->addItem(column, sf::Color::White);
|
||||
|
||||
m_header->setNormalBackgroundColor({234,97,83});
|
||||
setHeader(m_header);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setFixedColumnWidth(std::size_t column, float size)
|
||||
{
|
||||
m_header->setFixedSize(column, size);
|
||||
for (std::size_t i = 0; i < m_widgets.size(); ++i)
|
||||
std::dynamic_pointer_cast<HorizontalLayout>(m_widgets[i])->setFixedSize(column, size);
|
||||
|
||||
updateColumnsDelimitatorsPosition();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setColumnRatio(std::size_t column, float ratio)
|
||||
{
|
||||
m_header->setRatio(column, ratio);
|
||||
for (std::size_t i = 0; i < m_widgets.size(); ++i)
|
||||
std::dynamic_pointer_cast<HorizontalLayout>(m_widgets[i])->setRatio(column, ratio);
|
||||
|
||||
updateColumnsDelimitatorsPosition();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setRowsColor(const sf::Color& color)
|
||||
{
|
||||
m_rowsOddColor = color;
|
||||
m_rowsEvenColor = sf::Color::Transparent;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setStripesRowsColor(const sf::Color& evenColor, const sf::Color& oddColor)
|
||||
{
|
||||
m_rowsOddColor = oddColor;
|
||||
m_rowsEvenColor = evenColor;
|
||||
|
||||
for (std::size_t i = 0; i < m_widgets.size(); ++i)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
std::dynamic_pointer_cast<TableRow>(m_widgets[i])->setNormalBackgroundColor(evenColor);
|
||||
else
|
||||
std::dynamic_pointer_cast<TableRow>(m_widgets[i])->setNormalBackgroundColor(oddColor);
|
||||
|
||||
std::dynamic_pointer_cast<TableRow>(m_widgets[i])->setHoverBackgroundColor({255,255,0});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::setTextColor(const sf::Color& color)
|
||||
{
|
||||
m_normalTextColor = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::updateWidgetPositions()
|
||||
{
|
||||
if (m_header != nullptr)
|
||||
{
|
||||
m_header->setPosition(0, 0);
|
||||
m_header->setSize(getSize().x, m_rowHeight);
|
||||
updateColumnsDelimitatorsPosition();
|
||||
m_headerSeparator.setPosition(0, m_rowHeight);
|
||||
}
|
||||
|
||||
if (m_widgets.empty())
|
||||
return;
|
||||
|
||||
m_widgets[0]->setPosition(0, m_header->getSize().y + m_header->getPosition().y + 1.f);
|
||||
|
||||
auto row = std::dynamic_pointer_cast<TableRow>(m_widgets[0]);
|
||||
float customHeight = row->getCustomHeight();
|
||||
row->setSize(getSize().x, (customHeight > m_rowHeight) ? customHeight : m_rowHeight);
|
||||
|
||||
for (std::size_t i = 1; i < m_widgets.size(); ++i)
|
||||
{
|
||||
m_widgets[i]->setPosition(0, m_widgets[i-1]->getSize().y + m_widgets[i-1]->getPosition().y + 1.f);
|
||||
|
||||
row = std::dynamic_pointer_cast<TableRow>(m_widgets[i]);
|
||||
customHeight = row->getCustomHeight();
|
||||
row->setSize(getSize().x, (customHeight > m_rowHeight) ? customHeight : m_rowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::calculateLabelHeight()
|
||||
{
|
||||
auto label = std::make_shared<Label>();
|
||||
label->setFont(getFont());
|
||||
label->setTextSize(m_characterSize);
|
||||
|
||||
m_rowHeight = label->getSize().y;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::updateColumnsDelimitatorsPosition()
|
||||
{
|
||||
auto headerWidgets = m_header->getWidgets();
|
||||
for (std::size_t i = 1; i < headerWidgets.size(); ++i)
|
||||
m_columnsDelimitators[i-1].setPosition(headerWidgets[i]->getPosition().x, 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::updateColumnsDelimitatorsSize()
|
||||
{
|
||||
for (std::size_t i = 0; i < m_columnsDelimitators.size(); ++i)
|
||||
{
|
||||
m_columnsDelimitators[i].setFillColor(sf::Color::Black);
|
||||
m_columnsDelimitators[i].setSize({1.f, getSize().y});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Table::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
// Set the position
|
||||
states.transform.translate(getPosition());
|
||||
|
||||
// Draw the background
|
||||
if (m_backgroundColor != sf::Color::Transparent)
|
||||
{
|
||||
sf::RectangleShape background(getSize());
|
||||
background.setFillColor(m_backgroundColor);
|
||||
target.draw(background, states);
|
||||
}
|
||||
|
||||
// Draw the widgets
|
||||
target.draw(*m_header, states);
|
||||
drawWidgetContainer(&target, states);
|
||||
|
||||
/// TODO
|
||||
/*
|
||||
target.draw(m_tableBorder, states);
|
||||
//target.draw(m_headerSeparator, states);
|
||||
*/
|
||||
for (std::size_t i = 0; i < m_columnsDelimitators.size(); ++i)
|
||||
target.draw(m_columnsDelimitators[i], states);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,97 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/Widgets/devel/TableItem.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TableItem::TableItem()
|
||||
{
|
||||
m_callback.widgetType = "TableItem";
|
||||
setBackgroundColor(sf::Color::Transparent);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableItem::setItem(const Widget::Ptr& widgetPtr, HorizontalAlign align)
|
||||
{
|
||||
if (m_widget != nullptr)
|
||||
remove(m_widget);
|
||||
|
||||
m_widget = widgetPtr;
|
||||
m_align = align;
|
||||
updateItem();
|
||||
|
||||
if (m_widget != nullptr)
|
||||
add(m_widget);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableItem::setHorizontalAlign(HorizontalAlign align)
|
||||
{
|
||||
m_align = align;
|
||||
updateItem();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableItem::setFont(const Font& font)
|
||||
{
|
||||
m_widget->setFont(font);
|
||||
updateItem();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableItem::setSize(const Layout2d& size)
|
||||
{
|
||||
Panel::setSize(size);
|
||||
updateItem();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableItem::updateItem()
|
||||
{
|
||||
if (m_widget != nullptr)
|
||||
{
|
||||
if (m_align == Left)
|
||||
m_widget->setPosition(m_widget->getWidgetOffset().x, m_widget->getWidgetOffset().y + (getSize().y - m_widget->getFullSize().y) / 2.f);
|
||||
else if (m_align == Center)
|
||||
m_widget->setPosition(m_widget->getWidgetOffset().x + (getSize().x - m_widget->getSize().x) / 2.f, m_widget->getWidgetOffset().y + (getSize().y - m_widget->getSize().y) / 2.f);
|
||||
else
|
||||
m_widget->setPosition(m_widget->getWidgetOffset().x + getSize().x - m_widget->getSize().x, m_widget->getWidgetOffset().y + (getSize().y - m_widget->getSize().y) / 2.f);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,184 +0,0 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TGUI - Texus' Graphical User Interface
|
||||
// Copyright (C) 2012-2016 Bruno Van de Velde (vdv_b@tgui.eu)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <TGUI/Widgets/devel/TableRow.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace tgui
|
||||
{
|
||||
TableRow::TableRow()
|
||||
{
|
||||
m_callback.widgetType = "TableRow";
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setItem(unsigned int column, const std::string& name, TableItem::HorizontalAlign align)
|
||||
{
|
||||
BoxLayout::insert(column, createItem(name, align, m_normalTextColor));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setItem(unsigned int column, const std::string& name, const sf::Color& color, TableItem::HorizontalAlign align)
|
||||
{
|
||||
BoxLayout::insert(column, createItem(name, align, color));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::addItem(const std::string& name)
|
||||
{
|
||||
BoxLayout::add(createItem(name, m_align, m_normalTextColor));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::addItem(const std::string& name, const sf::Color& color)
|
||||
{
|
||||
BoxLayout::add(createItem(name, m_align, color));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::addItems(const std::vector<std::string>& columns, const sf::Color& color, TableItem::HorizontalAlign align)
|
||||
{
|
||||
for (std::string column : columns)
|
||||
BoxLayout::add(createItem(column, align, color));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TableRow::insert(std::size_t index, const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, const sf::String& widgetName)
|
||||
{
|
||||
return HorizontalLayout::insert(index, createItem(widget, align), widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::add(const tgui::Widget::Ptr& widget, const sf::String& widgetName)
|
||||
{
|
||||
HorizontalLayout::insert(m_widgets.size(), createItem(widget, m_align), widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::add(const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, const sf::String& widgetName)
|
||||
{
|
||||
HorizontalLayout::insert(m_widgets.size(), createItem(widget, align), widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::add(const tgui::Widget::Ptr& widget, bool fixedHeight, TableItem::HorizontalAlign align, const sf::String& widgetName)
|
||||
{
|
||||
HorizontalLayout::insert(m_widgets.size(),
|
||||
createItem(widget, (align == TableItem::None) ? m_align : align, fixedHeight),
|
||||
widgetName);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setHoverBackgroundColor(const sf::Color& color)
|
||||
{
|
||||
m_hoverBackgroundColor = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setNormalBackgroundColor(const sf::Color& color)
|
||||
{
|
||||
m_normalBackgroundColor = color;
|
||||
setBackgroundColor(color);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setNormalTextColor(const sf::Color& color)
|
||||
{
|
||||
m_normalTextColor = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::setItemsHorizontalAlign(TableItem::HorizontalAlign align)
|
||||
{
|
||||
m_align = align;
|
||||
|
||||
for (std::size_t i = 0; i < m_widgets.size(); ++i)
|
||||
std::dynamic_pointer_cast<TableItem>(m_widgets[i])->setHorizontalAlign(align);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::mouseEnteredWidget()
|
||||
{
|
||||
BoxLayout::mouseEnteredWidget();
|
||||
if (m_hoverBackgroundColor != sf::Color::Transparent)
|
||||
setBackgroundColor(m_hoverBackgroundColor);
|
||||
else
|
||||
setBackgroundColor(m_normalBackgroundColor);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TableRow::mouseLeftWidget()
|
||||
{
|
||||
BoxLayout::mouseLeftWidget();
|
||||
setBackgroundColor(m_normalBackgroundColor);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TableItem::Ptr TableRow::createItem(const std::string& name, TableItem::HorizontalAlign align, const sf::Color& color)
|
||||
{
|
||||
auto label = std::make_shared<tgui::Label>();
|
||||
label->setText(name);
|
||||
label->setTextColor(color);
|
||||
|
||||
auto layout = std::make_shared<tgui::TableItem>();
|
||||
layout->setItem(label, (align == TableItem::None) ? m_align : align);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TableItem::Ptr TableRow::createItem(const tgui::Widget::Ptr& widget, TableItem::HorizontalAlign align, bool fixedHeight)
|
||||
{
|
||||
if (fixedHeight && widget->getFullSize().y > m_customHeight)
|
||||
m_customHeight = widget->getFullSize().y;
|
||||
|
||||
auto layout = std::make_shared<tgui::TableItem>();
|
||||
layout->setItem(widget, align);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue