Crates.io | red-sdl |
lib.rs | red-sdl |
version | 0.1.2 |
source | src |
created_at | 2024-11-03 00:41:21.751336 |
updated_at | 2024-11-09 03:10:09.038466 |
description | sdl with grid layout and window management to help build apps or video game. |
homepage | |
repository | https://github.com/RedYou1/sdl |
max_upload_size | |
id | 1433296 |
size | 91,836 |
sdl with grid layout and window management to help build apps or video games.
you can see an example of usage at https://github.com/RedYou1/PVZ
use the function to create the window and run the application
red_sdl::run(
window title,
fps,
width,
height,
window builder: Fn(&mut WindowBuilder) -> &mut WindowBuilder, //ex:|window| window.fullscreen_desktop().resizable(),
your window constructor: Fn(&mut Canvas<Window>) -> Result<impl GameWindow, String>,
)
init when created loop the rest for each frame in this order:
Let you place elements in a grid without overlaps.
You can use his empty function for your new function of your parent element / window as long as you create it in the init function.
Usually used for dynamic number of columns or rows
Grid::new(
ptr to parent,//self
Vec of your columns,
Vec of you rows,
HashMap of Pos => Box of dyn GridChildren<ParentType>
)
Usually used for static number of columns or rows
simple_grid!(
RefToParent,//self
ParentType,//Win
//Your columns
ColType::Px(min 1.),
ColType::Ratio(minex 0.),
...; // char end of columns
//Your rows
RowType::Px(min 1.),
RowType::Ratio(minex 0.),
...; // char end of rows
Pos{x:min 0,y:min 0} => sub element,
...
)
Let you have the ownership of a sub element inside of another element. exemple:
Can be prone to errors if the sub element don't have the same lifetime of the parent.
RefElement::new(ref of the sub element)
Let you have an unrestrained sized sub element inside your restrained sized Window/SubElement.
ScrollView::new(
the child element,
the child width minex 0.,
the child height minex 0.,
Func for the scrollbar color: Box<dyn Fn(&Parent, &Element) -> Color>
)
Let you design a rectangle with the builder pattern.
UIRect::new(
state function: Box<dyn Fn(&Parent, &Element) -> StateEnum>,
back color function: Box<dyn Fn(&Parent, &Element) -> Color>
)
Setup an action function. Get called in the event function. It gets called when the mouse is hovering over the element and the left mouse button is down.
Box<dyn Fn(
&mut Parent,
&UIRect,
mouse_x,
mouse_y,
&mut Canvas) -> Result<(), String>
Setup the text to write in the rect. Get called in the draw function.
Box<dyn Fn(&Parent, &Element)
-> Result<(Option<UIString>, Color), String>>
Draw an image behind the text. Get called in the draw function.
Box<dyn Fn(&Parent, &Element)
-> Result<&'static Texture<'static>, String>>
Let the user enter text inside this element.
TextBox::new(
The id of the element,
ref to the selected element field,
the font,
ref to the current text in the element,
state function: Box<dyn Fn(&Parent, &Element) -> StateEnum>,
select_color function: Box<dyn Fn(&Parent, &Element) -> Color>,
line_color function: Box<dyn Fn(&Parent, &Element) -> Color>,
front_color function: Box<dyn Fn(&Parent, &Element) -> Color>,
back_color function: Box<dyn Fn(&Parent, &Element) -> Color>,
)