MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / drawCustomButtonItem

Method drawCustomButtonItem

source/MRViewer/MRRibbonButtonDrawer.cpp:262–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262void RibbonButtonDrawer::drawCustomButtonItem( const MenuItemInfo& item, const CustomButtonParameters& customParam,
263 const DrawButtonParams& params ) const
264{
265 std::string requirements = getRequirements_( item.item );
266 bool dropItem = item.item->type() == RibbonItemType::ButtonWithDrop;
267
268 ImVec2 itemSize = params.itemSize;
269 if ( dropItem && params.sizeType == DrawButtonParams::SizeType::Small )
270 itemSize.x += params.itemSize.x * cSmallItemDropSizeModifier;
271
272 ImGui::PushStyleVar( ImGuiStyleVar_FrameBorderSize, 0.0f );
273 ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0, 0 ) );
274 ImGui::BeginChild( ( "##childGroup" + item.item->name() ).c_str(), itemSize, ImGuiChildFlags_None,
275 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse );
276 ImGui::PopStyleVar();
277
278 ImGui::BeginGroup();
279
280 int colorChanged = customParam.pushColorsCb ?
281 customParam.pushColorsCb( requirements.empty(), item.item->isActive() ) :
282 pushRibbonButtonColors( requirements.empty(), item.item->isActive(), params.forceHovered, params.rootType );
283 ImGui::SetNextItemAllowOverlap();
284 bool pressed = ImGui::ButtonEx( ( "##wholeChildBtn" + item.item->name() ).c_str(), itemSize, ImGuiButtonFlags_AllowOverlap );
285 pressed = UI::TestEngine::createButton(
286 item.item->name(),
287 { .disabledReason = requirements } ) || pressed; // Must not short-circuit.
288 pressed = pressed || params.forcePressed;
289
290 float fontScale = 1.f;
291 if ( params.iconSize != 0 )
292 fontScale = params.iconSize / cBigIconSize;
293 else if ( params.sizeType != DrawButtonParams::SizeType::Big )
294 fontScale = cSmallIconSize / cBigIconSize;
295 RibbonFontHolder iconsFont( RibbonFontManager::FontType::Icons, fontScale );
296 if ( !iconsFont.isPushed() )
297 fontScale = 1.f;
298
299 auto imageRequiredSize = std::round( 32.0f * fontScale * UI::scale() );
300 ImVec2 iconRealSize = ImVec2( imageRequiredSize, imageRequiredSize );
301 bool needTextColor = !requirements.empty() || item.item->isActive() || params.rootType != DrawButtonParams::Ribbon;
302 bool needChangeColor = needTextColor || monochrome_.has_value();
303 auto* imageIcon = RibbonIcons::findByName( item.item->name(), iconRealSize.x, needChangeColor ?
304 RibbonIcons::ColorType::White : RibbonIcons::ColorType::Colored,
305 customParam.iconType );
306
307 if ( !imageIcon )
308 iconRealSize = ImGui::CalcTextSize( item.icon.c_str() );
309
310 if ( params.sizeType != DrawButtonParams::SizeType::SmallText )
311 {
312 ImGui::SetCursorPosX( ( params.itemSize.x - iconRealSize.x ) * 0.5f );
313 }
314 else
315 {
316 if ( !imageIcon )
317 ImGui::SetCursorPosX( ImGui::GetStyle().WindowPadding.x );
318 else
319 ImGui::SetCursorPosX( ImGui::GetStyle().WindowPadding.x * 0.5f );

Callers 2

drawToolbarMethod · 0.80
drawActiveListButton_Method · 0.80

Calls 13

ImVec2Class · 0.85
createButtonFunction · 0.85
roundFunction · 0.85
ImVec4Class · 0.85
TextClass · 0.85
popFontMethod · 0.80
scaleFunction · 0.70
ImageFunction · 0.70
translateFunction · 0.70
nameMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected