Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align text keyword for add_text (just like text alignment on buttons) #1111

Closed
DataExplorerUser opened this issue Jul 25, 2021 · 3 comments
Closed
Labels
type: feature New feature or request

Comments

@DataExplorerUser
Copy link
Contributor

It takes a lot of effort to align text to the right when using add_text. Text can be aligned on buttons, so it seems not too far-fetched to be able to specify alignment for add_text. Aligning numbers to the right is very useful for presenting data and financial information.

The text can be aligned on buttons and, with a bit of trickery, the fact that it's a button can be hidden, so that you end up with the following output.

align right with buttons

Code for creating the example above.

import dearpygui.dearpygui as dpg

BACKGROUND_COLOUR = (0,0,0)

with dpg.window(label="tutorial") as main_window:
    button1 = dpg.add_button(label="1.000,34", width=200)
    button2 = dpg.add_button(label="75,23", width=200)
    button3 = dpg.add_button(label="758,11", width=200)
    button4 = dpg.add_button(label="---------", width=200)
    button5 = dpg.add_button(label="1.833,68", width=200)

# create a button theme
with dpg.theme() as button_right:

    # set text alignment on button to align to the right
    dpg.add_theme_style(dpg.mvStyleVar_ButtonTextAlign, 1.00, category=dpg.mvThemeCat_Core)

    # set the colour of all states of a button to the background colour
    dpg.add_theme_color(dpg.mvThemeCol_Button, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
    dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
    dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)

# set the window background colour
with dpg.theme(default_theme=True) as theme_id:
    dpg.add_theme_color(dpg.mvThemeCol_WindowBg,BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)

def run():
    dpg.set_item_type_theme(dpg.mvButton, button_right)
    dpg.set_primary_window(main_window, True)
    dpg.start_dearpygui()

if __name__ == '__main__':
    run()

Related to #1057 but with 2 main differences:

  1. That issue applies to add_input_text, not add_text.
  2. That issue does not provide the hint to apply the imgui code from buttons to add_text / add_input_text.

Aligning text may not be as cool as 3D widgets, but very useful nonetheless 😉

@hoffstadt hoffstadt added the type: feature New feature or request label Jul 26, 2021
@hskun
Copy link

hskun commented Dec 4, 2021

I also need the align(start from right) funtion about add_text_input()
Capture

@west-rynes
Copy link

+1

@DataExplorerUser
Copy link
Contributor Author

Closed as part of the review of issues.

@DataExplorerUser DataExplorerUser closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants