drawBackground
Parameters
- self:*MenuItemWidget
- *MenuItemWidget
Source
Implementation
pub fn drawBackground(self: *MenuItemWidget) void {
var focused: bool = self.data().id == dvui.focusedWidgetId();
if (self.data().id == dvui.focusedWidgetIdInCurrentSubwindow()) {
menu().?.focused_menuItem_this_frame = true;
}
if (focused and menu().?.mouse_over and !self.mouse_over and (menu().?.submenus_activated or menu().?.floating())) {
// our menu got a mouse over but we didn't even though we were focused
focused = false;
dvui.focusWidget(menu().?.group.data().id, null, null);
}
if (focused or ((self.data().id == dvui.focusedWidgetIdInCurrentSubwindow()) and self.highlight)) {
if (!self.init_opts.submenu or !menu().?.submenus_activated) {
if (!self.init_opts.highlight_only) {
if (self.init_opts.focus_as_outline) {
self.show_active = true;
} else if (menu().?.mouse_mode and !menu().?.mouse_over) {
// following mouse but it's outside the menu
} else {
self.show_active = true;
}
}
}
}
if (self.data().visible()) {
const cols = self.style();
const rs = self.data().backgroundRectScale();
const cr = self.data().options.cornersGet().scale(rs.s, CornerRect.Physical);
if (self.show_active) {
if (self.init_opts.focus_as_outline) {
self.data().focusBorder();
if (self.highlight) {
rs.r.fill(cr, .{ .color = cols.color(.fill), .fade = 1.0 });
}
} else {
rs.r.fill(cr, .{ .color = cols.color(.fill), .fade = 1.0 });
}
} else if ((self.data().id == dvui.focusedWidgetIdInCurrentSubwindow()) or self.highlight) {
rs.r.fill(cr, .{ .color = cols.color(.fill), .fade = 1.0 });
} else if (self.data().options.backgroundGet()) {
rs.r.fill(cr, .{ .color = cols.color(.fill), .fade = 1.0 });
}
}
}