<commit_before>/* Copyright 2015 <NAME>
 *
 * Licensed under the MIT license <LICENSE or
 * http://opensource.org/licenses/MIT>. This file may not be copied,
 * modified, or distributed except according to those terms.
 */

use std::ffi::CStr;
use std::ptr;
use libc::{c_int};
use iup_sys::*;
use super::{CommonAttributes, TitleAttribute, Control, Container, MenuCommonCallbacks, NonMenuCommonCallbacks, UnwrapHandle};
use super::handle_rc::{HandleRc};

#[derive(Copy,Clone,PartialEq)]
pub enum Position {
    Left,
    Center,
    Right,
    MousePos,
    CenterParent,
    Current,
}

impl Position {
    //fn from_int(i: c_int) -> Position {
    //    match i {
    //        IUP_LEFT => Position::Left,
    //        IUP_CENTER => Position::Center,
    //        IUP_RIGHT => Position::Right,
    //        IUP_MOUSEPOS => Position::MousePos,
    //        IUP_CENTERPARENT => Position::CenterParent,
    //        IUP_CURRENT => Position::Current,
    //        _ => panic!("unknown position"),
    //    }
    //}

    fn to_int(self) -> c_int {
        match self {
            Position::Left => IUP_LEFT,
            Position::Center => IUP_CENTER,
            Position::Right => IUP_RIGHT,
            Position::MousePos => IUP_MOUSEPOS,
            Position::CenterParent => IUP_CENTERPARENT,
            Position::Current => IUP_CURRENT,
        }
    }
}

#[derive(Clone)]
pub struct Dialog(HandleRc);

impl Dialog {
    pub fn new(child: Option<&Control>) -> Dialog {
        unsafe {
            ::iup_open();
            let handle = IupDialog(child.map_or(ptr::null_mut(), |c| c.handle()));
            Dialog(HandleRc::new(handle))
        }
    }

    pub unsafe fn from_handle(handle: *mut Ihandle) -> Dialog {
        // got to already be IupOpen()ed
        assert!(CStr::from_ptr(IupGetClassName(handle)).to_string_lossy() == "dialog");
        Dialog(HandleRc::new(handle))
    }
<commit_msg>Add a default minimum size for dialogs<commit_after>/* Copyright 2015 <NAME>
 *
 * Licensed under the MIT license <LICENSE or
 * http://opensource.org/licenses/MIT>. This file may not be copied,
 * modified, or distributed except according to those terms.
 */

use std::ffi::CStr;
use std::ptr;
use libc::{c_int};
use iup_sys::*;
use super::{CommonAttributes, TitleAttribute, Control, Container, MenuCommonCallbacks, NonMenuCommonCallbacks, UnwrapHandle};
use super::handle_rc::{HandleRc};

#[derive(Copy,Clone,PartialEq)]
pub enum Position {
    Left,
    Center,
    Right,
    MousePos,
    CenterParent,
    Current,
}

impl Position {
    //fn from_int(i: c_int) -> Position {
    //    match i {
    //        IUP_LEFT => Position::Left,
    //        IUP_CENTER => Position::Center,
    //        IUP_RIGHT => Position::Right,
    //        IUP_MOUSEPOS => Position::MousePos,
    //        IUP_CENTERPARENT => Position::CenterParent,
    //        IUP_CURRENT => Position::Current,
    //        _ => panic!("unknown position"),
    //    }
    //}

    fn to_int(self) -> c_int {
        match self {
            Position::Left => IUP_LEFT,
            Position::Center => IUP_CENTER,
            Position::Right => IUP_RIGHT,
            Position::MousePos => IUP_MOUSEPOS,
            Position::CenterParent => IUP_CENTERPARENT,
            Position::Current => IUP_CURRENT,
        }
    }
}

#[derive(Clone)]
pub struct Dialog(HandleRc);

impl Dialog {
    pub fn new(child: Option<&Control>) -> Dialog {
        unsafe {
            ::iup_open();
            let handle = IupDialog(child.map_or(ptr::null_mut(), |c| c.handle()));
            let d = Dialog(HandleRc::new(handle));
            d.set_min_size(150, 0);
            d
        }
    }

    pub unsafe fn from_handle(handle: *mut Ihandle) -> Dialog {
        // got to already be IupOpen()ed
        assert!(CStr::from_ptr(IupGetClassName(handle)).to_string_lossy() == "dialog");
        Dialog(HandleRc::new(handle))
    }

{'fraction_non_alphanumeric': 0.1387327542156362, 'fraction_numerical': 0.0030659172202350538, 'mean_word_length': 2.4769094138543517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944955', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1223, 'n_words': 265}