windowHeader
Normal widgets seen at the top of floatingWindow. Includes a close
button, title str, and right_str, depends on dvui.Window.button_order:
- .cancel_ok -> close button left, title centered, right_str right
- .ok_cancel -> close button right, title left, right_str left of close
Handles raising and focusing the subwindow on click. To make
floatingWindow only move on a click-drag in the header, use:
floating_win.dragAreaSet(dvui.windowHeader("Title", "", show_flag));
Only valid between Window.beginand Window.end.
Parameters
- str:[]const u8
- []const u8
- right_str:[]const u8
- []const u8
- openflag:?*bool
- ?*bool
Source
Implementation
pub fn windowHeader(str: []const u8, right_str: []const u8, openflag: ?*bool) Rect.Physical {
var over = dvui.overlay(@src(), .{ .expand = .horizontal, .name = "WindowHeader" });
const bo = dvui.currentWindow().button_order;
const align_x: f32 = if (bo == .ok_cancel) 0.0 else 0.5;
dvui.labelNoFmt(@src(), str, .{ .align_x = align_x }, .{
.expand = .horizontal,
.font = .theme(.heading),
.padding = .{ .x = 6, .y = 6, .w = 6, .h = 4 },
.label = .{ .for_id = dvui.subwindowCurrentId() },
});
var hbox: ?*BoxWidget = null;
if (bo == .ok_cancel) hbox = dvui.box(@src(), .{ .dir = .horizontal }, .{ .gravity_x = 1.0 });
if (openflag) |of| {
const opts: Options = .{ .font = .theme(.heading), .corners = .all(1000), .padding = Rect.all(2), .margin = Rect.all(2), .gravity_y = 0.5, .expand = .ratio, .gravity_x = if (bo == .ok_cancel) 1.0 else 0.0 };
if (dvui.buttonIcon(
@src(),
"close",
entypo.cross,
.{},
.{},
opts,
)) {
of.* = false;
}
}
dvui.labelNoFmt(@src(), right_str, .{}, .{ .gravity_x = if (bo == .ok_cancel) 0.0 else 1.0 });
if (hbox) |hb| hb.deinit();
const evts = events();
for (evts) |*e| {
if (!eventMatch(e, .{ .id = over.data().id, .r = over.data().contentRectScale().r }))
continue;
if (e.evt == .mouse and e.evt.mouse.action == .press and e.evt.mouse.button.pointer()) {
// raise this subwindow but let the press continue so the window
// will do the drag-move
raiseSubwindow(subwindowCurrentId());
} else if (e.evt == .mouse and e.evt.mouse.action == .focus) {
// our window will already be focused, but this prevents the window
// from clearing the focused widget
e.handle(@src(), over.data());
}
}
var ret = over.data().rectScale().r;
over.deinit();
const swd = dvui.separator(@src(), .{ .expand = .horizontal });
ret.h += swd.rectScale().r.h;
return ret;
}