Skip to content

Commit

Permalink
showcase を少し調整した
Browse files Browse the repository at this point in the history
  • Loading branch information
mitoma committed Oct 19, 2024
1 parent f447e7a commit 1a61440
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
30 changes: 30 additions & 0 deletions font_rasterizer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ impl Default for TextContext {
}

impl TextContext {
#[inline]
pub fn with_row_interval(mut self, row_interval: f32) -> Self {
self.row_interval = row_interval;
self
}

#[inline]
pub fn with_col_interval(mut self, col_interval: f32) -> Self {
self.col_interval = col_interval;
self
}

#[inline]
pub fn with_row_scale(mut self, row_scale: f32) -> Self {
self.row_scale = row_scale;
self
}

#[inline]
pub fn with_col_scale(mut self, col_scale: f32) -> Self {
self.col_scale = col_scale;
self
}

#[inline]
pub fn with_max_col(mut self, max_col: usize) -> Self {
self.max_col = max_col;
self
}

pub fn instance_scale(&self) -> [f32; 2] {
match self.direction {
Direction::Horizontal => [self.col_scale, self.row_scale],
Expand Down
9 changes: 9 additions & 0 deletions font_rasterizer/src/ui/textedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ impl Default for TextEdit {
}
}

impl TextEdit {
pub fn new(config: TextContext) -> Self {
Self {
config,
..Default::default()
}
}
}

impl Model for TextEdit {
fn set_position(&mut self, position: Point3<f32>) {
let p: [f32; 3] = position.into();
Expand Down
4 changes: 2 additions & 2 deletions sample_codes/showcase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*;
use font_rasterizer::{
camera::{Camera, CameraAdjustment, CameraOperation},
color_theme::ColorTheme,
context::{StateContext, WindowSize},
context::{StateContext, TextContext, WindowSize},
font_buffer::{Direction, GlyphVertexBuffer},
instances::GlyphInstances,
layout_engine::{HorizontalWorld, Model, ModelOperation, World},
Expand Down Expand Up @@ -72,7 +72,7 @@ impl SingleCharCallback {
.for_each(|k| store.register_keybind(k));

let mut world = HorizontalWorld::new(window_size);
let mut textedit = TextEdit::default();
let mut textedit = TextEdit::new(TextContext::default().with_max_col(40));

textedit.editor_operation(&EditorOperation::InsertString(
include_str!("../asset/initial.txt").to_string(),
Expand Down
17 changes: 17 additions & 0 deletions site/src/showcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ Click area and edit it!
console.log("WASM Loaded");
});
</script>

Usage
- Allow key : move curser.
- Ctrl + 0 : Reset zoom.
- Ctrl + 9: Fit the document's width to the screen.
- Ctrl + 8: Fit the document's height to the screen.
- Ctrl + Minus : Zoom out.
- Ctrl + Plus : Zoom in.
- Ctrl + Shift + L : Fit the entire document within the screen.
- Ctrl + Shift + D : Toggle direction. You can switch between vertical and horizontal writing.
- Ctrl + X, Ctrl + D, Ctrl + D : Change Theme. (Soralized Dark)
- Ctrl + X, Ctrl + D, Ctrl + L : Change Theme. (Soralized Light)
- Alt + ←→ : Adjust character spacing.
- Alt + ↑↓ : Adjust line spacing.
- Alt + Shift + ←→ : Adjust char width.
- Alt + Shift + ↑↓ : Adjust char height.
- Some Emacs keybindings can be used, but be careful as they may conflict with browser shortcuts and surprise you. (e.g., Ctrl + w closes the tab)

0 comments on commit 1a61440

Please sign in to comment.