mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-21 03:34:54 +00:00
Add option to center env name (#683)
This commit is contained in:
@@ -54,7 +54,7 @@ fn drawItem(label: *MessageLabel, message: Message, _: usize, _: usize) bool {
|
||||
if (message.width == 0 or label.buffer.box_width <= message.width) return false;
|
||||
|
||||
const x = label.buffer.box_x + ((label.buffer.box_width - message.width) / 2);
|
||||
label.first_char_x = x;
|
||||
label.first_char_x = x + message.width;
|
||||
|
||||
TerminalBuffer.drawColorLabel(message.text, x, label.y, message.fg, message.bg);
|
||||
return true;
|
||||
|
||||
@@ -133,7 +133,10 @@ fn drawItem(label: *EnvironmentLabel, environment: Environment, x: usize, y: usi
|
||||
const length = @min(environment.name.len, label.visible_length - 3);
|
||||
if (length == 0) return false;
|
||||
|
||||
const nx = if (label.text_in_center) (label.x + (label.visible_length - environment.name.len) / 2) else (label.x + 2);
|
||||
label.first_char_x = nx + environment.name.len;
|
||||
|
||||
label.buffer.drawLabel(environment.specifier, x, y);
|
||||
label.buffer.drawLabel(environment.name, label.x + 2, label.y);
|
||||
label.buffer.drawLabel(environment.name, nx, label.y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
||||
x: usize,
|
||||
y: usize,
|
||||
first_char_x: usize,
|
||||
text_in_center: bool,
|
||||
draw_item_fn: DrawItemFn,
|
||||
|
||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, draw_item_fn: DrawItemFn) Self {
|
||||
@@ -33,6 +34,7 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.first_char_x = 0,
|
||||
.text_in_center = false,
|
||||
.draw_item_fn = draw_item_fn,
|
||||
};
|
||||
}
|
||||
@@ -41,11 +43,14 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
||||
self.list.deinit();
|
||||
}
|
||||
|
||||
pub fn position(self: *Self, x: usize, y: usize, visible_length: usize) void {
|
||||
pub fn position(self: *Self, x: usize, y: usize, visible_length: usize, text_in_center: ?bool) void {
|
||||
self.x = x;
|
||||
self.y = y;
|
||||
self.visible_length = visible_length;
|
||||
self.first_char_x = x + 2;
|
||||
if (text_in_center) |value| {
|
||||
self.text_in_center = value;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addItem(self: *Self, item: ItemType) !void {
|
||||
|
||||
Reference in New Issue
Block a user