Skip to content

Commit

Permalink
wip: app redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Mar 17, 2024
1 parent 59beb44 commit c516af0
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 178 deletions.
6 changes: 5 additions & 1 deletion recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
]
},
"build web": {
"cmd": "wasm-pack build --target web",
"cmd": "wasm-pack build --target web --dev",
"cwd": "./violet-demo/"
},
"build web profile": {
"cmd": "wasm-pack build --target web --profiling",
"cwd": "./violet-demo/"
},
"host": {
Expand Down
2 changes: 1 addition & 1 deletion violet-core/src/layout/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl LayoutCache {
pub(crate) fn insert_query_row(&mut self, value: CachedValue<Row>) {
self.query_row = Some(value);
if let Some(f) = self.on_invalidated.as_ref() {
// f(LayoutUpdate::SizeQueryUpdate)
f(LayoutUpdate::SizeQueryUpdate)
}
}

Expand Down
63 changes: 1 addition & 62 deletions violet-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
self, anchor, aspect_ratio, children, layout, max_size, maximize, min_size, offset,
padding, size, size_resolver,
},
layout::cache::{validate_cached_layout, validate_cached_query, CachedValue, LAYOUT_TOLERANCE},
layout::cache::{validate_cached_layout, validate_cached_query, CachedValue},
Edges, Rect,
};

Expand Down Expand Up @@ -223,67 +223,6 @@ impl SizingHints {
}
}

fn validate_sizing(entity: &EntityRef, sizing: &Sizing, limits: LayoutLimits) {
const TOLERANCE: f32 = 0.2;
if sizing.min.size().x > limits.max_size.x + TOLERANCE
|| sizing.min.size().y > limits.max_size.y + TOLERANCE
{
tracing::error!(
%entity,
min_size = %sizing.min.size(),
max_size = %limits.max_size,
"Minimum size exceeds size limit",
);
}

if sizing.preferred.size().x > limits.max_size.x + TOLERANCE
|| sizing.preferred.size().y > limits.max_size.y + TOLERANCE
{
tracing::error!(
%entity,
preferred_size = %sizing.preferred.size(),
?limits,
"Preferred size exceeds size limit",
);
}

if sizing.min.size().x + TOLERANCE < limits.min_size.x
|| sizing.min.size().y + TOLERANCE < limits.min_size.y
{
tracing::error!(
%entity,
min_size = %sizing.min.size(),
?limits,
"Minimum size is less than size limit",
);
}
}

fn validate_block(entity: &EntityRef, block: &Block, limits: LayoutLimits) {
const TOLERANCE: f32 = 0.2;
if block.rect.size().x > limits.max_size.x + TOLERANCE
|| block.rect.size().y > limits.max_size.y + TOLERANCE
{
tracing::error!(
%entity,
rect_size = %block.rect.size(),
max_size = %limits.max_size,
"Widget size exceeds size limit",
);
}

if block.rect.size().x + TOLERANCE < limits.min_size.x
|| block.rect.size().y + TOLERANCE < limits.min_size.y
{
tracing::error!(
%entity,
rect_size = %block.rect.size(),
min_size = %limits.min_size,
"Widget size is less than size limit",
);
}
}

pub(crate) fn query_size(world: &World, entity: &EntityRef, args: QueryArgs) -> Sizing {
puffin::profile_function!(format!("{entity} {args:?}"));
// assert!(limits.min_size.x <= limits.max_size.x);
Expand Down
6 changes: 2 additions & 4 deletions violet-core/src/layout/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::{
Edges, Rect,
};

use super::{
apply_layout, resolve_pos, Alignment, Block, Direction, LayoutLimits, QueryArgs, Sizing,
};
use super::{apply_layout, resolve_pos, Alignment, Block, LayoutLimits, QueryArgs, Sizing};

#[derive(Debug)]
pub struct StackableBounds {
Expand Down Expand Up @@ -203,7 +201,7 @@ impl StackLayout {
},
);

maximize = maximize + sizing.maximize;
maximize += sizing.maximize;

hints = hints.combine(sizing.hints);

Expand Down
7 changes: 2 additions & 5 deletions violet-core/src/state/dedup.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::{future::ready, sync::Arc};
use std::future::ready;

use futures::{FutureExt, StreamExt};
use futures_signals::signal::{Mutable, SignalExt};
use parking_lot::Mutex;
use tracing::info;
use futures::StreamExt;

use super::{State, StateSink, StateStream, StateStreamRef};

Expand Down
2 changes: 0 additions & 2 deletions violet-core/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use flax::{
entity_ids,
events::{EventData, EventSubscriber},
filter::Or,
sink::Sink,
BoxedSystem, CommandBuffer, Dfs, DfsBorrow, Entity, Fetch, FetchExt, FetchItem, Query,
QueryBorrow, System, World,
};
use glam::Vec2;
use tracing::info;

use crate::{
components::{
Expand Down
8 changes: 5 additions & 3 deletions violet-core/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
};

use futures::{
channel::oneshot,
task::{ArcWake, AtomicWaker},
Future,
};
Expand Down Expand Up @@ -226,14 +225,17 @@ impl Timers {
#[cfg(target_arch = "wasm32")]
struct TickFuture {
inner: Arc<Inner>,
timeout: Option<(oneshot::Receiver<()>, gloo_timers::callback::Timeout)>,
timeout: Option<(
futures::channel::oneshot::Receiver<()>,
gloo_timers::callback::Timeout,
)>,
}

#[cfg(target_arch = "wasm32")]
impl TickFuture {
fn new(inner: Arc<Inner>, timeout: Option<Duration>) -> Self {
let timeout = if let Some(timeout) = timeout {
let (tx, rx) = oneshot::channel();
let (tx, rx) = futures::channel::oneshot::channel();

let timeout = gloo_timers::callback::Timeout::new(
timeout.as_millis().try_into().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion violet-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Rect {
}

#[must_use]
pub(crate) fn clamp_size(&self, min: Vec2, max: Vec2) -> Self {
pub fn clamp_size(&self, min: Vec2, max: Vec2) -> Self {
let size = self.size().clamp(min, max);
Self {
min: self.min,
Expand Down
9 changes: 2 additions & 7 deletions violet-core/src/widget/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ use palette::Srgba;

use crate::{
assets::AssetKey,
components::{
self, aspect_ratio, color, draw_shape, font_size, min_size, size, text, text_wrap,
},
components::{self, color, draw_shape, font_size, text, text_wrap},
shape,
style::{
colors::REDWOOD_DEFAULT, spacing_large, spacing_small, SizeExt, StyleExt, ValueOrRef,
WidgetSize,
},
style::{colors::REDWOOD_DEFAULT, spacing_small, SizeExt, StyleExt, ValueOrRef, WidgetSize},
text::{TextSegment, Wrap},
unit::Unit,
Scope, Widget,
Expand Down
4 changes: 1 addition & 3 deletions violet-core/src/widget/interactive/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use futures::{stream::BoxStream, StreamExt};
use futures_signals::signal::Mutable;
use glam::Vec2;
use palette::Srgba;
use web_time::Duration;
use winit::event::ElementState;

use crate::{
Expand All @@ -14,10 +13,9 @@ use crate::{
layout::Alignment,
state::{State, StateDuplex, StateStream},
style::{interactive_active, interactive_inactive, spacing_small, SizeExt, StyleExt},
time::sleep,
to_owned,
unit::Unit,
utils::{throttle, zip_latest},
utils::zip_latest,
widget::{row, ContainerStyle, Positioned, Rectangle, Stack, StreamWidget, Text},
Scope, StreamEffect, Widget,
};
Expand Down
3 changes: 3 additions & 0 deletions violet-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ wasm-bindgen-futures = "0.4"
itertools.workspace = true
tracing-tree.workspace = true
puffin.workspace = true

[package.metadata.wasm-pack.profile.profiling]
wasm-opt = false
Loading

0 comments on commit c516af0

Please sign in to comment.