Просмотр исходного кода

Debugger menu: Highlight open debug windows

Michael Ragazzon 1 месяц назад
Родитель
Сommit
f96fec3ae7

+ 40 - 21
Source/Debugger/DebuggerPlugin.cpp

@@ -239,32 +239,45 @@ void DebuggerPlugin::OnElementDestroy(Element* element)
 
 void DebuggerPlugin::ProcessEvent(Event& event)
 {
+	struct ButtonIdToDocumentMapping {
+		String id;
+		ElementDocument* document;
+	};
+	const ButtonIdToDocumentMapping button_mappings[] = {
+		{"event-log-button", log_element},
+		{"debug-info-button", info_element},
+		{"data-models-button", data_explorer_element},
+	};
+
 	if (event == EventId::Click)
 	{
-		if (event.GetTargetElement()->GetId() == "event-log-button")
-		{
-			if (log_element->IsVisible())
-				log_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
-			else
-				log_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
-		}
-		else if (event.GetTargetElement()->GetId() == "debug-info-button")
+		for (const ButtonIdToDocumentMapping& button_mapping : button_mappings)
 		{
-			if (info_element->IsVisible())
-				info_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
-			else
-				info_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
+			if (event.GetTargetElement()->GetId() == button_mapping.id)
+			{
+				if (button_mapping.document->IsVisible())
+					button_mapping.document->Hide();
+				else
+					button_mapping.document->Show();
+			}
 		}
-		else if (event.GetTargetElement()->GetId() == "outlines-button")
+
+		if (event.GetTargetElement()->GetId() == "outlines-button")
 		{
 			render_outlines = !render_outlines;
+			event.GetTargetElement()->SetClass("open", render_outlines);
 		}
-		else if (event.GetTargetElement()->GetId() == "data-models-button")
+	}
+	else if (event == EventId::Hide || event == EventId::Show)
+	{
+		for (const ButtonIdToDocumentMapping& button_mapping : button_mappings)
 		{
-			if (data_explorer_element->IsVisible())
-				data_explorer_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
-			else
-				data_explorer_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
+			if (event.GetTargetElement() == button_mapping.document)
+			{
+				Element* button = menu_element->GetElementById(button_mapping.id);
+				const bool set_open = (event == EventId::Show);
+				button->SetClass("open", set_open);
+			}
 		}
 	}
 }
@@ -330,10 +343,12 @@ bool DebuggerPlugin::LoadInfoElement()
 	{
 		host_context->UnloadDocument(info_element);
 		info_element = nullptr;
-
 		return false;
 	}
 
+	info_element->AddEventListener(EventId::Hide, this);
+	info_element->AddEventListener(EventId::Show, this);
+
 	return true;
 }
 
@@ -351,10 +366,12 @@ bool DebuggerPlugin::LoadLogElement()
 	{
 		host_context->UnloadDocument(log_element);
 		log_element = nullptr;
-
 		return false;
 	}
 
+	log_element->AddEventListener(EventId::Hide, this);
+	log_element->AddEventListener(EventId::Show, this);
+
 	// Make the system interface; this will trap the log messages for us.
 	application_interface = Rml::GetSystemInterface();
 	log_interface = MakeUnique<DebuggerSystemInterface>(application_interface, log_element);
@@ -377,10 +394,12 @@ bool DebuggerPlugin::LoadDataExplorerElement()
 	{
 		host_context->UnloadDocument(data_explorer_element);
 		data_explorer_element = nullptr;
-
 		return false;
 	}
 
+	data_explorer_element->AddEventListener(EventId::Hide, this);
+	data_explorer_element->AddEventListener(EventId::Show, this);
+
 	return true;
 }
 

+ 1 - 4
Source/Debugger/ElementDataModels.cpp

@@ -170,10 +170,7 @@ void ElementDataModels::ProcessEvent(Event& event)
 		const String& id = event.GetTargetElement()->GetId();
 
 		if (id == "close_button")
-		{
-			if (IsVisible())
-				SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
-		}
+			Hide();
 
 		event.StopPropagation();
 	}

+ 1 - 2
Source/Debugger/ElementInfo.cpp

@@ -208,8 +208,7 @@ void ElementInfo::ProcessEvent(Event& event)
 
 				if (id == "close_button")
 				{
-					if (IsVisible())
-						SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
+					Hide();
 				}
 				else if (id == "update_source")
 				{

+ 2 - 4
Source/Debugger/ElementLog.cpp

@@ -245,15 +245,13 @@ void ElementLog::ProcessEvent(Event& event)
 		{
 			if (event.GetTargetElement() == beacon->GetFirstChild())
 			{
-				if (!IsVisible())
-					SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
-
+				Show();
 				beacon->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
 				current_beacon_level = Log::LT_MAX;
 			}
 			else if (event.GetTargetElement()->GetId() == "close_button")
 			{
-				SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
+				Hide();
 			}
 			else if (event.GetTargetElement()->GetId() == "clear_button")
 			{

+ 8 - 7
Source/Debugger/MenuSource.h

@@ -57,14 +57,15 @@ button
 	line-height: 24dp;
 	text-align: center;
 }
-button:hover
-{
-	background: #eee;
-}
-button:active
-{
-	background: #fff;
+button.open {
+	border-color: #6cf;
+	color: #22a;
+	background: #cee;
 }
+button:hover { background: #eee; }
+button:active { background: #fff; }
+button.open:hover { background: #dff; }
+button.open:active { background: #eff; }
 div#version-info
 {
 	padding: 0px;