Skip to content

Instantly share code, notes, and snippets.

@Telzhaak
Created August 14, 2018 14:38
Show Gist options
  • Save Telzhaak/352491934a23a9940e3690ed9264ed3c to your computer and use it in GitHub Desktop.
Save Telzhaak/352491934a23a9940e3690ed9264ed3c to your computer and use it in GitHub Desktop.
#[derive(PartialEq, Eq)]
enum ContainerType{
HorizontalBox, //places contained_childrens in a horizontal manner
VerticalBox,//like above, but vertically
ScaleBox,//scales it's contents, e.g. to allow for a zoom-in on an item in the inventory
UniformGrid,//places all contained_children in a grid with uniformely sized and distributed boxes, ignoring desired_sizes, etc
//etc ...
}
//Containers hold Data for a LayoutSystem, that ONLY works on the layout.
//Looking at a containers's contained_childrens desired sizes (and minimum sizes, weighting, etc...),
//the widgets's actual rendered transformations get set recursively.
struct Container{
//So that the System knows what layout action to perform
pub container_type: ContainerType,
//The containers own desired transform
pub desired_height: f32,
pub desired_width: f32,
//The containers actual transform, used by the RenderingSystem.
//set by the LayoutSystem after evaluating all containers + widgets and setting each ones width, height, position
pub width; f32,
pub height: f32
pub pos: (f32, f32, i32) //xPos, yPos, z-Order (maybe not necessary, since LayoutSystem could handle this by throwing it out)
//These should only ever be ID's of other containers or widgets.
//If this is empty, then the Container either acts as a 'spacer' to lay out empty space,
//which would be against the rule that containers are not rendered themselves,
//or be discarded/ignored by the rendering system, which I would prefer. Spacers should be their own widget type.
pub contained_children: vec<Entity_ID>
}
impl Container{
fn new(container_type: ContainerType, des_width: f32, des_height: f32) -> Container{
Container{
container_type: container_type,
desired_height: des_height,
desired_width: des_width,
}
}
fn add_child(&mut self, id: i32){
//Needs a check on the entity, whether it's a container/widget or not
self.contained_children.push(id.clone());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment