mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
settle on using the common widget ID for everything (except rows/cols).
move some non-widget tools to a better module, and rename shaders directory
This commit is contained in:
parent
d7886fa85b
commit
2712ea8c74
@ -20,15 +20,13 @@ pub fn setup(
|
||||
let context = glutin::ContextBuilder::new()
|
||||
.with_multisampling(4)
|
||||
.with_depth_buffer(2);
|
||||
// TODO This step got slow
|
||||
println!("Initializing OpenGL window");
|
||||
let display = glium::Display::new(window, context, &event_loop).unwrap();
|
||||
|
||||
let (vertex_shader, fragment_shader) =
|
||||
if display.is_glsl_version_supported(&glium::Version(glium::Api::Gl, 1, 4)) {
|
||||
(
|
||||
include_str!("assets/vertex_140.glsl"),
|
||||
include_str!("assets/fragment_140.glsl"),
|
||||
include_str!("shaders/vertex_140.glsl"),
|
||||
include_str!("shaders/fragment_140.glsl"),
|
||||
)
|
||||
} else {
|
||||
panic!(
|
||||
@ -44,10 +42,10 @@ pub fn setup(
|
||||
let (vertex_shader, fragment_shader) = {
|
||||
use std::io::Read;
|
||||
|
||||
let mut f1 = std::fs::File:: open("../ezgui/src/assets/vertex_140.glsl").unwrap();
|
||||
let mut f1 = std::fs::File:: open("../ezgui/src/shaders/vertex_140.glsl").unwrap();
|
||||
f1.read_to_string(&mut vert).unwrap();
|
||||
|
||||
let mut f2 = std::fs::File:: open("../ezgui/src/assets/fragment_140.glsl").unwrap();
|
||||
let mut f2 = std::fs::File:: open("../ezgui/src/shaders/fragment_140.glsl").unwrap();
|
||||
f2.read_to_string(&mut frag).unwrap();
|
||||
|
||||
(&vert, &frag)
|
||||
|
@ -28,10 +28,10 @@ pub fn setup(
|
||||
|
||||
unsafe {
|
||||
let shaders = [
|
||||
(glow::VERTEX_SHADER, include_str!("assets/vertex_140.glsl")),
|
||||
(glow::VERTEX_SHADER, include_str!("shaders/vertex_140.glsl")),
|
||||
(
|
||||
glow::FRAGMENT_SHADER,
|
||||
include_str!("assets/fragment_140.glsl"),
|
||||
include_str!("shaders/fragment_140.glsl"),
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
|
@ -48,10 +48,10 @@ pub fn setup(
|
||||
|
||||
unsafe {
|
||||
let shaders = [
|
||||
(glow::VERTEX_SHADER, include_str!("assets/vertex_300.glsl")),
|
||||
(glow::VERTEX_SHADER, include_str!("shaders/vertex_300.glsl")),
|
||||
(
|
||||
glow::FRAGMENT_SHADER,
|
||||
include_str!("assets/fragment_300.glsl"),
|
||||
include_str!("shaders/fragment_300.glsl"),
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
|
@ -17,6 +17,7 @@ mod runner;
|
||||
mod screen_geom;
|
||||
mod svg;
|
||||
mod text;
|
||||
mod tools;
|
||||
mod widgets;
|
||||
|
||||
pub use crate::backend::Drawable;
|
||||
@ -31,6 +32,7 @@ pub use crate::managed::{Composite, Outcome, Widget};
|
||||
pub use crate::runner::{run, EventLoopMode, Settings, GUI};
|
||||
pub use crate::screen_geom::{ScreenDims, ScreenPt, ScreenRectangle};
|
||||
pub use crate::text::{Line, Text, TextExt, TextSpan, HOTKEY_COLOR};
|
||||
pub use crate::tools::warper::Warper;
|
||||
pub use crate::widgets::autocomplete::Autocomplete;
|
||||
pub use crate::widgets::button::Btn;
|
||||
pub(crate) use crate::widgets::button::Button;
|
||||
@ -44,7 +46,6 @@ pub use crate::widgets::plot::{Plot, PlotOptions, Series};
|
||||
pub(crate) use crate::widgets::popup_menu::PopupMenu;
|
||||
pub use crate::widgets::slider::{ItemSlider, Slider, WarpingItemSlider};
|
||||
pub(crate) use crate::widgets::text_box::TextBox;
|
||||
pub use crate::widgets::warper::Warper;
|
||||
pub use crate::widgets::wizard::{Choice, Wizard, WrappedWizard};
|
||||
pub(crate) use crate::widgets::WidgetImpl;
|
||||
|
||||
|
@ -206,8 +206,9 @@ impl Widget {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn named(mut self, id: &str) -> Widget {
|
||||
self.id = Some(id.to_string());
|
||||
pub fn named<I: Into<String>>(mut self, id: I) -> Widget {
|
||||
assert!(self.id.is_none());
|
||||
self.id = Some(id.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
@ -257,7 +258,8 @@ impl Widget {
|
||||
}
|
||||
|
||||
pub(crate) fn btn(btn: Button) -> Widget {
|
||||
Widget::new(WidgetType::Btn(btn))
|
||||
let action = btn.action.clone();
|
||||
Widget::new(WidgetType::Btn(btn)).named(action)
|
||||
}
|
||||
|
||||
pub fn slider(slider: Slider) -> Widget {
|
||||
@ -652,18 +654,6 @@ impl Widget {
|
||||
|
||||
fn find(&self, name: &str) -> Option<&Widget> {
|
||||
let found = match self.widget {
|
||||
// TODO Consolidate and just do this
|
||||
WidgetType::Draw(_)
|
||||
| WidgetType::Checkbox(_)
|
||||
| WidgetType::TextBox(_)
|
||||
| WidgetType::Dropdown(_)
|
||||
| WidgetType::Slider(_)
|
||||
| WidgetType::Filler(_)
|
||||
| WidgetType::Menu(_) => self.id == Some(name.to_string()),
|
||||
WidgetType::Btn(ref btn) => btn.action == name,
|
||||
WidgetType::DurationPlot(_) => false,
|
||||
WidgetType::UsizePlot(_) => false,
|
||||
WidgetType::Histogram(_) => false,
|
||||
WidgetType::Row(ref widgets) | WidgetType::Column(ref widgets) => {
|
||||
for widget in widgets {
|
||||
if let Some(w) = widget.find(name) {
|
||||
@ -672,7 +662,7 @@ impl Widget {
|
||||
}
|
||||
return None;
|
||||
}
|
||||
WidgetType::Nothing => unreachable!(),
|
||||
_ => self.id == Some(name.to_string()),
|
||||
};
|
||||
if found {
|
||||
Some(self)
|
||||
@ -682,18 +672,6 @@ impl Widget {
|
||||
}
|
||||
fn find_mut(&mut self, name: &str) -> Option<&mut Widget> {
|
||||
let found = match self.widget {
|
||||
// TODO Consolidate and just do this
|
||||
WidgetType::Draw(_)
|
||||
| WidgetType::Checkbox(_)
|
||||
| WidgetType::TextBox(_)
|
||||
| WidgetType::Dropdown(_)
|
||||
| WidgetType::Slider(_)
|
||||
| WidgetType::Filler(_)
|
||||
| WidgetType::Menu(_) => self.id == Some(name.to_string()),
|
||||
WidgetType::Btn(ref btn) => btn.action == name,
|
||||
WidgetType::DurationPlot(_) => false,
|
||||
WidgetType::UsizePlot(_) => false,
|
||||
WidgetType::Histogram(_) => false,
|
||||
WidgetType::Row(ref mut widgets) | WidgetType::Column(ref mut widgets) => {
|
||||
for widget in widgets {
|
||||
if let Some(w) = widget.find_mut(name) {
|
||||
@ -702,7 +680,7 @@ impl Widget {
|
||||
}
|
||||
return None;
|
||||
}
|
||||
WidgetType::Nothing => unreachable!(),
|
||||
_ => self.id == Some(name.to_string()),
|
||||
};
|
||||
if found {
|
||||
Some(self)
|
||||
@ -752,8 +730,6 @@ pub enum Outcome {
|
||||
|
||||
const SCROLL_SPEED: f64 = 5.0;
|
||||
|
||||
// TODO These APIs aren't composable. Need a builer pattern or ideally, to scrape all the special
|
||||
// objects from the tree.
|
||||
impl Composite {
|
||||
pub fn new(top_level: Widget) -> CompositeBuilder {
|
||||
CompositeBuilder {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::assets::Assets;
|
||||
use crate::widgets::screenshot::{screenshot_current, screenshot_everything};
|
||||
use crate::tools::screenshot::{screenshot_current, screenshot_everything};
|
||||
use crate::{Canvas, Event, EventCtx, GfxCtx, Key, Prerender, UserInput};
|
||||
use geom::Duration;
|
||||
use instant::Instant;
|
||||
|
2
ezgui/src/tools/mod.rs
Normal file
2
ezgui/src/tools/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod screenshot;
|
||||
pub mod warper;
|
@ -8,10 +8,8 @@ pub mod modal_menu;
|
||||
pub mod no_op;
|
||||
pub mod plot;
|
||||
pub mod popup_menu;
|
||||
pub mod screenshot;
|
||||
pub mod slider;
|
||||
pub mod text_box;
|
||||
pub mod warper;
|
||||
pub mod wizard;
|
||||
|
||||
use crate::{EventCtx, ScreenDims, ScreenPt};
|
||||
|
Loading…
Reference in New Issue
Block a user