fn position(self: Window, disp_frame: Frame) Position {
if (self.isTop(disp_frame)) {
if (self.isRight(disp_frame)) return .top_right;
if (self.isLeft(disp_frame)) return .top_left;
if (self.isFullWidth(disp_frame)) return .top_wide;
return .top_mid;
}
if (self.isBottom(disp_frame)) {
if (self.isRight(disp_frame)) return .bottom_right;
if (self.isLeft(disp_frame)) return .bottom_left;
if (self.isFullWidth(disp_frame)) return .bottom_wide;
return .bottom_mid;
}
if (self.isFullHeight(disp_frame)) {
if (self.isRight(disp_frame)) return .tall_right;
if (self.isLeft(disp_frame)) return .tall_left;
return .full;
}
return .other;
}
#Many ifs and returns, is there a better way to write this?
1 messages · Page 1 of 1 (latest)
LGTM
There is but I don't have the code no more
but basically a switch with a comptime function that compress it a bit
Otherwise this is the best way
thanks, at least I'm not doing something bad
You and also use and btw
but that only if you care about the little extra nesting
which is not much
and in zig is shortcircuiting
I had an and version but it just repeated the first condition a lot