Skip to content

Instantly share code, notes, and snippets.

@MoAlyousef
Created April 22, 2021 16:26
Show Gist options
  • Select an option

  • Save MoAlyousef/3981599e52274f73d6bc889b5a2c1d38 to your computer and use it in GitHub Desktop.

Select an option

Save MoAlyousef/3981599e52274f73d6bc889b5a2c1d38 to your computer and use it in GitHub Desktop.
Right to Left input (for RTL languages).
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