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
```
![image](/attachments/6595dfa9-aade-45f4-887c-e5db7f8d5a89)

Clock would be outside of the screen vertically:
```
box_h_position = 0.15
box_v_position = -1.0
```
![image](/attachments/0d6bdcc4-e9dd-4671-a65d-b8b9f063ffb6)

Clock would be outside of the screen horizontally and vertically:
```
box_h_position = -1.0
box_v_position = -1.0
input_len = 3
```
![image](/attachments/630b07fd-b400-4e71-8a67-1baf3a6700a0)

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
```
![image](/attachments/28902967-11a8-4c02-a4c9-1b92f9a728ee)

## 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:
MartorSkull
2026-05-01 20:09:34 +02:00
committed by AnErrupTion
parent 79eebd8ee0
commit fdf241bed5
3 changed files with 36 additions and 12 deletions

View File

@@ -97,6 +97,14 @@ blank_box = true
# Border foreground color id
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
# If set to null, none will be shown
box_title = null

View File

@@ -23,6 +23,8 @@ bigclock_12hr: bool = false,
bigclock_seconds: bool = false,
blank_box: bool = true,
border_fg: u32 = 0x00FFFFFF,
box_position_h: f32 = 0.5,
box_position_v: f32 = 0.4,
box_title: ?[]const u8 = null,
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q -n s 10%-",
brightness_down_key: ?[]const u8 = "F5",

View File

@@ -2046,22 +2046,36 @@ fn positionWidgets(ptr: *anyopaque) !void {
.childrenPosition()
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
state.box.positionXY(TerminalBuffer.START_POSITION
.addX((state.buffer.width - @min(state.buffer.width - 2, state.box.width)) / 2)
.addY((state.buffer.height - @min(state.buffer.height - 2, state.box.height)) / 2));
var bb_height = state.box.height;
var bb_width = state.box.width;
const clock_text_len = TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1);
if (state.config.bigclock != .none) {
const half_width = state.buffer.width / 2;
const half_label_width = (TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1)) / 2;
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));
bb_height += BigLabel.CHAR_HEIGHT + 2;
bb_width = @max(bb_width, clock_text_len);
}
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
.childrenPosition());