mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Horizontally wrap place tool prefabs, like tools themselves
This commit is contained in:
parent
6f95f29927
commit
8e76d85bf2
3 changed files with 61 additions and 6 deletions
|
|
@ -580,8 +580,7 @@ impl EditorScene {
|
|||
.size((300.0, 300.0), ImGuiCond::FirstUseEver)
|
||||
.resizable(!self.ui_lock_windows)
|
||||
.build(|| {
|
||||
let (width, _) = ui.get_window_size();
|
||||
let count = std::cmp::max(((width - 16.0) / 42.0).floor() as usize, 1);
|
||||
let count = ui.fits_width(34.0); // 32 + 2px border
|
||||
for (i, tool) in self.tools.iter().enumerate() {
|
||||
if i % count != 0 {
|
||||
ui.same_line(0.0);
|
||||
|
|
@ -1461,3 +1460,14 @@ impl<T> Fulfill<T> for Option<T> {
|
|||
self.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
trait UiExt {
|
||||
fn fits_width(&self, width: f32) -> usize;
|
||||
}
|
||||
|
||||
impl<'a> UiExt for Ui<'a> {
|
||||
fn fits_width(&self, element_width: f32) -> usize {
|
||||
let (width, _) = self.get_window_size();
|
||||
std::cmp::max(((width - 20.0) / (element_width + 8.0)) as usize, 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use super::*;
|
||||
use UiExt;
|
||||
|
||||
/// The standard placement tool.
|
||||
#[derive(Default)]
|
||||
|
|
@ -10,15 +11,40 @@ pub struct Place {
|
|||
impl ToolBehavior for Place {
|
||||
fn settings(&mut self, ui: &Ui) {
|
||||
ui.text(im_str!("current: {} / {}", self.fab_current, self.fabs.len()));
|
||||
for (i, fab) in self.fabs.iter().enumerate() {
|
||||
ui.text(im_str!("{}. {}", i, fab.path));
|
||||
}
|
||||
if ui.small_button(im_str!("test")) {
|
||||
ui.same_line(0.0);
|
||||
if ui.small_button(im_str!("Add")) {
|
||||
self.fabs.push(Prefab {
|
||||
path: "/obj/item/lighter".to_owned(),
|
||||
vars: Default::default(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut i = 0;
|
||||
let fab_current = &mut self.fab_current;
|
||||
|
||||
let count = ui.fits_width(32.0);
|
||||
self.fabs.retain(|fab| {
|
||||
if i % count != 0 {
|
||||
ui.same_line(0.0);
|
||||
}
|
||||
|
||||
let mut keep = true;
|
||||
//ui.small_button(im_str!("{}. {}", i, fab.path));
|
||||
ui.button(im_str!(""), (32.0, 32.0));
|
||||
if ui.is_item_hovered() {
|
||||
ui.tooltip_text(im_str!("{}", fab));
|
||||
if ui.imgui().is_mouse_clicked(ImMouseButton::Left) {
|
||||
*fab_current = i;
|
||||
} else if ui.imgui().is_mouse_clicked(ImMouseButton::Right) {
|
||||
keep = false;
|
||||
if *fab_current > i {
|
||||
*fab_current -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
keep
|
||||
});
|
||||
}
|
||||
|
||||
fn click(&mut self, hist: &mut History, env: &Environment, loc: (u32, u32, u32)) {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,25 @@ impl Map {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Prefab {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(&self.path)?;
|
||||
if !self.vars.is_empty() {
|
||||
write!(f, " {{")?;
|
||||
let mut first = true;
|
||||
for (k, v) in self.vars.iter() {
|
||||
if !first {
|
||||
write!(f, "; ")?;
|
||||
}
|
||||
first = false;
|
||||
write!(f, "{} = {}", k, v)?;
|
||||
}
|
||||
write!(f, "}}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Map Writer
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue