UI tweaks, use B8G8R8A8_UNORM in wgui

This commit is contained in:
Aleksander
2025-09-21 20:25:57 +02:00
parent 858c5da21c
commit 4afdde1793
10 changed files with 97 additions and 105 deletions

View File

@@ -62,14 +62,18 @@
overflow_x="scroll"> overflow_x="scroll">
<!-- CONTENT --> <!-- CONTENT -->
<rectangle <rectangle
color2="#0d131acc" color2="#0d131aee"
color="#244179aa" color="#244179dd"
gradient="vertical" gradient="vertical"
round="8" round="8"
flex_grow="1" flex_grow="1"
width="100%" width="100%"
overflow_y="scroll" overflow_y="scroll"
> >
<!-- radial gradient -->
<rectangle
position="absolute" width="100%" height="100%"
gradient="radial" color="#44BBFF22" color2="#00000000" />
<div <div
id="content" id="content"
overflow_x="scroll" overflow_x="scroll"

View File

@@ -3,5 +3,19 @@
<elements> <elements>
<TabTitle translation="APPLICATIONS" icon="dashboard/apps.svg" /> <TabTitle translation="APPLICATIONS" icon="dashboard/apps.svg" />
<!-- placeholders for now -->
<div gap="4" align_items="center">
<Button width="48" height="38">
<sprite src="dashboard/alphabetical.svg" width="24" height="24" />
</Button>
<Button width="48" height="38">
<sprite src="dashboard/category_search.svg" width="24" height="24" />
</Button>
<sprite src="dashboard/search.svg" width="24" height="24" />
<!-- placeholder editbox -->
<rectangle flex_grow="1" height="100%" color="#1d2e51" border_color="#294774" border="2" round="4" align_items="center" padding_left="12">
<label text="Search" color="#FFFFFF88" weight="bold" />
</rectangle>
</div>
</elements> </elements>
</layout> </layout>

View File

@@ -4,7 +4,6 @@ use chrono::Timelike;
use glam::Vec2; use glam::Vec2;
use wgui::{ use wgui::{
components::button::ComponentButton, components::button::ComponentButton,
drawing,
event::{CallbackDataCommon, EventAlterables, EventListenerCollection}, event::{CallbackDataCommon, EventAlterables, EventListenerCollection},
globals::WguiGlobals, globals::WguiGlobals,
i18n::Translation, i18n::Translation,
@@ -50,13 +49,7 @@ pub struct FrontendParams<'a> {
impl Frontend { impl Frontend {
pub fn new(params: FrontendParams) -> anyhow::Result<(RcFrontend, RcLayout)> { pub fn new(params: FrontendParams) -> anyhow::Result<(RcFrontend, RcLayout)> {
let globals = WguiGlobals::new( let globals = WguiGlobals::new(Box::new(assets::Asset {}), wgui::globals::Defaults::default())?;
Box::new(assets::Asset {}),
wgui::globals::Defaults {
dark_mode: true,
text_color: drawing::Color::new(1.0, 1.0, 1.0, 1.0),
},
)?;
let (layout, state) = wgui::parser::new_layout_from_assets( let (layout, state) = wgui::parser::new_layout_from_assets(
params.listeners, params.listeners,

View File

@@ -23,10 +23,7 @@ impl TestbedAny {
let globals = WguiGlobals::new( let globals = WguiGlobals::new(
Box::new(assets::Asset {}), Box::new(assets::Asset {}),
wgui::globals::Defaults { wgui::globals::Defaults::default(),
dark_mode: true,
text_color: wgui::drawing::Color::new(1.0, 1.0, 1.0, 1.0),
},
)?; )?;
let (layout, state) = wgui::parser::new_layout_from_assets( let (layout, state) = wgui::parser::new_layout_from_assets(

View File

@@ -61,10 +61,7 @@ impl TestbedGeneric {
let globals = WguiGlobals::new( let globals = WguiGlobals::new(
Box::new(assets::Asset {}), Box::new(assets::Asset {}),
wgui::globals::Defaults { wgui::globals::Defaults::default(),
text_color: wgui::drawing::Color::new(1.0, 1.0, 1.0, 1.0),
dark_mode: true,
},
)?; )?;
let extra = ParseDocumentExtra { let extra = ParseDocumentExtra {

View File

@@ -5,7 +5,6 @@ use vulkano::{
physical::{PhysicalDevice, PhysicalDeviceType}, physical::{PhysicalDevice, PhysicalDeviceType},
}, },
instance::{Instance, InstanceCreateInfo}, instance::{Instance, InstanceCreateInfo},
swapchain::SurfaceInfo,
}; };
use wgui::gfx::WGfx; use wgui::gfx::WGfx;
@@ -85,12 +84,6 @@ pub fn init_window() -> anyhow::Result<(
log::info!("img_filter_cubic!"); log::info!("img_filter_cubic!");
} }
let surface_format = physical_device
.surface_formats(&surface, SurfaceInfo::default())
.unwrap()[0] // want panic
.0;
log::info!("Using surface format: {surface_format:?}");
let (device, queues) = Device::new( let (device, queues) = Device::new(
physical_device, physical_device,
DeviceCreateInfo { DeviceCreateInfo {
@@ -113,7 +106,13 @@ pub fn init_window() -> anyhow::Result<(
let (queue_gfx, queue_xfer, _) = unwrap_queues(queues.collect()); let (queue_gfx, queue_xfer, _) = unwrap_queues(queues.collect());
let me = WGfx::new_from_raw(instance, device, queue_gfx, queue_xfer, surface_format); let me = WGfx::new_from_raw(
instance,
device,
queue_gfx,
queue_xfer,
vulkano::format::Format::B8G8R8A8_UNORM,
);
Ok((me, event_loop, window, surface)) Ok((me, event_loop, window, surface))
} }

View File

@@ -6,6 +6,7 @@ use crate::{
components::{Component, ComponentBase, ComponentTrait, InitData}, components::{Component, ComponentBase, ComponentTrait, InitData},
drawing::{self, Color}, drawing::{self, Color},
event::{CallbackDataCommon, EventListenerCollection, EventListenerKind, ListenerHandleVec}, event::{CallbackDataCommon, EventListenerCollection, EventListenerKind, ListenerHandleVec},
globals::Globals,
i18n::Translation, i18n::Translation,
layout::{Layout, WidgetID}, layout::{Layout, WidgetID},
renderer_vk::text::{FontWeight, TextStyle}, renderer_vk::text::{FontWeight, TextStyle},
@@ -18,10 +19,10 @@ use crate::{
pub struct Params { pub struct Params {
pub text: Translation, pub text: Translation,
pub color: drawing::Color, pub color: Option<drawing::Color>,
pub border_color: drawing::Color, pub border_color: Option<drawing::Color>,
pub hover_border_color: drawing::Color, pub hover_border_color: Option<drawing::Color>,
pub hover_color: drawing::Color, pub hover_color: Option<drawing::Color>,
pub round: WLength, pub round: WLength,
pub style: taffy::Style, pub style: taffy::Style,
pub text_style: TextStyle, pub text_style: TextStyle,
@@ -31,10 +32,10 @@ impl Default for Params {
fn default() -> Self { fn default() -> Self {
Self { Self {
text: Translation::from_raw_text(""), text: Translation::from_raw_text(""),
color: drawing::Color::new(0.7, 0.7, 0.7, 1.0), color: None,
hover_color: drawing::Color::new(1.0, 1.0, 1.0, 1.0), hover_color: None,
border_color: drawing::Color::new(0.0, 0.0, 0.0, 1.0), border_color: None,
hover_border_color: drawing::Color::new(0.25, 0.25, 0.25, 1.0), hover_border_color: None,
round: WLength::Units(4.0), round: WLength::Units(4.0),
style: Default::default(), style: Default::default(),
text_style: TextStyle::default(), text_style: TextStyle::default(),
@@ -93,7 +94,7 @@ fn get_color2(color: &drawing::Color) -> drawing::Color {
} }
fn anim_hover(rect: &mut WidgetRectangle, data: &Data, pos: f32, pressed: bool) { fn anim_hover(rect: &mut WidgetRectangle, data: &Data, pos: f32, pressed: bool) {
let mult = pos * if pressed { 1.25 } else { 1.0 }; let mult = pos * if pressed { 1.5 } else { 1.0 };
let bgcolor = data.initial_color.lerp(&data.initial_hover_color, mult); let bgcolor = data.initial_color.lerp(&data.initial_hover_color, mult);
rect.params.color = bgcolor; rect.params.color = bgcolor;
@@ -220,6 +221,7 @@ fn register_event_mouse_release<U1, U2>(
} }
pub fn construct<U1, U2>( pub fn construct<U1, U2>(
globals: &mut Globals,
layout: &mut Layout, layout: &mut Layout,
listeners: &mut EventListenerCollection<U1, U2>, listeners: &mut EventListenerCollection<U1, U2>,
parent: WidgetID, parent: WidgetID,
@@ -232,28 +234,51 @@ pub fn construct<U1, U2>(
style.justify_content = Some(JustifyContent::Center); style.justify_content = Some(JustifyContent::Center);
style.padding = length(1.0); style.padding = length(1.0);
let globals = layout.state.globals.clone(); // update colors to default ones if they are not specified
let color = if let Some(color) = params.color {
color
} else {
globals.defaults.button_color
};
let border_color = if let Some(border_color) = params.border_color {
border_color
} else {
Color::new(color.r, color.g, color.b, color.a + 0.4)
};
let hover_color = if let Some(hover_color) = params.hover_color {
hover_color
} else {
Color::new(color.r + 0.25, color.g + 0.25, color.g + 0.25, color.a + 0.25)
};
let hover_border_color = if let Some(hover_border_color) = params.hover_border_color {
hover_border_color
} else {
Color::new(color.r + 0.5, color.g + 0.5, color.g + 0.5, color.a + 0.5)
};
let (id_root, _) = layout.add_child( let (id_root, _) = layout.add_child(
parent, parent,
WidgetRectangle::create(WidgetRectangleParams { WidgetRectangle::create(WidgetRectangleParams {
color: params.color, color,
color2: get_color2(&params.color), color2: get_color2(&color),
gradient: drawing::GradientMode::Vertical, gradient: drawing::GradientMode::Vertical,
round: params.round, round: params.round,
border_color: params.border_color, border_color,
border: 2.0, border: 2.0,
}), }),
style, style,
)?; )?;
let id_rect = id_root; let id_rect = id_root;
let light_text = (params.color.r + params.color.g + params.color.b) < 1.5; let light_text = (color.r + color.g + color.b) < 1.5;
let (id_label, _node_label) = layout.add_child( let (id_label, _node_label) = layout.add_child(
id_rect, id_rect,
WidgetLabel::create( WidgetLabel::create(
&mut globals.get(), globals,
WidgetLabelParams { WidgetLabelParams {
content: params.text, content: params.text,
style: TextStyle { style: TextStyle {
@@ -273,10 +298,10 @@ pub fn construct<U1, U2>(
let data = Rc::new(Data { let data = Rc::new(Data {
id_label, id_label,
id_rect, id_rect,
initial_color: params.color, initial_color: color,
initial_border_color: params.border_color, initial_border_color: border_color,
initial_hover_color: params.hover_color, initial_hover_color: hover_color,
initial_hover_border_color: params.hover_border_color, initial_hover_border_color: hover_border_color,
}); });
let state = Rc::new(RefCell::new(State { let state = Rc::new(RefCell::new(State {

View File

@@ -13,19 +13,14 @@ use vulkano::{
AutoCommandBufferBuilder, CommandBufferUsage, AutoCommandBufferBuilder, CommandBufferUsage,
allocator::{StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo}, allocator::{StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo},
}, },
descriptor_set::allocator::{ descriptor_set::allocator::{StandardDescriptorSetAllocator, StandardDescriptorSetAllocatorCreateInfo},
StandardDescriptorSetAllocator, StandardDescriptorSetAllocatorCreateInfo,
},
device::{Device, Queue}, device::{Device, Queue},
format::Format, format::Format,
image::{Image, ImageCreateInfo, ImageType, ImageUsage, sampler::Filter}, image::{Image, ImageCreateInfo, ImageType, ImageUsage, sampler::Filter},
instance::Instance, instance::Instance,
memory::{ memory::{
MemoryPropertyFlags, MemoryPropertyFlags,
allocator::{ allocator::{AllocationCreateInfo, GenericMemoryAllocatorCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
AllocationCreateInfo, GenericMemoryAllocatorCreateInfo, MemoryTypeFilter,
StandardMemoryAllocator,
},
}, },
pipeline::graphics::{ pipeline::graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp}, color_blend::{AttachmentBlend, BlendFactor, BlendOp},
@@ -128,19 +123,14 @@ impl WGfx {
..Default::default() ..Default::default()
}, },
AllocationCreateInfo { AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE memory_type_filter: MemoryTypeFilter::PREFER_DEVICE | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default() ..Default::default()
}, },
capacity, capacity,
)?) )?)
} }
pub fn new_buffer<T>( pub fn new_buffer<T>(&self, usage: BufferUsage, contents: Iter<'_, T>) -> anyhow::Result<Subbuffer<[T]>>
&self,
usage: BufferUsage,
contents: Iter<'_, T>,
) -> anyhow::Result<Subbuffer<[T]>>
where where
T: BufferContents + Clone, T: BufferContents + Clone,
{ {
@@ -151,21 +141,14 @@ impl WGfx {
..Default::default() ..Default::default()
}, },
AllocationCreateInfo { AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE memory_type_filter: MemoryTypeFilter::PREFER_DEVICE | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default() ..Default::default()
}, },
contents.cloned(), contents.cloned(),
)?) )?)
} }
pub fn new_image( pub fn new_image(&self, width: u32, height: u32, format: Format, usage: ImageUsage) -> anyhow::Result<Arc<Image>> {
&self,
width: u32,
height: u32,
format: Format,
usage: ImageUsage,
) -> anyhow::Result<Arc<Image>> {
Ok(Image::new( Ok(Image::new(
self.memory_allocator.clone(), self.memory_allocator.clone(),
ImageCreateInfo { ImageCreateInfo {
@@ -202,10 +185,7 @@ impl WGfx {
)?)) )?))
} }
pub fn create_gfx_command_buffer( pub fn create_gfx_command_buffer(self: &Arc<Self>, usage: CommandBufferUsage) -> anyhow::Result<GfxCommandBuffer> {
self: &Arc<Self>,
usage: CommandBufferUsage,
) -> anyhow::Result<GfxCommandBuffer> {
self.create_gfx_command_buffer_with_queue(self.queue_gfx.clone(), usage) self.create_gfx_command_buffer_with_queue(self.queue_gfx.clone(), usage)
} }
@@ -214,11 +194,8 @@ impl WGfx {
queue: Arc<Queue>, queue: Arc<Queue>,
usage: CommandBufferUsage, usage: CommandBufferUsage,
) -> anyhow::Result<GfxCommandBuffer> { ) -> anyhow::Result<GfxCommandBuffer> {
let command_buffer = AutoCommandBufferBuilder::primary( let command_buffer =
self.command_buffer_allocator.clone(), AutoCommandBufferBuilder::primary(self.command_buffer_allocator.clone(), queue.queue_family_index(), usage)?;
queue.queue_family_index(),
usage,
)?;
Ok(GfxCommandBuffer { Ok(GfxCommandBuffer {
graphics: self.clone(), graphics: self.clone(),
queue, queue,
@@ -227,10 +204,7 @@ impl WGfx {
}) })
} }
pub fn create_xfer_command_buffer( pub fn create_xfer_command_buffer(self: &Arc<Self>, usage: CommandBufferUsage) -> anyhow::Result<XferCommandBuffer> {
self: &Arc<Self>,
usage: CommandBufferUsage,
) -> anyhow::Result<XferCommandBuffer> {
self.create_xfer_command_buffer_with_queue(self.queue_gfx.clone(), usage) self.create_xfer_command_buffer_with_queue(self.queue_gfx.clone(), usage)
} }
@@ -239,11 +213,8 @@ impl WGfx {
queue: Arc<Queue>, queue: Arc<Queue>,
usage: CommandBufferUsage, usage: CommandBufferUsage,
) -> anyhow::Result<XferCommandBuffer> { ) -> anyhow::Result<XferCommandBuffer> {
let command_buffer = AutoCommandBufferBuilder::primary( let command_buffer =
self.command_buffer_allocator.clone(), AutoCommandBufferBuilder::primary(self.command_buffer_allocator.clone(), queue.queue_family_index(), usage)?;
queue.queue_family_index(),
usage,
)?;
Ok(XferCommandBuffer { Ok(XferCommandBuffer {
graphics: self.clone(), graphics: self.clone(),
queue, queue,

View File

@@ -8,13 +8,15 @@ use crate::{assets::AssetProvider, drawing, i18n::I18n};
pub struct Defaults { pub struct Defaults {
pub dark_mode: bool, pub dark_mode: bool,
pub text_color: drawing::Color, pub text_color: drawing::Color,
pub button_color: drawing::Color,
} }
impl Default for Defaults { impl Default for Defaults {
fn default() -> Self { fn default() -> Self {
Self { Self {
dark_mode: true, dark_mode: true,
text_color: drawing::Color::new(0.0, 0.0, 0.0, 1.0), text_color: drawing::Color::new(1.0, 1.0, 1.0, 1.0),
button_color: drawing::Color::new(1.0, 1.0, 1.0, 0.05),
} }
} }
} }

View File

@@ -5,7 +5,7 @@ use crate::{
layout::WidgetID, layout::WidgetID,
parser::{ parser::{
ParserContext, ParserFile, iter_attribs, parse_children, process_component, ParserContext, ParserFile, iter_attribs, parse_children, process_component,
style::{parse_color, parse_color_opt, parse_round, parse_style, parse_text_style}, style::{parse_color_opt, parse_round, parse_style, parse_text_style},
}, },
widget::util::WLength, widget::util::WLength,
}; };
@@ -16,7 +16,7 @@ pub fn parse_component_button<'a, U1, U2>(
node: roxmltree::Node<'a, 'a>, node: roxmltree::Node<'a, 'a>,
parent_id: WidgetID, parent_id: WidgetID,
) -> anyhow::Result<WidgetID> { ) -> anyhow::Result<WidgetID> {
let mut color = Color::new(1.0, 1.0, 1.0, 1.0); let mut color: Option<Color> = None;
let mut border_color: Option<Color> = None; let mut border_color: Option<Color> = None;
let mut hover_color: Option<Color> = None; let mut hover_color: Option<Color> = None;
let mut hover_border_color: Option<Color> = None; let mut hover_border_color: Option<Color> = None;
@@ -39,7 +39,7 @@ pub fn parse_component_button<'a, U1, U2>(
parse_round(&value, &mut round); parse_round(&value, &mut round);
} }
"color" => { "color" => {
parse_color(&value, &mut color); parse_color_opt(&value, &mut color);
} }
"border_color" => { "border_color" => {
parse_color_opt(&value, &mut border_color); parse_color_opt(&value, &mut border_color);
@@ -54,28 +54,18 @@ pub fn parse_component_button<'a, U1, U2>(
} }
} }
// slight border outlines by default let globals = ctx.layout.state.globals.clone();
if border_color.is_none() {
border_color = Some(Color::lerp(&color, &Color::new(0.0, 0.0, 0.0, color.a), 0.3));
}
if hover_color.is_none() {
hover_color = Some(color.add_rgb(0.5));
}
if hover_border_color.is_none() {
hover_border_color = Some(border_color.unwrap().add_rgb(0.75));
}
let (new_id, component) = button::construct( let (new_id, component) = button::construct(
&mut globals.get(),
ctx.layout, ctx.layout,
ctx.listeners, ctx.listeners,
parent_id, parent_id,
button::Params { button::Params {
color, color,
border_color: border_color.unwrap(), border_color,
hover_border_color: hover_border_color.unwrap(), hover_border_color,
hover_color: hover_color.unwrap(), hover_color,
text: translation, text: translation,
style, style,
text_style, text_style,