Calculate the space needed

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7480
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Calculate the space needed

Post by ONEEYEMAN »

Hi, ALL,
Let's say I have a wxTextCtrl.
I also have a text in a form of:
SELECT "a"."x", "b"."y" FROM "a", "b" WHERE "a".id" = "b"."id";
What I'd like to do is to display that string in that text control as:

Code: Select all

SELECT "a"."x",
             "b"."y"
FROM "a",
          "b"
WHERE "a"."id" = "b"."id;
I need a string "b"."y" to be exactly under "a"."x" (unfortunately the formatting is not preserved).

For that I need to calculate the number of spaces I need to add in order to format the string nicely.

What is the best way of doing it?

Or maybe there is a better way?

Thank you.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Calculate the space needed

Post by Kvaz1r »

First of all you should use monospace font and after that just find length of "SELECT " for second line and "FROM " for forth line. Am I understood you correct?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7480
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calculate the space needed

Post by ONEEYEMAN »

Hi,
Which fonts are monospace?
How to identify that the font is monospace?
And what do you mean - "identify the length"?

Thank you.
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: Calculate the space needed

Post by alys666 »

read about wxFont and search around <wxFONTFAMILY_TELETYPE>
ubuntu 20.04, wxWidgets 3.2.1
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7480
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calculate the space needed

Post by ONEEYEMAN »

Thank you guys.
Works as expected.
Post Reply