Struct pushrod::widget::push_button_widget::PushButtonWidget
source · pub struct PushButtonWidget { /* private fields */ }Expand description
Draws a push button that triggers a WidgetClicked event when activated.
Implementations§
source§impl PushButtonWidget
impl PushButtonWidget
sourcepub fn new(
font_name: String,
text: String,
font_size: u32,
justify: TextJustify,
) -> Self
pub fn new( font_name: String, text: String, font_size: u32, justify: TextJustify, ) -> Self
Constructor. Requires the name of the font, the text to display, the size of the font, and the font justification when rendered.
Examples found in repository?
examples/simple.rs (lines 710-715)
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
fn add_horizontal_layout_buttons(&mut self) {
let mut base_widget: CanvasWidget = CanvasWidget::new();
base_widget.set_point(CONFIG_ORIGIN, 20, 270);
base_widget.set_size(CONFIG_BODY_SIZE, 760, 36);
base_widget.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 1.0]);
let base_widget_id = self.pushrod.borrow_mut().add_widget_to_parent_by_name(
"MainContainerWidget",
"HorizontalManagerWidget2",
Box::new(base_widget),
);
let base_layout_id =
self.pushrod
.borrow_mut()
.add_layout_manager(Box::new(HorizontalLayoutManager::new(
base_widget_id,
LayoutManagerPadding {
top: 0,
left: 4,
right: 4,
bottom: 4,
spacing: 4,
},
)));
let mut button1 = PushButtonWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"Hide".to_string(),
18,
TextJustify::Center,
);
button1.set_point(CONFIG_ORIGIN, 30, 236);
button1.set_size(CONFIG_BODY_SIZE, 180, 32);
button1.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
button1.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"BoxInLayoutWidgetButton1",
Box::new(button1),
base_layout_id,
make_origin_point(),
);
let mut button3 = PushButtonWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"Disable".to_string(),
18,
TextJustify::Center,
);
button3.set_point(CONFIG_ORIGIN, 30, 236);
button3.set_size(CONFIG_BODY_SIZE, 180, 32);
button3.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
button3.set_numeric(CONFIG_BORDER_WIDTH, 2);
button3.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"BoxInLayoutWidgetButton2",
Box::new(button3),
base_layout_id,
make_origin_point(),
);
let mut button5 = PushButtonWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"Randomize".to_string(),
18,
TextJustify::Center,
);
button5.set_point(CONFIG_ORIGIN, 30, 236);
button5.set_size(CONFIG_BODY_SIZE, 180, 32);
button5.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
button5.set_numeric(CONFIG_BORDER_WIDTH, 2);
button5.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"BoxInLayoutWidgetButton3",
Box::new(button5),
base_layout_id,
make_origin_point(),
);
}
fn add_vertical_layout(&mut self) {
let mut base_widget: CanvasWidget = CanvasWidget::new();
base_widget.set_point(CONFIG_ORIGIN, 20, 330);
base_widget.set_size(CONFIG_BODY_SIZE, 200, 180);
base_widget.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 1.0]);
let base_widget_id = self.pushrod.borrow_mut().add_widget_to_parent_by_name(
"MainContainerWidget",
"VerticalManagerWidget1",
Box::new(base_widget),
);
let base_layout_id =
self.pushrod
.borrow_mut()
.add_layout_manager(Box::new(VerticalLayoutManager::new(
base_widget_id,
LayoutManagerPadding {
top: 4,
left: 4,
right: 4,
bottom: 4,
spacing: 2,
},
)));
let mut progress_widget = ProgressWidget::new();
progress_widget.set_point(CONFIG_ORIGIN, 20, 360);
progress_widget.set_size(CONFIG_BODY_SIZE, 230, 32);
progress_widget.set_color(CONFIG_MAIN_COLOR, [1.0, 1.0, 1.0, 1.0]);
progress_widget.set_color(CONFIG_SECONDARY_COLOR, [0.5, 0.5, 0.5, 1.0]);
progress_widget.set_numeric(CONFIG_PROGRESS, 50);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"ProgressWidget",
Box::new(progress_widget),
base_layout_id,
make_origin_point(),
);
let mut progress_text = TextWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"50%".to_string(),
18,
TextJustify::Center,
);
progress_text.set_point(CONFIG_ORIGIN, 260, 360);
progress_text.set_size(CONFIG_BODY_SIZE, 50, 32);
progress_text.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"ProgressText1",
Box::new(progress_text),
base_layout_id,
make_origin_point(),
);
let mut button1 = ToggleButtonWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"Animate".to_string(),
18,
TextJustify::Center,
);
button1.set_point(CONFIG_ORIGIN, 340, 360);
button1.set_size(CONFIG_BODY_SIZE, 160, 32);
button1.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
button1.set_numeric(CONFIG_BORDER_WIDTH, 2);
button1.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
button1.set_toggle(CONFIG_SELECTED, true);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"AnimateButton1",
Box::new(button1),
base_layout_id,
make_origin_point(),
);
let mut button2 = PushButtonWidget::new(
"assets/OpenSans-Regular.ttf".to_string(),
"Randomize".to_string(),
18,
TextJustify::Center,
);
button2.set_point(CONFIG_ORIGIN, 520, 360);
button2.set_size(CONFIG_BODY_SIZE, 160, 32);
button2.set_color(CONFIG_TEXT_COLOR, [0.0, 0.0, 0.0, 1.0]);
button2.set_numeric(CONFIG_BORDER_WIDTH, 2);
button2.set_color(CONFIG_BORDER_COLOR, [0.0, 0.0, 0.0, 1.0]);
self.pushrod.borrow_mut().add_widget_to_layout_manager(
"RandomColorButton2",
Box::new(button2),
base_layout_id,
make_origin_point(),
);
}Trait Implementations§
source§impl Drawable for PushButtonWidget
impl Drawable for PushButtonWidget
source§fn draw(&mut self, c: Context, g: &mut GlGraphics, clip: &DrawState)
fn draw(&mut self, c: Context, g: &mut GlGraphics, clip: &DrawState)
Draws the
Widget’s contents. Only gets called if the Widget is in invalidated
state. Provides a modified Context object that has an origin of 0x0 in drawing
space for the draw routine. Also provides a mut G2d object against which to draw,
and a clip, which is automatically set to provide a clipping area for the Widget. If
the Widget draws outside of the clipped bounds, that will not be drawn on the
screen.source§fn draw_disabled(
&mut self,
c: Context,
size: Size,
g: &mut GlGraphics,
clip: &DrawState,
)
fn draw_disabled( &mut self, c: Context, size: Size, g: &mut GlGraphics, clip: &DrawState, )
Internal method that is used to draw a box around the
Widget when in disabled state.
You can override this method, should you choose to, so that the disabled state appears
differently in your application. It is safe to leave this alone.source§fn draw_with_offset(
&mut self,
c: Context,
g: &mut GlGraphics,
clip: &DrawState,
point_offset: Point,
)
fn draw_with_offset( &mut self, c: Context, g: &mut GlGraphics, clip: &DrawState, point_offset: Point, )
Draws an object at an offset on the screen. This is a convenience method that is used
by other
Widgets that contain multiple widgets. (See CheckboxWidget and
ImageButtonWidget for good examples of this use.)source§impl InjectableCustomEvents for PushButtonWidget
impl InjectableCustomEvents for PushButtonWidget
source§fn inject_custom_event(&mut self, _widget_id: i32) -> Option<CallbackEvent>
fn inject_custom_event(&mut self, _widget_id: i32) -> Option<CallbackEvent>
Injects an event into the run loop. This can be a timer event, a refresh event, or
whatever the
Widget wants to inject. These should be custom events, not system
events. This method only gets called if injects_events returns true.source§impl InjectableSystemEvents for PushButtonWidget
impl InjectableSystemEvents for PushButtonWidget
source§fn inject_system_event(&mut self) -> Option<CallbackEvent>
fn inject_system_event(&mut self) -> Option<CallbackEvent>
Part of the main loop that queries the
Widget for any system-level events that should
be injected into the PushrodCallbackEvents trait, and not handled by the top-level
run loop. This sends out messages that are bypassed from being used by the Run Loop,
so be very careful. Use this for sending things like custom messages (such as a Widget
move or Widget resize message, which is irrelevant to the run loop.)source§impl Widget for PushButtonWidget
impl Widget for PushButtonWidget
source§fn config(&mut self) -> &mut Configurable
fn config(&mut self) -> &mut Configurable
Retrieves the
Configurable object for this Widget. All Widget implementations
must provide this. (See the CanvasWidget implementation.)source§fn set_config(&mut self, config: u8, config_value: Config)
fn set_config(&mut self, config: u8, config_value: Config)
Master config setter - use convenience methods.
source§fn handle_event(
&mut self,
injected: bool,
event: CallbackEvent,
) -> Option<CallbackEvent>
fn handle_event( &mut self, injected: bool, event: CallbackEvent, ) -> Option<CallbackEvent>
Custom handler to receive an event. Any
Widget that implements this does so to handle
top-level GUI events, such as a mouse entering or exiting the bounds of this Widget.
If the injected flag is set, it indicates that the event supplied was generate by
a Widget, and not by the run loop.source§fn handles_events(&mut self) -> bool
fn handles_events(&mut self) -> bool
Indicates to the run loop whether or not the
Widget handles system-generated events.fn set_widget_id(&mut self, widget_id: i32)
fn get_widget_id(&mut self) -> i32
source§fn get_injectable_custom_events(&mut self) -> &mut dyn InjectableCustomEvents
fn get_injectable_custom_events(&mut self) -> &mut dyn InjectableCustomEvents
Retrieves the
InjectableCustomEvents trait of this class, which is responsible for
injecting custom events when appropriate. Injecting system events is used with the
InjectableSystemEvents, and things like mouse clicks and widget clicks are used
with the handle_event block. This code is used to inject events that are not
triggered by other events in the system.source§fn get_injectable_system_events(&mut self) -> &mut dyn InjectableSystemEvents
fn get_injectable_system_events(&mut self) -> &mut dyn InjectableSystemEvents
Retrieves the trait for injecting system events. Only use this if your
Widget injects
custom system-level events that the top-level application needs to use. Anything other
than that should be ignored completely.source§fn get_drawable(&mut self) -> &mut dyn Drawable
fn get_drawable(&mut self) -> &mut dyn Drawable
Retrieves the
Drawable functionality of this Widget.source§fn invalidate(&mut self)
fn invalidate(&mut self)
Indicates that a
Widget object needs to be repainted.source§fn clear_invalidate(&mut self)
fn clear_invalidate(&mut self)
Clears the invalidation flag. Set this when the
draw function completes. Otherwise,
this Widget object may be continuously repainted.source§fn is_invalidated(&mut self) -> bool
fn is_invalidated(&mut self) -> bool
Indicates whether or not a
Widget needs to be repainted.source§fn get_config(&mut self, config: u8) -> Option<&Config>
fn get_config(&mut self, config: u8) -> Option<&Config>
Master config getter - use convenience methods.
source§fn set_point(&mut self, config: u8, x: i32, y: i32)
fn set_point(&mut self, config: u8, x: i32, y: i32)
Sets a point value for a configuration key.
source§fn set_numeric(&mut self, config: u8, value: u64)
fn set_numeric(&mut self, config: u8, value: u64)
Sets a numeric value for a configuration key.
source§fn set_toggle(&mut self, config: u8, flag: bool)
fn set_toggle(&mut self, config: u8, flag: bool)
Sets a toggle value for a configuration key.
source§fn injects_custom_events(&mut self) -> bool
fn injects_custom_events(&mut self) -> bool
If this
Widget provides custom injected events that are generated outside of the
handle_event loop, indicate true. Only override if necessary. (See TimerWidget
for reference.)source§fn is_drawable(&mut self) -> bool
fn is_drawable(&mut self) -> bool
Describes whether or not the
Widget returns a Drawable trait. This function is called each
time a frame is refreshed, so if there is no Drawable available, this function could
serve as a way to indicate a frame tick. Only override this to set it to false if your
Widget does not draw anything on the screen.source§fn injects_system_events(&mut self) -> bool
fn injects_system_events(&mut self) -> bool
Indicates to the run loop whether or not a
Widget injects system-level events.Auto Trait Implementations§
impl Freeze for PushButtonWidget
impl RefUnwindSafe for PushButtonWidget
impl Send for PushButtonWidget
impl Sync for PushButtonWidget
impl Unpin for PushButtonWidget
impl UnwindSafe for PushButtonWidget
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more