[glom: 3/4] List views and related records portals: Enough space for titles.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom: 3/4] List views and related records portals: Enough space for titles.
- Date: Fri, 30 Oct 2009 16:03:17 +0000 (UTC)
commit fb690e8b5e89051ce212dfabc5c94076c16bd2c9
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Oct 30 17:01:07 2009 +0100
List views and related records portals: Enough space for titles.
* glom/utils_ui.[h|cc]: get_suitable_field_width_for_widget():
Optionally calculate enough space for the title too, for TreeView
columns.
* glom/utility_widgets/db_adddel/db_adddel.cc: treeview_append_column():
When choosing a default column width, make sure there's enough for the
title too.
ChangeLog | 11 ++++++
.../test_sqlite_music/test_sqlite_music.glom | 6 ++--
glom/utility_widgets/db_adddel/db_adddel.cc | 2 +-
glom/utils_ui.cc | 34 ++++++++++++++-----
glom/utils_ui.h | 10 +++++-
5 files changed, 48 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 15d1d8f..186c83b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2009-10-30 Murray Cumming <murrayc murrayc com>
+ List views and related records portals: Enough space for titles.
+
+ * glom/utils_ui.[h|cc]: get_suitable_field_width_for_widget():
+ Optionally calculate enough space for the title too, for TreeView
+ columns.
+ * glom/utility_widgets/db_adddel/db_adddel.cc: treeview_append_column():
+ When choosing a default column width, make sure there's enough for the
+ title too.
+
+2009-10-30 Murray Cumming <murrayc murrayc com>
+
List views and related records portals: Avoid zero-width columns.
* glom/utility_widgets/db_adddel/db_adddel.cc: treeview_append_column():
diff --git a/examples/sqlite/test_sqlite_music/test_sqlite_music.glom b/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
index 47cc95f..5168eb0 100644
--- a/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
+++ b/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
@@ -197,13 +197,13 @@
<data_layout name="list" parent_table="artists">
<data_layout_groups>
<data_layout_group name="main">
- <data_layout_item name="artist_id" editable="true" use_default_formatting="true" column_width="40">
+ <data_layout_item name="artist_id" editable="true" use_default_formatting="true">
<formatting format_thousands_separator="true" format_decimal_places="2"/>
</data_layout_item>
- <data_layout_item name="name" editable="true" use_default_formatting="true" column_width="93">
+ <data_layout_item name="name" editable="true" use_default_formatting="true">
<formatting format_thousands_separator="true" format_decimal_places="2" format_text_multiline_height_lines="6"/>
</data_layout_item>
- <data_layout_item name="description" editable="true" use_default_formatting="true" column_width="93">
+ <data_layout_item name="description" editable="true" use_default_formatting="true">
<formatting format_thousands_separator="true" format_decimal_places="2" format_text_multiline_height_lines="6"/>
</data_layout_item>
<data_layout_item name="somenum" editable="true" use_default_formatting="true">
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 41e526c..77bd7b5 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -2016,7 +2016,7 @@ guint DbAddDel::treeview_append_column(const Glib::ustring& title, Gtk::CellRend
//TODO: Choose a width based on the first 100 values.
if(layout_item_field)
{
- column_width = Utils::get_suitable_field_width_for_widget(*this, layout_item_field);
+ column_width = Utils::get_suitable_field_width_for_widget(*this, layout_item_field, true /* or_title */);
column_width = column_width / 3;
//std::cout << "DEBUG: column_width=" << column_width << std::endl;
}
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index c97a8c5..d15ea04 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -323,7 +323,22 @@ Glib::RefPtr<Gdk::Pixbuf> Utils::get_pixbuf_for_gda_value(const Gnome::Gda::Valu
return result;
}
-int Utils::get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<const LayoutItem_Field>& field_layout)
+static int get_width_for_text(Gtk::Widget& widget, const Glib::ustring& text)
+{
+ //Get the width required for this string in the current font:
+ Glib::RefPtr<Pango::Layout> refLayout = widget.create_pango_layout(text);
+ int width = 0;
+ int height = 0;
+ refLayout->get_pixel_size(width, height);
+ int result = width;
+
+ //Add a bit more:
+ result += 10;
+
+ return result;
+}
+
+int Utils::get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<const LayoutItem_Field>& field_layout, bool or_title)
{
int result = 150;
@@ -379,14 +394,15 @@ int Utils::get_suitable_field_width_for_widget(Gtk::Widget& widget, const shared
if(!example_text.empty())
{
//Get the width required for this string in the current font:
- Glib::RefPtr<Pango::Layout> refLayout = widget.create_pango_layout(example_text);
- int width = 0;
- int height = 0;
- refLayout->get_pixel_size(width, height);
- result = width;
-
- //Add a bit more:
- result += 10;
+ result += get_width_for_text(widget, example_text);
+ }
+
+ if(or_title)
+ {
+ //Make sure that there's enough space for the title too.
+ const int title_width = get_width_for_text(widget, field_layout->get_title());
+ if(title_width > result)
+ result = title_width;
}
return result;
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index 20b98d5..a0a9041 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -73,8 +73,14 @@ Glib::ustring bold_message(const Glib::ustring& message);
Glib::RefPtr<Gdk::Pixbuf> get_pixbuf_for_gda_value(const Gnome::Gda::Value& value);
-
-int get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<const LayoutItem_Field>& field_layout);
+/** Get the width required for typical data of this type in the current font.
+ *
+ * @widget The widget whose font should be used.
+ * @field_layout The layout item whose data type should be used.
+ * @or_title If true, check the width of the item's title too, returning the larger of the two values.
+ * @result The width in pixels.
+ */
+int get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<const LayoutItem_Field>& field_layout, bool or_title = false);
/// Add the @a extension if no extension is there already:
std::string get_filepath_with_extension(const std::string& filepath, const std::string& extension);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]