Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new fe.Text property msg_wrapped #507

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ otherwise instantiated in a script.
Properties:
* `msg` - Get/set the text label's message. Magic tokens can be used here,
see [Magic Tokens](#magic) for more information.
* `msg_wrapped` - Get the text label's message after word wrapping.
* `x` - Get/set x position of top left corner (in layout coordinates).
* `y` - Get/set y position of top left corner (in layout coordinates).
* `width` - Get/set width of text (in layout coordinates).
Expand Down
5 changes: 5 additions & 0 deletions src/fe_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ const char *FeText::get_string()
return m_string.c_str();
}

const char *FeText::get_string_wrapped()
{
return m_draw_text.getStringWrapped();
}

void FeText::set_string(const char *s)
{
m_string=s;
Expand Down
1 change: 1 addition & 0 deletions src/fe_text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class FeText : public FeBasePresentable, public sf::Drawable

const char *get_string();
void set_string(const char *s);
const char *get_string_wrapped();

int get_actual_width() { return m_draw_text.getActualWidth(); };

Expand Down
1 change: 1 addition & 0 deletions src/fe_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ bool FeVM::on_new_layout()
fe.Bind( _SC("Text"),
DerivedClass<FeText, FeBasePresentable, NoConstructor>()
.Prop(_SC("msg"), &FeText::get_string, &FeText::set_string )
.Prop(_SC("msg_wrapped"), &FeText::get_string_wrapped )
.Prop(_SC("bg_red"), &FeText::get_bgr, &FeText::set_bgr )
.Prop(_SC("bg_green"), &FeText::get_bgg, &FeText::set_bgg )
.Prop(_SC("bg_blue"), &FeText::get_bgb, &FeText::set_bgb )
Expand Down
11 changes: 11 additions & 0 deletions src/tp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ int FeTextPrimative::getFirstLineHint() const
return m_first_line;
}

const char *FeTextPrimative::getStringWrapped()
{
std::string str;
for ( unsigned int i=0; i < m_texts.size(); i++ )
{
str += m_texts[i].getString();
str += "\n";
}
return str.c_str();
}

void FeTextPrimative::draw( sf::RenderTarget &target, sf::RenderStates states ) const
{
if ( m_needs_pos_set )
Expand Down
1 change: 1 addition & 0 deletions src/tp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class FeTextPrimative : public sf::Drawable
int getStyle() const;
int getFirstLineHint() const;
const sf::Vector2f &getTextScale() const;
const char *getStringWrapped();

int getActualWidth(); // return the width of the actual text

Expand Down