Skip to content

Commit

Permalink
font size
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Jan 22, 2023
1 parent ae63c3a commit 1f2ac41
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ lint:
cargo fmt -- --check --color always
cargo clippy --all-targets --all-features -- -D warnings

test:
make lint
cargo test --release

watch:
cargo watch -- cargo run

Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Basic features are under development for MacOs right now.

| Platform | Development Status |
| --- | --- |
| MacOs | In development |
| MacOs | In development 👷 |
| Linux | Not started yet |
| Windows | Not started yet |

Expand Down Expand Up @@ -84,16 +84,25 @@ Description: Set terminal window width.
width = 600
```

### Style
### Colors

- `background` - Set background color.

```toml
[style]
[colors]
background = "#151515"
cursor = "#8E12CC"
```

### Style

- `font_size` - Set font size.

```toml
[style]
font_size = 16.0
```



## TODO
Expand All @@ -108,7 +117,7 @@ cursor = "#8E12CC"
- [ ] Render font with custom color, size and family
- [ ] Fix topbar when resize
- [ ] Keep rendering with intervals
- [ ] Read and use configuration
- [x] Read and use configuration
- [ ] Keyboard input
- [ ] Alphabet keys (uppercase/lowcase)
- [x] Numbers keys
Expand Down
27 changes: 21 additions & 6 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ pub enum Performance {

#[derive(Default, Debug, Deserialize, PartialEq, Clone)]
pub struct Style {
background: String,
pub font_size: f32,
}

#[derive(Default, Debug, Deserialize, PartialEq, Clone)]
pub struct Colors {
pub background: String,
}

#[derive(Debug, Deserialize, PartialEq)]
Expand All @@ -21,6 +26,7 @@ pub struct Config {
pub width: u16,
pub height: u16,
pub style: Style,
pub colors: Colors,
}

impl Config {
Expand Down Expand Up @@ -58,9 +64,10 @@ impl Default for Config {
performance: Performance::default(),
width: 600,
height: 400,
style: Style {
colors: Colors {
background: String::from("#151515"),
},
style: Style { font_size: 16.0 },
}
}
}
Expand All @@ -74,7 +81,8 @@ mod tests {
performance: Performance,
width: u16,
height: u16,
style_background: String,
style_font_size: f32,
color_background: String,
) -> Config {
let toml_str = format!(
r#"
Expand All @@ -94,11 +102,14 @@ mod tests {
width = {}
[style]
font_size = {}
[colors]
background = {:?}
## TODO: Add more configs
"#,
performance, height, width, style_background
performance, height, width, style_font_size, color_background
);
let binding = format!("/tmp/{:?}-config.toml", performance);
let file_name = binding.as_str();
Expand All @@ -115,15 +126,17 @@ mod tests {
performance: Performance::High,
width: 300,
height: 200,
style: Style {
colors: Colors {
background: String::from("#151515"),
},
style: Style { font_size: 18.0 },
};

let result = create_temporary_config(
expected.performance,
300,
200,
18.0,
String::from("#151515"),
);
assert_eq!(result, expected);
Expand All @@ -135,15 +148,17 @@ mod tests {
performance: Performance::Low,
width: 400,
height: 400,
style: Style {
colors: Colors {
background: String::from("#151515"),
},
style: Style { font_size: 22.0 },
};

let result = create_temporary_config(
expected.performance,
400,
400,
22.0,
String::from("#151515"),
);
assert_eq!(result, expected);
Expand Down
5 changes: 4 additions & 1 deletion rio/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Arc;
use std::sync::Mutex;

pub struct Term {
font_size: f32,
device: wgpu::Device,
surface: wgpu::Surface,
queue: wgpu::Queue,
Expand Down Expand Up @@ -160,6 +161,8 @@ impl Term {
let current_transform = Self::projection(size.width, size.height);

Ok(Term {
// TODO: fix style propagation
font_size: config.style.font_size,
device,
surface,
staging_belt,
Expand Down Expand Up @@ -391,7 +394,7 @@ impl Term {
),
text: vec![Text::new(&output.lock().unwrap())
.with_color([1.0, 1.0, 1.0, 1.0])
.with_scale(18.0 * self.scale)],
.with_scale(self.font_size * self.scale)],
..Section::default()
});

Expand Down

0 comments on commit 1f2ac41

Please sign in to comment.