Skip to content

Commit

Permalink
PR #12588 from Tamir91: [Viewer] Font size slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az committed Feb 5, 2024
2 parents 6287dc7 + e8e38d6 commit 6926aff
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 66 deletions.
37 changes: 21 additions & 16 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,31 @@ using namespace rs2::sw_update;

namespace rs2
{
void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18, ImFont*& monofont)
void imgui_easy_theming(ImFont*& font_dynamic, ImFont*& font_18, ImFont*& monofont, int& font_size)
{
ImGuiStyle& style = ImGui::GetStyle();

ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr;

const int OVERSAMPLE = config_file::instance().get(configurations::performance::font_oversample);
font_size = config_file::instance().get( configurations::window::font_size );

static const ImWchar icons_ranges[] = { 0xf000, 0xf999, 0 }; // will not be copied by AddFont* so keep in scope.

{
ImFontConfig config_words;
config_words.OversampleV = OVERSAMPLE;
config_words.OversampleH = OVERSAMPLE;
font_14 = io.Fonts->AddFontFromMemoryCompressedTTF(karla_regular_compressed_data, karla_regular_compressed_size, 16.f);
font_dynamic = io.Fonts->AddFontFromMemoryCompressedTTF( karla_regular_compressed_data,
karla_regular_compressed_size,
(float)font_size );

ImFontConfig config_glyphs;
config_glyphs.MergeMode = true;
config_glyphs.OversampleV = OVERSAMPLE;
config_glyphs.OversampleH = OVERSAMPLE;
font_14 = io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data,
font_dynamic = io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data,
font_awesome_compressed_size, 14.f, &config_glyphs, icons_ranges);
}

Expand Down Expand Up @@ -2701,7 +2704,7 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_FrameBg, sensor_bg);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue);
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
ImGui::SetCursorPos({ rc.x + 145, rc.y + 1 });
ImGui::SetCursorPos({ rc.x + 9.f * window.get_font_size(), rc.y + 1 });
std::string label = rsutils::string::from() << "##" << id << " " << pair.first;
ImGui::InputText(label.c_str(),
(char*)pair.second.data(),
Expand Down Expand Up @@ -2741,13 +2744,16 @@ namespace rs2
{
bool stop_recording = false;

ImGui::SetCursorPos({ windows_width - 35, pos.y + 3 });
ImGui::SetCursorPos({ windows_width - 42, pos.y + 3 });
ImGui_ScopePushFont(window.get_font());

ImGui_ScopePushStyleColor(ImGuiCol_Button, sensor_bg);
ImGui_ScopePushStyleColor(ImGuiCol_ButtonHovered, sensor_bg);
ImGui_ScopePushStyleColor(ImGuiCol_ButtonActive, sensor_bg);

int font_size = window.get_font_size();
ImVec2 button_size = { font_size * 1.9f, font_size * 1.9f };

if (!sub->streaming)
{
std::string label = rsutils::string::from()
Expand Down Expand Up @@ -2790,7 +2796,7 @@ namespace rs2
}
if (can_stream)
{
if (ImGui::Button(label.c_str(), { 30,30 }))
if( ImGui::Button( label.c_str(), button_size ) )
{
if (profiles.empty()) // profiles might be already filled
profiles = sub->get_selected_profiles();
Expand Down Expand Up @@ -2838,7 +2844,7 @@ namespace rs2
ImGui_ScopePushStyleColor(ImGuiCol_Text, light_blue);
ImGui_ScopePushStyleColor(ImGuiCol_TextSelectedBg, light_blue + 0.1f);

if (ImGui::Button(label.c_str(), { 30,30 }))
if( ImGui::Button( label.c_str(), button_size ) )
{
sub->stop(viewer.not_model);
std::string friendly_name = sub->s->get_info(RS2_CAMERA_INFO_NAME);
Expand Down Expand Up @@ -3022,8 +3028,7 @@ namespace rs2
const ImVec2 pos = ImGui::GetCursorPos();

draw_later.push_back([windows_width, &window, sub, pos, &viewer, this]() {
if (!sub->streaming) ImGui::SetCursorPos({ windows_width - 34 , pos.y - 3 });
else ImGui::SetCursorPos({ windows_width - 34, pos.y - 3 });
ImGui::SetCursorPos({ windows_width - 41, pos.y - 3 });

try
{
Expand Down Expand Up @@ -3112,9 +3117,7 @@ namespace rs2
const ImVec2 pos = ImGui::GetCursorPos();

draw_later.push_back([windows_width, &window, sub, pos, &viewer, this, pb]() {
if (!sub->streaming || !sub->post_processing_enabled) ImGui::SetCursorPos({ windows_width - 35, pos.y - 3 });
else
ImGui::SetCursorPos({ windows_width - 35, pos.y - 3 });
ImGui::SetCursorPos({ windows_width - 42, pos.y - 3 });

try
{
Expand All @@ -3123,6 +3126,8 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_Button, sensor_bg);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, sensor_bg);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, sensor_bg);
int font_size = window.get_font_size();
const ImVec2 button_size = { font_size * 2.f, font_size * 1.5f };

if (!sub->post_processing_enabled)
{
Expand All @@ -3135,7 +3140,7 @@ namespace rs2

ImGui::PushStyleColor(ImGuiCol_Text, redish);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, redish + 0.1f);
ImGui::ButtonEx(label.c_str(), { 25,24 }, ImGuiButtonFlags_Disabled);
ImGui::ButtonEx(label.c_str(), button_size, ImGuiButtonFlags_Disabled);
}
else
{
Expand All @@ -3145,7 +3150,7 @@ namespace rs2
<< pb->get_name();
ImGui::PushStyleColor(ImGuiCol_Text, light_blue);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue + 0.1f);
ImGui::ButtonEx(label.c_str(), { 25,24 }, ImGuiButtonFlags_Disabled);
ImGui::ButtonEx(label.c_str(), button_size, ImGuiButtonFlags_Disabled);
}
}
else
Expand All @@ -3160,7 +3165,7 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_Text, redish);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, redish + 0.1f);

if (ImGui::Button(label.c_str(), { 25,24 }))
if (ImGui::Button(label.c_str(), button_size))
{
pb->enable(true);
pb->save_to_config_file();
Expand All @@ -3181,7 +3186,7 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_Text, light_blue);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue + 0.1f);

if (ImGui::Button(label.c_str(), { 25,24 }))
if (ImGui::Button(label.c_str(), button_size))
{
pb->enable(false);
pb->save_to_config_file();
Expand Down
3 changes: 2 additions & 1 deletion common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ inline ImVec4 blend(const ImVec4& c, float a)

namespace rs2
{
void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18, ImFont*& monofont);
void imgui_easy_theming(ImFont*& font_dynamic, ImFont*& font_18, ImFont*& monofont, int& font_size);

constexpr const char* server_versions_db_url = "https://librealsense.intel.com/Releases/rs_versions_db.json";

Expand Down Expand Up @@ -147,6 +147,7 @@ namespace rs2
static const char* width{ "window.width" };
static const char* height{ "window.height" };
static const char* maximized{ "window.maximized" };
static const char* font_size{ "window.font_size" };
}
namespace performance
{
Expand Down
7 changes: 4 additions & 3 deletions common/option-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ bool option_model::draw_combobox( notifications_model & model,
std::string txt = rsutils::string::from()
<< ( use_option_name ? endpoint->get_option_name( opt ) : description ) << ":";

auto pos_x = ImGui::GetCursorPosX();
float text_length = ImGui::CalcTextSize( txt.c_str() ).x;
float combo_position_x = ImGui::GetCursorPosX() + text_length + 5;

ImGui::Text( "%s", txt.c_str() );
if( ImGui::IsItemHovered() && description )
Expand All @@ -239,7 +240,7 @@ bool option_model::draw_combobox( notifications_model & model,

ImGui::SameLine();
if( new_line )
ImGui::SetCursorPosX( pos_x + 140 );
ImGui::SetCursorPosX( combo_position_x );

ImGui::PushItemWidth( new_line ? -1.f : 100.f );

Expand All @@ -259,7 +260,7 @@ bool option_model::draw_combobox( notifications_model & model,
{
int tmp_selected = selected;
float tmp_value = value;
ImGui::PushItemWidth( 105.f );

if( ImGui::Combo( id.c_str(),
&tmp_selected,
labels.data(),
Expand Down
4 changes: 2 additions & 2 deletions common/output-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,13 @@ void frame_drops_dashboard::draw(ux_window& win, rect r)
ImGui::Text("%s", "Measurement Metric:"); ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 3);

ImGui::SetCursorPosX(200);
ImGui::SetCursorPosX( 11.5f * win.get_font_size() );

std::vector<const char*> methods;
methods.push_back("Viewer Processing Rate");
methods.push_back("Camera Timestamp Rate");

ImGui::PushItemWidth(r.w - 207);
ImGui::PushItemWidth(-1.f);
if (ImGui::Combo("##fps_method", &method, methods.data(), (int)(methods.size())))
{
clear(false);
Expand Down
2 changes: 1 addition & 1 deletion common/subdevice-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ namespace rs2
};

auto col0 = ImGui::GetCursorPosX();
auto col1 = 155.f;
auto col1 = 9.f * (float)config_file::instance().get( configurations::window::font_size );

if (ui.is_multiple_resolutions && !strcmp(s->get_info(RS2_CAMERA_INFO_NAME), "Stereo Module"))
{
Expand Down
5 changes: 3 additions & 2 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace rs2
config_file::instance().set_default(configurations::window::is_fullscreen, false);
config_file::instance().set_default(configurations::window::saved_pos, false);
config_file::instance().set_default(configurations::window::saved_size, false);
config_file::instance().set_default(configurations::window::font_size, 16);

config_file::instance().set_default(configurations::viewer::is_measuring, false);
config_file::instance().set_default(configurations::viewer::log_to_console, true);
Expand Down Expand Up @@ -376,7 +377,7 @@ namespace rs2
_2d_vis = std::make_shared<visualizer_2d>(std::make_shared<splash_screen_shader>());

// Load fonts to be used with the ImGui - TODO move to RAII
imgui_easy_theming(_font_14, _font_18, _monofont);
imgui_easy_theming(_font_dynamic, _font_18, _monofont, font_size);

// Register for UI-controller events
glfwSetWindowUserPointer(_win, this);
Expand Down Expand Up @@ -431,7 +432,7 @@ namespace rs2

ux_window::ux_window(const char* title, context &ctx) :
_win(nullptr), _width(0), _height(0), _output_height(0),
_font_14(nullptr), _font_18(nullptr), _monofont(nullptr), _app_ready(false),
_font_dynamic(nullptr), _font_18(nullptr), _monofont(nullptr), font_size(16), _app_ready(false),
_first_frame(true), _query_devices(true), _missing_device(false),
_hourglass_index(0), _dev_stat_message{}, _keep_alive(true), _title(title), _ctx(ctx)
{
Expand Down
6 changes: 4 additions & 2 deletions common/ux-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace rs2

ImFont* get_large_font() const { return _font_18; }
ImFont* get_monofont() const { return _monofont; }
ImFont* get_font() const { return _font_14; }
ImFont* get_font() const { return _font_dynamic; }
int get_font_size() const { return font_size; }

rs2::mouse_info& get_mouse() { return _mouse; }
float get_scale_factor() const { return _scale_factor; }
Expand Down Expand Up @@ -100,7 +101,8 @@ namespace rs2
int _fb_height = 0;
rs2::rect _viewer_rect;

ImFont *_font_14, *_font_18, *_monofont;
ImFont *_font_dynamic, *_font_18, *_monofont;
int font_size;
rs2::mouse_info _mouse{};
std::string _error_message;
float _scale_factor;
Expand Down
Loading

0 comments on commit 6926aff

Please sign in to comment.