Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Weikert <elubie@gmx.net>2010-11-06 20:03:11 +0300
committerAndrea Weikert <elubie@gmx.net>2010-11-06 20:03:11 +0300
commit5b0e1520cfc21fe4c9eafcb7c2d5416ca73ec7af (patch)
tree800b1869c199d15abe4ed575c053faaeb5328e24 /source/blender/editors/space_file/filesel.c
parent06a53cde7db9227c7d41418fa52ed937a9cf166e (diff)
== filebrowser ==
Center Text underneath the icons in thumbnail view. (Small request from Sergey)
Diffstat (limited to 'source/blender/editors/space_file/filesel.c')
-rw-r--r--source/blender/editors/space_file/filesel.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 6442cfbb4eb..58e881abff4 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -283,6 +283,57 @@ void ED_fileselect_layout_tilepos(FileLayout* layout, int tile, int *x, int *y)
}
}
+/* Shorten a string to a given width w.
+ If front is set, shorten from the front,
+ otherwise shorten from the end. */
+float file_shorten_string(char* string, float w, int front)
+{
+ char temp[FILE_MAX];
+ short shortened = 0;
+ float sw = 0;
+ float pad = 0;
+
+ if (w <= 0) {
+ *string = '\0';
+ return 0.0;
+ }
+
+ sw = file_string_width(string);
+ if (front == 1) {
+ char *s = string;
+ BLI_strncpy(temp, "...", 4);
+ pad = file_string_width(temp);
+ while ((*s) && (sw+pad>w)) {
+ s++;
+ sw = file_string_width(s);
+ shortened = 1;
+ }
+ if (shortened) {
+ int slen = strlen(s);
+ BLI_strncpy(temp+3, s, slen+1);
+ temp[slen+4] = '\0';
+ BLI_strncpy(string, temp, slen+4);
+ }
+ } else {
+ char *s = string;
+ while (sw>w) {
+ int slen = strlen(string);
+ string[slen-1] = '\0';
+ sw = file_string_width(s);
+ shortened = 1;
+ }
+
+ if (shortened) {
+ int slen = strlen(string);
+ if (slen > 3) {
+ BLI_strncpy(string+slen-3, "...", 4);
+ }
+ }
+ }
+
+ return sw;
+}
+
float file_string_width(const char* str)
{
uiStyle *style= U.uistyles.first;
@@ -290,6 +341,16 @@ float file_string_width(const char* str)
return BLF_width(style->widget.uifont_id, (char *)str);
}
+/* gives the exact width of the string after being shortened to
+ the maximum width. Assumes shortening from the end of the string. */
+float file_string_width_shortened(const char* str, float width)
+{
+ char fname[FILE_MAXFILE];
+
+ BLI_strncpy(fname, str, FILE_MAXFILE);
+ return file_shorten_string(fname, width, 0 );
+}
+
float file_font_pointsize()
{
float s;