mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-06 15:20:36 +00:00
Add option to move the box relative to the screen size (#964)
## What are the changes about? Added a new option in the configuration file for moving the box relative to the screen size. ``` box_h_position = 0.5 box_v_position = 0.5 ``` The big clock is centered relative to the box. In the cases where it would be outside of the screen, it moves the box to fit in the screen. ## What existing issue does this resolve? Add more options for personalization ## Examples Normal usage: ``` box_h_position = 0.15 box_v_position = 0.35 ```  Clock would be outside of the screen vertically: ``` box_h_position = 0.15 box_v_position = -1.0 ```  Clock would be outside of the screen horizontally and vertically: ``` box_h_position = -1.0 box_v_position = -1.0 input_len = 3 ```  Clock would be outside of the screen horizontally and vertically on the bottom left of the screen: ``` box_h_position = 2.0 box_v_position = 2.0 input_len = 3 ```  ## What existing issue does this resolve? _Replace this with a reference to an existing issue, or N/A if there is none_ ## Pre-requisites - [x] I have tested & confirmed the changes work locally - [x] I have run `zig fmt` throughout my changes Co-authored-by: AnErrupTion <anerruption+codeberg@disroot.org> Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/964 Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org>
This commit is contained in:
@@ -97,6 +97,14 @@ blank_box = true
|
|||||||
# Border foreground color id
|
# Border foreground color id
|
||||||
border_fg = 0x00FFFFFF
|
border_fg = 0x00FFFFFF
|
||||||
|
|
||||||
|
# Relative horizontal position from the end of the screen
|
||||||
|
# default: 0.5
|
||||||
|
box_position_h = 0.5
|
||||||
|
|
||||||
|
# Relative vertical position from the bottom of the screen
|
||||||
|
# default: 0.4
|
||||||
|
box_position_v = 0.4
|
||||||
|
|
||||||
# Title to show at the top of the main box
|
# Title to show at the top of the main box
|
||||||
# If set to null, none will be shown
|
# If set to null, none will be shown
|
||||||
box_title = null
|
box_title = null
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ bigclock_12hr: bool = false,
|
|||||||
bigclock_seconds: bool = false,
|
bigclock_seconds: bool = false,
|
||||||
blank_box: bool = true,
|
blank_box: bool = true,
|
||||||
border_fg: u32 = 0x00FFFFFF,
|
border_fg: u32 = 0x00FFFFFF,
|
||||||
|
box_position_h: f32 = 0.5,
|
||||||
|
box_position_v: f32 = 0.4,
|
||||||
box_title: ?[]const u8 = null,
|
box_title: ?[]const u8 = null,
|
||||||
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q -n s 10%-",
|
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q -n s 10%-",
|
||||||
brightness_down_key: ?[]const u8 = "F5",
|
brightness_down_key: ?[]const u8 = "F5",
|
||||||
|
|||||||
38
src/main.zig
38
src/main.zig
@@ -2046,22 +2046,36 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||||||
.childrenPosition()
|
.childrenPosition()
|
||||||
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
|
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
|
||||||
|
|
||||||
state.box.positionXY(TerminalBuffer.START_POSITION
|
var bb_height = state.box.height;
|
||||||
.addX((state.buffer.width - @min(state.buffer.width - 2, state.box.width)) / 2)
|
var bb_width = state.box.width;
|
||||||
.addY((state.buffer.height - @min(state.buffer.height - 2, state.box.height)) / 2));
|
const clock_text_len = TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1);
|
||||||
|
|
||||||
if (state.config.bigclock != .none) {
|
if (state.config.bigclock != .none) {
|
||||||
const half_width = state.buffer.width / 2;
|
bb_height += BigLabel.CHAR_HEIGHT + 2;
|
||||||
const half_label_width = (TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1)) / 2;
|
bb_width = @max(bb_width, clock_text_len);
|
||||||
const half_height = (if (state.buffer.height > state.box.height) state.buffer.height - state.box.height else state.buffer.height) / 2;
|
|
||||||
|
|
||||||
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
|
|
||||||
.addX(half_width)
|
|
||||||
.removeXIf(half_label_width, half_width > half_label_width)
|
|
||||||
.addY(half_height)
|
|
||||||
.removeYIf(BigLabel.CHAR_HEIGHT + 2, half_height > BigLabel.CHAR_HEIGHT + 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const max_v_position: f32 = @floatFromInt(state.buffer.height - bb_height - 1);
|
||||||
|
const max_h_position: f32 = @floatFromInt(state.buffer.width - bb_width - 1);
|
||||||
|
|
||||||
|
bb_height = @min(bb_height, state.buffer.height - 2);
|
||||||
|
bb_width = @min(bb_width, state.buffer.width - 2);
|
||||||
|
|
||||||
|
const v_space: f32 = @floatFromInt(state.buffer.height - bb_height);
|
||||||
|
const v_position: usize = @intFromFloat(std.math.clamp(v_space * state.config.box_position_v, 1.0, max_v_position));
|
||||||
|
const h_space: f32 = @floatFromInt(state.buffer.width - bb_width);
|
||||||
|
const h_position: usize = @intFromFloat(std.math.clamp(h_space * state.config.box_position_h, 1.0, max_h_position));
|
||||||
|
|
||||||
|
if (state.config.bigclock != .none) {
|
||||||
|
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
|
||||||
|
.addX(h_position + (bb_width - clock_text_len) / 2)
|
||||||
|
.addY(v_position));
|
||||||
|
}
|
||||||
|
|
||||||
|
state.box.positionXY(TerminalBuffer.START_POSITION
|
||||||
|
.addX(h_position + (bb_width - state.box.width) / 2)
|
||||||
|
.addY(v_position + (bb_height - state.box.height)));
|
||||||
|
|
||||||
state.info_line.label.positionY(state.box
|
state.info_line.label.positionY(state.box
|
||||||
.childrenPosition());
|
.childrenPosition());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user