Proposal for GTK+ advanced formatted entry and spinner API



Hi all.
I would like to propose my idea for Format-Elements, that will be used to control GtkEntry and GtkSpinButton.
The idea is to allow organized, element-based formatting of data displayed textually.
The current common formatting methods include regular expressions and masking, and can be done either "real-time" (as you type) or "offline" (upon validation request, like a "lose-focus-event").
While these methods are sufficient in some places, they are very limited for the common uses and I see it. For example, the most common uses for formatted entries include a date/time entry and an IP address entry.
With the lack of a good formatting method, these are implemented as a set of spin-buttons or with an offline-validators.
It would look much nicer if there could be a formatted spin-button that could handle each of the elements separately, while maintaining the outputted, visible value as a simple textual string.

What I would like to propose is as follows:
  1. Define a base "format_element" structure that will dictate the interface. It will include methods for getting the value as a string (formatted to fit in a given minimum width), the minimum width (in characters) of the element, and scrolling methods (step up, step down, page up, page down, top, and bottom). It will also allow the programmer to define whether the element is editable or static (say, a separator or a format specifier, like the brackets in a phone-number). The format element also holds its own value.
  2. Define several format elements implementing this interface, each handles a different type of data. There will be format elements to handle integer values, floating-point values, enumeration/completion strings, general strings, and others as needed.
  3. Let GtkEntry contain a list of format elements (and the needed API to handle this list). The entry need to know what is the current focused format element (this can be done by checking the cursor position whenever it changes, using the notify::cursor_position event), and need to pass the element the character that the user wanted to enter. The only change in value in this case is done within the format-element. When a change in a format element occures, the entry need to rewrite itself by concatanating the values of all its format elements in order.
  4. Let GtkSpinButton send the relevant scroll requests to the focused format-element.
  5. Create a simple, non-programmative API for definition of the format (say, using a string in a defined format) that will internally create the needed format-elements and will add them to the list. This way, creating a date/time field will look something like this:
GtkWidget *spinner;
spinner = gtk_spin_button_new ();
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (1, 31));         // day
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static ("-")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (1, 12));         // month
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static ("-")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (0, 9999));       // year
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static (" ")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (1, 12));         // hour
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static (":")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (0, 59));         // minute
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static (":")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_int_new (0, 59));         // second
gtk_entry_add_format_element (spinner, gtk_format_element_string_new_static (" ")); // separator
gtk_entry_add_format_element (spinner, gtk_format_element_enum_new ("AM", "PM", NULL));

(simply, adding the wanted format elements in the wanted order to the spin button.)

The value of the spin-button could be taken as a string in this case, or a reference can be held to  each of the non-static format elements, and its inner, real value can be used.

This is my proposal, I would like to know what you think and receive comments about it.

Itai.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]