15 MenuItem::MenuItem(
const char* label) : Button(new DefaultSkins::MenuItemSkin(), label) {}
17 const Insets ContextMenu::DEFAULT_PADDING = {2};
18 const Border ContextMenu::DEFAULT_BORDER = {1, 0xC9'C9'C9'66};
19 const ColorFill ContextMenu::DEFAULT_BACKGROUND_FILL = {0xEE'EE'EE'FF};
20 const Background ContextMenu::DEFAULT_BACKGROUND = {&DEFAULT_BACKGROUND_FILL};
21 const ShadowSpecification ContextMenu::DEFAULT_SHADOW = {{0, 3}, {1.05, 0.95}, 7, 0x22'22'22'18};
23 void MenuItem::setOnAction(ActionListener<MenuItem>* listener)
27 Button::setOnAction(
reinterpret_cast<ActionListener<Button>*
>(listener));
37 if (getComponent()->isAutoHide() && !getComponent()->containsComponent(event->getNewFocus()))
39 LOG_LIB_INFO(
"Hide ContextMenu!");
40 getComponent()->hide();
46 : m_Source(sourceComponent)
50 setPadding(DEFAULT_PADDING);
51 setBorder(&DEFAULT_BORDER);
52 setBackground(&DEFAULT_BACKGROUND);
53 setShadow(&DEFAULT_SHADOW);
58 scene->registerContextMenu(
this);
63 ContextMenu::~ContextMenu()
67 m_Source->getScene()->detachContextMenu(
this);
70 void ContextMenu::render(
const Sml::Rectangle<int32_t>& targetRegion)
72 Container::render(targetRegion);
75 Component* ContextMenu::getSource() {
return m_Source; }
76 void ContextMenu::setSource(Component* source) { m_Source = source; }
78 bool ContextMenu::isAutoHide()
const {
return m_AutoHide; }
79 void ContextMenu::setAutoHide(
bool autoHide) { m_AutoHide = autoHide; }
81 void ContextMenu::show()
83 setVisibility(Component::Visibility::VISIBLE_INTERACTABLE);
87 void ContextMenu::hide()
89 setVisibility(Component::Visibility::INVISIBLE_DISABLED);