Skip to content

Commit

Permalink
added: preliminary trait definition for interactable UI elements
Browse files Browse the repository at this point in the history
micutio committed Nov 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent edc61a6 commit 6a4ed92
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ui/interactable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use tcod::input::Event;

/// Interactables are UI elements that can be interacted with via the mouse.
/// To realise that, this trait provides the interface for a callback that can handle mouse events.
trait Interactable {

/// Returns the element layout (min_x, min_y, max_x, max_y) as absolute screen coordinates.
fn get_layout_abs() -> (i32, i32, i32, i32);

/// Returns the element layout (min_x, min_y, max_x, max_y) as coordinates relative to the
/// parent interactable. If there is no parent interactable this is identical to
/// `get_layout_abs()`
fn get_layout_rel() -> (i32, i32, i32, i32);

/// Handle a mouse event.
// TODO: How to do different return values, e.g.: selected option or no return values?
fn callback(event: Event::Mouse);
}
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ pub mod game_frontend;
pub mod game_input;

mod color_palette;
mod interactable;

0 comments on commit 6a4ed92

Please sign in to comment.