mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Replace DoButton_Menu
with DoButton_Ex
This adds highlighting color when hovering the main menu buttons (File, Tools, Settings), which was previously missing for these buttons. This also reduced duplicate code. Extract font size for menu buttons into constant `MENU` in new namespace `EditorFontSizes`.
This commit is contained in:
parent
af99f5ba57
commit
ca56aa0b4a
|
@ -218,16 +218,6 @@ int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const
|
|||
return DoButton_Editor_Common(pID, pText, Checked, pRect, 0, pToolTip);
|
||||
}
|
||||
|
||||
int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip)
|
||||
{
|
||||
pRect->Draw(ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), IGraphics::CORNER_T, 3.0f);
|
||||
|
||||
CUIRect Rect;
|
||||
pRect->VMargin(5.0f, &Rect);
|
||||
UI()->DoLabel(&Rect, pText, 10.0f, TEXTALIGN_ML);
|
||||
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
|
||||
}
|
||||
|
||||
int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip)
|
||||
{
|
||||
if(UI()->HotItem() == pID || Checked)
|
||||
|
@ -244,17 +234,17 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked,
|
|||
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
|
||||
}
|
||||
|
||||
int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize)
|
||||
int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize, int Align)
|
||||
{
|
||||
pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f);
|
||||
|
||||
CUIRect Rect;
|
||||
pRect->VMargin(pRect->w > 20.0f ? 5.0f : 0.0f, &Rect);
|
||||
pRect->VMargin(((Align & TEXTALIGN_MASK_HORIZONTAL) == TEXTALIGN_CENTER) ? 1.0f : 5.0f, &Rect);
|
||||
|
||||
SLabelProperties Props;
|
||||
Props.m_MaxWidth = Rect.w;
|
||||
Props.m_EllipsisAtEnd = true;
|
||||
UI()->DoLabel(&Rect, pText, FontSize, TEXTALIGN_MC, Props);
|
||||
UI()->DoLabel(&Rect, pText, FontSize, Align, Props);
|
||||
|
||||
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
|
||||
}
|
||||
|
@ -1263,7 +1253,7 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
|
|||
{
|
||||
// refocus button
|
||||
{
|
||||
TB_Bottom.VSplitLeft(45.0f, &Button, &TB_Bottom);
|
||||
TB_Bottom.VSplitLeft(50.0f, &Button, &TB_Bottom);
|
||||
static int s_RefocusButton = 0;
|
||||
int FocusButtonChecked = MapView()->IsFocused() ? -1 : 1;
|
||||
if(DoButton_Editor(&s_RefocusButton, "Refocus", FocusButtonChecked, &Button, 0, "[HOME] Restore map focus") || (m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_HOME)))
|
||||
|
@ -7654,7 +7644,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
|
|||
CUIRect FileButton;
|
||||
static int s_FileButton = 0;
|
||||
MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar);
|
||||
if(DoButton_Menu(&s_FileButton, "File", 0, &FileButton, 0, nullptr))
|
||||
if(DoButton_Ex(&s_FileButton, "File", 0, &FileButton, 0, nullptr, IGraphics::CORNER_T, EditorFontSizes::MENU, TEXTALIGN_ML))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuFileId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuFileId, FileButton.x, FileButton.y + FileButton.h - 1.0f, 120.0f, 174.0f, this, PopupMenuFile, PopupProperties);
|
||||
|
@ -7665,7 +7655,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
|
|||
CUIRect ToolsButton;
|
||||
static int s_ToolsButton = 0;
|
||||
MenuBar.VSplitLeft(60.0f, &ToolsButton, &MenuBar);
|
||||
if(DoButton_Menu(&s_ToolsButton, "Tools", 0, &ToolsButton, 0, nullptr))
|
||||
if(DoButton_Ex(&s_ToolsButton, "Tools", 0, &ToolsButton, 0, nullptr, IGraphics::CORNER_T, EditorFontSizes::MENU, TEXTALIGN_ML))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuToolsId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuToolsId, ToolsButton.x, ToolsButton.y + ToolsButton.h - 1.0f, 200.0f, 64.0f, this, PopupMenuTools, PopupProperties);
|
||||
|
@ -7676,7 +7666,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
|
|||
CUIRect SettingsButton;
|
||||
static int s_SettingsButton = 0;
|
||||
MenuBar.VSplitLeft(60.0f, &SettingsButton, &MenuBar);
|
||||
if(DoButton_Menu(&s_SettingsButton, "Settings", 0, &SettingsButton, 0, nullptr))
|
||||
if(DoButton_Ex(&s_SettingsButton, "Settings", 0, &SettingsButton, 0, nullptr, IGraphics::CORNER_T, EditorFontSizes::MENU, TEXTALIGN_ML))
|
||||
{
|
||||
static SPopupMenuId s_PopupMenuEntitiesId;
|
||||
UI()->DoPopupMenu(&s_PopupMenuEntitiesId, SettingsButton.x, SettingsButton.y + SettingsButton.h - 1.0f, 200.0f, 92.0f, this, PopupMenuSettings, PopupProperties);
|
||||
|
|
|
@ -827,10 +827,8 @@ public:
|
|||
int DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
|
||||
int DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, ColorRGBA Color, int Corners);
|
||||
|
||||
int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f);
|
||||
int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = EditorFontSizes::MENU, int Align = TEXTALIGN_MC);
|
||||
int DoButton_FontIcon(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f);
|
||||
|
||||
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
|
||||
int DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags = 0, const char *pToolTip = nullptr);
|
||||
|
||||
int DoButton_DraggableEx(const void *pID, const char *pText, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted, int Flags, const char *pToolTip = nullptr, int Corners = IGraphics::CORNER_ALL, float FontSize = 10.0f);
|
||||
|
|
|
@ -15,4 +15,8 @@ struct SEditBoxDropdownContext
|
|||
int m_Width = 0;
|
||||
};
|
||||
|
||||
namespace EditorFontSizes {
|
||||
MAYBE_UNUSED static constexpr float MENU = 10.0f;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue