mirror of https://git.sr.ht/~kikoodx/kble
Out of bounds cursor safety + update README.md with mouse controls
This commit is contained in:
parent
8fc2e3fefb
commit
170409c014
|
@ -41,6 +41,11 @@ Actions:
|
|||
* `-`: decrease scale (dezoom)
|
||||
* `=`: reset scale
|
||||
|
||||
# Mouse control
|
||||
* Right click: reset selection.
|
||||
* Hold left click: add to selection.
|
||||
* Hold left click + shift: select rectangle.
|
||||
|
||||
# License
|
||||
Copyright (c) 2021 KikooDX
|
||||
|
||||
|
|
|
@ -104,8 +104,11 @@ pub fn draw_selection(self: *Self, scale: u16, offset: Vec2) void {
|
|||
/// Set the `state` of a cell at `cursor` if possible
|
||||
pub fn select_cell(self: *Self, cursor: Vec2, state: bool) void {
|
||||
const target: u32 = @intCast(u32, cursor.y) * self.width + @intCast(u32, cursor.x);
|
||||
if (target < self.width * self.height and target >= 0)
|
||||
if (cursor.x < self.width and cursor.y < self.height and
|
||||
target < self.width * self.height and target >= 0)
|
||||
{
|
||||
self.selection[target] = state;
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset state of selection: `state` everywhere.
|
||||
|
|
Loading…
Reference in New Issue