Struct design_pattern_examples_rust::handlerchain::handlerchain_messagewindow::MessageWindow
source · pub struct MessageWindow {
id: i32,
title: String,
window_box: WindowRectangle,
close_box: WindowRectangle,
selected: bool,
}
Expand description
Represents a rectangular region that can handle messages directed to that region.
Note: The IMessageHandler interface is an example of a “Facade” design pattern, where the complexity of the MessageWindow is exposed only through a few methods to a system that only needs to deal with those few methods.
Fields§
§id: i32
Unique ID of this window.
title: String
Title/Name of this window.
window_box: WindowRectangle
Position of this window in global coordinates.
close_box: WindowRectangle
Position of the close window within the window box, although the coordinates are also global coordinates to eliminate the need to convert between window and global coordinates.
selected: bool
Whether this window has been selected (a button click occurred within the window).
Implementations§
source§impl MessageWindow
impl MessageWindow
sourcepub fn new(title: &str, x: i32, y: i32, width: i32, height: i32) -> MessageWindow
pub fn new(title: &str, x: i32, y: i32, width: i32, height: i32) -> MessageWindow
Constructor
Parameters
-
title
Title of the MessageWindow.
-
x
X position of the upper left corner of the window’s region.
-
y
Y position of the upper left corner of the window’s region.
-
width
Width of the window’s region.
-
height
Height of the window’s region.
Returns
Returns a new instance of the MessageWindow struct.
Helper method to handle the ButtonDown message.
Parameters
-
message
A Message object describing the ButtonDown message.
Returns
Returns a value from the MessageReturnTypes enumeration indicating what action the caller should take. In this case, always return Continue so other handlers can react to the same message (assumes no windows are overlapping).
Helper method to handle the ButtonUp message.
Parameters
-
message
A Message object describing the ButtonUp message.
Returns
Returns a value from the MessageReturnTypes enumeration indicating what action the caller should take: (Stop) This message was handled and processing should stop, (Continue) this message can be passed on to other handlers, or (Close) this handler is closed so remove from the handlers list and stop further processing.
sourcefn handle_close_message(&mut self, _message: &Message) -> MessageReturnTypes
fn handle_close_message(&mut self, _message: &Message) -> MessageReturnTypes
Helper method to handle the Close message.
Parameters
-
_message
NOT USED.
Returns
Returns a value from the MessageReturnTypes enumeration indicating what action the caller should take. In this case, always return Close to indicate this handler should be removed from the handler list so no further messages can be sent to this window.