瀏覽代碼

Fix some todos.

Michael Ragazzon 6 年之前
父節點
當前提交
2f1d96b751
共有 2 個文件被更改,包括 9 次插入8 次删除
  1. 7 2
      Samples/invaders/src/EventHandlerHighScore.cpp
  2. 2 6
      Source/Core/ElementTextDefault.cpp

+ 7 - 2
Samples/invaders/src/EventHandlerHighScore.cpp

@@ -65,7 +65,12 @@ void EventHandlerHighScore::ProcessEvent(Rml::Core::Event& event, const Rml::Cor
 	}
 	else if (value == "check_name")
 	{
-		/* TODO: Check if the player hasn't set their name first. */
-		HighScores::SubmitName("Anon.");
+		Rml::Core::String name = "Anon.";
+		
+		// Submit the name the user started typing
+		if(auto element = event.GetCurrentElement()->GetOwnerDocument()->GetElementById("player_input"))
+			name = element->GetAttribute<Rml::Core::String>("value", name);
+
+		HighScores::SubmitName(name);
 	}
 }

+ 2 - 6
Source/Core/ElementTextDefault.cpp

@@ -146,7 +146,6 @@ void ElementTextDefault::OnRender()
 // Generates a token of text from this element, returning only the width.
 bool ElementTextDefault::GenerateToken(float& token_width, int line_begin)
 {
-	RMLUI_ASSERT_NONRECURSIVE;
 	RMLUI_ZoneScoped;
 
 	// Bail if we don't have a valid font face.
@@ -167,8 +166,7 @@ bool ElementTextDefault::GenerateToken(float& token_width, int line_begin)
 							white_space_property == WhiteSpace::Preline;
 
 	const word* token_begin = text.c_str() + line_begin;
-	static WString token; // Avoids allocations, requires non-recursiveness. TODO: Doesn't actually behave like this, maybe use a stack-allocated string instead?
-	token.clear();
+	WString token;
 
 	BuildToken(token, token_begin, text.c_str() + text.size(), true, collapse_white_space, break_at_endline, computed.text_transform);
 	token_width = (float) font_face_handle->GetStringWidth(token, 0);
@@ -179,7 +177,6 @@ bool ElementTextDefault::GenerateToken(float& token_width, int line_begin)
 // Generates a line of text rendered from this element
 bool ElementTextDefault::GenerateLine(WString& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width, bool trim_whitespace_prefix)
 {
-	RMLUI_ASSERT_NONRECURSIVE;
 	RMLUI_ZoneScoped;
 
 	FontFaceHandle* font_face_handle = GetFontFaceHandle();
@@ -219,8 +216,7 @@ bool ElementTextDefault::GenerateLine(WString& line, int& line_length, float& li
 	const word* string_end = text.c_str() + text.size();
 	while (token_begin != string_end)
 	{
-		static WString token;  // Avoids allocations, requires non-recursiveness. TODO: Doesn't actually behave like this, maybe use a stack-allocated string instead?
-		token.clear();
+		WString token;
 		const word* next_token_begin = token_begin;
 
 		// Generate the next token and determine its pixel-length.