MCPcopy Create free account
hub / github.com/davisking/dlib / compute_menu_geometry

Method compute_menu_geometry

dlib/gui_widgets/widgets.cpp:3714–3763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3712// ----------------------------------------------------------------------------------------
3713
3714 void menu_bar::
3715 compute_menu_geometry (
3716 )
3717 {
3718 long x = 7;
3719 long bg_x = 0;
3720 for (unsigned long i = 0; i < menus.size(); ++i)
3721 {
3722 // compute the locations of the text rectangles
3723 menus[i].rect.set_top(5);
3724 menus[i].rect.set_left(x);
3725 menus[i].rect.set_bottom(rect.bottom()-2);
3726
3727 unsigned long width, height;
3728 mfont->compute_size(menus[i].name,width,height);
3729 menus[i].rect = resize_rect_width(menus[i].rect, width);
3730 x = menus[i].rect.right()+10;
3731
3732 menus[i].bgrect.set_top(0);
3733 menus[i].bgrect.set_left(bg_x);
3734 menus[i].bgrect.set_bottom(rect.bottom()-2);
3735 menus[i].bgrect.set_right(x-5);
3736 bg_x = menus[i].bgrect.right()+1;
3737
3738 if (menus[i].underline_pos != std::string::npos)
3739 {
3740 // now compute the location of the underline bar
3741 rectangle r1 = mfont->compute_cursor_rect(
3742 menus[i].rect,
3743 menus[i].name,
3744 menus[i].underline_pos);
3745
3746 rectangle r2 = mfont->compute_cursor_rect(
3747 menus[i].rect,
3748 menus[i].name,
3749 menus[i].underline_pos+1);
3750
3751 menus[i].underline_p1.x() = r1.left()+1;
3752 menus[i].underline_p2.x() = r2.left()-1;
3753 menus[i].underline_p1.y() = r1.bottom()-mfont->height()+mfont->ascender()+2;
3754 menus[i].underline_p2.y() = r2.bottom()-mfont->height()+mfont->ascender()+2;
3755 }
3756 else
3757 {
3758 // there is no underline in this case
3759 menus[i].underline_p1 = menus[i].underline_p2;
3760 }
3761
3762 }
3763 }
3764
3765// ----------------------------------------------------------------------------------------
3766

Callers

nothing calls this directly

Calls 13

resize_rect_widthFunction · 0.85
set_topMethod · 0.80
set_leftMethod · 0.80
set_bottomMethod · 0.80
compute_sizeMethod · 0.80
set_rightMethod · 0.80
compute_cursor_rectMethod · 0.80
sizeMethod · 0.45
bottomMethod · 0.45
rightMethod · 0.45
leftMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected