Created
April 22, 2021 16:26
-
-
Save MoAlyousef/3981599e52274f73d6bc889b5a2c1d38 to your computer and use it in GitHub Desktop.
Right to Left input (for RTL languages).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use fltk::{enums::*, prelude::*, *}; | |
| use std::ops::{Deref, DerefMut}; | |
| pub struct RtlInput { | |
| inp: input::Input, | |
| } | |
| impl RtlInput { | |
| pub fn new(x: i32, y: i32, w: i32, h: i32, label: &'static str) -> Self { | |
| let mut inp = input::Input::new(x, y, w, h, label).with_align(Align::Right); | |
| let mut frame = frame::Frame::new(x, y, w, h, None).with_align(Align::Inside | Align::Right); | |
| frame.set_frame(FrameType::DownBox); | |
| frame.set_color(Color::White); | |
| inp.set_trigger(CallbackTrigger::Changed); | |
| inp.set_callback(move |i| { | |
| frame.set_label(&i.value()); | |
| }); | |
| Self { | |
| inp | |
| } | |
| } | |
| } | |
| impl Deref for RtlInput { | |
| type Target = input::Input; | |
| fn deref(&self) -> &Self::Target { | |
| &self.inp | |
| } | |
| } | |
| impl DerefMut for RtlInput { | |
| fn deref_mut(&mut self) -> &mut Self::Target { | |
| &mut self.inp | |
| } | |
| } | |
| fn main() { | |
| let app = app::App::default(); | |
| let mut win = window::Window::default().with_size(400, 300); | |
| let _inp = RtlInput::new(160, 190, 100, 40, "الاسم"); | |
| win.end(); | |
| win.show(); | |
| app.run().unwrap(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment