Compare commits

...

2 commits

Author SHA1 Message Date
griffi-gh 3a50d2d0dd add support for winit 0.30 2024-05-04 21:43:03 +02:00
griffi-gh e7b2a8ff69 skip rendering transparent rects 2024-05-04 17:23:39 +02:00
6 changed files with 29 additions and 10 deletions

View file

@ -90,7 +90,7 @@
</td> </td>
<td> <td>
<code>hui-winit = &lt;master&gt;</code><br> <code>hui-winit = &lt;master&gt;</code><br>
<code>winit = "0.29"</code> <code>winit = "0.30"</code> or <code>winit = "0.29"</code>
</td> </td>
<td align="center">(support planned)</td> <td align="center">(support planned)</td>
</tr> </tr>

View file

@ -8,7 +8,7 @@ publish = false
[dev-dependencies] [dev-dependencies]
hui = { path = "../hui" } hui = { path = "../hui" }
hui-glium = { path = "../hui-glium" } hui-glium = { path = "../hui-glium" }
hui-winit = { path = "../hui-winit" } hui-winit = { path = "../hui-winit", features = ["winit_29"] }
kubi-logging = { git = "https://github.com/griffi-gh/kubi", rev = "c162893fd" } kubi-logging = { git = "https://github.com/griffi-gh/kubi", rev = "c162893fd" }
glium = "0.34" glium = "0.34"
winit = "0.29" winit = "0.29"

View file

@ -15,6 +15,12 @@ include = [
[dependencies] [dependencies]
hui = { version = "=0.1.0-alpha.5", path = "../hui", default-features = false } hui = { version = "=0.1.0-alpha.5", path = "../hui", default-features = false }
winit = { version = "0.29", default-features = false } winit_30 = { package = "winit", version = "0.30", default-features = false, optional = true }
winit_29 = { package = "winit", version = "0.29", default-features = false, optional = true }
glam = "0.27" glam = "0.27"
log = "0.4" log = "0.4"
[features]
default = []
winit_30 = ["dep:winit_30"]
winit_29 = ["dep:winit_29"]

View file

@ -1,6 +1,13 @@
#[cfg(all(feature = "winit_30", feature = "winit_29"))]
compile_error!("Only one of the winit_30 and winit_29 features can be enabled at a time");
#[cfg(not(any(feature = "winit_30", feature = "winit_29")))]
compile_error!("One of the winit_30 and winit_29 features must be enabled");
#[cfg(feature = "winit_30")] extern crate winit_30 as winit;
#[cfg(feature = "winit_29")] extern crate winit_29 as winit;
use glam::vec2; use glam::vec2;
use hui::{event::UiEvent, UiInstance}; use hui::{event::UiEvent, UiInstance};
use winit::event::{Event, WindowEvent}; use winit::event::{Event, WindowEvent, MouseButton, ElementState};
//TODO: check window id //TODO: check window id
pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) { pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) {
@ -12,15 +19,15 @@ pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) {
WindowEvent::MouseInput { state, button, .. } => { WindowEvent::MouseInput { state, button, .. } => {
ui.push_event(UiEvent::MouseButton { ui.push_event(UiEvent::MouseButton {
button: match button { button: match button {
winit::event::MouseButton::Left => hui::input::MouseButton::Primary, MouseButton::Left => hui::input::MouseButton::Primary,
winit::event::MouseButton::Right => hui::input::MouseButton::Secondary, MouseButton::Right => hui::input::MouseButton::Secondary,
winit::event::MouseButton::Middle => hui::input::MouseButton::Middle, MouseButton::Middle => hui::input::MouseButton::Middle,
winit::event::MouseButton::Other(id) => hui::input::MouseButton::Other(*id as u8), MouseButton::Other(id) => hui::input::MouseButton::Other(*id as u8),
_ => return, _ => return,
}, },
state: match state { state: match state {
winit::event::ElementState::Pressed => hui::input::ButtonState::Pressed, ElementState::Pressed => hui::input::ButtonState::Pressed,
winit::event::ElementState::Released => hui::input::ButtonState::Released, ElementState::Released => hui::input::ButtonState::Released,
}, },
}) })
}, },

View file

@ -25,6 +25,9 @@ impl Frame for ImageHandle {
impl Frame for FillColor { impl Frame for FillColor {
fn draw(&self, draw: &mut UiDrawCommandList, rect: Rect) { fn draw(&self, draw: &mut UiDrawCommandList, rect: Rect) {
if self.is_transparent() {
return
}
draw.add(UiDrawCommand::Rectangle { draw.add(UiDrawCommand::Rectangle {
position: rect.position, position: rect.position,
size: rect.size, size: rect.size,

View file

@ -116,6 +116,9 @@ impl Default for RectFrame {
impl Frame for RectFrame { impl Frame for RectFrame {
fn draw(&self, draw: &mut UiDrawCommandList, rect: Rect) { fn draw(&self, draw: &mut UiDrawCommandList, rect: Rect) {
if self.color.is_transparent() {
return
}
//TODO: handle bottom_right < top_left //TODO: handle bottom_right < top_left
let top_left = self.top_left.resolve(rect.size); let top_left = self.top_left.resolve(rect.size);
let bottom_right = self.bottom_right.resolve(rect.size); let bottom_right = self.bottom_right.resolve(rect.size);