mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:58:12 +00:00
VisualBuilder: Add [x, y, width, height] properties for all widgets.
At first I tried doing this as a single "rect" property but I like the feel of the individual properties much better. :^)
This commit is contained in:
parent
c425bc2e71
commit
3cddc3484e
5 changed files with 32 additions and 5 deletions
|
@ -10,6 +10,7 @@ public:
|
|||
|
||||
String name() const { return m_name; }
|
||||
const GVariant& value() const { return m_value; }
|
||||
void set_value(const GVariant& value) { m_value = value; }
|
||||
|
||||
bool is_readonly() const { return m_readonly; }
|
||||
void set_readonly(bool b) { m_readonly = b; }
|
||||
|
|
|
@ -24,7 +24,10 @@ Rect VBWidget::rect() const
|
|||
|
||||
void VBWidget::set_rect(const Rect& rect)
|
||||
{
|
||||
if (rect == m_gwidget->relative_rect())
|
||||
return;
|
||||
m_gwidget->set_relative_rect(rect);
|
||||
synchronize_properties();
|
||||
}
|
||||
|
||||
bool VBWidget::is_selected() const
|
||||
|
@ -74,3 +77,22 @@ void VBWidget::for_each_property(Function<void(VBProperty&)> callback)
|
|||
callback(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void VBWidget::synchronize_properties()
|
||||
{
|
||||
property_by_name("width")->set_value(m_gwidget->width());
|
||||
property_by_name("height")->set_value(m_gwidget->height());
|
||||
property_by_name("x")->set_value(m_gwidget->x());
|
||||
property_by_name("y")->set_value(m_gwidget->y());
|
||||
|
||||
m_property_model->update();
|
||||
}
|
||||
|
||||
VBProperty* VBWidget::property_by_name(const String& name)
|
||||
{
|
||||
for (auto& property : m_properties) {
|
||||
if (property->name() == name)
|
||||
return property.ptr();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -51,10 +51,11 @@ public:
|
|||
|
||||
VBWidgetPropertyModel& property_model() { return *m_property_model; }
|
||||
|
||||
protected:
|
||||
VBWidget(VBWidgetType, VBForm&);
|
||||
void synchronize_properties();
|
||||
|
||||
private:
|
||||
VBWidget(VBWidgetType, VBForm&);
|
||||
|
||||
VBWidgetType m_type { VBWidgetType::None };
|
||||
VBForm& m_form;
|
||||
GWidget* m_gwidget { nullptr };
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual String column_name(int column) const override;
|
||||
virtual ColumnMetadata column_metadata(int column) const override;
|
||||
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override { }
|
||||
virtual void update() override { did_update(); }
|
||||
|
||||
private:
|
||||
explicit VBWidgetPropertyModel(VBWidget&);
|
||||
|
|
|
@ -73,15 +73,18 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
GWidget* VBWidgetRegistry::build_gwidget(VBWidgetType type, GWidget* parent, Vector<OwnPtr<VBProperty>>& properties)
|
||||
{
|
||||
auto* gwidget = ::build_gwidget(type, parent);
|
||||
auto add_property = [&properties] (const String& name, const GVariant& value, bool is_readonly) {
|
||||
auto add_property = [&properties] (const String& name, const GVariant& value = { }, bool is_readonly = false) {
|
||||
auto property = make<VBProperty>(name, value);
|
||||
property->set_readonly(is_readonly);
|
||||
properties.append(move(property));
|
||||
};
|
||||
add_property("class", to_class_name(type), true);
|
||||
add_property("width");
|
||||
add_property("height");
|
||||
add_property("x");
|
||||
add_property("y");
|
||||
return gwidget;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue