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

Function checkboxWithoutTestEngine

source/MRViewer/MRUIStyle.cpp:766–884  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766static bool checkboxWithoutTestEngine( const char* label, bool* value )
767{
768 const ImGuiStyle& style = ImGui::GetStyle();
769
770 StyleParamHolder sh;
771 sh.addVar( ImGuiStyleVar_ItemInnerSpacing, ImVec2( cRadioInnerSpacingX * UI::scale(), style.ItemInnerSpacing.y * UI::scale() ) );
772 auto& texture = getTexture( TextureType::Gradient );
773 if ( !texture )
774 return ImGui::Checkbox( label, value );
775
776 if ( *value )
777 sh.addColor( ImGuiCol_FrameBg, Color::transparent() );
778 sh.addColor( ImGuiCol_CheckMark, Color::white() );
779 sh.addVar( ImGuiStyleVar_FrameBorderSize, 1.5f );
780 sh.addVar( ImGuiStyleVar_FramePadding, { cCheckboxPadding * UI::scale(), cCheckboxPadding * UI::scale() } );
781
782 auto window = ImGui::GetCurrentContext()->CurrentWindow;
783 const float clickSize = ImGui::GetFrameHeight();
784
785 ImVec2 pos = window->DC.CursorPos;
786 const ImRect bb( pos, ImVec2( pos.x + clickSize, pos.y + clickSize ) );
787
788 if ( value && *value )
789 ImGui::GetCurrentContext()->CurrentWindow->DrawList->AddImageRounded(
790 texture->getImTextureId(),
791 bb.Min, bb.Max,
792 ImVec2( 0.5f, 0.25f ), ImVec2( 0.5f, 0.75f ),
793 Color::white().getUInt32(), style.FrameRounding * 0.5f );
794
795 //code of this lambda is copied from ImGui::Checkbox in order to decrease thickness and change appearance of the check mark
796 auto drawCustomCheckbox = [] ( const char* label, bool* v )
797 {
798 if ( !ImGui::GetCurrentContext() || !v )
799 return false;
800
801 ImGuiContext& g = *ImGui::GetCurrentContext();
802 ImGuiWindow* window = g.CurrentWindow;
803 if ( !window || window->SkipItems )
804 return false;
805
806 const ImGuiStyle& style = ImGui::GetStyle();
807 const ImGuiID id = window->GetID( label );
808 const ImVec2 label_size = ImGui::CalcTextSize( label, NULL, true );
809
810 const float square_sz = ImGui::GetFrameHeight();
811 const ImVec2 pos = window->DC.CursorPos;
812 const ImRect total_bb( pos, ImVec2( pos.x + square_sz + ( label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f ), pos.y + label_size.y + style.FramePadding.y * 2.0f ) );
813 ImGui::ItemSize( total_bb, style.FramePadding.y );
814 if ( !ImGui::ItemAdd( total_bb, id ) )
815 {
816 IMGUI_TEST_ENGINE_ITEM_INFO( id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | ( *v ? ImGuiItemStatusFlags_Checked : 0 ) );
817 return false;
818 }
819
820 bool hovered, held;
821 bool pressed = ImGui::ButtonBehavior( total_bb, id, &hovered, &held );
822 if ( pressed )
823 {

Callers 3

checkboxFunction · 0.85
checkboxOrFixedValueFunction · 0.85
checkboxMixedFunction · 0.85

Calls 6

ImVec2Class · 0.85
CheckboxFunction · 0.85
addVarMethod · 0.80
addColorMethod · 0.80
getUInt32Method · 0.80
scaleFunction · 0.70

Tested by

no test coverage detected