Skip to content

Commit 99bdd0d

Browse files
Added math operations to vec2 type
Added methods for getting attributes of cells mutably
1 parent 5923e5b commit 99bdd0d

File tree

7 files changed

+190
-0
lines changed

7 files changed

+190
-0
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export DIRENV_WARN_TIMEOUT=20s
2+
3+
eval "$(devenv direnvrc)"
4+
5+
# The use_devenv function supports passing flags to the devenv command
6+
# For example: use devenv --impure --option services.postgres.enable:bool true
7+
use devenv

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
/target
2+
3+
# Devenv
4+
.devenv*
5+
devenv.local.nix
6+
7+
# direnv
8+
.direnv
9+
10+
# pre-commit
11+
.pre-commit-config.yaml

devenv.lock

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1749934215,
7+
"owner": "cachix",
8+
"repo": "devenv",
9+
"rev": "0ad2d684f722b41578b34670428161d996382e64",
10+
"type": "github"
11+
},
12+
"original": {
13+
"dir": "src/modules",
14+
"owner": "cachix",
15+
"repo": "devenv",
16+
"type": "github"
17+
}
18+
},
19+
"flake-compat": {
20+
"flake": false,
21+
"locked": {
22+
"lastModified": 1747046372,
23+
"owner": "edolstra",
24+
"repo": "flake-compat",
25+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
26+
"type": "github"
27+
},
28+
"original": {
29+
"owner": "edolstra",
30+
"repo": "flake-compat",
31+
"type": "github"
32+
}
33+
},
34+
"git-hooks": {
35+
"inputs": {
36+
"flake-compat": "flake-compat",
37+
"gitignore": "gitignore",
38+
"nixpkgs": [
39+
"nixpkgs"
40+
]
41+
},
42+
"locked": {
43+
"lastModified": 1749636823,
44+
"owner": "cachix",
45+
"repo": "git-hooks.nix",
46+
"rev": "623c56286de5a3193aa38891a6991b28f9bab056",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "cachix",
51+
"repo": "git-hooks.nix",
52+
"type": "github"
53+
}
54+
},
55+
"gitignore": {
56+
"inputs": {
57+
"nixpkgs": [
58+
"git-hooks",
59+
"nixpkgs"
60+
]
61+
},
62+
"locked": {
63+
"lastModified": 1709087332,
64+
"owner": "hercules-ci",
65+
"repo": "gitignore.nix",
66+
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
67+
"type": "github"
68+
},
69+
"original": {
70+
"owner": "hercules-ci",
71+
"repo": "gitignore.nix",
72+
"type": "github"
73+
}
74+
},
75+
"nixpkgs": {
76+
"locked": {
77+
"lastModified": 1746807397,
78+
"owner": "cachix",
79+
"repo": "devenv-nixpkgs",
80+
"rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90",
81+
"type": "github"
82+
},
83+
"original": {
84+
"owner": "cachix",
85+
"ref": "rolling",
86+
"repo": "devenv-nixpkgs",
87+
"type": "github"
88+
}
89+
},
90+
"root": {
91+
"inputs": {
92+
"devenv": "devenv",
93+
"git-hooks": "git-hooks",
94+
"nixpkgs": "nixpkgs",
95+
"pre-commit-hooks": [
96+
"git-hooks"
97+
]
98+
}
99+
}
100+
},
101+
"root": "root",
102+
"version": 7
103+
}

devenv.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
inputs,
6+
...
7+
}: {
8+
languages.rust.enable = true;
9+
}

devenv.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
2+
inputs:
3+
nixpkgs:
4+
url: github:cachix/devenv-nixpkgs/rolling
5+
6+
# If you're using non-OSS software, you can set allowUnfree to true.
7+
# allowUnfree: true
8+
9+
# If you're willing to use a package that's vulnerable
10+
# permittedInsecurePackages:
11+
# - "openssl-1.1.1w"
12+
13+
# If you have more than one devenv you can merge them
14+
#imports:
15+
# - ./backend

src/math.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::{Add, AddAssign, Sub, SubAssign};
2+
13
/// A 2d Vector that has no math, is only used as a pretty version of a tuple of u16s
24
/// Can be made from (u16, u16).
35
/// Using a single u16.into() will create a vec2 where both values are the same.
@@ -19,6 +21,42 @@ impl From<u16> for Vec2 {
1921
}
2022
}
2123

24+
impl<V: Into<Vec2>> Add<V> for Vec2 {
25+
type Output = Vec2;
26+
fn add(mut self, rhs: V) -> Self::Output {
27+
let rhs = rhs.into();
28+
self.x += rhs.x;
29+
self.y += rhs.y;
30+
self
31+
}
32+
}
33+
34+
impl<V: Into<Vec2>> AddAssign<V> for Vec2 {
35+
fn add_assign(&mut self, rhs: V) {
36+
let rhs = rhs.into();
37+
self.x += rhs.x;
38+
self.y += rhs.y;
39+
}
40+
}
41+
42+
impl<V: Into<Vec2>> Sub<V> for Vec2 {
43+
type Output = Vec2;
44+
fn sub(mut self, rhs: V) -> Self::Output {
45+
let rhs = rhs.into();
46+
self.x -= rhs.x;
47+
self.y -= rhs.y;
48+
self
49+
}
50+
}
51+
52+
impl<V: Into<Vec2>> SubAssign<V> for Vec2 {
53+
fn sub_assign(&mut self, rhs: V) {
54+
let rhs = rhs.into();
55+
self.x -= rhs.x;
56+
self.y -= rhs.y;
57+
}
58+
}
59+
2260
/// Creates a Vec2 from the given inputs.
2361
pub fn vec2(x: u16, y: u16) -> Vec2 {
2462
Vec2 { x, y }

src/renderer/cell.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ impl Cell {
5353
&self.text
5454
}
5555

56+
pub fn text_mut(&mut self) -> &mut CompactString {
57+
&mut self.text
58+
}
59+
5660
pub fn style(&self) -> &ContentStyle {
5761
&self.style
5862
}
63+
64+
pub fn style_mut(&mut self) -> &mut ContentStyle {
65+
&mut self.style
66+
}
5967
}
6068

6169
impl Render for Cell {

0 commit comments

Comments
 (0)