Skip to content

Commit

Permalink
chore: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Mar 28, 2024
1 parent 90fba29 commit 6f459a9
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 179 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ opt-level = 2
[profile.dev.package.puffin]
opt-level = 2

[profile.dev.package.puffin_server]
[profile.dev.package.puffin_http]
opt-level = 2

[profile.dev.package.cosmic-text]
Expand All @@ -129,4 +129,5 @@ opt-level = 2
palette = { git = "https://github.com/Ogeon/palette" }

[profile.release]
debug = true
opt-level = 2
# debug = true
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ useState hooks.
## [Live Demo](https://ten3roberts.github.io/violet/demo)

## Example

![image](https://github.com/ten3roberts/violet/assets/25723553/b9882e28-9e4b-49be-8dcc-9c12d42e12b1)

```rust
let name = Mutable::new("".to_string());
let quest = Mutable::new("".to_string());
let color = Mutable::new(Srgba::new(0.0, 0.61, 0.388, 1.0));

// Map a `Mutable<Srgba>` into a `StateDuplex<f32>` for each field
Expand All @@ -23,8 +27,9 @@ let speed = Mutable::new(None as Option<f32>);

col((
card(row((label("What is your name?"), TextInput::new(name)))),
card(row((label("What is your quest?"), TextInput::new(quest)))),
card(col((
label("What is your favorite color?"),
label("What is your favorite colour?"),
SliderWithLabel::new(r, 0.0, 1.0).round(0.01),
SliderWithLabel::new(g, 0.0, 1.0).round(0.01),
SliderWithLabel::new(b, 0.0, 1.0).round(0.01),
Expand All @@ -45,16 +50,16 @@ col((
StreamWidget(speed.stream().map(|v| {
match v {
Some(v) => pill(Text::new(format!("{v} m/s"))),
None => pill(Text::new("×".to_string()))
.with_background(Background::new(danger_background())),
None => pill(Text::rich([
TextSegment::new("×").with_weight(violet::core::text::Weight::BOLD)
]))
.with_background(danger_surface()),
}
})),
))),
))
```

![image](https://github.com/ten3roberts/violet/assets/25723553/10e76b9a-8f2d-4b74-aaa7-b9faf04a22dc)

## Features
- Declarative Widgets and reactive state
- Flexible layout system for responsive layouts
Expand Down
22 changes: 11 additions & 11 deletions colors.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@
"950": "#28100e"
},
"amber": {
"50": "#f5e7c6",
"100": "#ead9b2",
"200": "#d6bf86",
"300": "#c6a349",
"400": "#b88700",
"500": "#a46c00",
"600": "#865600",
"700": "#644400",
"800": "#463200",
"900": "#2c2000",
"950": "#211700"
"50": "#f7e6c3",
"100": "#ecd9af",
"200": "#d9be80",
"300": "#caa13e",
"400": "#be8400",
"500": "#aa6800",
"600": "#8b5300",
"700": "#684200",
"800": "#493100",
"900": "#2e1f00",
"950": "#221600"
},
"rose": {
"50": "#fddeeb",
Expand Down
6 changes: 3 additions & 3 deletions colors.save.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
},
{
"color": {
"l": 0.50735986,
"chroma": 0.185,
"hue": 88.0
"l": 0.83,
"chroma": 0.2,
"hue": 86.046814
},
"falloff": 15.0,
"name": "Amber"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pub fn main() -> anyhow::Result<()> {

violet_wgpu::AppBuilder::new()
.with_renderer_config(RendererConfig { debug_mode: false })
.run(violet_demo::basic::app())
.run(violet_demo::bridge_of_death::app())
}
12 changes: 6 additions & 6 deletions examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use violet::core::{
Scope, Widget,
};
use violet_core::{
style::{self, primary_background, secondary_background, spacing_small, Background, SizeExt},
style::{self, primary_surface, secondary_surface, spacing_small, Background, SizeExt},
text::Wrap,
widget::{card, col, label, row, Button, ButtonStyle, SliderWithLabel, TextInput},
};
Expand Down Expand Up @@ -61,21 +61,21 @@ impl Widget for MainApp {
col((
Button::label("Button"),
Button::label("Button").with_style(ButtonStyle {
normal_color: style::success_item().into(),
normal_color: style::success_element().into(),
..Default::default()
}),
Button::label("Warning").with_style(ButtonStyle {
normal_color: style::warning_item().into(),
normal_color: style::warning_element().into(),
..Default::default()
}),
Button::label("Error").with_style(ButtonStyle {
normal_color: style::danger_item().into(),
normal_color: style::danger_element().into(),
..Default::default()
}),
))
.with_stretch(true),
),
Rectangle::new(secondary_background())
Rectangle::new(secondary_surface())
.with_size(Unit::rel2(1.0, 0.0) + Unit::px2(0.0, 1.0)),
card(col((
col((
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Widget for MainApp {
.map(|color| Tints { color })
.collect_vec()),
))
.with_background(Background::new(primary_background()))
.with_background(Background::new(primary_surface()))
.contain_margins(true)
.mount(scope)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use violet::core::{
widget::{Button, List, SignalWidget, Stack, Text},
Scope, Widget,
};
use violet_core::style::{accent_item, secondary_background, spacing_small, Background, SizeExt};
use violet_core::style::{accent_element, secondary_surface, spacing_small, Background, SizeExt};

macro_rules! srgba {
($color:literal) => {{
Expand All @@ -34,7 +34,7 @@ pub const CHILI_RED: Srgba = srgba!("#d34131");

fn pill(widget: impl Widget) -> impl Widget {
Stack::new(widget)
.with_background(Background::new(secondary_background()))
.with_background(Background::new(secondary_surface()))
.with_margin(spacing_small())
.with_padding(spacing_small())
}
Expand All @@ -60,7 +60,7 @@ impl Widget for MainApp {
"Please click the button to increment the counter",
)),
))
.with_background(Background::new(accent_item()))
.with_background(Background::new(accent_element()))
.with_cross_align(Alignment::Center)
.mount(scope);
}
Expand Down
1 change: 0 additions & 1 deletion examples/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use violet::core::{
widget::{col, row, Button},
Edges, Widget,
};
use violet_core::unit::Unit;
use violet_wgpu::renderer::RendererConfig;

pub fn main() -> anyhow::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions examples/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_subscriber::{
};
use tracing_tree::HierarchicalLayer;
use violet::core::{
style::{colors::EMERALD_500, secondary_background, spacing_medium, Background, SizeExt},
style::{colors::EMERALD_500, secondary_surface, spacing_medium, Background, SizeExt},
unit::Unit,
widget::{Positioned, Rectangle, Stack},
Widget,
Expand Down Expand Up @@ -33,5 +33,5 @@ fn app() -> impl Widget {
.with_offset(Unit::px2(10.0, 10.0)),
)
.with_padding(spacing_medium())
.with_background(Background::new(secondary_background()))
.with_background(Background::new(secondary_surface()))
}
6 changes: 3 additions & 3 deletions examples/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing_tree::HierarchicalLayer;

use violet::core::{style::Background, unit::Unit, widget::Rectangle, Scope, Widget};
use violet_core::{
style::{accent_item, primary_background, spacing_small, SizeExt},
style::{accent_element, primary_surface, spacing_small, SizeExt},
widget::{centered, col, row, Image, Stack},
};
use violet_wgpu::renderer::RendererConfig;
Expand Down Expand Up @@ -57,7 +57,7 @@ impl Widget for MainApp {
row((0..4)
.map(|_| Box::new(Stack::new(Item)) as Box<dyn Widget>)
.chain([Box::new(
centered((Rectangle::new(accent_item())
centered((Rectangle::new(accent_element())
.with_maximize(vec2(1.0, 0.0))
.with_size(Unit::px2(0.0, 50.0))
.with_max_size(Unit::px2(1000.0, 100.0)),))
Expand All @@ -69,7 +69,7 @@ impl Widget for MainApp {
// .with_padding(spacing_medium())
.contain_margins(true),
)
.with_background(Background::new(primary_background()))
.with_background(Background::new(primary_surface()))
.mount(scope)
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::StreamExt;
use futures_signals::signal::Mutable;
use glam::{BVec2, Vec2};
use itertools::Itertools;
use palette::{Hsl, Hsv, IntoColor, Oklcha, Srgba};
use palette::{Hsv, IntoColor, Oklcha, Srgba};
use tracing_subscriber::{
prelude::__tracing_subscriber_SubscriberExt, registry, util::SubscriberInitExt, EnvFilter,
};
Expand All @@ -15,7 +15,7 @@ use violet::core::{
};
use violet_core::{
state::{State, StateStream},
style::{secondary_background, spacing_medium, Background},
style::{secondary_surface, spacing_medium, Background},
utils::zip_latest,
widget::{label, Button, Checkbox, ScrollArea, SliderWithLabel, StreamWidget, WidgetExt},
};
Expand Down Expand Up @@ -88,6 +88,6 @@ fn app() -> impl Widget {
Button::label("Button"),
))
.with_padding(spacing_medium())
.with_background(Background::new(secondary_background()))
.with_background(Background::new(secondary_surface()))
// .with_padding(spacing_medium())
}
8 changes: 3 additions & 5 deletions examples/sizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use violet::core::{
text::Wrap,
unit::Unit,
widget::{card, centered, col, label, row, Rectangle, SignalWidget, Slider, Text, WidgetExt},
Edges, Scope, Widget,
Scope, Widget,
};
use violet_core::style::{
colors::{AMBER_500, EMERALD_500, EMERALD_800, REDWOOD_500, TEAL_500},
primary_background,
primary_surface,
};
use violet_wgpu::renderer::RendererConfig;

const MARGIN_SM: Edges = Edges::even(4.0);

pub fn main() -> anyhow::Result<()> {
registry()
.with(
Expand Down Expand Up @@ -86,7 +84,7 @@ impl Widget for MainApp {
// AnimatedSize,
))
.contain_margins(true)
.with_background(Background::new(primary_background()))
.with_background(Background::new(primary_surface()))
.mount(scope)
}
}
Expand Down
3 changes: 1 addition & 2 deletions violet-core/src/components.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::time::Duration;

use cosmic_text::LayoutLine;
use flax::{component, Debuggable, Entity, EntityRef, Exclusive};
use glam::{Mat4, Vec2};
use image::DynamicImage;
use palette::Srgba;

use crate::{
assets::Asset,
layout::{Layout, LayoutArgs, LayoutLimits, SizeResolver},
layout::{Layout, LayoutArgs, SizeResolver},
stored::UntypedHandle,
text::{LayoutGlyphs, TextSegment, Wrap},
unit::Unit,
Expand Down
36 changes: 2 additions & 34 deletions violet-core/src/layout/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::sync::Arc;

use flax::{Entity, EntityRef, World};
use glam::{vec2, BVec2, Vec2};
use image::flat::NormalForm;
use itertools::Itertools;

use crate::{
Expand Down Expand Up @@ -100,21 +99,6 @@ impl QueryCursor {
(placement_pos, cross_size)
}

fn rect(&self) -> Rect {
let cross_cursor = self.cross_cursor + self.cross_size;

let main_cursor = if self.contain_margins {
self.main_cursor + self.pending_margin
} else {
self.main_cursor
};

Rect::from_two_points(
self.start,
main_cursor * self.axis + cross_cursor * self.cross_axis,
)
}

/// Finishes the current line and moves the cursor to the next
fn finish(&mut self) -> Rect {
self.cross_cursor += self.cross_size;
Expand Down Expand Up @@ -203,7 +187,7 @@ impl AlignCursor {
self.main_cursor += advance; // + block.rect.support(-self.axis);

// Cross axis margin calculation
let (start_margin, end_margin) = block.margin.in_axis(self.cross_axis);
let (start_margin, _) = block.margin.in_axis(self.cross_axis);

let placement_pos;

Expand Down Expand Up @@ -259,21 +243,6 @@ impl AlignCursor {
placement_pos
}

fn rect(&self) -> Rect {
let cross_cursor = self.cross_cursor + self.cross_size;

let main_cursor = if self.contain_margins {
self.main_cursor + self.pending_margin
} else {
self.main_cursor
};

Rect::from_two_points(
self.start,
main_cursor * self.axis + cross_cursor * self.cross_axis,
)
}

/// Finishes the current line and moves the cursor to the next
fn finish(&mut self) -> Rect {
self.cross_cursor += self.cross_size;
Expand Down Expand Up @@ -702,7 +671,6 @@ impl FlowLayout {
min_cursor.put(&Block::new(sizing.min, sizing.margin, sizing.hints.can_grow));
cursor.put(&Block::new(sizing.preferred, sizing.margin, sizing.hints.can_grow));

tracing::debug!(min_cursor=%min_cursor.rect().size(), cursor=%cursor.rect().size(), "cursor");
sizing
}).collect_vec();

Expand Down Expand Up @@ -753,7 +721,7 @@ impl FlowLayout {
puffin::profile_function!();
if let Some(value) = cache.query_row.as_ref() {
if validate_cached_row(value, args.limits, args.content_area) {
// return value.value.clone();
return value.value.clone();
}
}

Expand Down
Loading

0 comments on commit 6f459a9

Please sign in to comment.