diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-01-02 22:34:20 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-01-02 22:34:20 (GMT) |
commit | 28bfc34862513acb8fe9fcd02afca493c2411c02 (patch) | |
tree | 262f2c748f575854214801edf2c0647d9b4a2cfc | |
parent | 9bcc244de4b2f07e37025d5180fa37bbe6028fa1 (diff) |
Handled collapsing tiles.
-rw-r--r-- | src/gtkext/tiledgrid.c | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/src/gtkext/tiledgrid.c b/src/gtkext/tiledgrid.c index 0256563..289d358 100644 --- a/src/gtkext/tiledgrid.c +++ b/src/gtkext/tiledgrid.c @@ -84,6 +84,9 @@ static grid_tile_t *split_tile(grid_tile_t **, const char *, char, GtkTiledGrid /* Tente de mettre la main sur une station d'accueil. */ static grid_tile_t *find_tile_for_widget(grid_tile_t *, GtkWidget *); +/* Retire une moitié de tuile vide au plein profit de l'autre. */ +static void collapse_tile(grid_tile_t *, grid_tile_t *); + /* --------------------------- INTERFACE DU COMPOSANT GTK --------------------------- */ @@ -492,6 +495,7 @@ static grid_tile_t *find_suitable_tile(grid_tile_t **tile, const char *path, Gtk } + /****************************************************************************** * * * Paramètres : tile = tuile à découper en deux. [OUT] * @@ -569,6 +573,59 @@ static grid_tile_t *split_tile(grid_tile_t **tile, const char *path, char endpoi /****************************************************************************** * * +* Paramètres : tile = tuile parente, prochaine victime de promotion. * +* side = côté de tuile amené à disparaître. * +* * +* Description : Retire une moitié de tuile vide au plein profit de l'autre. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void collapse_tile(grid_tile_t *tile, grid_tile_t *side) +{ + grid_tile_t *promoted; /* Tuile à faire remonter */ + GtkWidget *container; /* Conteneur à vider */ + + assert(!IS_LEAF_TILE(tile)); + + /* Sélection du remplaçant */ + + if (side == tile->children[0]) + promoted = tile->children[1]; + else + promoted = tile->children[0]; + + /* Etablissement d'une place nette */ + + gtk_container_remove(GTK_CONTAINER(tile->widget), promoted->widget); + + container = gtk_widget_get_parent(tile->widget); + gtk_container_remove(GTK_CONTAINER(container), tile->widget); + + delete_tile(side); + + /* Promotion effective */ + + tile->widget = promoted->widget; + + tile->path = promoted->path; + + tile->children[0] = promoted->children[0]; + tile->children[1] = promoted->children[1]; + + g_object_ref(G_OBJECT(promoted->widget)); + gtk_container_add(GTK_CONTAINER(container), tile->widget); + + free(promoted); + +} + + +/****************************************************************************** +* * * Paramètres : tile = point de départ des recherches locales. * * widget = composant graphique à retrouver. * * * @@ -906,12 +963,30 @@ void gtk_tiled_grid_remove(GtkTiledGrid *tgrid, GPanelItem *panel) if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(station)) == 0) { - //delete_panel_node(node); - /* Si le panneau par défaut devient nécessaire */ if (tgrid->def_panel != NULL && tile->path[0] == 'M' && tile->path[1] == '\0') gtk_tiled_grid_add(tgrid, tgrid->def_panel); + else + { + /* La racine est concernée ! */ + if (tile->parent == NULL) + { + assert(tile == tgrid->tiles); + + g_object_ref(G_OBJECT(tile->widget)); + gtk_container_remove(GTK_CONTAINER(tgrid), tile->widget); + + delete_tile(tile); + tgrid->tiles = NULL; + + } + + else + collapse_tile(tile->parent, tile); + + } + } } |