From af818e3becefb49656e1587ec7602ac7329f9b1d Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 30 Jun 2007 14:35:41 +0000 Subject: [PATCH] Width of labels in native look editor is adjusted based on the longest label git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@449 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/control/native_look_editor.cpp | 17 +++++++++++++++++ src/gui/control/native_look_editor.hpp | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gui/control/native_look_editor.cpp b/src/gui/control/native_look_editor.cpp index 8832dd5b..c5472a36 100644 --- a/src/gui/control/native_look_editor.cpp +++ b/src/gui/control/native_look_editor.cpp @@ -58,6 +58,23 @@ void NativeLookEditor::resizeViewers() { int w, h; GetClientSize(&w, &h); const int default_height = 17; + // Determine label width + { + label_width = 0; + wxClientDC dc(this); + dc.SetFont(*wxNORMAL_FONT); + FOR_EACH(v, viewers) { + ValueEditor* e = v->getEditor(); + if (!e || e->drawLabel()) { + // width of the label string + int w; + Style& s = *v->getStyle(); + String text = tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)); + dc.GetTextExtent(text,&w,nullptr); + label_width = max(label_width, w + label_margin); + } + } + } // Set editor sizes FOR_EACH(v, viewers) { StyleP s = v->getStyle(); diff --git a/src/gui/control/native_look_editor.hpp b/src/gui/control/native_look_editor.hpp index e1c68465..729c9961 100644 --- a/src/gui/control/native_look_editor.hpp +++ b/src/gui/control/native_look_editor.hpp @@ -35,10 +35,11 @@ class NativeLookEditor : public DataEditor { virtual void onInit(); private: - static const UInt margin = 6; - static const UInt margin_left = 4; - static const UInt label_width = 150; - static const UInt vspace = 10; + static const int margin = 6; + static const int margin_left = 4; + static const int vspace = 10; + static const int label_margin = 10; + int label_width; DECLARE_EVENT_TABLE();