Compare commits
2 commits
6092de0769
...
0d4ee1455b
Author | SHA1 | Date | |
---|---|---|---|
0d4ee1455b | |||
6d19f9bceb |
4 changed files with 45 additions and 38 deletions
|
@ -116,7 +116,7 @@ impl ButtonBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<Button>> {
|
pub fn build(self, gui_handler: Arc<GuiHandler<'_>>) -> Result<Arc<Button<'_>>> {
|
||||||
let framable = Framable::new(gui_handler.clone(), false)?;
|
let framable = Framable::new(gui_handler.clone(), false)?;
|
||||||
|
|
||||||
let normal = FillType::new(
|
let normal = FillType::new(
|
||||||
|
@ -150,7 +150,7 @@ impl ButtonBuilder {
|
||||||
let clickable = Clickable::new(framable.clone(), click_executable.clone());
|
let clickable = Clickable::new(framable.clone(), click_executable.clone());
|
||||||
|
|
||||||
let selectable = Selectable::new(
|
let selectable = Selectable::new(
|
||||||
gui_handler,
|
&gui_handler,
|
||||||
click_executable.clone(),
|
click_executable.clone(),
|
||||||
select_executable.clone(),
|
select_executable.clone(),
|
||||||
on_select_executable.clone(),
|
on_select_executable.clone(),
|
||||||
|
@ -253,10 +253,10 @@ pub enum ButtonSelectMode {
|
||||||
Bigger,
|
Bigger,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Button {
|
pub struct Button<'a> {
|
||||||
clickable: Arc<Clickable>,
|
clickable: Arc<Clickable>,
|
||||||
hoverable: Arc<Hoverable>,
|
hoverable: Arc<Hoverable>,
|
||||||
selectable: Arc<Selectable>,
|
selectable: Arc<Selectable<'a>>,
|
||||||
framable: Arc<Framable>,
|
framable: Arc<Framable>,
|
||||||
iconizable: IconizableWrapper,
|
iconizable: IconizableWrapper,
|
||||||
textable: TextableWrapper,
|
textable: TextableWrapper,
|
||||||
|
@ -280,7 +280,7 @@ pub struct Button {
|
||||||
visible: AtomicBool,
|
visible: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl<'a> Button<'a> {
|
||||||
pub fn builder() -> ButtonBuilder {
|
pub fn builder() -> ButtonBuilder {
|
||||||
ButtonBuilder {
|
ButtonBuilder {
|
||||||
icon: None,
|
icon: None,
|
||||||
|
@ -366,7 +366,10 @@ impl Button {
|
||||||
self.textable.set_text_color(text_color)
|
self.textable.set_text_color(text_color)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_from(button_info: &ButtonInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
pub fn try_from(
|
||||||
|
button_info: &ButtonInfo,
|
||||||
|
gui_handler: &Arc<GuiHandler<'a>>,
|
||||||
|
) -> Result<Arc<Self>> {
|
||||||
let mut button_builder = Button::builder()
|
let mut button_builder = Button::builder()
|
||||||
.set_select_mode(button_info.select_mode)
|
.set_select_mode(button_info.select_mode)
|
||||||
.set_isolate(button_info.isolate);
|
.set_isolate(button_info.isolate);
|
||||||
|
@ -423,7 +426,7 @@ impl Button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiElementTraits for Button {
|
impl<'a> GuiElementTraits for Button<'a> {
|
||||||
fn gridable(&self) -> Option<&dyn Gridable> {
|
fn gridable(&self) -> Option<&dyn Gridable> {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
@ -432,12 +435,12 @@ impl GuiElementTraits for Button {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn downcast<'a>(&'a self) -> Option<GuiElement<'a>> {
|
fn downcast<'b>(&'b self) -> Option<GuiElement<'b>> {
|
||||||
Some(GuiElement::Button(self))
|
Some(GuiElement::Button(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visibility for Button {
|
impl<'a> Visibility for Button<'a> {
|
||||||
fn visible(&self) -> bool {
|
fn visible(&self) -> bool {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
@ -469,7 +472,7 @@ impl Visibility for Button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gridable for Button {
|
impl<'a> Gridable for Button<'a> {
|
||||||
fn set_frame(
|
fn set_frame(
|
||||||
&self,
|
&self,
|
||||||
x: i32,
|
x: i32,
|
||||||
|
@ -494,7 +497,7 @@ impl Gridable for Button {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selectable(&self) -> Option<&Arc<Selectable>> {
|
fn selectable(&self) -> Option<&Arc<Selectable<'_>>> {
|
||||||
Some(&self.selectable)
|
Some(&self.selectable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +525,7 @@ impl Gridable for Button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Button {
|
impl<'a> Drop for Button<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.visible.load(SeqCst) {
|
if self.visible.load(SeqCst) {
|
||||||
self.disable_base().unwrap();
|
self.disable_base().unwrap();
|
||||||
|
@ -531,7 +534,7 @@ impl Drop for Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
impl Button {
|
impl<'a> Button<'a> {
|
||||||
// fn create_hovered_changed_callback(button: Arc<Button>) -> Result<()> {
|
// fn create_hovered_changed_callback(button: Arc<Button>) -> Result<()> {
|
||||||
// let button_weak = Arc::downgrade(&button);
|
// let button_weak = Arc::downgrade(&button);
|
||||||
|
|
||||||
|
@ -554,7 +557,7 @@ impl Button {
|
||||||
// .set_hovered_changed_callback(Some(hovered_changed))
|
// .set_hovered_changed_callback(Some(hovered_changed))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fn create_clicked_changed_callback(button: Arc<Button>) {
|
fn create_clicked_changed_callback(button: Arc<Button<'a>>) {
|
||||||
let button_weak = Arc::downgrade(&button);
|
let button_weak = Arc::downgrade(&button);
|
||||||
|
|
||||||
let clicked_changed = Box::new(move || {
|
let clicked_changed = Box::new(move || {
|
||||||
|
@ -576,7 +579,7 @@ impl Button {
|
||||||
.set_clicked_changed_callback(Some(clicked_changed));
|
.set_clicked_changed_callback(Some(clicked_changed));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_selected_changed_callback(button: Arc<Button>) {
|
fn create_selected_changed_callback(button: Arc<Button<'a>>) {
|
||||||
let button_weak = Arc::downgrade(&button);
|
let button_weak = Arc::downgrade(&button);
|
||||||
|
|
||||||
let selected_changed = move |selected| {
|
let selected_changed = move |selected| {
|
||||||
|
@ -697,8 +700,8 @@ impl Button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Button {
|
impl<'a> Deref for Button<'a> {
|
||||||
type Target = Arc<Selectable>;
|
type Target = Arc<Selectable<'a>>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.selectable
|
&self.selectable
|
||||||
|
|
|
@ -12,8 +12,8 @@ use std::sync::{
|
||||||
/// `Selectable` gives the ability to navigate per button or controller to
|
/// `Selectable` gives the ability to navigate per button or controller to
|
||||||
/// optionally adjacent neighbour Selectables and to execute a closure
|
/// optionally adjacent neighbour Selectables and to execute a closure
|
||||||
/// when the current Selectable is pressed
|
/// when the current Selectable is pressed
|
||||||
pub struct Selectable {
|
pub struct Selectable<'a> {
|
||||||
gui_handler: Arc<GuiHandler>,
|
|
||||||
|
|
||||||
selected: AtomicBool,
|
selected: AtomicBool,
|
||||||
|
|
||||||
|
@ -32,33 +32,33 @@ pub struct Selectable {
|
||||||
isolate: bool,
|
isolate: bool,
|
||||||
|
|
||||||
// used when clicked
|
// used when clicked
|
||||||
executable: Arc<Executable<()>>,
|
executable: Arc<Executable<&'a mut World>>,
|
||||||
|
|
||||||
// used internally by button
|
// used internally by button
|
||||||
selected_changed_executable: Arc<Executable<bool>>,
|
selected_changed_executable: Arc<Executable<(&'a mut World, bool)>>,
|
||||||
|
|
||||||
// exposed externally for event
|
// exposed externally for event
|
||||||
on_select_executable: Arc<Executable<bool>>,
|
on_select_executable: Arc<Executable<(&'mut World, bool)>>,
|
||||||
|
|
||||||
// used for custom buttons
|
// used for custom buttons
|
||||||
custom_callback: RwLock<Option<Box<dyn Fn(ControllerButton) -> Result<bool> + Send + Sync>>>,
|
custom_callback: RwLock<Option<Box<dyn Fn(&mut World, ControllerButton) -> Result<bool> + Send + Sync>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable {
|
impl<'a> Selectable<'a> {
|
||||||
/// Factory method for `Selectable`, returns `Arc<Selectable>`.
|
/// Factory method for `Selectable`, returns `Arc<Selectable>`.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `executable` is a `Arc<Executable>` instance
|
/// * `executable` is a `Arc<Executable>` instance
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gui_handler: Arc<GuiHandler>,
|
gui_handler: &'a GuiHandler<'a>,
|
||||||
executable: Arc<Executable<()>>,
|
executable: Arc<Executable<()>>,
|
||||||
selected_changed_executable: Arc<Executable<bool>>,
|
selected_changed_executable: Arc<Executable<bool>>,
|
||||||
on_select_executable: Arc<Executable<bool>>,
|
on_select_executable: Arc<Executable<bool>>,
|
||||||
isolate: bool,
|
isolate: bool,
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
Arc::new(Selectable {
|
Arc::new(Selectable {
|
||||||
gui_handler,
|
|
||||||
|
|
||||||
selected: AtomicBool::new(false),
|
selected: AtomicBool::new(false),
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ impl TextToScreen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GuiHandler {
|
pub struct GuiHandler<'a> {
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
queue: Arc<Mutex<Queue>>,
|
queue: Arc<Mutex<Queue>>,
|
||||||
|
|
||||||
|
@ -241,18 +241,18 @@ pub struct GuiHandler {
|
||||||
current_writeable: RwLock<Option<Arc<Writeable>>>,
|
current_writeable: RwLock<Option<Arc<Writeable>>>,
|
||||||
current_hoverable: RwLock<Option<Arc<Hoverable>>>,
|
current_hoverable: RwLock<Option<Arc<Hoverable>>>,
|
||||||
current_clickable: RwLock<Option<Arc<Clickable>>>,
|
current_clickable: RwLock<Option<Arc<Clickable>>>,
|
||||||
current_selectable: RwLock<Option<Arc<Selectable>>>,
|
current_selectable: RwLock<Option<Arc<Selectable<'a>>>>,
|
||||||
|
|
||||||
text_sample_count: VkSampleCountFlags,
|
text_sample_count: VkSampleCountFlags,
|
||||||
|
|
||||||
callback_list: Mutex<Vec<Box<dyn FnOnce() -> Result<()> + Send + Sync>>>,
|
callback_list: Mutex<Vec<Box<dyn FnOnce() -> Result<()> + Send + Sync>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiHandler {
|
impl<'a> GuiHandler<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
||||||
context: &impl ContextInterface,
|
context: &impl ContextInterface,
|
||||||
) -> Result<Arc<GuiHandler>> {
|
) -> Result<Arc<Self>> {
|
||||||
let device = context.device();
|
let device = context.device();
|
||||||
let queue = context.queue();
|
let queue = context.queue();
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ impl GuiHandler {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_selectable(&self) -> Result<Option<Arc<Selectable>>> {
|
pub fn current_selectable(&self) -> Result<Option<Arc<Selectable<'a>>>> {
|
||||||
match self.current_selectable.read().unwrap().as_ref() {
|
match self.current_selectable.read().unwrap().as_ref() {
|
||||||
Some(selectable) => Ok(Some(selectable.clone())),
|
Some(selectable) => Ok(Some(selectable.clone())),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
|
@ -1064,7 +1064,7 @@ macro_rules! remove_element {
|
||||||
}
|
}
|
||||||
|
|
||||||
// object handling
|
// object handling
|
||||||
impl GuiHandler {
|
impl<'a> GuiHandler<'a> {
|
||||||
// framable
|
// framable
|
||||||
pub(crate) fn add_framable(&self, layer: i32, framable: Arc<Framable>) -> Result<()> {
|
pub(crate) fn add_framable(&self, layer: i32, framable: Arc<Framable>) -> Result<()> {
|
||||||
add_element!(self.layers, layer, framable);
|
add_element!(self.layers, layer, framable);
|
||||||
|
@ -1101,13 +1101,17 @@ impl GuiHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectable
|
// selectable
|
||||||
pub(crate) fn add_selectable(&self, layer: i32, selectable: Arc<Selectable>) -> Result<()> {
|
pub(crate) fn add_selectable(&self, layer: i32, selectable: Arc<Selectable<'a>>) -> Result<()> {
|
||||||
add_element!(self.layers, layer, selectable);
|
add_element!(self.layers, layer, selectable);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn delete_selectable(&self, layer: i32, selectable: &Arc<Selectable>) -> Result<()> {
|
pub(crate) fn delete_selectable(
|
||||||
|
&self,
|
||||||
|
layer: i32,
|
||||||
|
selectable: &Arc<Selectable<'a>>,
|
||||||
|
) -> Result<()> {
|
||||||
let mut current_selectable = self.current_selectable.write().unwrap();
|
let mut current_selectable = self.current_selectable.write().unwrap();
|
||||||
if current_selectable.is_some() {
|
if current_selectable.is_some() {
|
||||||
// unwrap is safe, just tested for `is_some`
|
// unwrap is safe, just tested for `is_some`
|
||||||
|
@ -1232,7 +1236,7 @@ impl GuiHandler {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_selectable(&self, selectable: Option<Arc<Selectable>>) -> Result<()> {
|
pub(crate) fn set_selectable(&self, selectable: Option<Arc<Selectable<'a>>>) -> Result<()> {
|
||||||
let mut current_selectable = self.current_selectable.write().unwrap();
|
let mut current_selectable = self.current_selectable.write().unwrap();
|
||||||
|
|
||||||
if let Some(selectable) = current_selectable.as_ref() {
|
if let Some(selectable) = current_selectable.as_ref() {
|
||||||
|
@ -1268,7 +1272,7 @@ impl GuiHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// private - create rendering stuff
|
// private - create rendering stuff
|
||||||
impl GuiHandler {
|
impl<'a> GuiHandler<'a> {
|
||||||
fn create_render_targets(
|
fn create_render_targets(
|
||||||
device: &Arc<Device>,
|
device: &Arc<Device>,
|
||||||
target_images: &TargetMode<Vec<Arc<Image>>>,
|
target_images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
|
@ -1594,7 +1598,7 @@ impl GuiHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiHandler {
|
impl<'a> GuiHandler<'a> {
|
||||||
pub fn process(
|
pub fn process(
|
||||||
&self,
|
&self,
|
||||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub struct Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyboard {
|
impl Keyboard {
|
||||||
pub fn new(gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
pub fn new(gui_handler: &Arc<GuiHandler<'a>>) -> Result<Arc<Self>> {
|
||||||
let text_field_gui: Arc<GuiBuilder> =
|
let text_field_gui: Arc<GuiBuilder> =
|
||||||
GuiBuilder::from_str(gui_handler, include_str!("text_field.xml"))?;
|
GuiBuilder::from_str(gui_handler, include_str!("text_field.xml"))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue