示例#1
0
	void TextBox::setText( const char *text )
	{
		int size = min( (unsigned int)(strlen(text)), bufferSize-1 );
		memcpy( buffer, text, size );
		buffer[size] = '\0';
		cursorPosition = size;
		if ( TextChange )
			TextChange( this );
	}
示例#2
0
	void TextBox::ClearText()
	{
		if ( !bufferSize )
			return;

		buffer[0] = '\0';

		if ( TextChange )
			TextChange( this );
	}
static Optional<TextChange> handle_command_key(const KeyPress& key,
  ObjText* obj)
{
  auto toggler = [obj](const BoolSetting& setting, const utf8_string& name){
    auto setter = [obj](const auto& setting, const auto& value){
      return [obj, setting, value](){
        return obj->Set(setting, value);
      };
    };

    auto value = obj->GetSettings().Get(setting);
    return TextChange(setter(setting, !value), setter(setting, value),
      value ? "Clear " + name : "Set " + name);
  };

  if (key.Is(Ctrl, key::B)){
    return option(toggler(ts_FontBold, "bold"));
  }
  else if (key.Is(Ctrl, key::I)){
    return option(toggler(ts_FontItalic, "italic"));
  }
  return no_option();
}