Minor improvements
This commit is contained in:
parent
2583fd2c52
commit
da6d590908
4 changed files with 45 additions and 17 deletions
8
build.sh
8
build.sh
|
@ -4,7 +4,7 @@ set -eu
|
||||||
# Pre-requisites:
|
# Pre-requisites:
|
||||||
rustup target add wasm32-unknown-unknown
|
rustup target add wasm32-unknown-unknown
|
||||||
if ! [[ $(wasm-bindgen --version) ]]; then
|
if ! [[ $(wasm-bindgen --version) ]]; then
|
||||||
cargo update -p wasm-bindgen
|
cargo clean
|
||||||
cargo install -f wasm-bindgen-cli
|
cargo install -f wasm-bindgen-cli
|
||||||
cargo update
|
cargo update
|
||||||
fi
|
fi
|
||||||
|
@ -15,8 +15,6 @@ BUILD=debug
|
||||||
# Clear output from old stuff:
|
# Clear output from old stuff:
|
||||||
rm -rf docs/*.wasm
|
rm -rf docs/*.wasm
|
||||||
|
|
||||||
function build_rust
|
|
||||||
{
|
|
||||||
echo "Build rust:"
|
echo "Build rust:"
|
||||||
cargo build --target wasm32-unknown-unknown
|
cargo build --target wasm32-unknown-unknown
|
||||||
|
|
||||||
|
@ -25,7 +23,3 @@ function build_rust
|
||||||
TARGET_NAME="example.wasm"
|
TARGET_NAME="example.wasm"
|
||||||
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
|
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
|
||||||
--out-dir docs --no-modules --no-typescript
|
--out-dir docs --no-modules --no-typescript
|
||||||
# --no-modules-global hoboho
|
|
||||||
}
|
|
||||||
|
|
||||||
build_rust
|
|
||||||
|
|
|
@ -409,7 +409,7 @@ impl Region {
|
||||||
options: self.options,
|
options: self.options,
|
||||||
id: self.id,
|
id: self.id,
|
||||||
dir: self.dir,
|
dir: self.dir,
|
||||||
cursor: vec2((self.available_space.x - width) / 2.0, self.cursor.y),
|
cursor: self.cursor + vec2((self.available_space.x - width) / 2.0, 0.0),
|
||||||
align,
|
align,
|
||||||
bounding_size: vec2(0.0, 0.0),
|
bounding_size: vec2(0.0, 0.0),
|
||||||
available_space: vec2(width, self.available_space.y),
|
available_space: vec2(width, self.available_space.y),
|
||||||
|
@ -560,6 +560,31 @@ impl Region {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function
|
||||||
|
pub fn floating_text(
|
||||||
|
&mut self,
|
||||||
|
pos: Vec2,
|
||||||
|
text: &str,
|
||||||
|
text_style: TextStyle,
|
||||||
|
align: (Align, Align),
|
||||||
|
text_color: Option<Color>,
|
||||||
|
) {
|
||||||
|
let font = &self.fonts()[text_style];
|
||||||
|
let (text, text_size) = font.layout_multiline(text, std::f32::INFINITY);
|
||||||
|
|
||||||
|
let x = match align.0 {
|
||||||
|
Align::Min => pos.x,
|
||||||
|
Align::Center => pos.x - 0.5 * text_size.x,
|
||||||
|
Align::Max => pos.x - text_size.x,
|
||||||
|
};
|
||||||
|
let y = match align.1 {
|
||||||
|
Align::Min => pos.y,
|
||||||
|
Align::Center => pos.y - 0.5 * text_size.y,
|
||||||
|
Align::Max => pos.y - text_size.y,
|
||||||
|
};
|
||||||
|
self.add_text(vec2(x, y), text_style, text, text_color);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_text(
|
pub fn add_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
pos: Vec2,
|
pos: Vec2,
|
||||||
|
|
|
@ -134,6 +134,7 @@ impl Rect {
|
||||||
pub fn min(&self) -> Vec2 {
|
pub fn min(&self) -> Vec2 {
|
||||||
self.pos
|
self.pos
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max(&self) -> Vec2 {
|
pub fn max(&self) -> Vec2 {
|
||||||
self.pos + self.size
|
self.pos + self.size
|
||||||
}
|
}
|
||||||
|
@ -141,6 +142,12 @@ impl Rect {
|
||||||
pub fn size(&self) -> Vec2 {
|
pub fn size(&self) -> Vec2 {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
|
pub fn width(&self) -> f32 {
|
||||||
|
self.size.x
|
||||||
|
}
|
||||||
|
pub fn height(&self) -> f32 {
|
||||||
|
self.size.y
|
||||||
|
}
|
||||||
|
|
||||||
// Convenience functions:
|
// Convenience functions:
|
||||||
pub fn left_top(&self) -> Vec2 {
|
pub fn left_top(&self) -> Vec2 {
|
||||||
|
|
|
@ -84,8 +84,9 @@ impl App {
|
||||||
.rect
|
.rect
|
||||||
.min();
|
.min();
|
||||||
|
|
||||||
|
let mut cmds = vec![];
|
||||||
for i in 0..self.num_boxes {
|
for i in 0..self.num_boxes {
|
||||||
gui.add_graphic(GuiCmd::PaintCommands(vec![PaintCmd::Rect {
|
cmds.push(PaintCmd::Rect {
|
||||||
corner_radius: self.corner_radius,
|
corner_radius: self.corner_radius,
|
||||||
fill_color: Some(srgba(136, 136, 136, 255)),
|
fill_color: Some(srgba(136, 136, 136, 255)),
|
||||||
rect: Rect::from_min_size(
|
rect: Rect::from_min_size(
|
||||||
|
@ -96,8 +97,9 @@ impl App {
|
||||||
width: self.stroke_width,
|
width: self.stroke_width,
|
||||||
color: srgba(255, 255, 255, 255),
|
color: srgba(255, 255, 255, 255),
|
||||||
}),
|
}),
|
||||||
}]));
|
});
|
||||||
}
|
}
|
||||||
|
gui.add_graphic(GuiCmd::PaintCommands(cmds));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue