isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.09k stars 2.26k forks source link

How to adjust text size when using gui.Label() method? #5228

Open howz-chen opened 2 years ago

howz-chen commented 2 years ago

Checklist

My Question

My request is that draw a window and show some text info at the left-top corner of the window, and I use gui.Label('label_name') to realize this. But the text size is too small for the whole window, I checked the document about gui.Label and search the issues and then found that there was no method to adjust text size directly (but there was a method about gui.label3D, but this method not fit my request), so I want to ask is there any method to adjust label text size?

Below is the pseudo-code

import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering

gui.Application.instance.initialize()
self.window = gui.Application.instance.create_window('Example', width=1200, height=800)
self.widget = gui.SceneWidget()
self.widget.scene = rendering.Open3DScene(self.window.renderer)
self.widget.scene.set_background([0, 0, 0, 1])
self.window.add_child(self.widget)

em = self.window.theme.font_size
self._timestamp_text = gui.Label('TimeStamp')
self._timestamp_text.text_color = gui.Color(0.0, 1.0, 0.0)
horizon_layout = gui.Horiz()
horizon_layout.add_child(self._timestamp_text)
vertical_layout = gui.Vert()
vertical_layout.add_fixed(0.5 *em)
vertical_layout.add_child(horizon_layout)
self.window.add_child(vertical_layout)

And the visualization result like: Screenshot from 2022-06-21 15-12-29

It seems that text info font size is too small relative to thole window.

netbeifeng commented 1 year ago

Hi, you can add new font and adjust the font size there.

You may refer to this:

font_sans_serif = gui.FontDescription(
    typeface="sans-serif", style=gui.FontStyle.NORMAL, point_size=28)
font_monospace = gui.FontDescription(
    typeface="monospace", style=gui.FontStyle.BOLD, point_size=32)

# Must be run before application.create_window()
font_id_sans_serif = gui.Application.instance.add_font(font_sans_serif)
font_id_monospace = gui.Application.instance.add_font(font_monospace)

text = gui.Label("Some Text ... ")
# Change the font of Label
text.font_id = font_id_sans_serif
# Change the font color of Label
text.text_color = gui.Color(0, 0.396, 0.741)