gansm / finalcut

A text-based widget toolkit
https://github.com/gansm/finalcut/wiki/First-steps#first-steps-with-the-final-cut-widget-toolkit
GNU Lesser General Public License v3.0
981 stars 52 forks source link

Support of expanding text widget (+ / - syntax) #96

Closed siddharth99 closed 1 year ago

siddharth99 commented 2 years ago

I'm printing very simple pre-formatted text in a tabular format; I am tabulating myself using snprintf(..) etc. In below example I have a (X, *) that is the summation of (X, x1) and (X, x2). I am wondering if there's a way to support a expand section / contract section type syntax with some minor effort or reasonably achieve the same thing by placing buttons to the left of each expanding section and clicking on them.

My widget architecture is FDialog -> FScrollView -> FLabel and I just call FLabel::setText(..) to update the text.

    Current Layout
    -------------------------
    | id | mode | A | B | C |
    | X  | *    | 2 | 2 | 2 |
    | X  | x1   | 1 | 1 | 1 |
    | X  | x2   | 1 | 1 | 1 |
    | Y  | *    | 3 | 3 | 3 |
    | Y  | y1   | 1 | 1 | 1 |
    | Y  | y2   | 2 | 2 | 2 |
    -------------------------
    Desired unexpanded layout
    -------------------------
    | id | mode | A | B | C |
    + X  | *    | 2 | 2 | 2 |
    + Y  | *    | 3 | 3 | 3 |
    -------------------------
    Desired expanded layout when both expanded
    -------------------------
    | id | mode | A | B | C |
    - X  | *    | 2 | 2 | 2 |
    | X  | x1   | 1 | 1 | 1 |
    | X  | x2   | 1 | 1 | 1 |
    - Y  | *    | 3 | 3 | 3 |
    | Y  | y1   | 1 | 1 | 1 |
    | Y  | y2   | 2 | 2 | 2 |
    -------------------------

Thanks in advance!

gansm commented 2 years ago

I think you want to use a FListView widget in tree view mode. You can expand and collapse sub-lines by clicking the triangle, double-clicking a line, or using the +, -, , or keyboard keys.

Here is a small code example:

#include <final/final.h>

using namespace finalcut;

int main (int argc, char* argv[])
{
  FApplication app(argc, argv);

  FDialog dialog ("Expand and collapse data", &app);
  dialog.setGeometry (FPoint(30, 6), FSize(33, 10));

  FListView list (&dialog);
  list.ignorePadding();
  list.setGeometry (FPoint(1, 2), FSize(33, 9));

  // Add columns to the view
  list.addColumn ("id", 5);
  list.addColumn ("mode", 5);
  list.addColumn ("A", 5);
  list.addColumn ("B", 5);
  list.addColumn ("C", 5);

  // Activate tree view
  list.setTreeView();

  auto iter1 = list.insert ({"X", "*", "2", "2", "2"});
  list.insert ({"X", "x1", "1", "1", "1"}, iter1);
  list.insert ({"X", "x2", "1", "1", "1"}, iter1);

  auto iter2 = list.insert ({"Y", "*", "3", "3", "3"});
  list.insert ({"Y", "y1", "1", "1", "1"}, iter2);
  list.insert ({"Y", "y2", "2", "2", "2"}, iter2);

  app.setMainWidget(&dialog);
  dialog.show();
  return app.exec();
}

 

image

image

PS: Removing the ID in the sub-lines would emphasize the togetherness.

gansm commented 2 years ago

@siddharth99:

I have not received any further feedback from you. Can I assume that this is a working solution for you?

gansm commented 1 year ago

@siddharth99:

Is this a workable solution for you?

gansm commented 1 year ago

Based on the absence of feedback, I will be closing this issue.