LibGUI: Implement save_to(JsonObject&) for GWindow and GWidget

This commit is contained in:
Andreas Kling 2019-08-18 20:39:46 +02:00
parent c2213449c0
commit 3792c91059
Notes: sideshowbarker 2024-07-19 12:35:54 +09:00
4 changed files with 45 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "GEventLoop.h"
#include "GWindow.h"
#include <AK/Assertions.h>
#include <AK/JsonObject.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GLayout.h>
@ -585,3 +586,18 @@ void GWidget::set_forecolor(const StringView& color_string)
return;
set_foreground_color(color.value());
}
void GWidget::save_to(AK::JsonObject& json)
{
json.set("relative_rect", relative_rect().to_string());
json.set("fill_with_background_color", fill_with_background_color());
json.set("tooltip", tooltip());
json.set("visible", is_visible());
json.set("focused", is_focused());
json.set("enabled", is_enabled());
json.set("background_color", background_color().to_string());
json.set("foreground_color", foreground_color().to_string());
json.set("preferred_size", preferred_size().to_string());
json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy())));
CObject::save_to(json);
}

View File

@ -22,6 +22,17 @@ enum class SizePolicy {
Fixed,
Fill
};
inline const char* to_string(SizePolicy policy)
{
switch (policy) {
case SizePolicy::Fixed:
return "SizePolicy::Fixed";
case SizePolicy::Fill:
return "SizePolicy::Fill";
}
return "SizePolicy::(Invalid)";
}
enum class HorizontalDirection {
Left,
Right
@ -206,6 +217,8 @@ public:
virtual bool is_radio_button() const { return false; }
virtual bool is_abstract_button() const { return false; }
virtual void save_to(AK::JsonObject&) override;
private:
void handle_paint_event(GPaintEvent&);
void handle_resize_event(GResizeEvent&);

View File

@ -1,4 +1,5 @@
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/StringBuilder.h>
#include <LibC/SharedBuffer.h>
#include <LibC/stdio.h>
@ -696,3 +697,16 @@ Vector<GWidget*> GWindow::focusable_widgets() const
collect_focusable_widgets(*m_main_widget);
return collected_widgets;
}
void GWindow::save_to(AK::JsonObject& json)
{
json.set("title", title());
json.set("visible", is_visible());
json.set("active", is_active());
json.set("resizable", is_resizable());
json.set("fullscreen", is_fullscreen());
json.set("rect", rect().to_string());
json.set("base_size", base_size().to_string());
json.set("size_increment", size_increment().to_string());
CObject::save_to(json);
}

View File

@ -125,6 +125,8 @@ public:
Vector<GWidget*> focusable_widgets() const;
virtual void save_to(AK::JsonObject&) override;
protected:
virtual void wm_event(GWMEvent&);