diff options
Diffstat (limited to 'src/glibext/widthtracker.c')
-rw-r--r-- | src/glibext/widthtracker.c | 155 |
1 files changed, 121 insertions, 34 deletions
diff --git a/src/glibext/widthtracker.c b/src/glibext/widthtracker.c index 274b53c..8ecaad0 100644 --- a/src/glibext/widthtracker.c +++ b/src/glibext/widthtracker.c @@ -122,10 +122,13 @@ struct _GWidthTracker GObject parent; /* A laisser en premier */ GBufferCache *cache; /* Ensemble complet de lignes */ + size_t col_count; /* Nombre maximum de colonnes */ common_metrics *portions; /* Portions représentées */ size_t count; /* Quantité de ces portions */ + gint *min_widths; /* Largeurs min. à respecter */ + line_width_summary summary; /* Largeurs requises suivies */ bool cached; /* Mise en cache des calculs */ @@ -457,6 +460,9 @@ static void g_width_tracker_dispose(GWidthTracker *tracker) static void g_width_tracker_finalize(GWidthTracker *tracker) { + if (tracker->min_widths != NULL) + free(tracker->min_widths); + G_OBJECT_CLASS(g_width_tracker_parent_class)->finalize(G_OBJECT(tracker)); } @@ -464,9 +470,8 @@ static void g_width_tracker_finalize(GWidthTracker *tracker) /****************************************************************************** * * -* Paramètres : buffer = tampon contenant les lignes à surveiller. * -* first = adresse contenant l'indice de la première ligne. * -* last = adresse contenant l'indice de la dernière ligne. * +* Paramètres : cache = tampon de lignes à lier au futur élément. * +* col_count = quantité maximale de colonnes à considérer. * * * * Description : Crée un nouveau suivi de largeurs au sein de lignes. * * * @@ -476,7 +481,7 @@ static void g_width_tracker_finalize(GWidthTracker *tracker) * * ******************************************************************************/ -GWidthTracker *g_width_tracker_new(GBufferCache *cache) +GWidthTracker *g_width_tracker_new(GBufferCache *cache, size_t col_count) { GWidthTracker *result; /* Composant à retourner */ @@ -485,6 +490,10 @@ GWidthTracker *g_width_tracker_new(GBufferCache *cache) g_object_ref(G_OBJECT(cache)); result->cache = cache; + result->col_count = col_count; + + result->min_widths = calloc(col_count, sizeof(gint)); + return result; } @@ -516,6 +525,8 @@ GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *template, siz g_object_ref(G_OBJECT(template->cache)); result->cache = template->cache; + result->col_count = template->col_count; + start = g_width_tracker_find_metrics(template, first); assert(start < template->count); @@ -523,7 +534,7 @@ GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *template, siz assert(end < template->count); result->count = end - start + 1; - result->portions = (common_metrics *)calloc(result->count, sizeof(common_metrics)); + result->portions = calloc(result->count, sizeof(common_metrics)); for (i = 0; i < result->count; i++) memcpy(&result->portions[i], &template->portions[start + i], sizeof(common_metrics)); @@ -540,6 +551,34 @@ GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *template, siz g_width_tracker_reset_widths(result, result->count - 1); } + result->min_widths = calloc(template->col_count, sizeof(gint)); + + for (i = 0; i < template->col_count; i++) + result->min_widths[i] = template->min_widths[i]; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : tracker = gestionnaire de largeurs de lignes à consulter. * +* * +* Description : Indique le nombre de colonnes prises en compte. * +* * +* Retour : Quantité normalement strictement positive. * +* * +* Remarques : - * +* * +******************************************************************************/ + +size_t g_width_tracker_count_columns(const GWidthTracker *tracker) +{ + size_t result; /* Quantité à retourner */ + + result = tracker->col_count; + return result; } @@ -547,6 +586,29 @@ GWidthTracker *g_width_tracker_new_restricted(const GWidthTracker *template, siz /****************************************************************************** * * +* Paramètres : tracker = gestionnaire de largeurs de lignes à mettre jour. * +* col = indice de colonne visée. * +* width = largeur minimale à imposer. * +* * +* Description : Impose une largeur minimale pour une colonne donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_width_tracker_set_column_min_width(GWidthTracker *tracker, size_t col, gint width) +{ + assert(col < tracker->col_count); + + tracker->min_widths[col] = width; + +} + + +/****************************************************************************** +* * * Paramètres : tracker = gestionnaire de suivi à consulter. * * index = indice d'une ligne dont la portion est inconnue. * * * @@ -761,7 +823,7 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c { assert(index == 0); - tracker->portions = (common_metrics *)calloc(1, sizeof(common_metrics)); + tracker->portions = calloc(1, sizeof(common_metrics)); tracker->count = 1; tracker->portions[0].first = 0; @@ -805,8 +867,7 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c tracker->count++; - tracker->portions = (common_metrics *)realloc(tracker->portions, - tracker->count * sizeof(common_metrics)); + tracker->portions = realloc(tracker->portions, tracker->count * sizeof(common_metrics)); portion = &tracker->portions[current]; @@ -910,8 +971,7 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t tracker->count -= (src - dest); - tracker->portions = (common_metrics *)realloc(tracker->portions, - tracker->count * sizeof(common_metrics)); + tracker->portions = realloc(tracker->portions, tracker->count * sizeof(common_metrics)); } @@ -927,8 +987,7 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t tracker->count--; - tracker->portions = (common_metrics *)realloc(tracker->portions, - tracker->count * sizeof(common_metrics)); + tracker->portions = realloc(tracker->portions, tracker->count * sizeof(common_metrics)); keep_last = false; @@ -1002,7 +1061,7 @@ void g_width_tracker_build_initial_cache(GWidthTracker *tracker, wgroup_id_t gid run_size = compute_run_size(tracker->count, &runs_count); - updates = (GWidthUpdate **)calloc(runs_count, sizeof(GWidthUpdate *)); + updates = calloc(runs_count, sizeof(GWidthUpdate *)); queue = get_work_queue(); @@ -1101,27 +1160,6 @@ static void g_width_tracker_ensure_valid_required_widths(GWidthTracker *tracker) /****************************************************************************** * * * Paramètres : tracker = suivi de largeurs à consulter. * -* * -* Description : Fournit un bon résumé des largeurs en vigueur. * -* * -* Retour : Ensemble des largeurs collectées. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const line_width_summary *g_width_tracker_get_width_summary(GWidthTracker *tracker) -{ - g_width_tracker_ensure_valid_required_widths(tracker); - - return &tracker->summary; - -} - - -/****************************************************************************** -* * -* Paramètres : tracker = suivi de largeurs à consulter. * * index = indice de la ligne dont la portion est recherchée. * * summary = ensemble ciblé de largeurs collectées. [OUT] * * * @@ -1269,3 +1307,52 @@ gint g_width_tracker_get_margin(GWidthTracker *tracker, const GDisplayOptions *o return result; } + + +/****************************************************************************** +* * +* Paramètres : tracker = suivi de largeurs à consulter. * +* index = indice de la ligne dont la portion est visée. * +* col = indice de la colonne visée par l'opération. * +* opt_count = quantité de colonnes initiales en options. * +* * +* Description : Indique la largeur locale d'une colonne donnée. * +* * +* Retour : Taille positive ou nulle. * +* * +* Remarques : - * +* * +******************************************************************************/ + +gint g_width_tracker_get_local_column_width(GWidthTracker *tracker, size_t index, size_t col, size_t opt_count) +{ + gint result; /* Largeur à retourner */ + size_t current; /* Indice de portion visée */ + const line_width_summary *local; /* Valeurs à intégrer */ + + g_width_tracker_ensure_valid_required_widths(tracker); + + assert(col < tracker->col_count); + + if (col < opt_count) + { + assert(opt_count < tracker->col_count); + result = tracker->summary.max_widths[col]; + } + + else + { + current = g_width_tracker_find_metrics(tracker, index); + assert(current < tracker->count); + + local = g_width_tracker_get_up_to_date_widths(tracker, current); + + result = local->max_widths[col]; + + } + + result = MAX(result, tracker->min_widths[col]); + + return result; + +} |