ide: Layout designer now reacts to property name width

This commit is contained in:
Mirek Fidler 2022-05-12 11:47:01 +02:00
parent b640bf7f42
commit 76cc33f2f1
5 changed files with 33 additions and 18 deletions

View file

@ -118,6 +118,10 @@ struct ItemProperty : public Ctrl {
virtual void Read(CParser& p);
virtual String Save() const;
virtual bool PlaceFocus(dword k, int c);
virtual void AdjustLabelWidth(int cx);
virtual bool InlineEditor() const;
int GetLabelWidth() const;
ItemProperty() { NoWantFocus(); level = 0; }
virtual ~ItemProperty() {}
@ -132,6 +136,8 @@ class EditorProperty : public ItemProperty {
public:
virtual Value GetData() const { return ~editor; }
virtual bool PlaceFocus(dword k, int c) { editor.SetFocus(); return editor.Key(k, c); }
virtual void AdjustLabelWidth(int cx) { editor.HSizePos(cx, Zx(2)); }
virtual bool InlineEditor() const { return true; }
protected:
void EditAction() { this->UpdateActionRefresh(); }
@ -139,6 +145,7 @@ protected:
Editor editor;
EditorProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
editor.WhenAction = callback(this, &EditorProperty::EditAction);
}
};
@ -151,10 +158,6 @@ struct RawProperty : public EditorProperty<EditString>
virtual void Read(CParser& p);
static ItemProperty *Create() { return new RawProperty; }
RawProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
}
};
struct PropertyPane : StaticRect {

View file

@ -8,7 +8,6 @@ struct EnumProperty : public EditorProperty<DropList> {
virtual void Read(CParser& p) { SetData(ReadPropertyParam(p)); }
EnumProperty(LayoutEnum& e) {
Add(editor.HSizePosZ(100, 2).TopPos(2));
for(int i = 0; i < e.items.GetCount(); i++)
editor.Add(e.items.GetKey(i), e.items[i]);
if(e.items.GetCount())

View file

@ -14,6 +14,14 @@ void PropertyPane::Layout()
{
sb.SetTotal(y);
sb.SetPage(GetSize().cy);
int labelwidth = Zx(100);
for(Ctrl& q : pane)
if(ItemProperty *m = dynamic_cast<ItemProperty *>(&q))
if(m->InlineEditor())
labelwidth = max(labelwidth, m->GetLabelWidth());
for(Ctrl& q : pane)
if(ItemProperty *m = dynamic_cast<ItemProperty *>(&q))
m->AdjustLabelWidth(labelwidth);
}
void PropertyPane::Clear()

View file

@ -10,11 +10,25 @@ void ItemProperty::Paint(Draw& w)
GetData() == defval ? StdFont()() : StdFont().Bold());
}
int ItemProperty::GetLabelWidth() const
{
return GetTextSize(name, StdFont().Bold()).cx + 2;
}
int ItemProperty::GetHeight() const
{
return EditField::GetStdHeight() + 5;
}
void ItemProperty::AdjustLabelWidth(int cx)
{
}
bool ItemProperty::InlineEditor() const
{
return false;
}
bool ItemProperty::PlaceFocus(dword, int) { return false; }
void ItemProperty::SetCharset(byte charset)
@ -113,10 +127,6 @@ struct IntProperty : public EditorProperty<EditInt> {
return IsNull(q) ? "Null" : AsString(q);
}
IntProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
}
static ItemProperty *Create() { return new IntProperty; }
};
@ -131,10 +141,6 @@ struct DoubleProperty : public EditorProperty<EditDouble> {
return FormatDouble(~editor, 10);
}
DoubleProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
}
static ItemProperty *Create() { return new DoubleProperty; }
};
@ -148,9 +154,6 @@ struct StringProperty : public EditorProperty<EditString> {
virtual String Save() const {
return AsCString(~editor);
}
StringProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
}
static ItemProperty *Create() { return new StringProperty; }
};
@ -168,7 +171,7 @@ struct BoolProperty : public EditorProperty<Option> {
return (int)~editor ? "true" : "false";
}
BoolProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(3));
editor.TopPos(3);
}
static ItemProperty *Create() { return new BoolProperty; }
@ -184,7 +187,6 @@ struct ColorProperty : public EditorProperty<ColorPusher> {
typedef ColorProperty CLASSNAME;
ColorProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));
editor.WithText().SColors().NullText("Null").Track();
}

View file

@ -200,6 +200,9 @@ struct TextProperty : public SmartTextEditProperty<EditString>
virtual int GetHeight() const {
return 2 * EditField::GetStdHeight() + 6;
}
virtual void AdjustLabelWidth(int cx) { editor.HSizePos(cx, Zx(2)); }
virtual bool InlineEditor() const { return true; }
TextProperty() {
Add(editor.HSizePosZ(100, 2).TopPos(2));