Skip to content

Commit

Permalink
port settings to yakui
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 7, 2024
1 parent aa48a15 commit c50c170
Show file tree
Hide file tree
Showing 26 changed files with 621 additions and 658 deletions.
81 changes: 18 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions assets_gui/src/yakui_gui.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use yakui::widgets::{CountGrid, List, Pad, StateResponse};
use yakui::{
colored_box_container, column, constrained, row, use_state, Constraints, CrossAxisAlignment,
MainAxisAlignment, MainAxisSize, Response, Vec2,
colored_box_container, column, constrained, divider, row, use_state, Constraints,
CrossAxisAlignment, MainAxisAlignment, MainAxisSize, Response, Vec2,
};

use engine::meshload::CPUMesh;
use engine::wgpu::RenderPass;
use engine::{set_cursor_icon, CursorIcon, Drawable, GfxContext, InstancedMesh, Mesh, SpriteBatch};
use geom::Matrix4;
use goryak::{
background, button_primary, checkbox_value, divider, dragvalue, icon, interact_box_radius,
is_hovered, on_secondary_container, on_surface, outline_variant, round_rect, scroll_vertical,
secondary_container, set_theme, surface, surface_variant, textc, use_changed, RoundRect, Theme,
background, button_primary, checkbox_value, constrained_viewport, dragvalue, icon,
interact_box_radius, is_hovered, on_secondary_container, on_surface, outline_variant,
round_rect, secondary_container, set_theme, surface, surface_variant, textc, use_changed,
RoundRect, Theme, VertScroll,
};
use prototypes::{prototypes_iter, GoodsCompanyID, GoodsCompanyPrototype};

Expand Down Expand Up @@ -48,10 +49,12 @@ impl Gui {

impl State {
pub fn gui_yakui(&mut self) {
row(|| {
self.explorer();
self.model_properties();
//self.properties();
constrained_viewport(|| {
row(|| {
self.explorer();
self.model_properties();
//self.properties();
});
});
}

Expand All @@ -77,9 +80,10 @@ impl State {
}
});
});
scroll_vertical(1000.0, || {
VertScroll::Percent(1.0).show(|| {
let mut l = List::column();
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.main_axis_size = MainAxisSize::Min;
l.show(|| {
let companies_open = use_state(|| false);
Self::explore_item(
Expand Down Expand Up @@ -190,8 +194,7 @@ impl State {
textc(tc, "quality");
dragvalue().min(0.0).max(1.0).show(&mut params.quality);

textc(tc, "sloppy");
checkbox_value(&mut params.sloppy);
checkbox_value(&mut params.sloppy, tc, "sloppy");

params
});
Expand Down
7 changes: 7 additions & 0 deletions engine/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ async fn run<S: State>(el: EventLoop<()>, window: Arc<Window>) {
Event::WindowEvent { event, .. } => {
ctx.input.handle(&event);

if ctx.gfx.update_sc {
ctx.gfx.update_sc = false;
let size = (ctx.gfx.size.0, ctx.gfx.size.1, scale_factor);
ctx.gfx.resize(size);
state.resized(&mut ctx, size);
}

match event {
WindowEvent::Resized(physical_size) => {
log::info!("resized: {:?}", physical_size);
Expand Down
8 changes: 4 additions & 4 deletions engine/src/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub enum ShadowQuality {
Low,
Medium,
High,
TooHigh,
Ultra,
}

impl AsRef<str> for ShadowQuality {
Expand All @@ -96,7 +96,7 @@ impl AsRef<str> for ShadowQuality {
ShadowQuality::Low => "Low",
ShadowQuality::Medium => "Medium",
ShadowQuality::High => "High",
ShadowQuality::TooHigh => "Too High",
ShadowQuality::Ultra => "Ultra",
}
}
}
Expand All @@ -108,7 +108,7 @@ impl From<u8> for ShadowQuality {
1 => ShadowQuality::Low,
2 => ShadowQuality::Medium,
3 => ShadowQuality::High,
4 => ShadowQuality::TooHigh,
4 => ShadowQuality::Ultra,
_ => ShadowQuality::High,
}
}
Expand All @@ -120,7 +120,7 @@ impl ShadowQuality {
ShadowQuality::Low => Some(512),
ShadowQuality::Medium => Some(1024),
ShadowQuality::High => Some(2048),
ShadowQuality::TooHigh => Some(4096),
ShadowQuality::Ultra => Some(4096),
ShadowQuality::NoShadows => None,
}
}
Expand Down
5 changes: 4 additions & 1 deletion engine/src/yakui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ impl YakuiWrapper {

self.yakui.start();
ui_render();
self.yakui.finish();
{
profiling::scope!("yakui::finish");
self.yakui.finish();
}

self.renderer.paint_with_encoder(
&mut self.yakui,
Expand Down
71 changes: 36 additions & 35 deletions goryak/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,50 @@ use yakui_widgets::{colored_box_container, constrained, pad, reflow, use_state};
pub fn combo_box(selected: &mut usize, items: &[&str], w: f32) -> bool {
let mut changed = false;

pad(Pad::horizontal(10.0), || {
let mut l = List::column();
l.main_axis_alignment = MainAxisAlignment::Center;
l.main_axis_size = MainAxisSize::Min;
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.show(|| {
let open = use_state(|| false);
constrained(Constraints::loose(Vec2::new(w, f32::INFINITY)), || {
pad(Pad::horizontal(10.0), || {
let mut l = List::column();
l.main_axis_alignment = MainAxisAlignment::Center;
l.main_axis_size = MainAxisSize::Min;
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.show(|| {
let open = use_state(|| false);

if button_secondary(items[*selected].to_string())
.show()
.clicked
{
open.modify(|x| !x);
}
if button_secondary(items[*selected].to_string())
.show()
.clicked
{
open.modify(|x| !x);
}

if open.get() {
Layer::new().show(|| {
reflow(Alignment::BOTTOM_LEFT, Dim2::ZERO, || {
constrained(Constraints::loose(Vec2::new(w, f32::INFINITY)), || {
colored_box_container(background(), || {
Pad::all(3.0).show(|| {
let mut l = List::column();
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.item_spacing = 3.0;
l.show(|| {
for (i, item) in items.iter().enumerate() {
if i == *selected {
continue;
if open.get() {
Layer::new().show(|| {
reflow(Alignment::BOTTOM_LEFT, Dim2::ZERO, || {
constrained(Constraints::loose(Vec2::new(w, f32::INFINITY)), || {
colored_box_container(background(), || {
Pad::all(3.0).show(|| {
let mut l = List::column();
l.cross_axis_alignment = CrossAxisAlignment::Stretch;
l.item_spacing = 3.0;
l.show(|| {
for (i, item) in items.iter().enumerate() {
if button_secondary(item.to_string()).show().clicked
{
open.set(false);
if i != *selected {
*selected = i;
changed = true;
}
}
}

if button_secondary(item.to_string()).show().clicked {
*selected = i;
open.set(false);
changed = true;
}
}
});
});
});
});
});
});
});
}
}
});
});
});

Expand Down
Loading

0 comments on commit c50c170

Please sign in to comment.