mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 15:18:43 -06:00
wip rounded corners api
This commit is contained in:
parent
b04694ce83
commit
4828500c45
|
@ -14,6 +14,9 @@ pub enum UiDrawCommand {
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
///Color (RGBA)
|
///Color (RGBA)
|
||||||
color: Vec4,
|
color: Vec4,
|
||||||
|
//TODO: rounded corners per side
|
||||||
|
///Rounded corners
|
||||||
|
corner_radius: Option<f32>,
|
||||||
},
|
},
|
||||||
Text {
|
Text {
|
||||||
///Position in pixels
|
///Position in pixels
|
||||||
|
@ -129,8 +132,14 @@ impl UiDrawPlan {
|
||||||
}
|
}
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
UiDrawCommand::Rectangle { position, size, color } => {
|
UiDrawCommand::Rectangle { position, size, color, corner_radius } => {
|
||||||
|
let corner_radius = corner_radius.unwrap_or(0.0);
|
||||||
let vidx = swapper.current().vertices.len() as u32;
|
let vidx = swapper.current().vertices.len() as u32;
|
||||||
|
if corner_radius > 0.0 {
|
||||||
|
todo!("rounded corners are not implemented");
|
||||||
|
//TODO vtx-based rounded corners
|
||||||
|
//swapper.current_mut().indices.extend();
|
||||||
|
} else {
|
||||||
swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
|
swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
|
||||||
swapper.current_mut().vertices.extend([
|
swapper.current_mut().vertices.extend([
|
||||||
UiVertex {
|
UiVertex {
|
||||||
|
@ -154,6 +163,7 @@ impl UiDrawPlan {
|
||||||
uv: vec2(0.0, 1.0),
|
uv: vec2(0.0, 1.0),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
UiDrawCommand::Text { position, size, color, text, font } => {
|
UiDrawCommand::Text { position, size, color, text, font } => {
|
||||||
//XXX: should we be doing this every time?
|
//XXX: should we be doing this every time?
|
||||||
|
|
|
@ -62,6 +62,7 @@ pub struct Container {
|
||||||
pub borders: Sides<Option<Border>>,
|
pub borders: Sides<Option<Border>>,
|
||||||
pub clip: bool,
|
pub clip: bool,
|
||||||
pub elements: Vec<Box<dyn UiElement>>,
|
pub elements: Vec<Box<dyn UiElement>>,
|
||||||
|
pub corner_radius: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Container {
|
impl Default for Container {
|
||||||
|
@ -79,6 +80,7 @@ impl Default for Container {
|
||||||
borders: Default::default(),
|
borders: Default::default(),
|
||||||
clip: Default::default(),
|
clip: Default::default(),
|
||||||
elements: Vec::new(),
|
elements: Vec::new(),
|
||||||
|
corner_radius: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,8 @@ impl UiElement for Container {
|
||||||
ctx.draw.add(UiDrawCommand::Rectangle {
|
ctx.draw.add(UiDrawCommand::Rectangle {
|
||||||
position,
|
position,
|
||||||
size: ctx.measure.size,
|
size: ctx.measure.size,
|
||||||
color
|
color,
|
||||||
|
corner_radius: self.corner_radius,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,14 +55,16 @@ impl UiElement for ProgressBar {
|
||||||
ctx.draw.add(UiDrawCommand::Rectangle {
|
ctx.draw.add(UiDrawCommand::Rectangle {
|
||||||
position: ctx.layout.position,
|
position: ctx.layout.position,
|
||||||
size: ctx.measure.size,
|
size: ctx.measure.size,
|
||||||
color: self.color_background
|
color: self.color_background,
|
||||||
|
corner_radius: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if value > 0. {
|
if value > 0. {
|
||||||
ctx.draw.add(UiDrawCommand::Rectangle {
|
ctx.draw.add(UiDrawCommand::Rectangle {
|
||||||
position: ctx.layout.position,
|
position: ctx.layout.position,
|
||||||
size: ctx.measure.size * vec2(value, 1.0),
|
size: ctx.measure.size * vec2(value, 1.0),
|
||||||
color: self.color_foreground
|
color: self.color_foreground,
|
||||||
|
corner_radius: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ impl UiElement for Rect {
|
||||||
position: ctx.layout.position,
|
position: ctx.layout.position,
|
||||||
size: ctx.measure.size,
|
size: ctx.measure.size,
|
||||||
color,
|
color,
|
||||||
|
corner_radius: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue