Skip to content

Commit

Permalink
better time controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 24, 2024
1 parent cbf85e3 commit dee11d5
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 27 deletions.
3 changes: 3 additions & 0 deletions assets/SpaceMono-Regular.ttf
Git LFS file not shown
6 changes: 3 additions & 3 deletions assets_gui/src/yakui_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ impl State {
l.main_axis_alignment = MainAxisAlignment::Center;
Pad::all(5.0).show(|| {
l.show(|| {
if button_primary("Dark theme").clicked {
if button_primary("Dark theme").show().clicked {
set_theme(Theme::Dark);
}
if button_primary("Light theme").clicked {
if button_primary("Light theme").show().clicked {
set_theme(Theme::Light);
}
});
Expand Down Expand Up @@ -197,7 +197,7 @@ impl State {
params
});
});
if button_primary("Generate LODs").clicked {
if button_primary("Generate LODs").show().clicked {
let asset_path = &props.asset_path;

self.actions
Expand Down
8 changes: 7 additions & 1 deletion engine/src/yakui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ impl YakuiWrapper {
FontSettings::default(),
)
.unwrap();

fonts.add(font, Some("icons"));

let font = Font::from_bytes(
include_bytes!("../../assets/SpaceMono-Regular.ttf").as_slice(),
FontSettings::default(),
)
.unwrap();
fonts.add(font, Some("monospace"));

let platform = yakui_winit::YakuiWinit::new(el);

let mut renderer = yakui_wgpu::YakuiWgpu::new(&gfx.device, &gfx.queue);
Expand Down
2 changes: 1 addition & 1 deletion goryak/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ pub use text::*;
pub use theme::*;
pub use util::*;

const DEFAULT_FONT_SIZE: f32 = 14.0;
pub const DEFAULT_FONT_SIZE: f32 = 14.0;
7 changes: 7 additions & 0 deletions goryak/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use crate::DEFAULT_FONT_SIZE;
use std::borrow::Cow;
use yakui_core::Response;
use yakui_widgets::font::FontName;
use yakui_widgets::widgets::{Text, TextResponse};

pub fn text<S: Into<Cow<'static, str>>>(text: S) -> Response<TextResponse> {
Text::new(DEFAULT_FONT_SIZE, text.into()).show()
}

pub fn monospace<S: Into<Cow<'static, str>>>(text: S) -> Response<TextResponse> {
let mut t = Text::new(DEFAULT_FONT_SIZE, text.into());
t.style.font = FontName::new("monospace");
t.show()
}
52 changes: 48 additions & 4 deletions goryak/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::borrow::Cow;
use std::panic::Location;

use yakui_core::geometry::{Color, Constraints, Vec2};
use yakui_core::geometry::{Color, Constraints, FlexFit, Vec2};
use yakui_core::widget::{LayoutContext, PaintContext, Widget};
use yakui_core::{Response, WidgetId};
use yakui_core::{context, Response, WidgetId};
use yakui_widgets::util::widget;
use yakui_widgets::widgets::{Button, ButtonResponse, Text};

Expand Down Expand Up @@ -31,15 +31,59 @@ pub fn labelc(c: Color, text: impl Into<Cow<'static, str>>) {
t.show();
}

pub fn button_primary(text: impl Into<String>) -> Response<ButtonResponse> {
#[derive(Debug)]
pub struct FixedSizeWidget {
props: Vec2,
}

pub fn fixed_spacer(size: impl Into<Vec2>) -> Response<<FixedSizeWidget as Widget>::Response> {
widget::<FixedSizeWidget>(size.into())
}

impl Widget for FixedSizeWidget {
type Props<'a> = Vec2;
type Response = ();

fn new() -> Self {
Self { props: Vec2::ZERO }
}

fn update(&mut self, props: Self::Props<'_>) -> Self::Response {
self.props = props;
}

fn flex(&self) -> (u32, FlexFit) {
(0, FlexFit::Tight)
}

fn layout(&self, _ctx: LayoutContext<'_>, _constraints: Constraints) -> Vec2 {
self.props
}

fn paint(&self, _ctx: PaintContext<'_>) {}
}

pub fn widget_inner<T, F, U>(children: F, props: T::Props<'_>) -> U
where
T: Widget,
F: FnOnce() -> U,
{
let dom = context::dom();
let response = dom.begin_widget::<T>(props);
let r = children();
dom.end_widget::<T>(response.id);
r
}

pub fn button_primary(text: impl Into<String>) -> Button {
let mut b = Button::styled(text.into());
b.style.fill = primary();
b.style.text.color = on_primary();
b.hover_style.fill = primary().adjust(1.2);
b.hover_style.text.color = on_primary();
b.down_style.fill = primary().adjust(1.3);
b.down_style.text.color = on_primary();
b.show()
b
}

pub fn button_secondary(text: impl Into<String>) -> Response<ButtonResponse> {
Expand Down
57 changes: 39 additions & 18 deletions native_app/src/newgui/topgui.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use yakui::widgets::{List, Pad};
use yakui::widgets::{List, Pad, PadWidget};
use yakui::{
colored_box, column, draggable, offset, pad, reflow, row, use_state, Alignment, Color, Dim2,
MainAxisAlignment, MainAxisSize, Vec2,
colored_box, column, constrained, draggable, offset, pad, reflow, row, spacer, use_state,
Alignment, Color, Constraints, CrossAxisAlignment, Dim2, MainAxisAlignment, MainAxisSize, Vec2,
};

use goryak::{blur_bg, button_primary, constrained_viewport, labelc, on_primary_container, text};
use goryak::{
blur_bg, button_primary, constrained_viewport, labelc, monospace, on_primary_container,
widget_inner,
};
use prototypes::GameTime;
use simulation::map_dynamic::ElectricityFlow;
use simulation::Simulation;
Expand Down Expand Up @@ -73,51 +76,69 @@ impl Gui {

if *warp == 0 {
yakui::canvas(|ctx| {
let w = ctx.layout.viewport().size().length() * 0.002;
yakui::shapes::outline(
ctx.paint,
ctx.layout.viewport(),
2.0,
Color::rgba(255, 0, 0, 196),
w,
Color::rgba(255, 0, 0, 128),
);
});
}

let mut time_text = || {
row(|| {
text(format!(" Day {}", time.day));

text(format!(
monospace(format!("Day {}", time.day));
spacer(1);
monospace(format!(
"{:02}:{:02}:{:02}",
time.hour, time.minute, time.second
));
});
row(|| {
if button_primary("||").clicked {
let time_button = |text: &str| {
widget_inner::<PadWidget, _, _>(
|| {
let mut b = button_primary(text);
b.padding = Pad::balanced(10.0, 3.0);
b.show()
},
Pad::all(3.0),
)
};

if time_button("||").clicked {
*depause_warp = *warp;
*warp = 0;
}
if button_primary("1x").clicked {
if time_button("1x").clicked {
*warp = 1;
}
if button_primary("3x").clicked {
if time_button("3x").clicked {
*warp = 3;
}
if button_primary("Max").clicked {
if time_button("Max").clicked {
*warp = 1000;
}
});
};

reflow(Alignment::TOP_LEFT, Dim2::pixels(0.0, 40.0), || {
reflow(Alignment::TOP_LEFT, Dim2::pixels(0.0, 30.0), || {
constrained_viewport(|| {
let mut l = List::row();
l.main_axis_alignment = MainAxisAlignment::End;
l.show(|| {
blur_bg(goryak::primary_container().with_alpha(0.5), 10.0, || {
pad(Pad::all(3.0), || {
let mut l = List::column();
l.main_axis_size = MainAxisSize::Min;
l.show(|| time_text());
pad(Pad::all(10.0), || {
constrained(
Constraints::loose(Vec2::new(200.0, f32::INFINITY)),
|| {
let mut l = List::column();
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.main_axis_size = MainAxisSize::Min;
l.show(|| time_text());
},
);
});
});
});
Expand Down

0 comments on commit dee11d5

Please sign in to comment.