Commit fb690e8b authored by Murray Cumming's avatar Murray Cumming
Browse files

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.
parent 7cf5ef35
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.
......
......@@ -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">
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment