Skip to content
Closed
18 changes: 12 additions & 6 deletions source/MRViewer/ImGuiHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void PlotCustomHistogram( const char* str_id,
const ImU32 col_hovered_top = GetColorU32(ImGuiCol_TabHovered);
ImVec4 col{ 1.0f, 0.2f, 0.2f, 1.0f };
const ImU32 col_selected = GetColorU32(col);
const ImU32 col_selected_top = GetColorU32(ImGuiCol_TabActive);
const ImU32 col_selected_top = GetColorU32( ImGuiCol_TabSelected );
const ImU32 col_grid = GetColorU32(ImGuiCol_PlotLines, 0.5f);
const ImU32 col_labels = GetColorU32(ImGuiCol_Text);

Expand Down Expand Up @@ -1083,14 +1083,14 @@ bool DragInputInt( const char* label, int* value, float speed /*= 1*/, int min /
DragInt( labelStr.c_str(), value, speed, min, max, format, flags );
drawTooltip( min, max );
ImGui::SameLine( 0, style.ItemInnerSpacing.x );
ImGui::PushButtonRepeat( true );
ImGui::PushItemFlag( ImGuiItemFlags_ButtonRepeat, true );

if ( MR::UI::button( "-", MR::Vector2f( sizeSide, sizeSide ) ) )
--valueRef;
ImGui::SameLine( 0, style.ItemInnerSpacing.x );
if ( MR::UI::button( "+", MR::Vector2f( sizeSide, sizeSide ) ) )
++valueRef;
ImGui::PopButtonRepeat();
ImGui::PopItemFlag();
valueRef = std::clamp( valueRef, min, max );

PopID();
Expand Down Expand Up @@ -1543,7 +1543,7 @@ void Plane( MR::PlaneWidget& planeWidget, PlaneWidgetFlags flags )

ImGui::SetNextItemWidth( 200.0f * UI::scale() );
UI::drag<NoUnit>( "Normal", plane.n, 0.001f );
ImGui::PushButtonRepeat( true );
ImGui::PushItemFlag( ImGuiItemFlags_ButtonRepeat, true );

const float arrowButtonSize = 2.0f * MR::cGradientButtonFramePadding * UI::scale() + ImGui::GetTextLineHeight();
ImFont* iconsFont = MR::RibbonFontManager::getFontByTypeStatic( MR::RibbonFontManager::FontType::Icons );
Expand Down Expand Up @@ -1571,7 +1571,7 @@ void Plane( MR::PlaneWidget& planeWidget, PlaneWidgetFlags flags )
}

ImGui::SameLine();
ImGui::PopButtonRepeat();
ImGui::PopItemFlag();

ImGui::SetNextItemWidth( 80.0f * UI::scale() );
UI::drag<LengthUnit>( "Shift", shift, dragspeed );
Expand Down Expand Up @@ -1632,7 +1632,7 @@ void Image( const MR::ImGuiImage& image, const ImVec2& size, const MR::Color& mu

void Image( const MR::ImGuiImage& image, const ImVec2& size, const ImVec4& multColor )
{
Image( image.getImTextureId(), size, ImVec2( 0, 1 ), ImVec2( 1, 0 ), multColor );
ImageWithBg( image.getImTextureId(), size, ImVec2( 0, 1 ), ImVec2( 1, 0 ), ImVec4(0, 0, 0, 0), multColor );
}

MR::Vector2i GetImagePointerCoord( const MR::ImGuiImage& image, const ImVec2& size, const ImVec2& imagePos )
Expand Down Expand Up @@ -1708,4 +1708,10 @@ bool ModalExitButton()
return false;
}

ImVec2 GetWindowContentRegionMax()
{
ImGuiWindow* window = GImGui->CurrentWindow;
return window->ContentRegionRect.Max - window->Pos;
}

} // namespace ImGui
37 changes: 29 additions & 8 deletions source/MRViewer/ImGuiHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "MRViewer/MRViewerFwd.h"
#include "MRViewer/MRUnits.h"
#include "MRViewer/MRImGui.h"
#include "MRViewer/MRImGuiVectorOperators.h"
#include <misc/cpp/imgui_stdlib.h>
#include <algorithm>
#include <functional>
Expand All @@ -30,12 +31,15 @@
namespace ImGui
{

static auto vector_getter = [](void* vec, int idx, const char** out_text)
static auto vector_getter = [] ( void* vec, int idx ) -> const char*
{
auto& vector = *static_cast<std::vector<std::string>*>(vec);
if (idx < 0 || idx >= static_cast<int>(vector.size())) { return false; }
*out_text = vector.at(idx).c_str();
return true;
auto& vector = *static_cast< std::vector<std::string>* >( vec );
if ( idx < 0 || idx >= static_cast< int >( vector.size() ) )
{
assert( false && "Combo: vector_getter invalid index" );
return "";
}
return vector.at( idx ).c_str();
};

inline bool Combo(const char* label, int* idx, const std::vector<std::string>& values)
Expand All @@ -47,11 +51,17 @@ inline bool Combo(const char* label, int* idx, const std::vector<std::string>& v

inline bool Combo(const char* label, int* idx, std::function<const char *(int)> getter, int items_count)
{
auto func = [](void* data, int i, const char** out_text) {
auto func = [](void* data, int i) -> const char*
{
auto &getter = *reinterpret_cast<std::function<const char *(int)> *>(data);
const char *s = getter(i);
if (s) { *out_text = s; return true; }
else { return false; }
if ( s )
return s;
else
{
assert( false && "Combo: getter return nullptr" );
return "";
}
};
return Combo(label, idx, func, reinterpret_cast<void *>(&getter), items_count);
}
Expand Down Expand Up @@ -345,4 +355,15 @@ inline float getLuminance( const ImVec4& col )
return 0.2126f * col.x + 0.7152f * col.y + 0.0722f * col.z;
}

/// content boundaries max for the full window (roughly (0,0)+Size-Scroll) where Size can be overridden with SetNextWindowContentSize(), in window coordinates
/// \note copied from imgui because imgui recommends against using this method
MRVIEWER_API ImVec2 GetWindowContentRegionMax();

/// current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
/// \note copied from imgui because imgui recommends against using this method
inline ImVec2 GetContentRegionMax()
{
return GetContentRegionAvail() + GetCursorScreenPos() - GetWindowPos();
}

} // namespace ImGui
2 changes: 1 addition & 1 deletion source/MRViewer/ImGuiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
namespace
{
// Reserved keys block
using OrderedKeys = std::bitset<ImGuiKey_KeysData_SIZE>;
using OrderedKeys = std::bitset<ImGuiKey_NamedKey_COUNT>;

OrderedKeys& getOrderedKeys()
{
Expand Down
4 changes: 2 additions & 2 deletions source/MRViewer/MRColorTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const char* ColorTheme::getRibbonColorTypeName( RibbonColorsType type )

"TabHovered",
"TabClicked",
"TabActive",
"TabActive", // in update ImGui 1.90.9 ImGuiCol_TabActive renamed to ImGuiCol_TabSelected, but we keep old name for backward compatibility with old color scheme files
"TabActiveHovered",
"TabActiveClicked",
"TabText",
Expand Down Expand Up @@ -453,7 +453,7 @@ void ColorTheme::resetImGuiStyle()
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4( 0, 0, 0, 0 );
style.Colors[ImGuiCol_PopupBg] = ImVec4( popupBg.x, popupBg.y, popupBg.z, popupBg.w );
style.Colors[ImGuiCol_Tab] = ImVec4( tabBg.x, tabBg.y, tabBg.z, tabBg.w );
style.Colors[ImGuiCol_TabActive] = ImVec4( tabBgActive.x, tabBgActive.y, tabBgActive.z, tabBgActive.w );
style.Colors[ImGuiCol_TabSelected] = ImVec4( tabBgActive.x, tabBgActive.y, tabBgActive.z, tabBgActive.w );
style.Colors[ImGuiCol_TabHovered] = ImVec4( tabBgHovered.x, tabBgHovered.y, tabBgHovered.z, tabBgHovered.w );

style.ScrollbarRounding = 4.0f;
Expand Down
6 changes: 4 additions & 2 deletions source/MRViewer/MRImGuiImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <MRMesh/MRMeshFwd.h>
#include <MRMesh/MRMeshTexture.h>
#include "MRRenderGLHelpers.h"
#include "MRViewer/MRImGui.h"

namespace MR
{
Expand All @@ -19,8 +20,9 @@ class MRVIEWER_CLASS ImGuiImage
// Sets image to texture
MRVIEWER_API void update( const MeshTexture& texture );

// Returns void* for ImGui::Image( getImTextureId(), ... )
void* getImTextureId() const { return (void*) (intptr_t) glTex_.getId(); }
// Returns ImTextureID for ImGui::Image( getImTextureId(), ... )
// ImGui recommends using the intermediate cast intptr_t
ImTextureID getImTextureId() const { return (ImTextureID) (intptr_t) glTex_.getId(); }

// Returns gl texture id
unsigned getId() const { return glTex_.getId(); }
Expand Down
6 changes: 3 additions & 3 deletions source/MRViewer/MRRibbonButtonDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ bool RibbonButtonDrawer::CustomCollapsingHeader( const char* label, ImGuiTreeNod
if ( bool( flags & ImGuiTreeNodeFlags_AllowOverlap ) )
{
setOverlap = true;
ImGui::GetCurrentContext()->LastItemData.InFlags |= ImGuiItemFlags_AllowOverlap;
ImGui::GetCurrentContext()->LastItemData.ItemFlags |= ImGuiItemFlags_AllowOverlap;
}
const auto isHovered = ImGui::IsItemHovered( ImGuiHoveredFlags_AllowWhenBlockedByActiveItem );
if ( setOverlap )
{
ImGui::GetCurrentContext()->LastItemData.InFlags &= ( ~ImGuiItemFlags_AllowOverlap );
ImGui::GetCurrentContext()->LastItemData.ItemFlags &= ( ~ImGuiItemFlags_AllowOverlap );
}

const auto windowBgColor = ImGui::GetStyleColorVec4( ImGuiCol_WindowBg );
Expand Down Expand Up @@ -269,7 +269,7 @@ void RibbonButtonDrawer::drawCustomButtonItem( const MenuItemInfo& item, const C

ImGui::PushStyleVar( ImGuiStyleVar_FrameBorderSize, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0, 0 ) );
ImGui::BeginChild( ( "##childGroup" + item.item->name() ).c_str(), itemSize, false,
ImGui::BeginChild( ( "##childGroup" + item.item->name() ).c_str(), itemSize, ImGuiChildFlags_None,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse );
ImGui::PopStyleVar();

Expand Down
11 changes: 9 additions & 2 deletions source/MRViewer/MRRibbonFontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ void RibbonFontManager::updateFontsScaledOffset_()
auto fontPath = fontPaths_[int( font.fontFile )];

ImFontConfig config;
if ( i != int( FontType::Icons ) )
config.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_Bitmap;
config.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_Bitmap;
if ( i == int( FontType::Icons ) )
continue; // skip icons, because AddFontFromFileTTF return a font without glyphs, after that, io.Fonts->Build() trigger assert and crash (after update ImGui to 1.91.9)

spdlog::info( "updateFontsScaledOffset_ 0 + {}", i );
auto fontSize = getFontSizeByType( FontType( i ) ) * UI::scale();
localFonts[i] = io.Fonts->AddFontFromFileTTF( utf8string( fontPath ).c_str(), fontSize, &config, wRange );
}
Expand All @@ -166,16 +168,21 @@ void RibbonFontManager::updateFontsScaledOffset_()
continue;
if ( lFont->Glyphs.size() != 1 )
continue;

spdlog::info( "updateFontsScaledOffset_ 1 + {} + 0", i );
const auto& glyph = lFont->Glyphs.back();
spdlog::info( "updateFontsScaledOffset_ 1 + {} + 1", i );

auto& fontRef = fonts_[int( i )];
auto fontSize = getFontSizeByType( FontType( i ) ) * UI::scale();
spdlog::info( "updateFontsScaledOffset_ 1 + {} + 2", i );
Box2f box;
box.include( Vector2f( glyph.X0, glyph.Y0 ) );
box.include( Vector2f( glyph.X1, glyph.Y1 ) );
fontRef.scaledOffset = 0.5f * ( Vector2f::diagonal( fontSize ) - box.size() ) - box.min;
fontRef.scaledOffset.x = std::round( -box.min.x ); // looks like Dear ImGui expecting glyph to start at the left side of the box, and not being in the center
fontRef.scaledOffset.y = std::round( fontRef.scaledOffset.y );
spdlog::info( "updateFontsScaledOffset_ 1 + {} + 3", i );
}
io.Fonts->Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion source/MRViewer/MRRibbonMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void RibbonMenu::drawActiveList_()
auto childName = "##CloseItemBlock" + item->name();

ImGui::PushStyleColor( ImGuiCol_ChildBg, ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::Background ).getUInt32() );
ImGui::BeginChild( childName.c_str(), blockSize, true,
ImGui::BeginChild( childName.c_str(), blockSize, ImGuiChildFlags_Borders,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse );
ImGui::PopStyleColor();
if ( sbFont )
Expand Down
9 changes: 7 additions & 2 deletions source/MRViewer/MRRibbonNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool RibbonNotifier::drawNotification_( const DrawNotificationSettings& settings
ImGuiWindowFlags flags =
ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoTitleBar | ( settings.historyMode ? ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysUseWindowPadding : 0 ) |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove;
std::string name = "##notification" + std::to_string( settings.index );
ImGui::PushStyleVar( settings.historyMode ? ImGuiStyleVar_ChildBorderSize : ImGuiStyleVar_WindowBorderSize, 0.0f );
Expand All @@ -295,7 +295,12 @@ bool RibbonNotifier::drawNotification_( const DrawNotificationSettings& settings

if ( !settings.historyMode && settings.index + 1 == cNotificationNumberLimit )
ImGui::SetNextWindowBgAlpha( 0.5f );
ImGui::Begin( name.c_str(), nullptr, flags );
if ( settings.historyMode )
{
ImGui::BeginChild( name.c_str(), {}, ImGuiChildFlags_AlwaysUseWindowPadding, flags );
}
else
ImGui::Begin( name.c_str(), nullptr, flags );

auto window = ImGui::GetCurrentContext()->CurrentWindow;

Expand Down
2 changes: 1 addition & 1 deletion source/MRViewer/MRRibbonSceneObjectsListDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void RibbonSceneObjectsListDrawer::drawObjectLine_( Object& object, const std::s
makeDragDropSource_( selected );
makeDragDropTarget_( object, false, false, uniqueStr );

context->LastItemData.InFlags |= ImGuiItemFlags_AllowOverlap; // needed so hover check respect overlap
context->LastItemData.ItemFlags |= ImGuiItemFlags_AllowOverlap; // needed so hover check respect overlap

bool frameHovered = ImGui::IsItemHovered();
if ( frameHovered )
Expand Down
4 changes: 2 additions & 2 deletions source/MRViewer/MRRibbonSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void RibbonSchemaLoader::readMenuItemsList( const Json::Value& root, MenuItemsLi
recalcItemSizes();
}

float sCalcSize( const ImFont* font, const char* begin, const char* end )
float sCalcSize( ImFont* font, const char* begin, const char* end )
{
float res = font->CalcTextSizeA( font->FontSize, FLT_MAX, -1.0f, begin, end ).x;
// Round
Expand All @@ -425,7 +425,7 @@ float sCalcSize( const ImFont* font, const char* begin, const char* end )
return float( int( res + +0.99999f ) );
}

SplitCaptionInfo sAutoSplit( const std::string& str, float maxWidth,const ImFont* font, float baseSize )
SplitCaptionInfo sAutoSplit( const std::string& str, float maxWidth, ImFont* font, float baseSize )
{
if ( baseSize < maxWidth )
return { { str, baseSize } };
Expand Down
2 changes: 1 addition & 1 deletion source/MRViewer/MRSceneObjectsListDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SkippableRenderer

void SceneObjectsListDrawer::draw( float height )
{
ImGui::BeginChild( "SceneObjectsList", ImVec2( -1, height ), false );
ImGui::BeginChild( "SceneObjectsList", ImVec2( -1, height ), ImGuiChildFlags_None );
updateSceneWindowScrollIfNeeded_();
drawObjectsList_();
// any click on empty space below Scene Tree removes object selection
Expand Down
9 changes: 5 additions & 4 deletions source/MRViewer/MRToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void Toolbar::drawCustomizeModal_()
DrawButtonParams params{ DrawButtonParams::SizeType::Small, smallItemSize, cMiddleIconSize, DrawButtonParams::RootType::Toolbar };

ImGui::PushStyleColor( ImGuiCol_ChildBg, ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::QuickAccessBackground ).getUInt32() );
ImGui::BeginChild( "##QuickAccessCustomizeItems", ImVec2( itemsWindowWidth, smallItemSize.y + childWindowPadding.y * 2 ), true );
ImGui::BeginChild( "##QuickAccessCustomizeItems", ImVec2( itemsWindowWidth, smallItemSize.y + childWindowPadding.y * 2 ), ImGuiChildFlags_Borders );
ImGui::PopStyleColor();

ImVec2 tooltipSize = ImVec2( Vector2f::diagonal( 4 * UI::scale() ) + Vector2f( params.itemSize ) );
Expand Down Expand Up @@ -299,12 +299,13 @@ void Toolbar::drawCustomizeModal_()
ImGui::SetNextItemAllowOverlap();

ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2() );
ImGui::SetNextWindowSize( tooltipSize );

ImGui::PushStyleColor( ImGuiCol_Border, 0 );
ImGui::PushStyleColor( ImGuiCol_WindowBg, 0 );
if ( ImGui::BeginDragDropSource( ImGuiDragDropFlags_AcceptNoDrawDefaultRect ) )
{
ImGui::Dummy( tooltipSize );
ImGui::SetCursorPos( { 0, 0 } );
ImGui::SetDragDropPayload( "ToolbarItemNumber", &i, sizeof( int ) );
const auto& item = itemsList_[i];
auto iterItem = RibbonSchemaHolder::schema().items.find( item );
Expand Down Expand Up @@ -384,7 +385,7 @@ void Toolbar::drawCustomizeModal_()
ImGui::PopStyleVar();

float tabsListWidth = std::max( 130 * UI::scale(), ( itemsWindowWidth - childWindowPadding.x * 2 ) * 0.25f );
ImGui::BeginChild( "##QuickAccessCustomizeTabsList", ImVec2( tabsListWidth, -1 ) );
ImGui::BeginChild( "###QuickAccessCustomizeTabsList", ImVec2( tabsListWidth, -1 ), ImGuiChildFlags_Borders );
drawCustomizeTabsList_();
ImGui::EndChild();

Expand Down Expand Up @@ -421,7 +422,7 @@ void Toolbar::drawCustomizeModal_()
ImGui::PopStyleVar();

ImGui::PushStyleColor( ImGuiCol_ChildBg, ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::Background ).getUInt32() );
ImGui::BeginChild( "##QuickAccessCustomizeItemsList", ImVec2( -1, -1 ), true );
ImGui::BeginChild( "##QuickAccessCustomizeItemsList", ImVec2( -1, -1 ), ImGuiChildFlags_Borders );
ImGui::PopStyleColor();

drawCustomizeItemsList_();
Expand Down
Loading
Loading